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) ((int32_t)rint(d))
27 #define llrint(d) ((int64_t)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 /*----------------------------------------------------------------------------
84 | Software IEC/IEEE single-precision conversion routines.
85 *----------------------------------------------------------------------------*/
86 int float32_to_int32( float32 a STATUS_PARAM)
90 int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
94 int64_t float32_to_int64( float32 a STATUS_PARAM)
99 int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM)
104 float64 float32_to_float64( float32 a STATUS_PARAM)
109 floatx80 float32_to_floatx80( float32 a STATUS_PARAM)
115 /*----------------------------------------------------------------------------
116 | Software IEC/IEEE single-precision operations.
117 *----------------------------------------------------------------------------*/
118 float32 float32_round_to_int( float32 a STATUS_PARAM)
123 float32 float32_sqrt( float32 a STATUS_PARAM)
127 char float32_is_signaling_nan( float32 a1)
133 return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF );
136 /*----------------------------------------------------------------------------
137 | Software IEC/IEEE double-precision conversion routines.
138 *----------------------------------------------------------------------------*/
139 int float64_to_int32( float64 a STATUS_PARAM)
143 int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
147 int64_t float64_to_int64( float64 a STATUS_PARAM)
151 int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM)
155 float32 float64_to_float32( float64 a STATUS_PARAM)
160 floatx80 float64_to_floatx80( float64 a STATUS_PARAM)
166 float128 float64_to_float128( float64 a STATUS_PARAM)
172 /*----------------------------------------------------------------------------
173 | Software IEC/IEEE double-precision operations.
174 *----------------------------------------------------------------------------*/
175 float64 float64_round_to_int( float64 a STATUS_PARAM )
178 switch(STATUS(float_rounding_mode)) {
180 case float_round_nearest_even:
181 asm("rndd %0, %1" : "=f" (a) : "f"(a));
183 case float_round_down:
184 asm("rnddm %0, %1" : "=f" (a) : "f"(a));
187 asm("rnddp %0, %1" : "=f" (a) : "f"(a));
189 case float_round_to_zero:
190 asm("rnddz %0, %1" : "=f" (a) : "f"(a));
198 float64 float64_sqrt( float64 a STATUS_PARAM)
202 char float64_is_signaling_nan( float64 a1)
209 ( ( ( a>>51 ) & 0xFFF ) == 0xFFE )
210 && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
216 /*----------------------------------------------------------------------------
217 | Software IEC/IEEE extended double-precision conversion routines.
218 *----------------------------------------------------------------------------*/
219 int floatx80_to_int32( floatx80 a STATUS_PARAM)
223 int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
227 int64_t floatx80_to_int64( floatx80 a STATUS_PARAM)
231 int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM)
235 float32 floatx80_to_float32( floatx80 a STATUS_PARAM)
239 float64 floatx80_to_float64( floatx80 a STATUS_PARAM)
244 /*----------------------------------------------------------------------------
245 | Software IEC/IEEE extended double-precision operations.
246 *----------------------------------------------------------------------------*/
247 floatx80 floatx80_round_to_int( floatx80 a STATUS_PARAM)
251 floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM)
255 char floatx80_is_signaling_nan( floatx80 a1)
259 return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 );