1 /* Native implementation of soft float functions. Only a single status
2 context is supported */
6 void set_float_rounding_mode(int val STATUS_PARAM
)
8 STATUS(float_rounding_mode
) = val
;
9 #if defined(HOST_BSD) && !defined(__APPLE__) || \
10 (defined(HOST_SOLARIS) && HOST_SOLARIS < 10)
12 #elif defined(__arm__)
20 void set_floatx80_rounding_precision(int val STATUS_PARAM
)
22 STATUS(floatx80_rounding_precision
) = val
;
26 #if defined(HOST_BSD) || (defined(HOST_SOLARIS) && HOST_SOLARIS < 10)
27 #define lrint(d) ((int32_t)rint(d))
28 #define llrint(d) ((int64_t)rint(d))
29 #define lrintf(f) ((int32_t)rint(f))
30 #define llrintf(f) ((int64_t)rint(f))
31 #define sqrtf(f) ((float)sqrt(f))
32 #define remainderf(fa, fb) ((float)remainder(fa, fb))
33 #define rintf(f) ((float)rint(f))
34 #if !defined(__sparc__) && defined(HOST_SOLARIS) && HOST_SOLARIS < 10
35 extern long double rintl(long double);
36 extern long double scalbnl(long double, int);
39 llrintl(long double x
) {
40 return ((long long) rintl(x
));
44 lrintl(long double x
) {
45 return ((long) rintl(x
));
49 ldexpl(long double x
, int n
) {
50 return (scalbnl(x
, n
));
55 #if defined(_ARCH_PPC)
57 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
58 static double qemu_rint(double x
)
60 double y
= 4503599627370496.0;
71 #define rint qemu_rint
74 /*----------------------------------------------------------------------------
75 | Software IEC/IEEE integer-to-floating-point conversion routines.
76 *----------------------------------------------------------------------------*/
77 float32
int32_to_float32(int v STATUS_PARAM
)
82 float32
uint32_to_float32(unsigned int v STATUS_PARAM
)
87 float64
int32_to_float64(int v STATUS_PARAM
)
92 float64
uint32_to_float64(unsigned int v STATUS_PARAM
)
98 floatx80
int32_to_floatx80(int v STATUS_PARAM
)
103 float32
int64_to_float32( int64_t v STATUS_PARAM
)
107 float32
uint64_to_float32( uint64_t v STATUS_PARAM
)
111 float64
int64_to_float64( int64_t v STATUS_PARAM
)
115 float64
uint64_to_float64( uint64_t v STATUS_PARAM
)
120 floatx80
int64_to_floatx80( int64_t v STATUS_PARAM
)
126 /* XXX: this code implements the x86 behaviour, not the IEEE one. */
127 #if HOST_LONG_BITS == 32
128 static inline int long_to_int32(long a
)
133 static inline int long_to_int32(long a
)
141 /*----------------------------------------------------------------------------
142 | Software IEC/IEEE single-precision conversion routines.
143 *----------------------------------------------------------------------------*/
144 int float32_to_int32( float32 a STATUS_PARAM
)
146 return long_to_int32(lrintf(a
));
148 int float32_to_int32_round_to_zero( float32 a STATUS_PARAM
)
152 int64_t float32_to_int64( float32 a STATUS_PARAM
)
157 int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM
)
162 float64
float32_to_float64( float32 a STATUS_PARAM
)
167 floatx80
float32_to_floatx80( float32 a STATUS_PARAM
)
173 unsigned int float32_to_uint32( float32 a STATUS_PARAM
)
181 } else if (v
> 0xffffffff) {
188 unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM
)
196 } else if (v
> 0xffffffff) {
204 /*----------------------------------------------------------------------------
205 | Software IEC/IEEE single-precision operations.
206 *----------------------------------------------------------------------------*/
207 float32
float32_round_to_int( float32 a STATUS_PARAM
)
212 float32
float32_rem( float32 a
, float32 b STATUS_PARAM
)
214 return remainderf(a
, b
);
217 float32
float32_sqrt( float32 a STATUS_PARAM
)
221 int float32_compare( float32 a
, float32 b STATUS_PARAM
)
224 return float_relation_less
;
226 return float_relation_equal
;
228 return float_relation_greater
;
230 return float_relation_unordered
;
233 int float32_compare_quiet( float32 a
, float32 b STATUS_PARAM
)
236 return float_relation_less
;
238 return float_relation_equal
;
239 } else if (isgreater(a
, b
)) {
240 return float_relation_greater
;
242 return float_relation_unordered
;
245 int float32_is_signaling_nan( float32 a1
)
251 return ( ( ( a
>>22 ) & 0x1FF ) == 0x1FE ) && ( a
& 0x003FFFFF );
254 int float32_is_nan( float32 a1
)
260 return ( 0xFF800000 < ( a
<<1 ) );
263 /*----------------------------------------------------------------------------
264 | Software IEC/IEEE double-precision conversion routines.
265 *----------------------------------------------------------------------------*/
266 int float64_to_int32( float64 a STATUS_PARAM
)
268 return long_to_int32(lrint(a
));
270 int float64_to_int32_round_to_zero( float64 a STATUS_PARAM
)
274 int64_t float64_to_int64( float64 a STATUS_PARAM
)
278 int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM
)
282 float32
float64_to_float32( float64 a STATUS_PARAM
)
287 floatx80
float64_to_floatx80( float64 a STATUS_PARAM
)
293 float128
float64_to_float128( float64 a STATUS_PARAM
)
299 unsigned int float64_to_uint32( float64 a STATUS_PARAM
)
307 } else if (v
> 0xffffffff) {
314 unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM
)
322 } else if (v
> 0xffffffff) {
329 uint64_t float64_to_uint64 (float64 a STATUS_PARAM
)
333 v
= llrint(a
+ (float64
)INT64_MIN
);
335 return v
- INT64_MIN
;
337 uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM
)
341 v
= (int64_t)(a
+ (float64
)INT64_MIN
);
343 return v
- INT64_MIN
;
346 /*----------------------------------------------------------------------------
347 | Software IEC/IEEE double-precision operations.
348 *----------------------------------------------------------------------------*/
349 #if defined(__sun__) && defined(HOST_SOLARIS) && HOST_SOLARIS < 10
350 static inline float64
trunc(float64 x
)
352 return x
< 0 ? -floor(-x
) : floor(x
);
355 float64
float64_trunc_to_int( float64 a STATUS_PARAM
)
360 float64
float64_round_to_int( float64 a STATUS_PARAM
)
363 switch(STATUS(float_rounding_mode
)) {
365 case float_round_nearest_even
:
366 asm("rndd %0, %1" : "=f" (a
) : "f"(a
));
368 case float_round_down
:
369 asm("rnddm %0, %1" : "=f" (a
) : "f"(a
));
372 asm("rnddp %0, %1" : "=f" (a
) : "f"(a
));
374 case float_round_to_zero
:
375 asm("rnddz %0, %1" : "=f" (a
) : "f"(a
));
383 float64
float64_rem( float64 a
, float64 b STATUS_PARAM
)
385 return remainder(a
, b
);
388 float64
float64_sqrt( float64 a STATUS_PARAM
)
392 int float64_compare( float64 a
, float64 b STATUS_PARAM
)
395 return float_relation_less
;
397 return float_relation_equal
;
399 return float_relation_greater
;
401 return float_relation_unordered
;
404 int float64_compare_quiet( float64 a
, float64 b STATUS_PARAM
)
407 return float_relation_less
;
409 return float_relation_equal
;
410 } else if (isgreater(a
, b
)) {
411 return float_relation_greater
;
413 return float_relation_unordered
;
416 int float64_is_signaling_nan( float64 a1
)
423 ( ( ( a
>>51 ) & 0xFFF ) == 0xFFE )
424 && ( a
& LIT64( 0x0007FFFFFFFFFFFF ) );
428 int float64_is_nan( float64 a1
)
435 return ( LIT64( 0xFFF0000000000000 ) < (bits64
) ( a
<<1 ) );
441 /*----------------------------------------------------------------------------
442 | Software IEC/IEEE extended double-precision conversion routines.
443 *----------------------------------------------------------------------------*/
444 int floatx80_to_int32( floatx80 a STATUS_PARAM
)
446 return long_to_int32(lrintl(a
));
448 int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM
)
452 int64_t floatx80_to_int64( floatx80 a STATUS_PARAM
)
456 int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM
)
460 float32
floatx80_to_float32( floatx80 a STATUS_PARAM
)
464 float64
floatx80_to_float64( floatx80 a STATUS_PARAM
)
469 /*----------------------------------------------------------------------------
470 | Software IEC/IEEE extended double-precision operations.
471 *----------------------------------------------------------------------------*/
472 floatx80
floatx80_round_to_int( floatx80 a STATUS_PARAM
)
476 floatx80
floatx80_rem( floatx80 a
, floatx80 b STATUS_PARAM
)
478 return remainderl(a
, b
);
480 floatx80
floatx80_sqrt( floatx80 a STATUS_PARAM
)
484 int floatx80_compare( floatx80 a
, floatx80 b STATUS_PARAM
)
487 return float_relation_less
;
489 return float_relation_equal
;
491 return float_relation_greater
;
493 return float_relation_unordered
;
496 int floatx80_compare_quiet( floatx80 a
, floatx80 b STATUS_PARAM
)
499 return float_relation_less
;
501 return float_relation_equal
;
502 } else if (isgreater(a
, b
)) {
503 return float_relation_greater
;
505 return float_relation_unordered
;
508 int floatx80_is_signaling_nan( floatx80 a1
)
514 aLow
= u
.i
.low
& ~ LIT64( 0x4000000000000000 );
516 ( ( u
.i
.high
& 0x7FFF ) == 0x7FFF )
517 && (bits64
) ( aLow
<<1 )
518 && ( u
.i
.low
== aLow
);
521 int floatx80_is_nan( floatx80 a1
)
525 return ( ( u
.i
.high
& 0x7FFF ) == 0x7FFF ) && (bits64
) ( u
.i
.low
<<1 );