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 * ====================================================
12 #ifndef _MATH_PRIVATE_H_
13 #define _MATH_PRIVATE_H_
18 * The original fdlibm code used statements like:
19 * n0 = ((*(int*)&one)>>29)^1; * index of high word *
20 * ix0 = *(n0+(int*)&x); * high word of x *
21 * ix1 = *((1-n0)+(int*)&x); * low word of x *
22 * to dig two 32 bit words out of the 64 bit IEEE floating point
23 * value. That is non-ANSI, and, moreover, the gcc instruction
24 * scheduler gets it wrong. We instead use the following macros.
25 * Unlike the original code, we determine the endianness at compile
26 * time, not at run time; I don't see much benefit to selecting
27 * endianness at run time.
31 * A union which permits us to convert between a double and two 32 bit
39 } ieee_double_shape_type;
41 /* Get two 32 bit ints from a double. */
43 #define EXTRACT_WORDS(ix0,ix1,d) \
45 ieee_double_shape_type ew_u; \
47 (ix0) = ew_u.words >> 32; \
48 (ix1) = (uint32_t)ew_u.words; \
51 /* Get the more significant 32 bit int from a double. */
53 #define GET_HIGH_WORD(i,d) \
55 ieee_double_shape_type gh_u; \
57 (i) = gh_u.words >> 32; \
60 /* Get the less significant 32 bit int from a double. */
62 #define GET_LOW_WORD(i,d) \
64 ieee_double_shape_type gl_u; \
66 (i) = (uint32_t)gl_u.words; \
69 /* Set a double from two 32 bit ints. */
71 #define INSERT_WORDS(d,ix0,ix1) \
73 ieee_double_shape_type iw_u; \
74 iw_u.words = ((uint64_t)(ix0) << 32) | (ix1); \
78 /* Set the more significant 32 bits of a double from an int. */
80 #define SET_HIGH_WORD(d,v) \
82 ieee_double_shape_type sh_u; \
84 sh_u.words &= 0xffffffff; \
85 sh_u.words |= ((uint64_t)(v) << 32); \
89 /* Set the less significant 32 bits of a double from an int. */
91 #define SET_LOW_WORD(d,v) \
93 ieee_double_shape_type sl_u; \
95 sl_u.words &= 0xffffffff00000000ull; \
96 sl_u.words |= (uint32_t)(v); \
101 * A union which permits us to convert between a float and a 32 bit
109 } ieee_float_shape_type;
111 /* Get a 32 bit int from a float. */
113 #define GET_FLOAT_WORD(i,d) \
115 ieee_float_shape_type gf_u; \
120 /* Set a float from a 32 bit int. */
122 #define SET_FLOAT_WORD(d,i) \
124 ieee_float_shape_type sf_u; \
129 /* fdlibm kernel function */
130 int __ieee754_rem_pio2(double,double*);
131 double __kernel_sin(double,double,int);
132 double __kernel_cos(double,double);
133 double __kernel_tan(double,double,int);
134 int __kernel_rem_pio2(double*,double*,int,int,int,const int*);
136 /* float versions of fdlibm kernel functions */
137 int __ieee754_rem_pio2f(float,float*);
138 float __kernel_sinf(float,float,int);
139 float __kernel_cosf(float,float);
140 float __kernel_tanf(float,float,int);
141 int __kernel_rem_pio2f(float*,float*,int,int,int,const int*);
143 #endif /* !_MATH_PRIVATE_H_ */