2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
9 * ====================================================
13 * from: @(#)fdlibm.h 5.1 93/09/24
17 #ifndef _MATH_PRIVATE_H_
18 #define _MATH_PRIVATE_H_
20 #include <sys/types.h>
21 #include <machine/endian.h>
24 * The original fdlibm code used statements like:
25 * n0 = ((*(int*)&one)>>29)^1; * index of high word *
26 * ix0 = *(n0+(int*)&x); * high word of x *
27 * ix1 = *((1-n0)+(int*)&x); * low word of x *
28 * to dig two 32 bit words out of the 64 bit IEEE floating point
29 * value. That is non-ANSI, and, moreover, the gcc instruction
30 * scheduler gets it wrong. We instead use the following macros.
31 * Unlike the original code, we determine the endianness at compile
32 * time, not at run time; I don't see much benefit to selecting
33 * endianness at run time.
37 * A union which permits us to convert between a double and two 32 bit
42 #if defined(__VFP_FP__)
43 #define IEEE_WORD_ORDER BYTE_ORDER
45 #define IEEE_WORD_ORDER BIG_ENDIAN
48 #define IEEE_WORD_ORDER BYTE_ORDER
51 #if IEEE_WORD_ORDER == BIG_ENDIAN
61 } ieee_double_shape_type;
65 #if IEEE_WORD_ORDER == LITTLE_ENDIAN
75 } ieee_double_shape_type;
79 /* Get two 32 bit ints from a double. */
81 #define EXTRACT_WORDS(ix0,ix1,d) \
83 ieee_double_shape_type ew_u; \
85 (ix0) = ew_u.parts.msw; \
86 (ix1) = ew_u.parts.lsw; \
89 /* Get the more significant 32 bit int from a double. */
91 #define GET_HIGH_WORD(i,d) \
93 ieee_double_shape_type gh_u; \
95 (i) = gh_u.parts.msw; \
98 /* Get the less significant 32 bit int from a double. */
100 #define GET_LOW_WORD(i,d) \
102 ieee_double_shape_type gl_u; \
104 (i) = gl_u.parts.lsw; \
107 /* Set a double from two 32 bit ints. */
109 #define INSERT_WORDS(d,ix0,ix1) \
111 ieee_double_shape_type iw_u; \
112 iw_u.parts.msw = (ix0); \
113 iw_u.parts.lsw = (ix1); \
117 /* Set the more significant 32 bits of a double from an int. */
119 #define SET_HIGH_WORD(d,v) \
121 ieee_double_shape_type sh_u; \
123 sh_u.parts.msw = (v); \
127 /* Set the less significant 32 bits of a double from an int. */
129 #define SET_LOW_WORD(d,v) \
131 ieee_double_shape_type sl_u; \
133 sl_u.parts.lsw = (v); \
138 * A union which permits us to convert between a float and a 32 bit
145 /* FIXME: Assumes 32 bit int. */
147 } ieee_float_shape_type;
149 /* Get a 32 bit int from a float. */
151 #define GET_FLOAT_WORD(i,d) \
153 ieee_float_shape_type gf_u; \
158 /* Set a float from a 32 bit int. */
160 #define SET_FLOAT_WORD(d,i) \
162 ieee_float_shape_type sf_u; \
167 #ifdef FLT_EVAL_METHOD
169 * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
171 #if FLT_EVAL_METHOD == 0 || __GNUC__ == 0
172 #define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval))
174 #define STRICT_ASSIGN(type, lval, rval) do { \
175 volatile type __lval; \
177 if (sizeof(type) >= sizeof(double)) \
188 * Common routine to process the arguments to nan(), nanf(), and nanl().
190 void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
195 * C99 specifies that complex numbers have the same representation as
196 * an array of two elements, where the first element is the real part
197 * and the second element is the imaginary part.
208 long double complex f;
210 } long_double_complex;
211 #define REALPART(z) ((z).a[0])
212 #define IMAGPART(z) ((z).a[1])
215 * Inline functions that can be used to construct complex values.
217 * The C99 standard intends x+I*y to be used for this, but x+I*y is
218 * currently unusable in general since gcc introduces many overflow,
219 * underflow, sign and efficiency bugs by rewriting I*y as
220 * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
221 * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
224 static __inline float complex
225 cpackf(float x, float y)
234 static __inline double complex
235 cpack(double x, double y)
244 static __inline long double complex
245 cpackl(long double x, long double y)
247 long_double_complex z;
253 #endif /* _COMPLEX_H */
255 #ifdef __GNUCLIKE_ASM
257 /* Asm versions of some functions. */
265 asm("cvtsd2si %1,%0" : "=r" (n) : "x" (x));
268 #define HAVE_EFFICIENT_IRINT
277 asm("fistl %0" : "=m" (n) : "t" (x));
280 #define HAVE_EFFICIENT_IRINT
283 #endif /* __GNUCLIKE_ASM */
286 * ieee style elementary functions
288 * We rename functions here to improve other sources' diffability
291 #define __ieee754_sqrt sqrt
292 #define __ieee754_acos acos
293 #define __ieee754_acosh acosh
294 #define __ieee754_log log
295 #define __ieee754_log2 log2
296 #define __ieee754_atanh atanh
297 #define __ieee754_asin asin
298 #define __ieee754_atan2 atan2
299 #define __ieee754_exp exp
300 #define __ieee754_cosh cosh
301 #define __ieee754_fmod fmod
302 #define __ieee754_pow pow
303 #define __ieee754_lgamma lgamma
304 #define __ieee754_gamma gamma
305 #define __ieee754_lgamma_r lgamma_r
306 #define __ieee754_gamma_r gamma_r
307 #define __ieee754_log10 log10
308 #define __ieee754_sinh sinh
309 #define __ieee754_hypot hypot
310 #define __ieee754_j0 j0
311 #define __ieee754_j1 j1
312 #define __ieee754_y0 y0
313 #define __ieee754_y1 y1
314 #define __ieee754_jn jn
315 #define __ieee754_yn yn
316 #define __ieee754_remainder remainder
317 #define __ieee754_scalb scalb
318 #define __ieee754_sqrtf sqrtf
319 #define __ieee754_acosf acosf
320 #define __ieee754_acoshf acoshf
321 #define __ieee754_logf logf
322 #define __ieee754_atanhf atanhf
323 #define __ieee754_asinf asinf
324 #define __ieee754_atan2f atan2f
325 #define __ieee754_expf expf
326 #define __ieee754_coshf coshf
327 #define __ieee754_fmodf fmodf
328 #define __ieee754_powf powf
329 #define __ieee754_lgammaf lgammaf
330 #define __ieee754_gammaf gammaf
331 #define __ieee754_lgammaf_r lgammaf_r
332 #define __ieee754_gammaf_r gammaf_r
333 #define __ieee754_log10f log10f
334 #define __ieee754_log2f log2f
335 #define __ieee754_sinhf sinhf
336 #define __ieee754_hypotf hypotf
337 #define __ieee754_j0f j0f
338 #define __ieee754_j1f j1f
339 #define __ieee754_y0f y0f
340 #define __ieee754_y1f y1f
341 #define __ieee754_jnf jnf
342 #define __ieee754_ynf ynf
343 #define __ieee754_remainderf remainderf
344 #define __ieee754_scalbf scalbf
346 /* fdlibm kernel function */
347 int __kernel_rem_pio2(double*,double*,int,int,int);
349 /* double precision kernel functions */
350 #ifdef INLINE_REM_PIO2
353 int __ieee754_rem_pio2(double,double*);
354 double __kernel_sin(double,double,int);
355 double __kernel_cos(double,double);
356 double __kernel_tan(double,double,int);
358 /* float precision kernel functions */
359 #ifdef INLINE_REM_PIO2F
362 int __ieee754_rem_pio2f(float,double*);
363 #ifdef INLINE_KERNEL_SINDF
366 float __kernel_sindf(double);
367 #ifdef INLINE_KERNEL_COSDF
370 float __kernel_cosdf(double);
371 #ifdef INLINE_KERNEL_TANDF
374 float __kernel_tandf(double,int);
376 /* long double precision kernel functions */
377 long double __kernel_sinl(long double, long double, int);
378 long double __kernel_cosl(long double, long double);
379 long double __kernel_tanl(long double, long double, int);
381 #endif /* !_MATH_PRIVATE_H_ */