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(_BSD) && !defined(__APPLE__) || (defined(HOST_SOLARIS) && HOST_SOLARIS < 10)
11 #elif defined(__arm__)
19 void set_floatx80_rounding_precision(int val STATUS_PARAM)
21 STATUS(floatx80_rounding_precision) = val;
25 #if defined(_BSD) || (defined(HOST_SOLARIS) && HOST_SOLARIS < 10)
26 #define lrint(d) ((int32_t)rint(d))
27 #define llrint(d) ((int64_t)rint(d))
28 #define lrintf(f) ((int32_t)rint(f))
29 #define llrintf(f) ((int64_t)rint(f))
30 #define sqrtf(f) ((float)sqrt(f))
31 #define remainderf(fa, fb) ((float)remainder(fa, fb))
32 #define rintf(f) ((float)rint(f))
35 #if defined(__powerpc__)
37 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
38 double qemu_rint(double x)
40 double y = 4503599627370496.0;
51 #define rint qemu_rint
54 /*----------------------------------------------------------------------------
55 | Software IEC/IEEE integer-to-floating-point conversion routines.
56 *----------------------------------------------------------------------------*/
57 float32 int32_to_float32(int v STATUS_PARAM)
62 float64 int32_to_float64(int v STATUS_PARAM)
68 floatx80 int32_to_floatx80(int v STATUS_PARAM)
73 float32 int64_to_float32( int64_t v STATUS_PARAM)
77 float64 int64_to_float64( int64_t v STATUS_PARAM)
82 floatx80 int64_to_floatx80( int64_t v STATUS_PARAM)
88 /* XXX: this code implements the x86 behaviour, not the IEEE one. */
89 #if HOST_LONG_BITS == 32
90 static inline int long_to_int32(long a)
95 static inline int long_to_int32(long a)
103 /*----------------------------------------------------------------------------
104 | Software IEC/IEEE single-precision conversion routines.
105 *----------------------------------------------------------------------------*/
106 int float32_to_int32( float32 a STATUS_PARAM)
108 return long_to_int32(lrintf(a));
110 int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
114 int64_t float32_to_int64( float32 a STATUS_PARAM)
119 int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM)
124 float64 float32_to_float64( float32 a STATUS_PARAM)
129 floatx80 float32_to_floatx80( float32 a STATUS_PARAM)
135 /*----------------------------------------------------------------------------
136 | Software IEC/IEEE single-precision operations.
137 *----------------------------------------------------------------------------*/
138 float32 float32_round_to_int( float32 a STATUS_PARAM)
143 float32 float32_rem( float32 a, float32 b STATUS_PARAM)
145 return remainderf(a, b);
148 float32 float32_sqrt( float32 a STATUS_PARAM)
152 char float32_compare( float32 a, float32 b STATUS_PARAM )
164 char float32_compare_quiet( float32 a, float32 b STATUS_PARAM )
170 } else if (isgreater(a, b)) {
176 char float32_is_signaling_nan( float32 a1)
182 return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
185 /*----------------------------------------------------------------------------
186 | Software IEC/IEEE double-precision conversion routines.
187 *----------------------------------------------------------------------------*/
188 int float64_to_int32( float64 a STATUS_PARAM)
190 return long_to_int32(lrint(a));
192 int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
196 int64_t float64_to_int64( float64 a STATUS_PARAM)
200 int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM)
204 float32 float64_to_float32( float64 a STATUS_PARAM)
209 floatx80 float64_to_floatx80( float64 a STATUS_PARAM)
215 float128 float64_to_float128( float64 a STATUS_PARAM)
221 /*----------------------------------------------------------------------------
222 | Software IEC/IEEE double-precision operations.
223 *----------------------------------------------------------------------------*/
224 float64 float64_round_to_int( float64 a STATUS_PARAM )
227 switch(STATUS(float_rounding_mode)) {
229 case float_round_nearest_even:
230 asm("rndd %0, %1" : "=f" (a) : "f"(a));
232 case float_round_down:
233 asm("rnddm %0, %1" : "=f" (a) : "f"(a));
236 asm("rnddp %0, %1" : "=f" (a) : "f"(a));
238 case float_round_to_zero:
239 asm("rnddz %0, %1" : "=f" (a) : "f"(a));
247 float64 float64_rem( float64 a, float64 b STATUS_PARAM)
249 return remainder(a, b);
252 float64 float64_sqrt( float64 a STATUS_PARAM)
256 char float64_compare( float64 a, float64 b STATUS_PARAM )
268 char float64_compare_quiet( float64 a, float64 b STATUS_PARAM )
274 } else if (isgreater(a, b)) {
280 char float64_is_signaling_nan( float64 a1)
287 ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
288 && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
294 /*----------------------------------------------------------------------------
295 | Software IEC/IEEE extended double-precision conversion routines.
296 *----------------------------------------------------------------------------*/
297 int floatx80_to_int32( floatx80 a STATUS_PARAM)
299 return long_to_int32(lrintl(a));
301 int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
305 int64_t floatx80_to_int64( floatx80 a STATUS_PARAM)
309 int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM)
313 float32 floatx80_to_float32( floatx80 a STATUS_PARAM)
317 float64 floatx80_to_float64( floatx80 a STATUS_PARAM)
322 /*----------------------------------------------------------------------------
323 | Software IEC/IEEE extended double-precision operations.
324 *----------------------------------------------------------------------------*/
325 floatx80 floatx80_round_to_int( floatx80 a STATUS_PARAM)
329 floatx80 floatx80_rem( floatx80 a, floatx80 b STATUS_PARAM)
331 return remainderl(a, b);
333 floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM)
337 char floatx80_compare( floatx80 a, floatx80 b STATUS_PARAM )
349 char floatx80_compare_quiet( floatx80 a, floatx80 b STATUS_PARAM )
355 } else if (isgreater(a, b)) {
361 char floatx80_is_signaling_nan( floatx80 a1)
365 return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 );