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 <machine/endian.h> 21 #include <sys/types.h> 22 23 /* The original fdlibm code used statements like: 24 n0 = ((*(int*)&one)>>29)^1; * index of high word * 25 ix0 = *(n0+(int*)&x); * high word of x * 26 ix1 = *((1-n0)+(int*)&x); * low word of x * 27 to dig two 32 bit words out of the 64 bit IEEE floating point 28 value. That is non-ANSI, and, moreover, the gcc instruction 29 scheduler gets it wrong. We instead use the following macros. 30 Unlike the original code, we determine the endianness at compile 31 time, not at run time; I don't see much benefit to selecting 32 endianness at run time. */ 33 34 /* A union which permits us to convert between a double and two 32 bit 35 ints. */ 36 37 #if BYTE_ORDER == BIG_ENDIAN 38 39 typedef union 40 { 41 double value; 42 struct 43 { 44 u_int32_t msw; 45 u_int32_t lsw; 46 } parts; 47 } ieee_double_shape_type; 48 49 #endif 50 51 #if BYTE_ORDER == LITTLE_ENDIAN 52 53 typedef union 54 { 55 double value; 56 struct 57 { 58 u_int32_t lsw; 59 u_int32_t msw; 60 } parts; 61 } ieee_double_shape_type; 62 63 #endif 64 65 /* Get two 32 bit ints from a double. */ 66 67 #define EXTRACT_WORDS(ix0,ix1,d) \ 68 do { \ 69 ieee_double_shape_type ew_u; \ 70 ew_u.value = (d); \ 71 (ix0) = ew_u.parts.msw; \ 72 (ix1) = ew_u.parts.lsw; \ 73 } while (0) 74 75 /* Get the more significant 32 bit int from a double. */ 76 77 #define GET_HIGH_WORD(i,d) \ 78 do { \ 79 ieee_double_shape_type gh_u; \ 80 gh_u.value = (d); \ 81 (i) = gh_u.parts.msw; \ 82 } while (0) 83 84 /* Get the less significant 32 bit int from a double. */ 85 86 #define GET_LOW_WORD(i,d) \ 87 do { \ 88 ieee_double_shape_type gl_u; \ 89 gl_u.value = (d); \ 90 (i) = gl_u.parts.lsw; \ 91 } while (0) 92 93 /* Set a double from two 32 bit ints. */ 94 95 #define INSERT_WORDS(d,ix0,ix1) \ 96 do { \ 97 ieee_double_shape_type iw_u; \ 98 iw_u.parts.msw = (ix0); \ 99 iw_u.parts.lsw = (ix1); \ 100 (d) = iw_u.value; \ 101 } while (0) 102 103 /* Set the more significant 32 bits of a double from an int. */ 104 105 #define SET_HIGH_WORD(d,v) \ 106 do { \ 107 ieee_double_shape_type sh_u; \ 108 sh_u.value = (d); \ 109 sh_u.parts.msw = (v); \ 110 (d) = sh_u.value; \ 111 } while (0) 112 113 /* Set the less significant 32 bits of a double from an int. */ 114 115 #define SET_LOW_WORD(d,v) \ 116 do { \ 117 ieee_double_shape_type sl_u; \ 118 sl_u.value = (d); \ 119 sl_u.parts.lsw = (v); \ 120 (d) = sl_u.value; \ 121 } while (0) 122 123 /* A union which permits us to convert between a float and a 32 bit 124 int. */ 125 126 typedef union 127 { 128 float value; 129 /* FIXME: Assumes 32 bit int. */ 130 unsigned int word; 131 } ieee_float_shape_type; 132 133 /* Get a 32 bit int from a float. */ 134 135 #define GET_FLOAT_WORD(i,d) \ 136 do { \ 137 ieee_float_shape_type gf_u; \ 138 gf_u.value = (d); \ 139 (i) = gf_u.word; \ 140 } while (0) 141 142 /* Set a float from a 32 bit int. */ 143 144 #define SET_FLOAT_WORD(d,i) \ 145 do { \ 146 ieee_float_shape_type sf_u; \ 147 sf_u.word = (i); \ 148 (d) = sf_u.value; \ 149 } while (0) 150 151 /* ieee style elementary functions */ 152 extern double __ieee754_sqrt __P((double)); 153 extern double __ieee754_acos __P((double)); 154 extern double __ieee754_acosh __P((double)); 155 extern double __ieee754_log __P((double)); 156 extern double __ieee754_atanh __P((double)); 157 extern double __ieee754_asin __P((double)); 158 extern double __ieee754_atan2 __P((double,double)); 159 extern double __ieee754_exp __P((double)); 160 extern double __ieee754_cosh __P((double)); 161 extern double __ieee754_fmod __P((double,double)); 162 extern double __ieee754_pow __P((double,double)); 163 extern double __ieee754_lgamma_r __P((double,int *)); 164 extern double __ieee754_gamma_r __P((double,int *)); 165 extern double __ieee754_lgamma __P((double)); 166 extern double __ieee754_gamma __P((double)); 167 extern double __ieee754_log10 __P((double)); 168 extern double __ieee754_sinh __P((double)); 169 extern double __ieee754_hypot __P((double,double)); 170 extern double __ieee754_j0 __P((double)); 171 extern double __ieee754_j1 __P((double)); 172 extern double __ieee754_y0 __P((double)); 173 extern double __ieee754_y1 __P((double)); 174 extern double __ieee754_jn __P((int,double)); 175 extern double __ieee754_yn __P((int,double)); 176 extern double __ieee754_remainder __P((double,double)); 177 extern int __ieee754_rem_pio2 __P((double,double*)); 178 extern double __ieee754_scalb __P((double,double)); 179 180 /* fdlibm kernel function */ 181 extern double __kernel_standard __P((double,double,int)); 182 extern double __kernel_sin __P((double,double,int)); 183 extern double __kernel_cos __P((double,double)); 184 extern double __kernel_tan __P((double,double,int)); 185 extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*)); 186 187 188 /* ieee style elementary float functions */ 189 extern float __ieee754_sqrtf __P((float)); 190 extern float __ieee754_acosf __P((float)); 191 extern float __ieee754_acoshf __P((float)); 192 extern float __ieee754_logf __P((float)); 193 extern float __ieee754_atanhf __P((float)); 194 extern float __ieee754_asinf __P((float)); 195 extern float __ieee754_atan2f __P((float,float)); 196 extern float __ieee754_expf __P((float)); 197 extern float __ieee754_coshf __P((float)); 198 extern float __ieee754_fmodf __P((float,float)); 199 extern float __ieee754_powf __P((float,float)); 200 extern float __ieee754_lgammaf_r __P((float,int *)); 201 extern float __ieee754_gammaf_r __P((float,int *)); 202 extern float __ieee754_lgammaf __P((float)); 203 extern float __ieee754_gammaf __P((float)); 204 extern float __ieee754_log10f __P((float)); 205 extern float __ieee754_sinhf __P((float)); 206 extern float __ieee754_hypotf __P((float,float)); 207 extern float __ieee754_j0f __P((float)); 208 extern float __ieee754_j1f __P((float)); 209 extern float __ieee754_y0f __P((float)); 210 extern float __ieee754_y1f __P((float)); 211 extern float __ieee754_jnf __P((int,float)); 212 extern float __ieee754_ynf __P((int,float)); 213 extern float __ieee754_remainderf __P((float,float)); 214 extern int __ieee754_rem_pio2f __P((float,float*)); 215 extern float __ieee754_scalbf __P((float,float)); 216 217 /* float versions of fdlibm kernel functions */ 218 extern float __kernel_sinf __P((float,float,int)); 219 extern float __kernel_cosf __P((float,float)); 220 extern float __kernel_tanf __P((float,float,int)); 221 extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*)); 222 223 #ifdef __alpha__ 224 #define __generic___ieee754_acos __ieee754_acos 225 #define __generic___ieee754_asin __ieee754_asin 226 #define __generic___ieee754_atan2 __ieee754_atan2 227 #define __generic___ieee754_exp __ieee754_exp 228 #define __generic___ieee754_fmod __ieee754_fmod 229 #define __generic___ieee754_log __ieee754_log 230 #define __generic___ieee754_log10 __ieee754_log10 231 #define __generic___ieee754_remainder __ieee754_remainder 232 #define __generic___ieee754_scalb __ieee754_scalb 233 #define __generic___ieee754_sqrt __ieee754_sqrt 234 #define __generic_atan atan 235 #define __generic_ceil ceil 236 #define __generic_copysign copysign 237 #define __generic_cos cos 238 #define __generic_finite finite 239 #define __generic_floor floor 240 #define __generic_ilogb ilogb 241 #define __generic_log1p log1p 242 #define __generic_logb logb 243 #define __generic_rint rint 244 #define __generic_scalbn scalbn 245 #define __generic_significand significand 246 #define __generic_sin sin 247 #define __generic_tan tan 248 #endif 249 250 #endif /* _MATH_PRIVATE_H_ */ 251