xref: /freebsd/lib/msun/src/math_private.h (revision eacee0ff7ec955b32e09515246bd97b6edcd2b0f)
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
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
8  * is preserved.
9  * ====================================================
10  */
11 
12 /*
13  * from: @(#)fdlibm.h 5.1 93/09/24
14  * $FreeBSD$
15  */
16 
17 #ifndef _MATH_PRIVATE_H_
18 #define	_MATH_PRIVATE_H_
19 
20 #include <sys/types.h>
21 #include <machine/endian.h>
22 
23 /*
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.
34  */
35 
36 /*
37  * A union which permits us to convert between a double and two 32 bit
38  * ints.
39  */
40 
41 #if BYTE_ORDER == BIG_ENDIAN
42 
43 typedef union
44 {
45   double value;
46   struct
47   {
48     u_int32_t msw;
49     u_int32_t lsw;
50   } parts;
51 } ieee_double_shape_type;
52 
53 #endif
54 
55 #if BYTE_ORDER == LITTLE_ENDIAN
56 
57 typedef union
58 {
59   double value;
60   struct
61   {
62     u_int32_t lsw;
63     u_int32_t msw;
64   } parts;
65 } ieee_double_shape_type;
66 
67 #endif
68 
69 /* Get two 32 bit ints from a double.  */
70 
71 #define EXTRACT_WORDS(ix0,ix1,d)				\
72 do {								\
73   ieee_double_shape_type ew_u;					\
74   ew_u.value = (d);						\
75   (ix0) = ew_u.parts.msw;					\
76   (ix1) = ew_u.parts.lsw;					\
77 } while (0)
78 
79 /* Get the more significant 32 bit int from a double.  */
80 
81 #define GET_HIGH_WORD(i,d)					\
82 do {								\
83   ieee_double_shape_type gh_u;					\
84   gh_u.value = (d);						\
85   (i) = gh_u.parts.msw;						\
86 } while (0)
87 
88 /* Get the less significant 32 bit int from a double.  */
89 
90 #define GET_LOW_WORD(i,d)					\
91 do {								\
92   ieee_double_shape_type gl_u;					\
93   gl_u.value = (d);						\
94   (i) = gl_u.parts.lsw;						\
95 } while (0)
96 
97 /* Set a double from two 32 bit ints.  */
98 
99 #define INSERT_WORDS(d,ix0,ix1)					\
100 do {								\
101   ieee_double_shape_type iw_u;					\
102   iw_u.parts.msw = (ix0);					\
103   iw_u.parts.lsw = (ix1);					\
104   (d) = iw_u.value;						\
105 } while (0)
106 
107 /* Set the more significant 32 bits of a double from an int.  */
108 
109 #define SET_HIGH_WORD(d,v)					\
110 do {								\
111   ieee_double_shape_type sh_u;					\
112   sh_u.value = (d);						\
113   sh_u.parts.msw = (v);						\
114   (d) = sh_u.value;						\
115 } while (0)
116 
117 /* Set the less significant 32 bits of a double from an int.  */
118 
119 #define SET_LOW_WORD(d,v)					\
120 do {								\
121   ieee_double_shape_type sl_u;					\
122   sl_u.value = (d);						\
123   sl_u.parts.lsw = (v);						\
124   (d) = sl_u.value;						\
125 } while (0)
126 
127 /*
128  * A union which permits us to convert between a float and a 32 bit
129  * int.
130  */
131 
132 typedef union
133 {
134   float value;
135   /* FIXME: Assumes 32 bit int.  */
136   unsigned int word;
137 } ieee_float_shape_type;
138 
139 /* Get a 32 bit int from a float.  */
140 
141 #define GET_FLOAT_WORD(i,d)					\
142 do {								\
143   ieee_float_shape_type gf_u;					\
144   gf_u.value = (d);						\
145   (i) = gf_u.word;						\
146 } while (0)
147 
148 /* Set a float from a 32 bit int.  */
149 
150 #define SET_FLOAT_WORD(d,i)					\
151 do {								\
152   ieee_float_shape_type sf_u;					\
153   sf_u.word = (i);						\
154   (d) = sf_u.value;						\
155 } while (0)
156 
157 /* ieee style elementary functions */
158 double	__ieee754_sqrt __P((double));
159 double	__ieee754_acos __P((double));
160 double	__ieee754_acosh __P((double));
161 double	__ieee754_log __P((double));
162 double	__ieee754_atanh __P((double));
163 double	__ieee754_asin __P((double));
164 double	__ieee754_atan2 __P((double,double));
165 double	__ieee754_exp __P((double));
166 double	__ieee754_cosh __P((double));
167 double	__ieee754_fmod __P((double,double));
168 double	__ieee754_pow __P((double,double));
169 double	__ieee754_lgamma_r __P((double,int *));
170 double	__ieee754_gamma_r __P((double,int *));
171 double	__ieee754_lgamma __P((double));
172 double	__ieee754_gamma __P((double));
173 double	__ieee754_log10 __P((double));
174 double	__ieee754_sinh __P((double));
175 double	__ieee754_hypot __P((double,double));
176 double	__ieee754_j0 __P((double));
177 double	__ieee754_j1 __P((double));
178 double	__ieee754_y0 __P((double));
179 double	__ieee754_y1 __P((double));
180 double	__ieee754_jn __P((int,double));
181 double	__ieee754_yn __P((int,double));
182 double	__ieee754_remainder __P((double,double));
183 int	__ieee754_rem_pio2 __P((double,double*));
184 double	__ieee754_scalb __P((double,double));
185 
186 /* fdlibm kernel function */
187 double	__kernel_standard __P((double,double,int));
188 double	__kernel_sin __P((double,double,int));
189 double	__kernel_cos __P((double,double));
190 double	__kernel_tan __P((double,double,int));
191 int	__kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
192 
193 /* ieee style elementary float functions */
194 float	__ieee754_sqrtf __P((float));
195 float	__ieee754_acosf __P((float));
196 float	__ieee754_acoshf __P((float));
197 float	__ieee754_logf __P((float));
198 float	__ieee754_atanhf __P((float));
199 float	__ieee754_asinf __P((float));
200 float	__ieee754_atan2f __P((float,float));
201 float	__ieee754_expf __P((float));
202 float	__ieee754_coshf __P((float));
203 float	__ieee754_fmodf __P((float,float));
204 float	__ieee754_powf __P((float,float));
205 float	__ieee754_lgammaf_r __P((float,int *));
206 float	__ieee754_gammaf_r __P((float,int *));
207 float	__ieee754_lgammaf __P((float));
208 float	__ieee754_gammaf __P((float));
209 float	__ieee754_log10f __P((float));
210 float	__ieee754_sinhf __P((float));
211 float	__ieee754_hypotf __P((float,float));
212 float	__ieee754_j0f __P((float));
213 float	__ieee754_j1f __P((float));
214 float	__ieee754_y0f __P((float));
215 float	__ieee754_y1f __P((float));
216 float	__ieee754_jnf __P((int,float));
217 float	__ieee754_ynf __P((int,float));
218 float	__ieee754_remainderf __P((float,float));
219 int	__ieee754_rem_pio2f __P((float,float*));
220 float	__ieee754_scalbf __P((float,float));
221 
222 /* float versions of fdlibm kernel functions */
223 float	__kernel_sinf __P((float,float,int));
224 float	__kernel_cosf __P((float,float));
225 float	__kernel_tanf __P((float,float,int));
226 int	__kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
227 
228 #if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__)
229 #define __generic___ieee754_acos	__ieee754_acos
230 #define __generic___ieee754_asin	__ieee754_asin
231 #define __generic___ieee754_atan2	__ieee754_atan2
232 #define __generic___ieee754_exp		__ieee754_exp
233 #define __generic___ieee754_fmod	__ieee754_fmod
234 #define __generic___ieee754_log		__ieee754_log
235 #define __generic___ieee754_log10	__ieee754_log10
236 #define __generic___ieee754_remainder	__ieee754_remainder
237 #define __generic___ieee754_scalb	__ieee754_scalb
238 #define __generic___ieee754_sqrt	__ieee754_sqrt
239 #define	__generic_atan			atan
240 #define	__generic_ceil			ceil
241 #define	__generic_copysign		copysign
242 #define	__generic_cos			cos
243 #define	__generic_finite		finite
244 #define	__generic_floor			floor
245 #define	__generic_ilogb			ilogb
246 #define	__generic_log1p			log1p
247 #define	__generic_logb			logb
248 #define	__generic_rint			rint
249 #define	__generic_scalbn		scalbn
250 #define	__generic_significand		significand
251 #define	__generic_sin			sin
252 #define	__generic_tan			tan
253 #endif
254 
255 #endif /* !_MATH_PRIVATE_H_ */
256