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
65 } ieee_double_shape_type;
69 #if IEEE_WORD_ORDER == LITTLE_ENDIAN
83 } ieee_double_shape_type;
87 /* Get two 32 bit ints from a double. */
89 #define EXTRACT_WORDS(ix0,ix1,d) \
91 ieee_double_shape_type ew_u; \
93 (ix0) = ew_u.parts.msw; \
94 (ix1) = ew_u.parts.lsw; \
97 /* Get a 64-bit int from a double. */
98 #define EXTRACT_WORD64(ix,d) \
100 ieee_double_shape_type ew_u; \
102 (ix) = ew_u.xparts.w; \
105 /* Get the more significant 32 bit int from a double. */
107 #define GET_HIGH_WORD(i,d) \
109 ieee_double_shape_type gh_u; \
111 (i) = gh_u.parts.msw; \
114 /* Get the less significant 32 bit int from a double. */
116 #define GET_LOW_WORD(i,d) \
118 ieee_double_shape_type gl_u; \
120 (i) = gl_u.parts.lsw; \
123 /* Set a double from two 32 bit ints. */
125 #define INSERT_WORDS(d,ix0,ix1) \
127 ieee_double_shape_type iw_u; \
128 iw_u.parts.msw = (ix0); \
129 iw_u.parts.lsw = (ix1); \
133 /* Set a double from a 64-bit int. */
134 #define INSERT_WORD64(d,ix) \
136 ieee_double_shape_type iw_u; \
137 iw_u.xparts.w = (ix); \
141 /* Set the more significant 32 bits of a double from an int. */
143 #define SET_HIGH_WORD(d,v) \
145 ieee_double_shape_type sh_u; \
147 sh_u.parts.msw = (v); \
151 /* Set the less significant 32 bits of a double from an int. */
153 #define SET_LOW_WORD(d,v) \
155 ieee_double_shape_type sl_u; \
157 sl_u.parts.lsw = (v); \
162 * A union which permits us to convert between a float and a 32 bit
169 /* FIXME: Assumes 32 bit int. */
171 } ieee_float_shape_type;
173 /* Get a 32 bit int from a float. */
175 #define GET_FLOAT_WORD(i,d) \
177 ieee_float_shape_type gf_u; \
182 /* Set a float from a 32 bit int. */
184 #define SET_FLOAT_WORD(d,i) \
186 ieee_float_shape_type sf_u; \
191 /* Get expsign as a 16 bit int from a long double. */
193 #define GET_LDBL_EXPSIGN(i,d) \
195 union IEEEl2bits ge_u; \
197 (i) = ge_u.xbits.expsign; \
200 /* Set expsign of a long double from a 16 bit int. */
202 #define SET_LDBL_EXPSIGN(d,v) \
204 union IEEEl2bits se_u; \
206 se_u.xbits.expsign = (v); \
210 #ifdef FLT_EVAL_METHOD
212 * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
214 #if FLT_EVAL_METHOD == 0 || __GNUC__ == 0
215 #define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval))
217 #define STRICT_ASSIGN(type, lval, rval) do { \
218 volatile type __lval; \
220 if (sizeof(type) >= sizeof(double)) \
231 * Common routine to process the arguments to nan(), nanf(), and nanl().
233 void _scan_nan(uint32_t *__words, int __num_words, const char *__s);
238 * C99 specifies that complex numbers have the same representation as
239 * an array of two elements, where the first element is the real part
240 * and the second element is the imaginary part.
251 long double complex f;
253 } long_double_complex;
254 #define REALPART(z) ((z).a[0])
255 #define IMAGPART(z) ((z).a[1])
258 * Inline functions that can be used to construct complex values.
260 * The C99 standard intends x+I*y to be used for this, but x+I*y is
261 * currently unusable in general since gcc introduces many overflow,
262 * underflow, sign and efficiency bugs by rewriting I*y as
263 * (0.0+I)*(y+0.0*I) and laboriously computing the full complex product.
264 * In particular, I*Inf is corrupted to NaN+I*Inf, and I*-0 is corrupted
267 static __inline float complex
268 cpackf(float x, float y)
277 static __inline double complex
278 cpack(double x, double y)
287 static __inline long double complex
288 cpackl(long double x, long double y)
290 long_double_complex z;
296 #endif /* _COMPLEX_H */
298 #ifdef __GNUCLIKE_ASM
300 /* Asm versions of some functions. */
308 asm("cvtsd2si %1,%0" : "=r" (n) : "x" (x));
311 #define HAVE_EFFICIENT_IRINT
320 asm("fistl %0" : "=m" (n) : "t" (x));
323 #define HAVE_EFFICIENT_IRINT
326 #endif /* __GNUCLIKE_ASM */
329 * ieee style elementary functions
331 * We rename functions here to improve other sources' diffability
334 #define __ieee754_sqrt sqrt
335 #define __ieee754_acos acos
336 #define __ieee754_acosh acosh
337 #define __ieee754_log log
338 #define __ieee754_log2 log2
339 #define __ieee754_atanh atanh
340 #define __ieee754_asin asin
341 #define __ieee754_atan2 atan2
342 #define __ieee754_exp exp
343 #define __ieee754_cosh cosh
344 #define __ieee754_fmod fmod
345 #define __ieee754_pow pow
346 #define __ieee754_lgamma lgamma
347 #define __ieee754_gamma gamma
348 #define __ieee754_lgamma_r lgamma_r
349 #define __ieee754_gamma_r gamma_r
350 #define __ieee754_log10 log10
351 #define __ieee754_sinh sinh
352 #define __ieee754_hypot hypot
353 #define __ieee754_j0 j0
354 #define __ieee754_j1 j1
355 #define __ieee754_y0 y0
356 #define __ieee754_y1 y1
357 #define __ieee754_jn jn
358 #define __ieee754_yn yn
359 #define __ieee754_remainder remainder
360 #define __ieee754_scalb scalb
361 #define __ieee754_sqrtf sqrtf
362 #define __ieee754_acosf acosf
363 #define __ieee754_acoshf acoshf
364 #define __ieee754_logf logf
365 #define __ieee754_atanhf atanhf
366 #define __ieee754_asinf asinf
367 #define __ieee754_atan2f atan2f
368 #define __ieee754_expf expf
369 #define __ieee754_coshf coshf
370 #define __ieee754_fmodf fmodf
371 #define __ieee754_powf powf
372 #define __ieee754_lgammaf lgammaf
373 #define __ieee754_gammaf gammaf
374 #define __ieee754_lgammaf_r lgammaf_r
375 #define __ieee754_gammaf_r gammaf_r
376 #define __ieee754_log10f log10f
377 #define __ieee754_log2f log2f
378 #define __ieee754_sinhf sinhf
379 #define __ieee754_hypotf hypotf
380 #define __ieee754_j0f j0f
381 #define __ieee754_j1f j1f
382 #define __ieee754_y0f y0f
383 #define __ieee754_y1f y1f
384 #define __ieee754_jnf jnf
385 #define __ieee754_ynf ynf
386 #define __ieee754_remainderf remainderf
387 #define __ieee754_scalbf scalbf
389 /* fdlibm kernel function */
390 int __kernel_rem_pio2(double*,double*,int,int,int);
392 /* double precision kernel functions */
393 #ifdef INLINE_REM_PIO2
396 int __ieee754_rem_pio2(double,double*);
397 double __kernel_sin(double,double,int);
398 double __kernel_cos(double,double);
399 double __kernel_tan(double,double,int);
400 double __ldexp_exp(double,int);
402 double complex __ldexp_cexp(double complex,int);
405 /* float precision kernel functions */
406 #ifdef INLINE_REM_PIO2F
409 int __ieee754_rem_pio2f(float,double*);
410 #ifdef INLINE_KERNEL_SINDF
413 float __kernel_sindf(double);
414 #ifdef INLINE_KERNEL_COSDF
417 float __kernel_cosdf(double);
418 #ifdef INLINE_KERNEL_TANDF
421 float __kernel_tandf(double,int);
422 float __ldexp_expf(float,int);
424 float complex __ldexp_cexpf(float complex,int);
427 /* long double precision kernel functions */
428 long double __kernel_sinl(long double, long double, int);
429 long double __kernel_cosl(long double, long double);
430 long double __kernel_tanl(long double, long double, int);
432 #endif /* !_MATH_PRIVATE_H_ */