VirtualBox

source: vbox/trunk/src/recompiler_new/fpu/softfloat-native.h@ 13359

最後變更 在這個檔案從13359是 13359,由 vboxsync 提交於 16 年 前

solaris new recompiler

檔案大小: 10.2 KB
 
1/* Native implementation of soft float functions */
2#include <math.h>
3
4#if (defined(_BSD) && !defined(__APPLE__)) || defined(HOST_SOLARIS)
5#include <ieeefp.h>
6#define fabsf(f) ((float)fabs(f))
7#else
8#include <fenv.h>
9#endif
10
11/*
12 * Define some C99-7.12.3 classification macros and
13 * some C99-.12.4 for Solaris systems OS less than 10,
14 * or Solaris 10 systems running GCC 3.x or less.
15 * Solaris 10 with GCC4 does not need these macros as they
16 * are defined in <iso/math_c99.h> with a compiler directive
17 */
18#if defined(HOST_SOLARIS) && (( HOST_SOLARIS <= 9 ) || ( ( HOST_SOLARIS >= 10 ) && ( __GNUC__ <= 4) ))
19/*
20 * C99 7.12.3 classification macros
21 * and
22 * C99 7.12.14 comparison macros
23 *
24 * ... do not work on Solaris 10 using GNU CC 3.4.x.
25 * Try to workaround the missing / broken C99 math macros.
26 */
27
28#define isnormal(x) (fpclass(x) >= FP_NZERO)
29#define isgreater(x, y) ((!unordered(x, y)) && ((x) > (y)))
30#define isgreaterequal(x, y) ((!unordered(x, y)) && ((x) >= (y)))
31#define isless(x, y) ((!unordered(x, y)) && ((x) < (y)))
32#define islessequal(x, y) ((!unordered(x, y)) && ((x) <= (y)))
33#define isunordered(x,y) unordered(x, y)
34#define isinf(x) ((fpclass(x) == FP_NINF) || (fpclass(x) == FP_PINF))
35
36#endif
37
38typedef float float32;
39typedef double float64;
40#ifdef FLOATX80
41typedef long double floatx80;
42#endif
43
44typedef union {
45 float32 f;
46 uint32_t i;
47} float32u;
48typedef union {
49 float64 f;
50 uint64_t i;
51} float64u;
52#ifdef FLOATX80
53typedef union {
54 floatx80 f;
55 struct {
56 uint64_t low;
57 uint16_t high;
58 } i;
59} floatx80u;
60#endif
61
62/*----------------------------------------------------------------------------
63| Software IEC/IEEE floating-point rounding mode.
64*----------------------------------------------------------------------------*/
65#if (defined(_BSD) && !defined(__APPLE__)) || defined(HOST_SOLARIS)
66enum {
67 float_round_nearest_even = FP_RN,
68 float_round_down = FP_RM,
69 float_round_up = FP_RP,
70 float_round_to_zero = FP_RZ
71};
72#elif defined(__arm__)
73enum {
74 float_round_nearest_even = 0,
75 float_round_down = 1,
76 float_round_up = 2,
77 float_round_to_zero = 3
78};
79#else
80enum {
81 float_round_nearest_even = FE_TONEAREST,
82 float_round_down = FE_DOWNWARD,
83 float_round_up = FE_UPWARD,
84 float_round_to_zero = FE_TOWARDZERO
85};
86#endif
87
88typedef struct float_status {
89 signed char float_rounding_mode;
90#ifdef FLOATX80
91 signed char floatx80_rounding_precision;
92#endif
93} float_status;
94
95void set_float_rounding_mode(int val STATUS_PARAM);
96#ifdef FLOATX80
97void set_floatx80_rounding_precision(int val STATUS_PARAM);
98#endif
99
100/*----------------------------------------------------------------------------
101| Software IEC/IEEE integer-to-floating-point conversion routines.
102*----------------------------------------------------------------------------*/
103float32 int32_to_float32( int STATUS_PARAM);
104float64 int32_to_float64( int STATUS_PARAM);
105#ifdef FLOATX80
106floatx80 int32_to_floatx80( int STATUS_PARAM);
107#endif
108#ifdef FLOAT128
109float128 int32_to_float128( int STATUS_PARAM);
110#endif
111float32 int64_to_float32( int64_t STATUS_PARAM);
112float64 int64_to_float64( int64_t STATUS_PARAM);
113#ifdef FLOATX80
114floatx80 int64_to_floatx80( int64_t STATUS_PARAM);
115#endif
116#ifdef FLOAT128
117float128 int64_to_float128( int64_t STATUS_PARAM);
118#endif
119
120/*----------------------------------------------------------------------------
121| Software IEC/IEEE single-precision conversion routines.
122*----------------------------------------------------------------------------*/
123int float32_to_int32( float32 STATUS_PARAM);
124int float32_to_int32_round_to_zero( float32 STATUS_PARAM);
125int64_t float32_to_int64( float32 STATUS_PARAM);
126int64_t float32_to_int64_round_to_zero( float32 STATUS_PARAM);
127float64 float32_to_float64( float32 STATUS_PARAM);
128#ifdef FLOATX80
129floatx80 float32_to_floatx80( float32 STATUS_PARAM);
130#endif
131#ifdef FLOAT128
132float128 float32_to_float128( float32 STATUS_PARAM);
133#endif
134
135/*----------------------------------------------------------------------------
136| Software IEC/IEEE single-precision operations.
137*----------------------------------------------------------------------------*/
138float32 float32_round_to_int( float32 STATUS_PARAM);
139INLINE float32 float32_add( float32 a, float32 b STATUS_PARAM)
140{
141 return a + b;
142}
143INLINE float32 float32_sub( float32 a, float32 b STATUS_PARAM)
144{
145 return a - b;
146}
147INLINE float32 float32_mul( float32 a, float32 b STATUS_PARAM)
148{
149 return a * b;
150}
151INLINE float32 float32_div( float32 a, float32 b STATUS_PARAM)
152{
153 return a / b;
154}
155float32 float32_rem( float32, float32 STATUS_PARAM);
156float32 float32_sqrt( float32 STATUS_PARAM);
157INLINE int float32_eq( float32 a, float32 b STATUS_PARAM)
158{
159 return a == b;
160}
161INLINE int float32_le( float32 a, float32 b STATUS_PARAM)
162{
163 return a <= b;
164}
165INLINE int float32_lt( float32 a, float32 b STATUS_PARAM)
166{
167 return a < b;
168}
169INLINE int float32_eq_signaling( float32 a, float32 b STATUS_PARAM)
170{
171 return a <= b && a >= b;
172}
173INLINE int float32_le_quiet( float32 a, float32 b STATUS_PARAM)
174{
175 return islessequal(a, b);
176}
177INLINE int float32_lt_quiet( float32 a, float32 b STATUS_PARAM)
178{
179 return isless(a, b);
180}
181INLINE int float32_unordered( float32 a, float32 b STATUS_PARAM)
182{
183 return isunordered(a, b);
184
185}
186int float32_compare( float32, float32 STATUS_PARAM );
187int float32_compare_quiet( float32, float32 STATUS_PARAM );
188int float32_is_signaling_nan( float32 );
189
190INLINE float32 float32_abs(float32 a)
191{
192 return fabsf(a);
193}
194
195INLINE float32 float32_chs(float32 a)
196{
197 return -a;
198}
199
200/*----------------------------------------------------------------------------
201| Software IEC/IEEE double-precision conversion routines.
202*----------------------------------------------------------------------------*/
203int float64_to_int32( float64 STATUS_PARAM );
204int float64_to_int32_round_to_zero( float64 STATUS_PARAM );
205int64_t float64_to_int64( float64 STATUS_PARAM );
206int64_t float64_to_int64_round_to_zero( float64 STATUS_PARAM );
207float32 float64_to_float32( float64 STATUS_PARAM );
208#ifdef FLOATX80
209floatx80 float64_to_floatx80( float64 STATUS_PARAM );
210#endif
211#ifdef FLOAT128
212float128 float64_to_float128( float64 STATUS_PARAM );
213#endif
214
215/*----------------------------------------------------------------------------
216| Software IEC/IEEE double-precision operations.
217*----------------------------------------------------------------------------*/
218float64 float64_round_to_int( float64 STATUS_PARAM );
219float64 float64_trunc_to_int( float64 STATUS_PARAM );
220INLINE float64 float64_add( float64 a, float64 b STATUS_PARAM)
221{
222 return a + b;
223}
224INLINE float64 float64_sub( float64 a, float64 b STATUS_PARAM)
225{
226 return a - b;
227}
228INLINE float64 float64_mul( float64 a, float64 b STATUS_PARAM)
229{
230 return a * b;
231}
232INLINE float64 float64_div( float64 a, float64 b STATUS_PARAM)
233{
234 return a / b;
235}
236float64 float64_rem( float64, float64 STATUS_PARAM );
237float64 float64_sqrt( float64 STATUS_PARAM );
238INLINE int float64_eq( float64 a, float64 b STATUS_PARAM)
239{
240 return a == b;
241}
242INLINE int float64_le( float64 a, float64 b STATUS_PARAM)
243{
244 return a <= b;
245}
246INLINE int float64_lt( float64 a, float64 b STATUS_PARAM)
247{
248 return a < b;
249}
250INLINE int float64_eq_signaling( float64 a, float64 b STATUS_PARAM)
251{
252 return a <= b && a >= b;
253}
254INLINE int float64_le_quiet( float64 a, float64 b STATUS_PARAM)
255{
256 return islessequal(a, b);
257}
258INLINE int float64_lt_quiet( float64 a, float64 b STATUS_PARAM)
259{
260 return isless(a, b);
261
262}
263INLINE int float64_unordered( float64 a, float64 b STATUS_PARAM)
264{
265 return isunordered(a, b);
266
267}
268int float64_compare( float64, float64 STATUS_PARAM );
269int float64_compare_quiet( float64, float64 STATUS_PARAM );
270int float64_is_signaling_nan( float64 );
271int float64_is_nan( float64 );
272
273INLINE float64 float64_abs(float64 a)
274{
275 return fabs(a);
276}
277
278INLINE float64 float64_chs(float64 a)
279{
280 return -a;
281}
282
283#ifdef FLOATX80
284
285/*----------------------------------------------------------------------------
286| Software IEC/IEEE extended double-precision conversion routines.
287*----------------------------------------------------------------------------*/
288int floatx80_to_int32( floatx80 STATUS_PARAM );
289int floatx80_to_int32_round_to_zero( floatx80 STATUS_PARAM );
290int64_t floatx80_to_int64( floatx80 STATUS_PARAM);
291int64_t floatx80_to_int64_round_to_zero( floatx80 STATUS_PARAM);
292float32 floatx80_to_float32( floatx80 STATUS_PARAM );
293float64 floatx80_to_float64( floatx80 STATUS_PARAM );
294#ifdef FLOAT128
295float128 floatx80_to_float128( floatx80 STATUS_PARAM );
296#endif
297
298/*----------------------------------------------------------------------------
299| Software IEC/IEEE extended double-precision operations.
300*----------------------------------------------------------------------------*/
301floatx80 floatx80_round_to_int( floatx80 STATUS_PARAM );
302INLINE floatx80 floatx80_add( floatx80 a, floatx80 b STATUS_PARAM)
303{
304 return a + b;
305}
306INLINE floatx80 floatx80_sub( floatx80 a, floatx80 b STATUS_PARAM)
307{
308 return a - b;
309}
310INLINE floatx80 floatx80_mul( floatx80 a, floatx80 b STATUS_PARAM)
311{
312 return a * b;
313}
314INLINE floatx80 floatx80_div( floatx80 a, floatx80 b STATUS_PARAM)
315{
316 return a / b;
317}
318floatx80 floatx80_rem( floatx80, floatx80 STATUS_PARAM );
319floatx80 floatx80_sqrt( floatx80 STATUS_PARAM );
320INLINE int floatx80_eq( floatx80 a, floatx80 b STATUS_PARAM)
321{
322 return a == b;
323}
324INLINE int floatx80_le( floatx80 a, floatx80 b STATUS_PARAM)
325{
326 return a <= b;
327}
328INLINE int floatx80_lt( floatx80 a, floatx80 b STATUS_PARAM)
329{
330 return a < b;
331}
332INLINE int floatx80_eq_signaling( floatx80 a, floatx80 b STATUS_PARAM)
333{
334 return a <= b && a >= b;
335}
336INLINE int floatx80_le_quiet( floatx80 a, floatx80 b STATUS_PARAM)
337{
338 return islessequal(a, b);
339}
340INLINE int floatx80_lt_quiet( floatx80 a, floatx80 b STATUS_PARAM)
341{
342 return isless(a, b);
343
344}
345INLINE int floatx80_unordered( floatx80 a, floatx80 b STATUS_PARAM)
346{
347 return isunordered(a, b);
348
349}
350int floatx80_compare( floatx80, floatx80 STATUS_PARAM );
351int floatx80_compare_quiet( floatx80, floatx80 STATUS_PARAM );
352int floatx80_is_signaling_nan( floatx80 );
353
354INLINE floatx80 floatx80_abs(floatx80 a)
355{
356 return fabsl(a);
357}
358
359INLINE floatx80 floatx80_chs(floatx80 a)
360{
361 return -a;
362}
363#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette