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__)
11 #elif defined(__arm__)
19 void set_floatx80_rounding_precision(int val STATUS_PARAM)
21 STATUS(floatx80_rounding_precision) = val;
26 #define lrint(d) ((long)rint(d))
27 #define llrint(d) ((long long)rint(d))
30 #if defined(__powerpc__)
32 /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
33 double qemu_rint(double x)
35 double y = 4503599627370496.0;
46 #define rint qemu_rint
49 /*----------------------------------------------------------------------------
50 | Software IEC/IEEE integer-to-floating-point conversion routines.
51 *----------------------------------------------------------------------------*/
52 float32 int32_to_float32(int v STATUS_PARAM)
57 float64 int32_to_float64(int v STATUS_PARAM)
63 floatx80 int32_to_floatx80(int v STATUS_PARAM)
68 float32 int64_to_float32( int64_t v STATUS_PARAM)
72 float64 int64_to_float64( int64_t v STATUS_PARAM)
77 floatx80 int64_to_floatx80( int64_t v STATUS_PARAM)
83 /* XXX: this code implements the x86 behaviour, not the IEEE one. */
84 #if HOST_LONG_BITS == 32
85 static inline int long_to_int32(long a)
90 static inline int long_to_int32(long a)
98 /*----------------------------------------------------------------------------
99 | Software IEC/IEEE single-precision conversion routines.
100 *----------------------------------------------------------------------------*/
101 int float32_to_int32( float32 a STATUS_PARAM)
103 return long_to_int32(lrintf(a));
105 int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
109 int64_t float32_to_int64( float32 a STATUS_PARAM)
114 int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM)
119 float64 float32_to_float64( float32 a STATUS_PARAM)
124 floatx80 float32_to_floatx80( float32 a STATUS_PARAM)
130 /*----------------------------------------------------------------------------
131 | Software IEC/IEEE single-precision operations.
132 *----------------------------------------------------------------------------*/
133 float32 float32_round_to_int( float32 a STATUS_PARAM)
138 float32 float32_rem( float32 a, float32 b STATUS_PARAM)
140 return remainderf(a, b);
143 float32 float32_sqrt( float32 a STATUS_PARAM)
147 char float32_compare( float32 a, float32 b STATUS_PARAM )
159 char float32_compare_quiet( float32 a, float32 b STATUS_PARAM )
165 } else if (isgreater(a, b)) {
171 char float32_is_signaling_nan( float32 a1)
177 return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
180 /*----------------------------------------------------------------------------
181 | Software IEC/IEEE double-precision conversion routines.
182 *----------------------------------------------------------------------------*/
183 int float64_to_int32( float64 a STATUS_PARAM)
185 return long_to_int32(lrint(a));
187 int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
191 int64_t float64_to_int64( float64 a STATUS_PARAM)
195 int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM)
199 float32 float64_to_float32( float64 a STATUS_PARAM)
204 floatx80 float64_to_floatx80( float64 a STATUS_PARAM)
210 float128 float64_to_float128( float64 a STATUS_PARAM)
216 /*----------------------------------------------------------------------------
217 | Software IEC/IEEE double-precision operations.
218 *----------------------------------------------------------------------------*/
219 float64 float64_round_to_int( float64 a STATUS_PARAM )
222 switch(STATUS(float_rounding_mode)) {
224 case float_round_nearest_even:
225 asm("rndd %0, %1" : "=f" (a) : "f"(a));
227 case float_round_down:
228 asm("rnddm %0, %1" : "=f" (a) : "f"(a));
231 asm("rnddp %0, %1" : "=f" (a) : "f"(a));
233 case float_round_to_zero:
234 asm("rnddz %0, %1" : "=f" (a) : "f"(a));
242 float64 float64_rem( float64 a, float64 b STATUS_PARAM)
244 return remainder(a, b);
247 float64 float64_sqrt( float64 a STATUS_PARAM)
251 char float64_compare( float64 a, float64 b STATUS_PARAM )
263 char float64_compare_quiet( float64 a, float64 b STATUS_PARAM )
269 } else if (isgreater(a, b)) {
275 char float64_is_signaling_nan( float64 a1)
282 ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
283 && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
289 /*----------------------------------------------------------------------------
290 | Software IEC/IEEE extended double-precision conversion routines.
291 *----------------------------------------------------------------------------*/
292 int floatx80_to_int32( floatx80 a STATUS_PARAM)
294 return long_to_int32(lrintl(a));
296 int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
300 int64_t floatx80_to_int64( floatx80 a STATUS_PARAM)
304 int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM)
308 float32 floatx80_to_float32( floatx80 a STATUS_PARAM)
312 float64 floatx80_to_float64( floatx80 a STATUS_PARAM)
317 /*----------------------------------------------------------------------------
318 | Software IEC/IEEE extended double-precision operations.
319 *----------------------------------------------------------------------------*/
320 floatx80 floatx80_round_to_int( floatx80 a STATUS_PARAM)
324 floatx80 floatx80_rem( floatx80 a, floatx80 b STATUS_PARAM)
326 return remainderl(a, b);
328 floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM)
332 char floatx80_compare( floatx80 a, floatx80 b STATUS_PARAM )
344 char floatx80_compare_quiet( floatx80 a, floatx80 b STATUS_PARAM )
350 } else if (isgreater(a, b)) {
356 char floatx80_is_signaling_nan( floatx80 a1)
360 return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 );