1 /* Native implementation of soft float functions. Only a single status
2 context is supported */
5 #if defined(CONFIG_SOLARIS)
9 void set_float_rounding_mode(int val STATUS_PARAM
)
11 STATUS(float_rounding_mode
) = val
;
12 #if (defined(CONFIG_BSD) && !defined(__APPLE__) && !defined(__GLIBC__)) || \
13 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
21 void set_floatx80_rounding_precision(int val STATUS_PARAM
)
23 STATUS(floatx80_rounding_precision
) = val
;
27 #if defined(CONFIG_BSD) || \
28 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
29 #define lrint(d) ((int32_t)rint(d))
30 #define llrint(d) ((int64_t)rint(d))
31 #define lrintf(f) ((int32_t)rint(f))
32 #define llrintf(f) ((int64_t)rint(f))
33 #define sqrtf(f) ((float)sqrt(f))
34 #define remainderf(fa, fb) ((float)remainder(fa, fb))
35 #define rintf(f) ((float)rint(f))
36 #if !defined(__sparc__) && \
37 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
38 extern long double rintl(long double);
39 extern long double scalbnl(long double, int);
42 llrintl(long double x
) {
43 return ((long long) rintl(x
));
47 lrintl(long double x
) {
48 return ((long) rintl(x
));
52 ldexpl(long double x
, int n
) {
53 return (scalbnl(x
, n
));
58 #if defined(_ARCH_PPC)
60 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
61 static double qemu_rint(double x
)
63 double y
= 4503599627370496.0;
74 #define rint qemu_rint
77 /*----------------------------------------------------------------------------
78 | Software IEC/IEEE integer-to-floating-point conversion routines.
79 *----------------------------------------------------------------------------*/
80 float32
int32_to_float32(int v STATUS_PARAM
)
85 float32
uint32_to_float32(unsigned int v STATUS_PARAM
)
90 float64
int32_to_float64(int v STATUS_PARAM
)
95 float64
uint32_to_float64(unsigned int v STATUS_PARAM
)
101 floatx80
int32_to_floatx80(int v STATUS_PARAM
)
106 float32
int64_to_float32( int64_t v STATUS_PARAM
)
110 float32
uint64_to_float32( uint64_t v STATUS_PARAM
)
114 float64
int64_to_float64( int64_t v STATUS_PARAM
)
118 float64
uint64_to_float64( uint64_t v STATUS_PARAM
)
123 floatx80
int64_to_floatx80( int64_t v STATUS_PARAM
)
129 /* XXX: this code implements the x86 behaviour, not the IEEE one. */
130 #if HOST_LONG_BITS == 32
131 static inline int long_to_int32(long a
)
136 static inline int long_to_int32(long a
)
144 /*----------------------------------------------------------------------------
145 | Software IEC/IEEE single-precision conversion routines.
146 *----------------------------------------------------------------------------*/
147 int float32_to_int32( float32 a STATUS_PARAM
)
149 return long_to_int32(lrintf(a
));
151 int float32_to_int32_round_to_zero( float32 a STATUS_PARAM
)
155 int64_t float32_to_int64( float32 a STATUS_PARAM
)
160 int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM
)
165 float64
float32_to_float64( float32 a STATUS_PARAM
)
170 floatx80
float32_to_floatx80( float32 a STATUS_PARAM
)
176 unsigned int float32_to_uint32( float32 a STATUS_PARAM
)
184 } else if (v
> 0xffffffff) {
191 unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM
)
199 } else if (v
> 0xffffffff) {
207 /*----------------------------------------------------------------------------
208 | Software IEC/IEEE single-precision operations.
209 *----------------------------------------------------------------------------*/
210 float32
float32_round_to_int( float32 a STATUS_PARAM
)
215 float32
float32_rem( float32 a
, float32 b STATUS_PARAM
)
217 return remainderf(a
, b
);
220 float32
float32_sqrt( float32 a STATUS_PARAM
)
224 int float32_compare( float32 a
, float32 b STATUS_PARAM
)
227 return float_relation_less
;
229 return float_relation_equal
;
231 return float_relation_greater
;
233 return float_relation_unordered
;
236 int float32_compare_quiet( float32 a
, float32 b STATUS_PARAM
)
239 return float_relation_less
;
241 return float_relation_equal
;
242 } else if (isgreater(a
, b
)) {
243 return float_relation_greater
;
245 return float_relation_unordered
;
248 int float32_is_signaling_nan( float32 a1
)
254 return ( ( ( a
>>22 ) & 0x1FF ) == 0x1FE ) && ( a
& 0x003FFFFF );
257 int float32_is_quiet_nan( float32 a1
)
263 return ( 0xFF800000 < ( a
<<1 ) );
266 int float32_is_any_nan( float32 a1
)
272 return (a
& ~(1 << 31)) > 0x7f800000U
;
275 /*----------------------------------------------------------------------------
276 | Software IEC/IEEE double-precision conversion routines.
277 *----------------------------------------------------------------------------*/
278 int float64_to_int32( float64 a STATUS_PARAM
)
280 return long_to_int32(lrint(a
));
282 int float64_to_int32_round_to_zero( float64 a STATUS_PARAM
)
286 int64_t float64_to_int64( float64 a STATUS_PARAM
)
290 int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM
)
294 float32
float64_to_float32( float64 a STATUS_PARAM
)
299 floatx80
float64_to_floatx80( float64 a STATUS_PARAM
)
305 float128
float64_to_float128( float64 a STATUS_PARAM
)
311 unsigned int float64_to_uint32( float64 a STATUS_PARAM
)
319 } else if (v
> 0xffffffff) {
326 unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM
)
334 } else if (v
> 0xffffffff) {
341 uint64_t float64_to_uint64 (float64 a STATUS_PARAM
)
345 v
= llrint(a
+ (float64
)INT64_MIN
);
347 return v
- INT64_MIN
;
349 uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM
)
353 v
= (int64_t)(a
+ (float64
)INT64_MIN
);
355 return v
- INT64_MIN
;
358 /*----------------------------------------------------------------------------
359 | Software IEC/IEEE double-precision operations.
360 *----------------------------------------------------------------------------*/
361 #if defined(__sun__) && \
362 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
363 static inline float64
trunc(float64 x
)
365 return x
< 0 ? -floor(-x
) : floor(x
);
368 float64
float64_trunc_to_int( float64 a STATUS_PARAM
)
373 float64
float64_round_to_int( float64 a STATUS_PARAM
)
378 float64
float64_rem( float64 a
, float64 b STATUS_PARAM
)
380 return remainder(a
, b
);
383 float64
float64_sqrt( float64 a STATUS_PARAM
)
387 int float64_compare( float64 a
, float64 b STATUS_PARAM
)
390 return float_relation_less
;
392 return float_relation_equal
;
394 return float_relation_greater
;
396 return float_relation_unordered
;
399 int float64_compare_quiet( float64 a
, float64 b STATUS_PARAM
)
402 return float_relation_less
;
404 return float_relation_equal
;
405 } else if (isgreater(a
, b
)) {
406 return float_relation_greater
;
408 return float_relation_unordered
;
411 int float64_is_signaling_nan( float64 a1
)
418 ( ( ( a
>>51 ) & 0xFFF ) == 0xFFE )
419 && ( a
& LIT64( 0x0007FFFFFFFFFFFF ) );
423 int float64_is_quiet_nan( float64 a1
)
430 return ( LIT64( 0xFFF0000000000000 ) < (uint64_t) ( a
<<1 ) );
434 int float64_is_any_nan( float64 a1
)
441 return (a
& ~(1ULL << 63)) > LIT64 (0x7FF0000000000000 );
446 /*----------------------------------------------------------------------------
447 | Software IEC/IEEE extended double-precision conversion routines.
448 *----------------------------------------------------------------------------*/
449 int floatx80_to_int32( floatx80 a STATUS_PARAM
)
451 return long_to_int32(lrintl(a
));
453 int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM
)
457 int64_t floatx80_to_int64( floatx80 a STATUS_PARAM
)
461 int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM
)
465 float32
floatx80_to_float32( floatx80 a STATUS_PARAM
)
469 float64
floatx80_to_float64( floatx80 a STATUS_PARAM
)
474 /*----------------------------------------------------------------------------
475 | Software IEC/IEEE extended double-precision operations.
476 *----------------------------------------------------------------------------*/
477 floatx80
floatx80_round_to_int( floatx80 a STATUS_PARAM
)
481 floatx80
floatx80_rem( floatx80 a
, floatx80 b STATUS_PARAM
)
483 return remainderl(a
, b
);
485 floatx80
floatx80_sqrt( floatx80 a STATUS_PARAM
)
489 int floatx80_compare( floatx80 a
, floatx80 b STATUS_PARAM
)
492 return float_relation_less
;
494 return float_relation_equal
;
496 return float_relation_greater
;
498 return float_relation_unordered
;
501 int floatx80_compare_quiet( floatx80 a
, floatx80 b STATUS_PARAM
)
504 return float_relation_less
;
506 return float_relation_equal
;
507 } else if (isgreater(a
, b
)) {
508 return float_relation_greater
;
510 return float_relation_unordered
;
513 int floatx80_is_signaling_nan( floatx80 a1
)
519 aLow
= u
.i
.low
& ~ LIT64( 0x4000000000000000 );
521 ( ( u
.i
.high
& 0x7FFF ) == 0x7FFF )
522 && (uint64_t) ( aLow
<<1 )
523 && ( u
.i
.low
== aLow
);
526 int floatx80_is_quiet_nan( floatx80 a1
)
530 return ( ( u
.i
.high
& 0x7FFF ) == 0x7FFF ) && (uint64_t) ( u
.i
.low
<<1 );
533 int floatx80_is_any_nan( floatx80 a1
)
537 return ((u
.i
.high
& 0x7FFF) == 0x7FFF) && ( u
.i
.low
<<1 );