VirtualBox

source: vbox/trunk/src/recompiler/fpu/softfloat-native.h@ 53007

最後變更 在這個檔案從53007是 37689,由 vboxsync 提交於 13 年 前

recompiler: Merged in changes from 0.13.0.

  • 屬性 svn:eol-style 設為 native
檔案大小: 13.3 KB
 
1/* Native implementation of soft float functions */
2#define __C99FEATURES__
3#include <math.h>
4
5#if (defined(CONFIG_BSD) && !defined(__APPLE__) && !defined(__GLIBC__) && !defined(__FreeBSD__)) \
6 || defined(CONFIG_SOLARIS) /* VBox: Added __FreeBSD__ */
7#include <ieeefp.h>
8#define fabsf(f) ((float)fabs(f))
9#else
10#include <fenv.h>
11#endif
12
13#if defined(__OpenBSD__) || defined(__NetBSD__)
14#include <sys/param.h>
15#endif
16
17/*
18 * Define some C99-7.12.3 classification macros and
19 * some C99-.12.4 for Solaris systems OS less than 10,
20 * or Solaris 10 systems running GCC 3.x or less.
21 * Solaris 10 with GCC4 does not need these macros as they
22 * are defined in <iso/math_c99.h> with a compiler directive
23 */
24#if defined(CONFIG_SOLARIS) && \
25 ((CONFIG_SOLARIS_VERSION <= 9 ) || \
26 ((CONFIG_SOLARIS_VERSION == 10) && (__GNUC__ < 4))) \
27 || (defined(__OpenBSD__) && (OpenBSD < 200811))
28/*
29 * C99 7.12.3 classification macros
30 * and
31 * C99 7.12.14 comparison macros
32 *
33 * ... do not work on Solaris 10 using GNU CC 3.4.x.
34 * Try to workaround the missing / broken C99 math macros.
35 */
36#if defined(__OpenBSD__)
37#define unordered(x, y) (isnan(x) || isnan(y))
38#endif
39
40#ifdef __NetBSD__
41#ifndef isgreater
42#define isgreater(x, y) __builtin_isgreater(x, y)
43#endif
44#ifndef isgreaterequal
45#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
46#endif
47#ifndef isless
48#define isless(x, y) __builtin_isless(x, y)
49#endif
50#ifndef islessequal
51#define islessequal(x, y) __builtin_islessequal(x, y)
52#endif
53#ifndef isunordered
54#define isunordered(x, y) __builtin_isunordered(x, y)
55#endif
56#endif
57
58
59#define isnormal(x) (fpclass(x) >= FP_NZERO)
60#define isgreater(x, y) ((!unordered(x, y)) && ((x) > (y)))
61#define isgreaterequal(x, y) ((!unordered(x, y)) && ((x) >= (y)))
62#define isless(x, y) ((!unordered(x, y)) && ((x) < (y)))
63#define islessequal(x, y) ((!unordered(x, y)) && ((x) <= (y)))
64#define isunordered(x,y) unordered(x, y)
65#endif
66
67#if defined(__sun__) && !defined(CONFIG_NEEDS_LIBSUNMATH)
68
69#ifndef isnan
70# define isnan(x) \
71 (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
72 : sizeof (x) == sizeof (double) ? isnan_d (x) \
73 : isnan_f (x))
74static inline int isnan_f (float x) { return x != x; }
75static inline int isnan_d (double x) { return x != x; }
76static inline int isnan_ld (long double x) { return x != x; }
77#endif
78
79#ifndef isinf
80# define isinf(x) \
81 (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
82 : sizeof (x) == sizeof (double) ? isinf_d (x) \
83 : isinf_f (x))
84static inline int isinf_f (float x) { return isnan (x - x); }
85static inline int isinf_d (double x) { return isnan (x - x); }
86static inline int isinf_ld (long double x) { return isnan (x - x); }
87#endif
88#endif
89
90typedef float float32;
91typedef double float64;
92#ifdef FLOATX80
93typedef long double floatx80;
94#endif
95
96typedef union {
97 float32 f;
98 uint32_t i;
99} float32u;
100typedef union {
101 float64 f;
102 uint64_t i;
103} float64u;
104#ifdef FLOATX80
105typedef union {
106 floatx80 f;
107 struct {
108 uint64_t low;
109 uint16_t high;
110 } i;
111} floatx80u;
112#endif
113
114/*----------------------------------------------------------------------------
115| Software IEC/IEEE floating-point rounding mode.
116*----------------------------------------------------------------------------*/
117#if (defined(CONFIG_BSD) && !defined(__APPLE__) && !defined(__GLIBC__)) \
118 || defined(CONFIG_SOLARIS)
119#if defined(__OpenBSD__)
120#define FE_RM FP_RM
121#define FE_RP FP_RP
122#define FE_RZ FP_RZ
123#endif
124enum {
125 float_round_nearest_even = FP_RN,
126 float_round_down = FP_RM,
127 float_round_up = FP_RP,
128 float_round_to_zero = FP_RZ
129};
130#else
131enum {
132 float_round_nearest_even = FE_TONEAREST,
133 float_round_down = FE_DOWNWARD,
134 float_round_up = FE_UPWARD,
135 float_round_to_zero = FE_TOWARDZERO
136};
137#endif
138
139typedef struct float_status {
140 int float_rounding_mode;
141#ifdef FLOATX80
142 int floatx80_rounding_precision;
143#endif
144} float_status;
145
146void set_float_rounding_mode(int val STATUS_PARAM);
147#ifdef FLOATX80
148void set_floatx80_rounding_precision(int val STATUS_PARAM);
149#endif
150
151/*----------------------------------------------------------------------------
152| Software IEC/IEEE integer-to-floating-point conversion routines.
153*----------------------------------------------------------------------------*/
154float32 int32_to_float32( int STATUS_PARAM);
155float32 uint32_to_float32( unsigned int STATUS_PARAM);
156float64 int32_to_float64( int STATUS_PARAM);
157float64 uint32_to_float64( unsigned int STATUS_PARAM);
158#ifdef FLOATX80
159floatx80 int32_to_floatx80( int STATUS_PARAM);
160#endif
161#ifdef FLOAT128
162float128 int32_to_float128( int STATUS_PARAM);
163#endif
164float32 int64_to_float32( int64_t STATUS_PARAM);
165float32 uint64_to_float32( uint64_t STATUS_PARAM);
166float64 int64_to_float64( int64_t STATUS_PARAM);
167float64 uint64_to_float64( uint64_t v STATUS_PARAM);
168#ifdef FLOATX80
169floatx80 int64_to_floatx80( int64_t STATUS_PARAM);
170#endif
171#ifdef FLOAT128
172float128 int64_to_float128( int64_t STATUS_PARAM);
173#endif
174
175/*----------------------------------------------------------------------------
176| Software IEC/IEEE single-precision conversion routines.
177*----------------------------------------------------------------------------*/
178int float32_to_int32( float32 STATUS_PARAM);
179int float32_to_int32_round_to_zero( float32 STATUS_PARAM);
180unsigned int float32_to_uint32( float32 a STATUS_PARAM);
181unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM);
182int64_t float32_to_int64( float32 STATUS_PARAM);
183int64_t float32_to_int64_round_to_zero( float32 STATUS_PARAM);
184float64 float32_to_float64( float32 STATUS_PARAM);
185#ifdef FLOATX80
186floatx80 float32_to_floatx80( float32 STATUS_PARAM);
187#endif
188#ifdef FLOAT128
189float128 float32_to_float128( float32 STATUS_PARAM);
190#endif
191
192/*----------------------------------------------------------------------------
193| Software IEC/IEEE single-precision operations.
194*----------------------------------------------------------------------------*/
195float32 float32_round_to_int( float32 STATUS_PARAM);
196INLINE float32 float32_add( float32 a, float32 b STATUS_PARAM)
197{
198 return a + b;
199}
200INLINE float32 float32_sub( float32 a, float32 b STATUS_PARAM)
201{
202 return a - b;
203}
204INLINE float32 float32_mul( float32 a, float32 b STATUS_PARAM)
205{
206 return a * b;
207}
208INLINE float32 float32_div( float32 a, float32 b STATUS_PARAM)
209{
210 return a / b;
211}
212float32 float32_rem( float32, float32 STATUS_PARAM);
213float32 float32_sqrt( float32 STATUS_PARAM);
214INLINE int float32_eq( float32 a, float32 b STATUS_PARAM)
215{
216 return a == b;
217}
218INLINE int float32_le( float32 a, float32 b STATUS_PARAM)
219{
220 return a <= b;
221}
222INLINE int float32_lt( float32 a, float32 b STATUS_PARAM)
223{
224 return a < b;
225}
226INLINE int float32_eq_signaling( float32 a, float32 b STATUS_PARAM)
227{
228 return a <= b && a >= b;
229}
230INLINE int float32_le_quiet( float32 a, float32 b STATUS_PARAM)
231{
232 return islessequal(a, b);
233}
234INLINE int float32_lt_quiet( float32 a, float32 b STATUS_PARAM)
235{
236 return isless(a, b);
237}
238INLINE int float32_unordered( float32 a, float32 b STATUS_PARAM)
239{
240 return isunordered(a, b);
241
242}
243int float32_compare( float32, float32 STATUS_PARAM );
244int float32_compare_quiet( float32, float32 STATUS_PARAM );
245int float32_is_signaling_nan( float32 );
246int float32_is_nan( float32 );
247
248INLINE float32 float32_abs(float32 a)
249{
250 return fabsf(a);
251}
252
253INLINE float32 float32_chs(float32 a)
254{
255 return -a;
256}
257
258INLINE float32 float32_is_infinity(float32 a)
259{
260 return fpclassify(a) == FP_INFINITE;
261}
262
263INLINE float32 float32_is_neg(float32 a)
264{
265 float32u u;
266 u.f = a;
267 return u.i >> 31;
268}
269
270INLINE float32 float32_is_zero(float32 a)
271{
272 return fpclassify(a) == FP_ZERO;
273}
274
275INLINE float32 float32_scalbn(float32 a, int n)
276{
277 return scalbnf(a, n);
278}
279
280/*----------------------------------------------------------------------------
281| Software IEC/IEEE double-precision conversion routines.
282*----------------------------------------------------------------------------*/
283int float64_to_int32( float64 STATUS_PARAM );
284int float64_to_int32_round_to_zero( float64 STATUS_PARAM );
285unsigned int float64_to_uint32( float64 STATUS_PARAM );
286unsigned int float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
287int64_t float64_to_int64( float64 STATUS_PARAM );
288int64_t float64_to_int64_round_to_zero( float64 STATUS_PARAM );
289uint64_t float64_to_uint64( float64 STATUS_PARAM );
290uint64_t float64_to_uint64_round_to_zero( float64 STATUS_PARAM );
291float32 float64_to_float32( float64 STATUS_PARAM );
292#ifdef FLOATX80
293floatx80 float64_to_floatx80( float64 STATUS_PARAM );
294#endif
295#ifdef FLOAT128
296float128 float64_to_float128( float64 STATUS_PARAM );
297#endif
298
299/*----------------------------------------------------------------------------
300| Software IEC/IEEE double-precision operations.
301*----------------------------------------------------------------------------*/
302float64 float64_round_to_int( float64 STATUS_PARAM );
303float64 float64_trunc_to_int( float64 STATUS_PARAM );
304INLINE float64 float64_add( float64 a, float64 b STATUS_PARAM)
305{
306 return a + b;
307}
308INLINE float64 float64_sub( float64 a, float64 b STATUS_PARAM)
309{
310 return a - b;
311}
312INLINE float64 float64_mul( float64 a, float64 b STATUS_PARAM)
313{
314 return a * b;
315}
316INLINE float64 float64_div( float64 a, float64 b STATUS_PARAM)
317{
318 return a / b;
319}
320float64 float64_rem( float64, float64 STATUS_PARAM );
321float64 float64_sqrt( float64 STATUS_PARAM );
322INLINE int float64_eq( float64 a, float64 b STATUS_PARAM)
323{
324 return a == b;
325}
326INLINE int float64_le( float64 a, float64 b STATUS_PARAM)
327{
328 return a <= b;
329}
330INLINE int float64_lt( float64 a, float64 b STATUS_PARAM)
331{
332 return a < b;
333}
334INLINE int float64_eq_signaling( float64 a, float64 b STATUS_PARAM)
335{
336 return a <= b && a >= b;
337}
338INLINE int float64_le_quiet( float64 a, float64 b STATUS_PARAM)
339{
340 return islessequal(a, b);
341}
342INLINE int float64_lt_quiet( float64 a, float64 b STATUS_PARAM)
343{
344 return isless(a, b);
345
346}
347INLINE int float64_unordered( float64 a, float64 b STATUS_PARAM)
348{
349 return isunordered(a, b);
350
351}
352int float64_compare( float64, float64 STATUS_PARAM );
353int float64_compare_quiet( float64, float64 STATUS_PARAM );
354int float64_is_signaling_nan( float64 );
355int float64_is_nan( float64 );
356
357INLINE float64 float64_abs(float64 a)
358{
359 return fabs(a);
360}
361
362INLINE float64 float64_chs(float64 a)
363{
364 return -a;
365}
366
367INLINE float64 float64_is_infinity(float64 a)
368{
369 return fpclassify(a) == FP_INFINITE;
370}
371
372INLINE float64 float64_is_neg(float64 a)
373{
374 float64u u;
375 u.f = a;
376 return u.i >> 63;
377}
378
379INLINE float64 float64_is_zero(float64 a)
380{
381 return fpclassify(a) == FP_ZERO;
382}
383
384INLINE float64 float64_scalbn(float64 a, int n)
385{
386 return scalbn(a, n);
387}
388
389#ifdef FLOATX80
390
391/*----------------------------------------------------------------------------
392| Software IEC/IEEE extended double-precision conversion routines.
393*----------------------------------------------------------------------------*/
394int floatx80_to_int32( floatx80 STATUS_PARAM );
395int floatx80_to_int32_round_to_zero( floatx80 STATUS_PARAM );
396int64_t floatx80_to_int64( floatx80 STATUS_PARAM);
397int64_t floatx80_to_int64_round_to_zero( floatx80 STATUS_PARAM);
398float32 floatx80_to_float32( floatx80 STATUS_PARAM );
399float64 floatx80_to_float64( floatx80 STATUS_PARAM );
400#ifdef FLOAT128
401float128 floatx80_to_float128( floatx80 STATUS_PARAM );
402#endif
403
404/*----------------------------------------------------------------------------
405| Software IEC/IEEE extended double-precision operations.
406*----------------------------------------------------------------------------*/
407floatx80 floatx80_round_to_int( floatx80 STATUS_PARAM );
408INLINE floatx80 floatx80_add( floatx80 a, floatx80 b STATUS_PARAM)
409{
410 return a + b;
411}
412INLINE floatx80 floatx80_sub( floatx80 a, floatx80 b STATUS_PARAM)
413{
414 return a - b;
415}
416INLINE floatx80 floatx80_mul( floatx80 a, floatx80 b STATUS_PARAM)
417{
418 return a * b;
419}
420INLINE floatx80 floatx80_div( floatx80 a, floatx80 b STATUS_PARAM)
421{
422 return a / b;
423}
424floatx80 floatx80_rem( floatx80, floatx80 STATUS_PARAM );
425floatx80 floatx80_sqrt( floatx80 STATUS_PARAM );
426INLINE int floatx80_eq( floatx80 a, floatx80 b STATUS_PARAM)
427{
428 return a == b;
429}
430INLINE int floatx80_le( floatx80 a, floatx80 b STATUS_PARAM)
431{
432 return a <= b;
433}
434INLINE int floatx80_lt( floatx80 a, floatx80 b STATUS_PARAM)
435{
436 return a < b;
437}
438INLINE int floatx80_eq_signaling( floatx80 a, floatx80 b STATUS_PARAM)
439{
440 return a <= b && a >= b;
441}
442INLINE int floatx80_le_quiet( floatx80 a, floatx80 b STATUS_PARAM)
443{
444 return islessequal(a, b);
445}
446INLINE int floatx80_lt_quiet( floatx80 a, floatx80 b STATUS_PARAM)
447{
448 return isless(a, b);
449
450}
451INLINE int floatx80_unordered( floatx80 a, floatx80 b STATUS_PARAM)
452{
453 return isunordered(a, b);
454
455}
456int floatx80_compare( floatx80, floatx80 STATUS_PARAM );
457int floatx80_compare_quiet( floatx80, floatx80 STATUS_PARAM );
458int floatx80_is_signaling_nan( floatx80 );
459int floatx80_is_nan( floatx80 );
460
461INLINE floatx80 floatx80_abs(floatx80 a)
462{
463 return fabsl(a);
464}
465
466INLINE floatx80 floatx80_chs(floatx80 a)
467{
468 return -a;
469}
470
471INLINE floatx80 floatx80_is_infinity(floatx80 a)
472{
473 return fpclassify(a) == FP_INFINITE;
474}
475
476INLINE floatx80 floatx80_is_neg(floatx80 a)
477{
478 floatx80u u;
479 u.f = a;
480 return u.i.high >> 15;
481}
482
483INLINE floatx80 floatx80_is_zero(floatx80 a)
484{
485 return fpclassify(a) == FP_ZERO;
486}
487
488INLINE floatx80 floatx80_scalbn(floatx80 a, int n)
489{
490 return scalbnl(a, n);
491}
492
493#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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