POK
math_private.h
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Jan 30 13:44:27 2009
15  */
16 
17 /*
18  * ====================================================
19  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
20  *
21  * Developed at SunPro, a Sun Microsystems, Inc. business.
22  * Permission to use, copy, modify, and distribute this
23  * software is freely granted, provided that this notice
24  * is preserved.
25  * ====================================================
26  */
27 
28 /*
29  * from: @(#)fdlibm.h 5.1 93/09/24
30  * $NetBSD: math_private.h,v 1.13 2008/04/26 23:49:50 christos Exp $
31  */
32 
33 #ifdef POK_NEEDS_LIBMATH
34 
35 #ifndef _MATH_PRIVATE_H_
36 #define _MATH_PRIVATE_H_
37 
38 #include <types.h>
39 
40 #define _IEEE_LIBM 1
41 
42 #define _LIB_VERSION 1
43 #define _POSIX_ 1
44 #define _SVID_ 2
45 #define _IEEE_ 3
46 
47 extern int signgam;
48 
49 #define __P(protos) protos /* full-blown ANSI C */
50 
51 
52 /* The original fdlibm code used statements like:
53  n0 = ((*(int*)&one)>>29)^1; * index of high word *
54  ix0 = *(n0+(int*)&x); * high word of x *
55  ix1 = *((1-n0)+(int*)&x); * low word of x *
56  to dig two 32 bit words out of the 64 bit IEEE floating point
57  value. That is non-ANSI, and, moreover, the gcc instruction
58  scheduler gets it wrong. We instead use the following macros.
59  Unlike the original code, we determine the endianness at compile
60  time, not at run time; I don't see much benefit to selecting
61  endianness at run time. */
62 
63 /* A union which permits us to convert between a double and two 32 bit
64  ints. */
65 
66 /*
67  * The ARM ports are little endian except for the FPA word order which is
68  * big endian.
69  */
70 /*
71 #if (BYTE_ORDER == BIG_ENDIAN) || (defined(__arm__) && !defined(__VFP_FP__))
72 
73 typedef union
74 {
75  double value;
76  struct
77  {
78  uint32_t msw;
79  uint32_t lsw;
80  } parts;
81 } ieee_double_shape_type;
82 
83 #endif
84 */
85 #if (BYTE_ORDER == LITTLE_ENDIAN) && \
86  !(defined(__arm__) && !defined(__VFP_FP__))
87 typedef union
88 {
89  double value;
90  struct
91  {
92  uint32_t lsw;
93  uint32_t msw;
94  } parts;
96 #endif
97 
98 /* Get two 32 bit ints from a double. */
99 
100 #define EXTRACT_WORDS(ix0,ix1,d) \
101 do { \
102  ieee_double_shape_type ew_u; \
103  ew_u.value = (d); \
104  (ix0) = ew_u.parts.msw; \
105  (ix1) = ew_u.parts.lsw; \
106 } while (/*CONSTCOND*/0)
107 
108 /* Get the more significant 32 bit int from a double. */
109 
110 #define GET_HIGH_WORD(i,d) \
111 do { \
112  ieee_double_shape_type gh_u; \
113  gh_u.value = (d); \
114  (i) = gh_u.parts.msw; \
115 } while (/*CONSTCOND*/0)
116 
117 /* Get the less significant 32 bit int from a double. */
118 
119 #define GET_LOW_WORD(i,d) \
120 do { \
121  ieee_double_shape_type gl_u; \
122  gl_u.value = (d); \
123  (i) = gl_u.parts.lsw; \
124 } while (/*CONSTCOND*/0)
125 
126 /* Set a double from two 32 bit ints. */
127 
128 #define INSERT_WORDS(d,ix0,ix1) \
129 do { \
130  ieee_double_shape_type iw_u; \
131  iw_u.parts.msw = (ix0); \
132  iw_u.parts.lsw = (ix1); \
133  (d) = iw_u.value; \
134 } while (/*CONSTCOND*/0)
135 
136 /* Set the more significant 32 bits of a double from an int. */
137 
138 #define SET_HIGH_WORD(d,v) \
139 do { \
140  ieee_double_shape_type sh_u; \
141  sh_u.value = (d); \
142  sh_u.parts.msw = (v); \
143  (d) = sh_u.value; \
144 } while (/*CONSTCOND*/0)
145 
146 /* Set the less significant 32 bits of a double from an int. */
147 
148 #define SET_LOW_WORD(d,v) \
149 do { \
150  ieee_double_shape_type sl_u; \
151  sl_u.value = (d); \
152  sl_u.parts.lsw = (v); \
153  (d) = sl_u.value; \
154 } while (/*CONSTCOND*/0)
155 
156 /* A union which permits us to convert between a float and a 32 bit
157  int. */
158 
159 typedef union
160 {
161  float value;
162  uint32_t word;
164 
165 /* Get a 32 bit int from a float. */
166 
167 #define GET_FLOAT_WORD(i,d) \
168 do { \
169  ieee_float_shape_type gf_u; \
170  gf_u.value = (d); \
171  (i) = gf_u.word; \
172 } while (/*CONSTCOND*/0)
173 
174 /* Set a float from a 32 bit int. */
175 
176 #define SET_FLOAT_WORD(d,i) \
177 do { \
178  ieee_float_shape_type sf_u; \
179  sf_u.word = (i); \
180  (d) = sf_u.value; \
181 } while (/*CONSTCOND*/0)
182 
183 /* ieee style elementary functions */
184 extern double __ieee754_sqrt __P((double));
185 extern double __ieee754_acos __P((double));
186 extern double __ieee754_acosh __P((double));
187 extern double __ieee754_log __P((double));
188 extern double __ieee754_atanh __P((double));
189 extern double __ieee754_asin __P((double));
190 extern double __ieee754_atan2 __P((double,double));
191 extern double __ieee754_exp __P((double));
192 extern double __ieee754_cosh __P((double));
193 extern double __ieee754_fmod __P((double,double));
194 extern double __ieee754_pow __P((double,double));
195 extern double __ieee754_lgamma_r __P((double,int *));
196 extern double __ieee754_gamma_r __P((double,int *));
197 extern double __ieee754_lgamma __P((double));
198 extern double __ieee754_gamma __P((double));
199 extern double __ieee754_log10 __P((double));
200 extern double __ieee754_log2 __P((double));
201 extern double __ieee754_sinh __P((double));
202 extern double __ieee754_hypot __P((double,double));
203 extern double __ieee754_j0 __P((double));
204 extern double __ieee754_j1 __P((double));
205 extern double __ieee754_y0 __P((double));
206 extern double __ieee754_y1 __P((double));
207 extern double __ieee754_jn __P((int,double));
208 extern double __ieee754_yn __P((int,double));
209 extern double __ieee754_remainder __P((double,double));
210 extern int32_t __ieee754_rem_pio2 __P((double,double*));
211 extern double __ieee754_scalb __P((double,double));
212 
213 /* fdlibm kernel function */
214 extern double __kernel_standard __P((double,double,int));
215 extern double __kernel_sin __P((double,double,int));
216 extern double __kernel_cos __P((double,double));
217 extern double __kernel_tan __P((double,double,int));
218 extern int __kernel_rem_pio2 __P((double*,double*,int,int,int,const int*));
219 
220 
221 /* ieee style elementary float functions */
222 extern float __ieee754_sqrtf __P((float));
223 extern float __ieee754_acosf __P((float));
224 extern float __ieee754_acoshf __P((float));
225 extern float __ieee754_logf __P((float));
226 extern float __ieee754_atanhf __P((float));
227 extern float __ieee754_asinf __P((float));
228 extern float __ieee754_atan2f __P((float,float));
229 extern float __ieee754_expf __P((float));
230 extern float __ieee754_coshf __P((float));
231 extern float __ieee754_fmodf __P((float,float));
232 extern float __ieee754_powf __P((float,float));
233 extern float __ieee754_lgammaf_r __P((float,int *));
234 extern float __ieee754_gammaf_r __P((float,int *));
235 extern float __ieee754_lgammaf __P((float));
236 extern float __ieee754_gammaf __P((float));
237 extern float __ieee754_log10f __P((float));
238 extern float __ieee754_log2f __P((float));
239 extern float __ieee754_sinhf __P((float));
240 extern float __ieee754_hypotf __P((float,float));
241 extern float __ieee754_j0f __P((float));
242 extern float __ieee754_j1f __P((float));
243 extern float __ieee754_y0f __P((float));
244 extern float __ieee754_y1f __P((float));
245 extern float __ieee754_jnf __P((int,float));
246 extern float __ieee754_ynf __P((int,float));
247 extern float __ieee754_remainderf __P((float,float));
248 extern int32_t __ieee754_rem_pio2f __P((float,float*));
249 extern float __ieee754_scalbf __P((float,float));
250 
251 /* float versions of fdlibm kernel functions */
252 extern float __kernel_sinf __P((float,float,int));
253 extern float __kernel_cosf __P((float,float));
254 extern float __kernel_tanf __P((float,float,int));
255 extern int __kernel_rem_pio2f __P((float*,float*,int,int,int,const int*));
256 
257 
258 #endif /* _MATH_PRIVATE_H_ */
259 
260 #endif
261