source: trunk/libs/newlib/src/newlib/libm/machine/spu/headers/ldexpd2.h @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 4.2 KB
Line 
1/* --------------------------------------------------------------  */
2/* (C)Copyright 2001,2008,                                         */
3/* International Business Machines Corporation,                    */
4/* Sony Computer Entertainment, Incorporated,                      */
5/* Toshiba Corporation,                                            */
6/*                                                                 */
7/* All Rights Reserved.                                            */
8/*                                                                 */
9/* Redistribution and use in source and binary forms, with or      */
10/* without modification, are permitted provided that the           */
11/* following conditions are met:                                   */
12/*                                                                 */
13/* - Redistributions of source code must retain the above copyright*/
14/*   notice, this list of conditions and the following disclaimer. */
15/*                                                                 */
16/* - Redistributions in binary form must reproduce the above       */
17/*   copyright notice, this list of conditions and the following   */
18/*   disclaimer in the documentation and/or other materials        */
19/*   provided with the distribution.                               */
20/*                                                                 */
21/* - Neither the name of IBM Corporation nor the names of its      */
22/*   contributors may be used to endorse or promote products       */
23/*   derived from this software without specific prior written     */
24/*   permission.                                                   */
25/*                                                                 */
26/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
27/* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
28/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
29/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
30/* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
31/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
32/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
33/* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
34/* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
35/* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
36/* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
37/* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
38/* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
39/* --------------------------------------------------------------  */
40/* PROLOG END TAG zYx                                              */
41#ifdef __SPU__
42
43#ifndef _LDEXPD2_H_
44#define _LDEXPD2_H_     1
45
46#include <spu_intrinsics.h>
47
48/*
49 * FUNCTION
50 *      vector double _ldexpd2(vector double x, vector signed long long exp)
51 *
52 * DESCRIPTION
53 *      The _ldexpd2 function Computes x * 2^exp for each of the two elements
54 *      of x using the corresponding elements of exp.
55 *
56 */
57static __inline vector double _ldexpd2(vector double x, vector signed long long llexp)
58{
59  vec_uchar16 odd_to_even = ((vec_uchar16) { 4,5,6,7,     0x80,0x80,0x80,0x80, 
60                                             12,13,14,15, 0x80,0x80,0x80,0x80 });
61  vec_int4 exp;
62  vec_int4 e1, e2;
63  vec_int4 min = spu_splats(-2044);
64  vec_int4 max = spu_splats(2046);
65  vec_uint4 cmp_min, cmp_max;
66  vec_uint4 shift = (vec_uint4) { 20, 32, 20, 32 };
67  vec_double2 f1, f2;
68  vec_double2 out;
69
70  exp = (vec_int4)spu_shuffle(llexp, llexp, odd_to_even);
71
72  /* Clamp the specified exponent to the range -2044 to 2046.
73   */
74
75  cmp_min = spu_cmpgt(exp, min);
76  cmp_max = spu_cmpgt(exp, max);
77  exp = spu_sel(min, exp, cmp_min);
78  exp = spu_sel(exp, max, cmp_max);
79
80  /* Generate the factors f1 = 2^e1 and f2 = 2^e2
81   */
82  e1 = spu_rlmaska(exp, -1);
83  e2 = spu_sub(exp, e1);
84
85  f1 = (vec_double2)spu_sl(spu_add(e1, 1023), shift);
86  f2 = (vec_double2)spu_sl(spu_add(e2, 1023), shift);
87
88  /* Compute the product x * 2^e1 * 2^e2
89   */
90  out = spu_mul(spu_mul(x, f1), f2);
91
92  return (out);
93}
94
95#endif /* _LDEXPD2_H_ */
96#endif /* __SPU__ */
97
Note: See TracBrowser for help on using the repository browser.