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 | * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $ |
15 | */ |
16 | |
17 | #ifndef _MATH_PRIVATE_H_ |
18 | #define _MATH_PRIVATE_H_ |
19 | |
20 | /* #include <endian.h> */ |
21 | #include "SDL_endian.h" |
22 | /* #include <sys/types.h> */ |
23 | |
24 | #define _IEEE_LIBM |
25 | #define attribute_hidden |
26 | #define libm_hidden_proto(x) |
27 | #define libm_hidden_def(x) |
28 | #define strong_alias(x, y) |
29 | |
30 | #ifndef __HAIKU__ /* already defined in a system header. */ |
31 | typedef unsigned int u_int32_t; |
32 | #endif |
33 | |
34 | #define atan SDL_uclibc_atan |
35 | #define __ieee754_atan2 SDL_uclibc_atan2 |
36 | #define copysign SDL_uclibc_copysign |
37 | #define cos SDL_uclibc_cos |
38 | #define __ieee754_exp SDL_uclibc_exp |
39 | #define fabs SDL_uclibc_fabs |
40 | #define floor SDL_uclibc_floor |
41 | #define __ieee754_fmod SDL_uclibc_fmod |
42 | #define __ieee754_log SDL_uclibc_log |
43 | #define __ieee754_log10 SDL_uclibc_log10 |
44 | #define __ieee754_pow SDL_uclibc_pow |
45 | #define scalbln SDL_uclibc_scalbln |
46 | #define scalbn SDL_uclibc_scalbn |
47 | #define sin SDL_uclibc_sin |
48 | #define __ieee754_sqrt SDL_uclibc_sqrt |
49 | #define tan SDL_uclibc_tan |
50 | |
51 | /* The original fdlibm code used statements like: |
52 | n0 = ((*(int*)&one)>>29)^1; * index of high word * |
53 | ix0 = *(n0+(int*)&x); * high word of x * |
54 | ix1 = *((1-n0)+(int*)&x); * low word of x * |
55 | to dig two 32 bit words out of the 64 bit IEEE floating point |
56 | value. That is non-ANSI, and, moreover, the gcc instruction |
57 | scheduler gets it wrong. We instead use the following macros. |
58 | Unlike the original code, we determine the endianness at compile |
59 | time, not at run time; I don't see much benefit to selecting |
60 | endianness at run time. */ |
61 | |
62 | /* A union which permits us to convert between a double and two 32 bit |
63 | ints. */ |
64 | |
65 | /* |
66 | * Math on arm is special: |
67 | * For FPA, float words are always big-endian. |
68 | * For VFP, floats words follow the memory system mode. |
69 | */ |
70 | |
71 | #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) |
72 | |
73 | typedef union |
74 | { |
75 | double value; |
76 | struct |
77 | { |
78 | u_int32_t msw; |
79 | u_int32_t lsw; |
80 | } parts; |
81 | } ieee_double_shape_type; |
82 | |
83 | #else |
84 | |
85 | typedef union |
86 | { |
87 | double value; |
88 | struct |
89 | { |
90 | u_int32_t lsw; |
91 | u_int32_t msw; |
92 | } parts; |
93 | } ieee_double_shape_type; |
94 | |
95 | #endif |
96 | |
97 | /* Get two 32 bit ints from a double. */ |
98 | |
99 | #define (ix0,ix1,d) \ |
100 | do { \ |
101 | ieee_double_shape_type ew_u; \ |
102 | ew_u.value = (d); \ |
103 | (ix0) = ew_u.parts.msw; \ |
104 | (ix1) = ew_u.parts.lsw; \ |
105 | } while (0) |
106 | |
107 | /* Get the more significant 32 bit int from a double. */ |
108 | |
109 | #define GET_HIGH_WORD(i,d) \ |
110 | do { \ |
111 | ieee_double_shape_type gh_u; \ |
112 | gh_u.value = (d); \ |
113 | (i) = gh_u.parts.msw; \ |
114 | } while (0) |
115 | |
116 | /* Get the less significant 32 bit int from a double. */ |
117 | |
118 | #define GET_LOW_WORD(i,d) \ |
119 | do { \ |
120 | ieee_double_shape_type gl_u; \ |
121 | gl_u.value = (d); \ |
122 | (i) = gl_u.parts.lsw; \ |
123 | } while (0) |
124 | |
125 | /* Set a double from two 32 bit ints. */ |
126 | |
127 | #define INSERT_WORDS(d,ix0,ix1) \ |
128 | do { \ |
129 | ieee_double_shape_type iw_u; \ |
130 | iw_u.parts.msw = (ix0); \ |
131 | iw_u.parts.lsw = (ix1); \ |
132 | (d) = iw_u.value; \ |
133 | } while (0) |
134 | |
135 | /* Set the more significant 32 bits of a double from an int. */ |
136 | |
137 | #define SET_HIGH_WORD(d,v) \ |
138 | do { \ |
139 | ieee_double_shape_type sh_u; \ |
140 | sh_u.value = (d); \ |
141 | sh_u.parts.msw = (v); \ |
142 | (d) = sh_u.value; \ |
143 | } while (0) |
144 | |
145 | /* Set the less significant 32 bits of a double from an int. */ |
146 | |
147 | #define SET_LOW_WORD(d,v) \ |
148 | do { \ |
149 | ieee_double_shape_type sl_u; \ |
150 | sl_u.value = (d); \ |
151 | sl_u.parts.lsw = (v); \ |
152 | (d) = sl_u.value; \ |
153 | } while (0) |
154 | |
155 | /* A union which permits us to convert between a float and a 32 bit |
156 | int. */ |
157 | |
158 | typedef union |
159 | { |
160 | float value; |
161 | u_int32_t word; |
162 | } ieee_float_shape_type; |
163 | |
164 | /* Get a 32 bit int from a float. */ |
165 | |
166 | #define GET_FLOAT_WORD(i,d) \ |
167 | do { \ |
168 | ieee_float_shape_type gf_u; \ |
169 | gf_u.value = (d); \ |
170 | (i) = gf_u.word; \ |
171 | } while (0) |
172 | |
173 | /* Set a float from a 32 bit int. */ |
174 | |
175 | #define SET_FLOAT_WORD(d,i) \ |
176 | do { \ |
177 | ieee_float_shape_type sf_u; \ |
178 | sf_u.word = (i); \ |
179 | (d) = sf_u.value; \ |
180 | } while (0) |
181 | |
182 | /* ieee style elementary functions */ |
183 | extern double |
184 | __ieee754_sqrt(double) |
185 | attribute_hidden; |
186 | extern double __ieee754_acos(double) attribute_hidden; |
187 | extern double __ieee754_acosh(double) attribute_hidden; |
188 | extern double __ieee754_log(double) attribute_hidden; |
189 | extern double __ieee754_atanh(double) attribute_hidden; |
190 | extern double __ieee754_asin(double) attribute_hidden; |
191 | extern double __ieee754_atan2(double, double) attribute_hidden; |
192 | extern double __ieee754_exp(double) attribute_hidden; |
193 | extern double __ieee754_cosh(double) attribute_hidden; |
194 | extern double __ieee754_fmod(double, double) attribute_hidden; |
195 | extern double __ieee754_pow(double, double) attribute_hidden; |
196 | extern double __ieee754_lgamma_r(double, int *) attribute_hidden; |
197 | extern double __ieee754_gamma_r(double, int *) attribute_hidden; |
198 | extern double __ieee754_lgamma(double) attribute_hidden; |
199 | extern double __ieee754_gamma(double) attribute_hidden; |
200 | extern double __ieee754_log10(double) attribute_hidden; |
201 | extern double __ieee754_sinh(double) attribute_hidden; |
202 | extern double __ieee754_hypot(double, double) attribute_hidden; |
203 | extern double __ieee754_j0(double) attribute_hidden; |
204 | extern double __ieee754_j1(double) attribute_hidden; |
205 | extern double __ieee754_y0(double) attribute_hidden; |
206 | extern double __ieee754_y1(double) attribute_hidden; |
207 | extern double __ieee754_jn(int, double) attribute_hidden; |
208 | extern double __ieee754_yn(int, double) attribute_hidden; |
209 | extern double __ieee754_remainder(double, double) attribute_hidden; |
210 | extern int32_t __ieee754_rem_pio2(double, double *) attribute_hidden; |
211 | #if defined(_SCALB_INT) |
212 | extern double __ieee754_scalb(double, int) attribute_hidden; |
213 | #else |
214 | extern double __ieee754_scalb(double, double) attribute_hidden; |
215 | #endif |
216 | |
217 | /* fdlibm kernel function */ |
218 | #ifndef _IEEE_LIBM |
219 | extern double __kernel_standard(double, double, int) attribute_hidden; |
220 | #endif |
221 | extern double __kernel_sin(double, double, int) attribute_hidden; |
222 | extern double __kernel_cos(double, double) attribute_hidden; |
223 | extern double __kernel_tan(double, double, int) attribute_hidden; |
224 | extern int32_t __kernel_rem_pio2(const double *, double *, int, int, const unsigned int, |
225 | const int32_t *) attribute_hidden; |
226 | |
227 | #endif /* _MATH_PRIVATE_H_ */ |
228 | |