1 /* Native implementation of soft float functions. Only a single status
2 context is supported */
5 #if defined(CONFIG_SOLARIS)
8 #include "config-host.h"
10 void set_float_rounding_mode(int val STATUS_PARAM
)
12 STATUS(float_rounding_mode
) = val
;
13 #if (defined(CONFIG_BSD) && !defined(__APPLE__) && !defined(__GLIBC__)) || \
14 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
22 void set_floatx80_rounding_precision(int val STATUS_PARAM
)
24 STATUS(floatx80_rounding_precision
) = val
;
28 #if defined(CONFIG_BSD) || \
29 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
30 #define lrint(d) ((int32_t)rint(d))
31 #define llrint(d) ((int64_t)rint(d))
32 #define lrintf(f) ((int32_t)rint(f))
33 #define llrintf(f) ((int64_t)rint(f))
34 #define sqrtf(f) ((float)sqrt(f))
35 #define remainderf(fa, fb) ((float)remainder(fa, fb))
36 #define rintf(f) ((float)rint(f))
37 #if !defined(__sparc__) && \
38 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
39 extern long double rintl(long double);
40 extern long double scalbnl(long double, int);
43 llrintl(long double x
) {
44 return ((long long) rintl(x
));
48 lrintl(long double x
) {
49 return ((long) rintl(x
));
53 ldexpl(long double x
, int n
) {
54 return (scalbnl(x
, n
));
59 #if defined(_ARCH_PPC)
61 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
62 static double qemu_rint(double x
)
64 double y
= 4503599627370496.0;
75 #define rint qemu_rint
78 /*----------------------------------------------------------------------------
79 | Software IEC/IEEE integer-to-floating-point conversion routines.
80 *----------------------------------------------------------------------------*/
81 float32
int32_to_float32(int v STATUS_PARAM
)
86 float32
uint32_to_float32(unsigned int v STATUS_PARAM
)
91 float64
int32_to_float64(int v STATUS_PARAM
)
96 float64
uint32_to_float64(unsigned int v STATUS_PARAM
)
102 floatx80
int32_to_floatx80(int v STATUS_PARAM
)
107 float32
int64_to_float32( int64_t v STATUS_PARAM
)
111 float32
uint64_to_float32( uint64_t v STATUS_PARAM
)
115 float64
int64_to_float64( int64_t v STATUS_PARAM
)
119 float64
uint64_to_float64( uint64_t v STATUS_PARAM
)
124 floatx80
int64_to_floatx80( int64_t v STATUS_PARAM
)
130 /* XXX: this code implements the x86 behaviour, not the IEEE one. */
131 #if HOST_LONG_BITS == 32
132 static inline int long_to_int32(long a
)
137 static inline int long_to_int32(long a
)
145 /*----------------------------------------------------------------------------
146 | Software IEC/IEEE single-precision conversion routines.
147 *----------------------------------------------------------------------------*/
148 int float32_to_int32( float32 a STATUS_PARAM
)
150 return long_to_int32(lrintf(a
));
152 int float32_to_int32_round_to_zero( float32 a STATUS_PARAM
)
156 int64_t float32_to_int64( float32 a STATUS_PARAM
)
161 int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM
)
166 float64
float32_to_float64( float32 a STATUS_PARAM
)
171 floatx80
float32_to_floatx80( float32 a STATUS_PARAM
)
177 unsigned int float32_to_uint32( float32 a STATUS_PARAM
)
185 } else if (v
> 0xffffffff) {
192 unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM
)
200 } else if (v
> 0xffffffff) {
208 /*----------------------------------------------------------------------------
209 | Software IEC/IEEE single-precision operations.
210 *----------------------------------------------------------------------------*/
211 float32
float32_round_to_int( float32 a STATUS_PARAM
)
216 float32
float32_rem( float32 a
, float32 b STATUS_PARAM
)
218 return remainderf(a
, b
);
221 float32
float32_sqrt( float32 a STATUS_PARAM
)
225 int float32_compare( float32 a
, float32 b STATUS_PARAM
)
228 return float_relation_less
;
230 return float_relation_equal
;
232 return float_relation_greater
;
234 return float_relation_unordered
;
237 int float32_compare_quiet( float32 a
, float32 b STATUS_PARAM
)
240 return float_relation_less
;
242 return float_relation_equal
;
243 } else if (isgreater(a
, b
)) {
244 return float_relation_greater
;
246 return float_relation_unordered
;
249 int float32_is_signaling_nan( float32 a1
)
255 return ( ( ( a
>>22 ) & 0x1FF ) == 0x1FE ) && ( a
& 0x003FFFFF );
258 int float32_is_nan( float32 a1
)
264 return ( 0xFF800000 < ( a
<<1 ) );
267 /*----------------------------------------------------------------------------
268 | Software IEC/IEEE double-precision conversion routines.
269 *----------------------------------------------------------------------------*/
270 int float64_to_int32( float64 a STATUS_PARAM
)
272 return long_to_int32(lrint(a
));
274 int float64_to_int32_round_to_zero( float64 a STATUS_PARAM
)
278 int64_t float64_to_int64( float64 a STATUS_PARAM
)
282 int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM
)
286 float32
float64_to_float32( float64 a STATUS_PARAM
)
291 floatx80
float64_to_floatx80( float64 a STATUS_PARAM
)
297 float128
float64_to_float128( float64 a STATUS_PARAM
)
303 unsigned int float64_to_uint32( float64 a STATUS_PARAM
)
311 } else if (v
> 0xffffffff) {
318 unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM
)
326 } else if (v
> 0xffffffff) {
333 uint64_t float64_to_uint64 (float64 a STATUS_PARAM
)
337 v
= llrint(a
+ (float64
)INT64_MIN
);
339 return v
- INT64_MIN
;
341 uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM
)
345 v
= (int64_t)(a
+ (float64
)INT64_MIN
);
347 return v
- INT64_MIN
;
350 /*----------------------------------------------------------------------------
351 | Software IEC/IEEE double-precision operations.
352 *----------------------------------------------------------------------------*/
353 #if defined(__sun__) && \
354 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
355 static inline float64
trunc(float64 x
)
357 return x
< 0 ? -floor(-x
) : floor(x
);
360 float64
float64_trunc_to_int( float64 a STATUS_PARAM
)
365 float64
float64_round_to_int( float64 a STATUS_PARAM
)
370 float64
float64_rem( float64 a
, float64 b STATUS_PARAM
)
372 return remainder(a
, b
);
375 float64
float64_sqrt( float64 a STATUS_PARAM
)
379 int float64_compare( float64 a
, float64 b STATUS_PARAM
)
382 return float_relation_less
;
384 return float_relation_equal
;
386 return float_relation_greater
;
388 return float_relation_unordered
;
391 int float64_compare_quiet( float64 a
, float64 b STATUS_PARAM
)
394 return float_relation_less
;
396 return float_relation_equal
;
397 } else if (isgreater(a
, b
)) {
398 return float_relation_greater
;
400 return float_relation_unordered
;
403 int float64_is_signaling_nan( float64 a1
)
410 ( ( ( a
>>51 ) & 0xFFF ) == 0xFFE )
411 && ( a
& LIT64( 0x0007FFFFFFFFFFFF ) );
415 int float64_is_nan( float64 a1
)
422 return ( LIT64( 0xFFF0000000000000 ) < (bits64
) ( a
<<1 ) );
428 /*----------------------------------------------------------------------------
429 | Software IEC/IEEE extended double-precision conversion routines.
430 *----------------------------------------------------------------------------*/
431 int floatx80_to_int32( floatx80 a STATUS_PARAM
)
433 return long_to_int32(lrintl(a
));
435 int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM
)
439 int64_t floatx80_to_int64( floatx80 a STATUS_PARAM
)
443 int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM
)
447 float32
floatx80_to_float32( floatx80 a STATUS_PARAM
)
451 float64
floatx80_to_float64( floatx80 a STATUS_PARAM
)
456 /*----------------------------------------------------------------------------
457 | Software IEC/IEEE extended double-precision operations.
458 *----------------------------------------------------------------------------*/
459 floatx80
floatx80_round_to_int( floatx80 a STATUS_PARAM
)
463 floatx80
floatx80_rem( floatx80 a
, floatx80 b STATUS_PARAM
)
465 return remainderl(a
, b
);
467 floatx80
floatx80_sqrt( floatx80 a STATUS_PARAM
)
471 int floatx80_compare( floatx80 a
, floatx80 b STATUS_PARAM
)
474 return float_relation_less
;
476 return float_relation_equal
;
478 return float_relation_greater
;
480 return float_relation_unordered
;
483 int floatx80_compare_quiet( floatx80 a
, floatx80 b STATUS_PARAM
)
486 return float_relation_less
;
488 return float_relation_equal
;
489 } else if (isgreater(a
, b
)) {
490 return float_relation_greater
;
492 return float_relation_unordered
;
495 int floatx80_is_signaling_nan( floatx80 a1
)
501 aLow
= u
.i
.low
& ~ LIT64( 0x4000000000000000 );
503 ( ( u
.i
.high
& 0x7FFF ) == 0x7FFF )
504 && (bits64
) ( aLow
<<1 )
505 && ( u
.i
.low
== aLow
);
508 int floatx80_is_nan( floatx80 a1
)
512 return ( ( u
.i
.high
& 0x7FFF ) == 0x7FFF ) && (bits64
) ( u
.i
.low
<<1 );