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__) || \
13 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
15 #elif defined(__arm__)
23 void set_floatx80_rounding_precision(int val STATUS_PARAM)
25 STATUS(floatx80_rounding_precision) = val;
29 #if defined(CONFIG_BSD) || \
30 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
31 #define lrint(d) ((int32_t)rint(d))
32 #define llrint(d) ((int64_t)rint(d))
33 #define lrintf(f) ((int32_t)rint(f))
34 #define llrintf(f) ((int64_t)rint(f))
35 #define sqrtf(f) ((float)sqrt(f))
36 #define remainderf(fa, fb) ((float)remainder(fa, fb))
37 #define rintf(f) ((float)rint(f))
38 #if !defined(__sparc__) && \
39 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
40 extern long double rintl(long double);
41 extern long double scalbnl(long double, int);
44 llrintl(long double x) {
45 return ((long long) rintl(x));
49 lrintl(long double x) {
50 return ((long) rintl(x));
54 ldexpl(long double x, int n) {
55 return (scalbnl(x, n));
60 #if defined(_ARCH_PPC)
62 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
63 static double qemu_rint(double x)
65 double y = 4503599627370496.0;
76 #define rint qemu_rint
79 /*----------------------------------------------------------------------------
80 | Software IEC/IEEE integer-to-floating-point conversion routines.
81 *----------------------------------------------------------------------------*/
82 float32 int32_to_float32(int v STATUS_PARAM)
87 float32 uint32_to_float32(unsigned int v STATUS_PARAM)
92 float64 int32_to_float64(int v STATUS_PARAM)
97 float64 uint32_to_float64(unsigned int v STATUS_PARAM)
103 floatx80 int32_to_floatx80(int v STATUS_PARAM)
108 float32 int64_to_float32( int64_t v STATUS_PARAM)
112 float32 uint64_to_float32( uint64_t v STATUS_PARAM)
116 float64 int64_to_float64( int64_t v STATUS_PARAM)
120 float64 uint64_to_float64( uint64_t v STATUS_PARAM)
125 floatx80 int64_to_floatx80( int64_t v STATUS_PARAM)
131 /* XXX: this code implements the x86 behaviour, not the IEEE one. */
132 #if HOST_LONG_BITS == 32
133 static inline int long_to_int32(long a)
138 static inline int long_to_int32(long a)
146 /*----------------------------------------------------------------------------
147 | Software IEC/IEEE single-precision conversion routines.
148 *----------------------------------------------------------------------------*/
149 int float32_to_int32( float32 a STATUS_PARAM)
151 return long_to_int32(lrintf(a));
153 int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
157 int64_t float32_to_int64( float32 a STATUS_PARAM)
162 int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM)
167 float64 float32_to_float64( float32 a STATUS_PARAM)
172 floatx80 float32_to_floatx80( float32 a STATUS_PARAM)
178 unsigned int float32_to_uint32( float32 a STATUS_PARAM)
186 } else if (v > 0xffffffff) {
193 unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM)
201 } else if (v > 0xffffffff) {
209 /*----------------------------------------------------------------------------
210 | Software IEC/IEEE single-precision operations.
211 *----------------------------------------------------------------------------*/
212 float32 float32_round_to_int( float32 a STATUS_PARAM)
217 float32 float32_rem( float32 a, float32 b STATUS_PARAM)
219 return remainderf(a, b);
222 float32 float32_sqrt( float32 a STATUS_PARAM)
226 int float32_compare( float32 a, float32 b STATUS_PARAM )
229 return float_relation_less;
231 return float_relation_equal;
233 return float_relation_greater;
235 return float_relation_unordered;
238 int float32_compare_quiet( float32 a, float32 b STATUS_PARAM )
241 return float_relation_less;
243 return float_relation_equal;
244 } else if (isgreater(a, b)) {
245 return float_relation_greater;
247 return float_relation_unordered;
250 int float32_is_signaling_nan( float32 a1)
256 return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
259 int float32_is_nan( float32 a1 )
265 return ( 0xFF800000 < ( a<<1 ) );
268 /*----------------------------------------------------------------------------
269 | Software IEC/IEEE double-precision conversion routines.
270 *----------------------------------------------------------------------------*/
271 int float64_to_int32( float64 a STATUS_PARAM)
273 return long_to_int32(lrint(a));
275 int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
279 int64_t float64_to_int64( float64 a STATUS_PARAM)
283 int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM)
287 float32 float64_to_float32( float64 a STATUS_PARAM)
292 floatx80 float64_to_floatx80( float64 a STATUS_PARAM)
298 float128 float64_to_float128( float64 a STATUS_PARAM)
304 unsigned int float64_to_uint32( float64 a STATUS_PARAM)
312 } else if (v > 0xffffffff) {
319 unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM)
327 } else if (v > 0xffffffff) {
334 uint64_t float64_to_uint64 (float64 a STATUS_PARAM)
338 v = llrint(a + (float64)INT64_MIN);
340 return v - INT64_MIN;
342 uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM)
346 v = (int64_t)(a + (float64)INT64_MIN);
348 return v - INT64_MIN;
351 /*----------------------------------------------------------------------------
352 | Software IEC/IEEE double-precision operations.
353 *----------------------------------------------------------------------------*/
354 #if defined(__sun__) && \
355 (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
356 static inline float64 trunc(float64 x)
358 return x < 0 ? -floor(-x) : floor(x);
361 float64 float64_trunc_to_int( float64 a STATUS_PARAM )
366 float64 float64_round_to_int( float64 a STATUS_PARAM )
369 switch(STATUS(float_rounding_mode)) {
371 case float_round_nearest_even:
372 asm("rndd %0, %1" : "=f" (a) : "f"(a));
374 case float_round_down:
375 asm("rnddm %0, %1" : "=f" (a) : "f"(a));
378 asm("rnddp %0, %1" : "=f" (a) : "f"(a));
380 case float_round_to_zero:
381 asm("rnddz %0, %1" : "=f" (a) : "f"(a));
389 float64 float64_rem( float64 a, float64 b STATUS_PARAM)
391 return remainder(a, b);
394 float64 float64_sqrt( float64 a STATUS_PARAM)
398 int float64_compare( float64 a, float64 b STATUS_PARAM )
401 return float_relation_less;
403 return float_relation_equal;
405 return float_relation_greater;
407 return float_relation_unordered;
410 int float64_compare_quiet( float64 a, float64 b STATUS_PARAM )
413 return float_relation_less;
415 return float_relation_equal;
416 } else if (isgreater(a, b)) {
417 return float_relation_greater;
419 return float_relation_unordered;
422 int float64_is_signaling_nan( float64 a1)
429 ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
430 && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
434 int float64_is_nan( float64 a1 )
441 return ( LIT64( 0xFFF0000000000000 ) < (bits64) ( a<<1 ) );
447 /*----------------------------------------------------------------------------
448 | Software IEC/IEEE extended double-precision conversion routines.
449 *----------------------------------------------------------------------------*/
450 int floatx80_to_int32( floatx80 a STATUS_PARAM)
452 return long_to_int32(lrintl(a));
454 int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
458 int64_t floatx80_to_int64( floatx80 a STATUS_PARAM)
462 int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM)
466 float32 floatx80_to_float32( floatx80 a STATUS_PARAM)
470 float64 floatx80_to_float64( floatx80 a STATUS_PARAM)
475 /*----------------------------------------------------------------------------
476 | Software IEC/IEEE extended double-precision operations.
477 *----------------------------------------------------------------------------*/
478 floatx80 floatx80_round_to_int( floatx80 a STATUS_PARAM)
482 floatx80 floatx80_rem( floatx80 a, floatx80 b STATUS_PARAM)
484 return remainderl(a, b);
486 floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM)
490 int floatx80_compare( floatx80 a, floatx80 b STATUS_PARAM )
493 return float_relation_less;
495 return float_relation_equal;
497 return float_relation_greater;
499 return float_relation_unordered;
502 int floatx80_compare_quiet( floatx80 a, floatx80 b STATUS_PARAM )
505 return float_relation_less;
507 return float_relation_equal;
508 } else if (isgreater(a, b)) {
509 return float_relation_greater;
511 return float_relation_unordered;
514 int floatx80_is_signaling_nan( floatx80 a1)
520 aLow = u.i.low & ~ LIT64( 0x4000000000000000 );
522 ( ( u.i.high & 0x7FFF ) == 0x7FFF )
523 && (bits64) ( aLow<<1 )
524 && ( u.i.low == aLow );
527 int floatx80_is_nan( floatx80 a1 )
531 return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 );