1 /* --------------------------------------------------------------  */
2 /* (C)Copyright 2006,2008,                                         */
3 /* International Business Machines Corporation                     */
4 /* All Rights Reserved.                                            */
5 /*                                                                 */
6 /* Redistribution and use in source and binary forms, with or      */
7 /* without modification, are permitted provided that the           */
8 /* following conditions are met:                                   */
9 /*                                                                 */
10 /* - Redistributions of source code must retain the above copyright*/
11 /*   notice, this list of conditions and the following disclaimer. */
12 /*                                                                 */
13 /* - Redistributions in binary form must reproduce the above       */
14 /*   copyright notice, this list of conditions and the following   */
15 /*   disclaimer in the documentation and/or other materials        */
16 /*   provided with the distribution.                               */
17 /*                                                                 */
18 /* - Neither the name of IBM Corporation nor the names of its      */
19 /*   contributors may be used to endorse or promote products       */
20 /*   derived from this software without specific prior written     */
21 /*   permission.                                                   */
22 /*                                                                 */
23 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
24 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
25 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
26 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
27 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
28 /* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
29 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
30 /* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
31 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
32 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
33 /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
34 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
35 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
36 /* --------------------------------------------------------------  */
37 /* PROLOG END TAG zYx                                              */
38 #ifndef __SIMD_MATH_H__
39 #define __SIMD_MATH_H__ 1
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #if !defined(__SPU__) && !defined(__ALTIVEC__)
46 #error Bad platform
47 #else
48 
49 #define SM_E		2.7182818284590452354	/* e */
50 #define SM_LOG2E        1.4426950408889634074	/* log_2 e */
51 #define SM_LOG10E	0.43429448190325182765	/* log_10 e */
52 #define SM_LN2		0.69314718055994530942	/* log_e 2 */
53 #define SM_LN10		2.30258509299404568402	/* log_e 10 */
54 #define SM_PI		3.14159265358979323846	/* pi */
55 #define SM_PI_2		1.57079632679489661923	/* pi/2 */
56 #define SM_PI_4		0.78539816339744830962	/* pi/4 */
57 #define SM_1_PI		0.31830988618379067154	/* 1/pi */
58 #define SM_2_PI		0.63661977236758134308	/* 2/pi */
59 #define SM_2_SQRTPI	1.12837916709551257390	/* 2/sqrt(pi) */
60 #define SM_SQRT2        1.41421356237309504880	/* sqrt(2) */
61 #define SM_SQRT1_2       0.70710678118654752440	/* 1/sqrt(2) */
62 
63 /* Typedefs common to both SPU and PPU */
64 typedef struct divi4_s {
65   vector signed int quot;
66   vector signed int rem;
67 } divi4_t;
68 
69 typedef struct divu4_s {
70   vector unsigned int quot;
71   vector unsigned int rem;
72 } divu4_t;
73 
74 
75 /*  Functions common to both SPU and PPU  */
76 vector signed int absi4(vector signed int x);
77 vector float acosf4(vector float x);
78 vector float acoshf4(vector float x);
79 vector float asinf4(vector float x);
80 vector float asinhf4(vector float x);
81 vector float atanf4(vector float x);
82 vector float atanhf4(vector float x);
83 vector float atan2f4(vector float y, vector float x);
84 vector float cbrtf4(vector float x);
85 vector float ceilf4(vector float x);
86 vector float copysignf4(vector float x, vector float y);
87 vector float cosf4(vector float x);
88 vector float coshf4(vector float x);
89 vector float divf4(vector float x, vector float y);
90 vector float divf4_fast(vector float x, vector float y);
91 divi4_t divi4(vector signed int dividend, vector signed int divisor);
92 divu4_t divu4(vector unsigned int dividend, vector unsigned int divisor);
93 vector float erff4(vector float x);
94 vector float erfcf4(vector float x);
95 vector float exp2f4(vector float x);
96 vector float expf4(vector float x);
97 vector float expm1f4(vector float x);
98 vector float fabsf4(vector float value);
99 vector float fdimf4(vector float x, vector float y);
100 vector float floorf4(vector float value);
101 vector float fmaf4(vector float x, vector float y, vector float z);
102 vector float fmaxf4(vector float x, vector float y);
103 vector float fminf4(vector float x, vector float y);
104 vector float fmodf4(vector float x, vector float y);
105 vector signed int fpclassifyf4(vector float x);
106 vector float frexpf4(vector float x, vector signed int *pexp);
107 vector float hypotf4(vector float x, vector float y);
108 vector signed int ilogbf4(vector float x);
109 vector signed int irintf4(vector float x);
110 vector signed int iroundf4(vector float x);
111 vector unsigned int is0denormf4(vector float x);
112 vector unsigned int isequalf4(vector float x, vector float y);
113 vector unsigned int isfinitef4(vector float x);
114 vector unsigned int isgreaterf4(vector float x, vector float y);
115 vector unsigned int isgreaterequalf4(vector float x, vector float y);
116 vector unsigned int isinff4(vector float x);
117 vector unsigned int islessf4(vector float x, vector float y);
118 vector unsigned int islessequalf4(vector float x, vector float y);
119 vector unsigned int islessgreaterf4(vector float x, vector float y);
120 vector unsigned int isnanf4(vector float x);
121 vector unsigned int isnormalf4(vector float x);
122 vector unsigned int isunorderedf4(vector float x, vector float y);
123 vector float ldexpf4(vector float x, vector signed int exp);
124 vector float lgammaf4(vector float x);
125 vector float log10f4(vector float x);
126 vector float log1pf4(vector float x);
127 vector float log2f4(vector float x);
128 vector float logbf4(vector float x);
129 vector float logf4(vector float x);
130 vector float modff4(vector float x, vector float *pint);
131 vector float nearbyintf4(vector float x);
132 vector float negatef4(vector float x);
133 vector signed int negatei4(vector signed int x);
134 vector float nextafterf4(vector float x, vector float y);
135 vector float powf4(vector float x, vector float y);
136 vector float recipf4(vector float a);
137 vector float remainderf4(vector float x, vector float y);
138 vector float remquof4(vector float x, vector float y, vector signed int *quo);
139 vector float rintf4(vector float x);
140 vector float roundf4(vector float x);
141 vector float rsqrtf4(vector float value);
142 vector float scalbnf4(vector float x, vector signed int exp);
143 vector unsigned int signbitf4(vector float x);
144 void sincosf4(vector float x, vector float *sx, vector float *cx);
145 vector float sinf4(vector float x);
146 vector float sinhf4(vector float x);
147 vector float sqrtf4(vector float in);
148 vector float tanf4(vector float angle);
149 vector float tanhf4(vector float x);
150 vector float tgammaf4(vector float x);
151 vector float truncf4(vector float x);
152 
153 
154 #ifdef __SPU__
155 /* Typedefs specific to SPU */
156 typedef struct llroundf4_s {
157   vector signed long long vll[2];
158 } llroundf4_t;
159 
160 typedef struct lldivi2_s {
161   vector signed long long quot;
162   vector signed long long rem;
163 } lldivi2_t;
164 
165 typedef struct lldivu2_s {
166   vector unsigned long long quot;
167   vector unsigned long long rem;
168 } lldivu2_t;
169 
170 
171 /*  Functions specific to SPU  */
172 llroundf4_t llrintf4(vector float in);
173 llroundf4_t llroundf4 (vector float x);
174 vector double acosd2(vector double x);
175 vector double acoshd2(vector double x);
176 vector double asind2(vector double x);
177 vector double asinhd2(vector double x);
178 vector double atan2d2(vector double y, vector double x);
179 vector double atand2(vector double x);
180 vector double atanhd2(vector double x);
181 vector double cbrtd2(vector double x);
182 vector double ceild2(vector double x);
183 vector float  ceilf4_fast(vector float x);
184 vector double copysignd2(vector double x, vector double y);
185 vector double cosd2(vector double x);
186 vector double coshd2(vector double x);
187 vector double divd2(vector double a, vector double b);
188 vector double erfcd2(vector double x);
189 vector double erfd2(vector double x);
190 vector double exp2d2(vector double x);
191 vector double expd2(vector double x);
192 vector double expm1d2(vector double x);
193 vector double fabsd2(vector double x);
194 vector double fdimd2(vector double x, vector double y);
195 vector double floord2(vector double x);
196 vector float  floorf4_fast(vector float value);
197 vector double fmad2(vector double x, vector double y, vector double z);
198 vector double fmaxd2(vector double x, vector double y);
199 vector double fmind2(vector double x, vector double y);
200 vector double fmodd2(vector double x, vector double y);
201 vector float  fmodf4_fast(vector float x, vector float y);
202 vector signed long long fpclassifyd2(vector double x);
203 vector double frexpd2(vector double x, vector signed long long *pexp);
204 vector double hypotd2(vector double x, vector double y);
205 vector signed long long ilogbd2(vector double x);
206 vector unsigned long long is0denormd2(vector double x);
207 vector unsigned long long isequald2(vector double x, vector double y);
208 vector unsigned long long isfinited2(vector double x);
209 vector unsigned long long isgreaterd2(vector double x, vector double y);
210 vector unsigned long long isgreaterequald2(vector double x, vector double y);
211 vector unsigned long long isinfd2(vector double x);
212 vector unsigned long long islessd2(vector double x, vector double y);
213 vector unsigned long long islessequald2(vector double x, vector double y);
214 vector unsigned long long islessgreaterd2(vector double x, vector double y);
215 vector unsigned long long isnand2(vector double x);
216 vector unsigned long long isnormald2(vector double x);
217 vector unsigned long long isunorderedd2(vector double x, vector double y);
218 vector double ldexpd2(vector double x, vector signed long long exp);
219 vector signed long long llabsi2(vector signed long long x);
220 lldivi2_t lldivi2(vector signed long long x, vector signed long long y);
221 lldivu2_t lldivu2(vector unsigned long long x, vector unsigned long long y);
222 vector double lgammad2(vector double x);
223 vector signed long long llrintd2(vector double in);
224 vector signed long long llroundd2(vector double x);
225 vector double log10d2(vector double x);
226 vector double log1pd2(vector double x);
227 vector double log2d2(vector double x);
228 vector double logbd2(vector double x);
229 vector double logd2(vector double x);
230 vector double modfd2(vector double x, vector double* pint);
231 vector double nearbyintd2(vector double x);
232 vector double negated2(vector double x);
233 vector double nextafterd2(vector double x, vector double y);
234 vector signed long long negatell2(vector signed long long x);
235 vector double powd2(vector double x, vector double y);
236 vector double recipd2(vector double value_d);
237 vector float  recipf4_fast(vector float a);
238 vector double remainderd2(vector double x, vector double y);
239 vector double remquod2(vector double x, vector double y, vector signed long long *quo);
240 vector double rintd2(vector double x);
241 vector double roundd2(vector double x);
242 vector double rsqrtd2(vector double x);
243 vector double scalbllnd2(vector double x, vector signed long long n);
244 vector unsigned long long signbitd2(vector double x);
245 void sincosd2(vector double x, vector double *sx, vector double *cx);
246 vector double sind2(vector double x);
247 vector double sinhd2(vector double x);
248 vector double sqrtd2(vector double x);
249 vector float  sqrtf4_fast(vector float in);
250 vector double tand2(vector double x);
251 vector double tanhd2(vector double x);
252 vector double tgammad2(vector double x);
253 vector double truncd2(vector double x);
254 
255 #endif /* __SPU__ */
256 
257 /*  Functions specific to PPU */
258 #ifdef __ALTIVEC__
259 #endif
260 
261 #endif /* __SPU__ || __ALTIVEC__ */
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif /* __SIMD_MATH_H__  */
268