root / fpu / softfloat-native.c @ dd4239d6
History | View | Annotate | Download (11.5 kB)
1 | 158142c2 | bellard | /* Native implementation of soft float functions. Only a single status
|
---|---|---|---|
2 | 158142c2 | bellard | context is supported */
|
3 | 158142c2 | bellard | #include "softfloat.h" |
4 | 158142c2 | bellard | #include <math.h> |
5 | dfe5fff3 | Juan Quintela | #if defined(CONFIG_SOLARIS)
|
6 | 14d483ec | blueswir1 | #include <fenv.h> |
7 | 14d483ec | blueswir1 | #endif
|
8 | 158142c2 | bellard | |
9 | 158142c2 | bellard | void set_float_rounding_mode(int val STATUS_PARAM) |
10 | 158142c2 | bellard | { |
11 | 158142c2 | bellard | STATUS(float_rounding_mode) = val; |
12 | 71e72a19 | Juan Quintela | #if defined(CONFIG_BSD) && !defined(__APPLE__) || \
|
13 | dfe5fff3 | Juan Quintela | (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
|
14 | 158142c2 | bellard | fpsetround(val); |
15 | 158142c2 | bellard | #elif defined(__arm__)
|
16 | 158142c2 | bellard | /* nothing to do */
|
17 | 158142c2 | bellard | #else
|
18 | 158142c2 | bellard | fesetround(val); |
19 | 158142c2 | bellard | #endif
|
20 | 158142c2 | bellard | } |
21 | 158142c2 | bellard | |
22 | 158142c2 | bellard | #ifdef FLOATX80
|
23 | 158142c2 | bellard | void set_floatx80_rounding_precision(int val STATUS_PARAM) |
24 | 158142c2 | bellard | { |
25 | 158142c2 | bellard | STATUS(floatx80_rounding_precision) = val; |
26 | 158142c2 | bellard | } |
27 | 158142c2 | bellard | #endif
|
28 | 158142c2 | bellard | |
29 | 71e72a19 | Juan Quintela | #if defined(CONFIG_BSD) || \
|
30 | dfe5fff3 | Juan Quintela | (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
|
31 | fdbb4691 | bellard | #define lrint(d) ((int32_t)rint(d))
|
32 | fdbb4691 | bellard | #define llrint(d) ((int64_t)rint(d))
|
33 | fdbb4691 | bellard | #define lrintf(f) ((int32_t)rint(f))
|
34 | fdbb4691 | bellard | #define llrintf(f) ((int64_t)rint(f))
|
35 | fdbb4691 | bellard | #define sqrtf(f) ((float)sqrt(f)) |
36 | fdbb4691 | bellard | #define remainderf(fa, fb) ((float)remainder(fa, fb)) |
37 | fdbb4691 | bellard | #define rintf(f) ((float)rint(f)) |
38 | dfe5fff3 | Juan Quintela | #if !defined(__sparc__) && \
|
39 | dfe5fff3 | Juan Quintela | (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
|
40 | 0475a5ca | ths | extern long double rintl(long double); |
41 | 0475a5ca | ths | extern long double scalbnl(long double, int); |
42 | 0475a5ca | ths | |
43 | 0475a5ca | ths | long long |
44 | 0475a5ca | ths | llrintl(long double x) { |
45 | 0475a5ca | ths | return ((long long) rintl(x)); |
46 | 0475a5ca | ths | } |
47 | 0475a5ca | ths | |
48 | 0475a5ca | ths | long
|
49 | 0475a5ca | ths | lrintl(long double x) { |
50 | 0475a5ca | ths | return ((long) rintl(x)); |
51 | 0475a5ca | ths | } |
52 | 0475a5ca | ths | |
53 | 0475a5ca | ths | long double |
54 | 0475a5ca | ths | ldexpl(long double x, int n) { |
55 | 0475a5ca | ths | return (scalbnl(x, n));
|
56 | 0475a5ca | ths | } |
57 | 0475a5ca | ths | #endif
|
58 | 158142c2 | bellard | #endif
|
59 | 158142c2 | bellard | |
60 | e58ffeb3 | malc | #if defined(_ARCH_PPC)
|
61 | 158142c2 | bellard | |
62 | 158142c2 | bellard | /* correct (but slow) PowerPC rint() (glibc version is incorrect) */
|
63 | 947f5fcb | malc | static double qemu_rint(double x) |
64 | 158142c2 | bellard | { |
65 | 158142c2 | bellard | double y = 4503599627370496.0; |
66 | 158142c2 | bellard | if (fabs(x) >= y)
|
67 | 158142c2 | bellard | return x;
|
68 | 5fafdf24 | ths | if (x < 0) |
69 | 158142c2 | bellard | y = -y; |
70 | 158142c2 | bellard | y = (x + y) - y; |
71 | 158142c2 | bellard | if (y == 0.0) |
72 | 158142c2 | bellard | y = copysign(y, x); |
73 | 158142c2 | bellard | return y;
|
74 | 158142c2 | bellard | } |
75 | 158142c2 | bellard | |
76 | 158142c2 | bellard | #define rint qemu_rint
|
77 | 158142c2 | bellard | #endif
|
78 | 158142c2 | bellard | |
79 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
80 | 158142c2 | bellard | | Software IEC/IEEE integer-to-floating-point conversion routines.
|
81 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
82 | 158142c2 | bellard | float32 int32_to_float32(int v STATUS_PARAM)
|
83 | 158142c2 | bellard | { |
84 | 158142c2 | bellard | return (float32)v;
|
85 | 158142c2 | bellard | } |
86 | 158142c2 | bellard | |
87 | 75d62a58 | j_mayer | float32 uint32_to_float32(unsigned int v STATUS_PARAM) |
88 | 75d62a58 | j_mayer | { |
89 | 75d62a58 | j_mayer | return (float32)v;
|
90 | 75d62a58 | j_mayer | } |
91 | 75d62a58 | j_mayer | |
92 | 158142c2 | bellard | float64 int32_to_float64(int v STATUS_PARAM)
|
93 | 158142c2 | bellard | { |
94 | 158142c2 | bellard | return (float64)v;
|
95 | 158142c2 | bellard | } |
96 | 158142c2 | bellard | |
97 | 75d62a58 | j_mayer | float64 uint32_to_float64(unsigned int v STATUS_PARAM) |
98 | 75d62a58 | j_mayer | { |
99 | 75d62a58 | j_mayer | return (float64)v;
|
100 | 75d62a58 | j_mayer | } |
101 | 75d62a58 | j_mayer | |
102 | 158142c2 | bellard | #ifdef FLOATX80
|
103 | 158142c2 | bellard | floatx80 int32_to_floatx80(int v STATUS_PARAM)
|
104 | 158142c2 | bellard | { |
105 | 158142c2 | bellard | return (floatx80)v;
|
106 | 158142c2 | bellard | } |
107 | 158142c2 | bellard | #endif
|
108 | 158142c2 | bellard | float32 int64_to_float32( int64_t v STATUS_PARAM) |
109 | 158142c2 | bellard | { |
110 | 158142c2 | bellard | return (float32)v;
|
111 | 158142c2 | bellard | } |
112 | 75d62a58 | j_mayer | float32 uint64_to_float32( uint64_t v STATUS_PARAM) |
113 | 75d62a58 | j_mayer | { |
114 | 75d62a58 | j_mayer | return (float32)v;
|
115 | 75d62a58 | j_mayer | } |
116 | 158142c2 | bellard | float64 int64_to_float64( int64_t v STATUS_PARAM) |
117 | 158142c2 | bellard | { |
118 | 158142c2 | bellard | return (float64)v;
|
119 | 158142c2 | bellard | } |
120 | 75d62a58 | j_mayer | float64 uint64_to_float64( uint64_t v STATUS_PARAM) |
121 | 75d62a58 | j_mayer | { |
122 | 75d62a58 | j_mayer | return (float64)v;
|
123 | 75d62a58 | j_mayer | } |
124 | 158142c2 | bellard | #ifdef FLOATX80
|
125 | 158142c2 | bellard | floatx80 int64_to_floatx80( int64_t v STATUS_PARAM) |
126 | 158142c2 | bellard | { |
127 | 158142c2 | bellard | return (floatx80)v;
|
128 | 158142c2 | bellard | } |
129 | 158142c2 | bellard | #endif
|
130 | 158142c2 | bellard | |
131 | 1b2b0af5 | bellard | /* XXX: this code implements the x86 behaviour, not the IEEE one. */
|
132 | 1b2b0af5 | bellard | #if HOST_LONG_BITS == 32 |
133 | 1b2b0af5 | bellard | static inline int long_to_int32(long a) |
134 | 1b2b0af5 | bellard | { |
135 | 1b2b0af5 | bellard | return a;
|
136 | 1b2b0af5 | bellard | } |
137 | 1b2b0af5 | bellard | #else
|
138 | 1b2b0af5 | bellard | static inline int long_to_int32(long a) |
139 | 1b2b0af5 | bellard | { |
140 | 5fafdf24 | ths | if (a != (int32_t)a)
|
141 | 1b2b0af5 | bellard | a = 0x80000000;
|
142 | 1b2b0af5 | bellard | return a;
|
143 | 1b2b0af5 | bellard | } |
144 | 1b2b0af5 | bellard | #endif
|
145 | 1b2b0af5 | bellard | |
146 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
147 | 158142c2 | bellard | | Software IEC/IEEE single-precision conversion routines.
|
148 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
149 | 158142c2 | bellard | int float32_to_int32( float32 a STATUS_PARAM)
|
150 | 158142c2 | bellard | { |
151 | 1b2b0af5 | bellard | return long_to_int32(lrintf(a));
|
152 | 158142c2 | bellard | } |
153 | 158142c2 | bellard | int float32_to_int32_round_to_zero( float32 a STATUS_PARAM)
|
154 | 158142c2 | bellard | { |
155 | 158142c2 | bellard | return (int)a; |
156 | 158142c2 | bellard | } |
157 | 158142c2 | bellard | int64_t float32_to_int64( float32 a STATUS_PARAM) |
158 | 158142c2 | bellard | { |
159 | 158142c2 | bellard | return llrintf(a);
|
160 | 158142c2 | bellard | } |
161 | 158142c2 | bellard | |
162 | 158142c2 | bellard | int64_t float32_to_int64_round_to_zero( float32 a STATUS_PARAM) |
163 | 158142c2 | bellard | { |
164 | 158142c2 | bellard | return (int64_t)a;
|
165 | 158142c2 | bellard | } |
166 | 158142c2 | bellard | |
167 | 158142c2 | bellard | float64 float32_to_float64( float32 a STATUS_PARAM) |
168 | 158142c2 | bellard | { |
169 | 158142c2 | bellard | return a;
|
170 | 158142c2 | bellard | } |
171 | 158142c2 | bellard | #ifdef FLOATX80
|
172 | 158142c2 | bellard | floatx80 float32_to_floatx80( float32 a STATUS_PARAM) |
173 | 158142c2 | bellard | { |
174 | 158142c2 | bellard | return a;
|
175 | 158142c2 | bellard | } |
176 | 158142c2 | bellard | #endif
|
177 | 158142c2 | bellard | |
178 | 75d62a58 | j_mayer | unsigned int float32_to_uint32( float32 a STATUS_PARAM) |
179 | 75d62a58 | j_mayer | { |
180 | 75d62a58 | j_mayer | int64_t v; |
181 | 75d62a58 | j_mayer | unsigned int res; |
182 | 75d62a58 | j_mayer | |
183 | 75d62a58 | j_mayer | v = llrintf(a); |
184 | 75d62a58 | j_mayer | if (v < 0) { |
185 | 75d62a58 | j_mayer | res = 0;
|
186 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
187 | 75d62a58 | j_mayer | res = 0xffffffff;
|
188 | 75d62a58 | j_mayer | } else {
|
189 | 75d62a58 | j_mayer | res = v; |
190 | 75d62a58 | j_mayer | } |
191 | 75d62a58 | j_mayer | return res;
|
192 | 75d62a58 | j_mayer | } |
193 | 75d62a58 | j_mayer | unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM) |
194 | 75d62a58 | j_mayer | { |
195 | 75d62a58 | j_mayer | int64_t v; |
196 | 75d62a58 | j_mayer | unsigned int res; |
197 | 75d62a58 | j_mayer | |
198 | 75d62a58 | j_mayer | v = (int64_t)a; |
199 | 75d62a58 | j_mayer | if (v < 0) { |
200 | 75d62a58 | j_mayer | res = 0;
|
201 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
202 | 75d62a58 | j_mayer | res = 0xffffffff;
|
203 | 75d62a58 | j_mayer | } else {
|
204 | 75d62a58 | j_mayer | res = v; |
205 | 75d62a58 | j_mayer | } |
206 | 75d62a58 | j_mayer | return res;
|
207 | 75d62a58 | j_mayer | } |
208 | 75d62a58 | j_mayer | |
209 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
210 | 158142c2 | bellard | | Software IEC/IEEE single-precision operations.
|
211 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
212 | 158142c2 | bellard | float32 float32_round_to_int( float32 a STATUS_PARAM) |
213 | 158142c2 | bellard | { |
214 | 158142c2 | bellard | return rintf(a);
|
215 | 158142c2 | bellard | } |
216 | 158142c2 | bellard | |
217 | b109f9f8 | bellard | float32 float32_rem( float32 a, float32 b STATUS_PARAM) |
218 | b109f9f8 | bellard | { |
219 | b109f9f8 | bellard | return remainderf(a, b);
|
220 | b109f9f8 | bellard | } |
221 | b109f9f8 | bellard | |
222 | 158142c2 | bellard | float32 float32_sqrt( float32 a STATUS_PARAM) |
223 | 158142c2 | bellard | { |
224 | 158142c2 | bellard | return sqrtf(a);
|
225 | 158142c2 | bellard | } |
226 | 750afe93 | bellard | int float32_compare( float32 a, float32 b STATUS_PARAM )
|
227 | b109f9f8 | bellard | { |
228 | b109f9f8 | bellard | if (a < b) {
|
229 | 30e7a22e | aurel32 | return float_relation_less;
|
230 | b109f9f8 | bellard | } else if (a == b) { |
231 | 30e7a22e | aurel32 | return float_relation_equal;
|
232 | b109f9f8 | bellard | } else if (a > b) { |
233 | 30e7a22e | aurel32 | return float_relation_greater;
|
234 | b109f9f8 | bellard | } else {
|
235 | 30e7a22e | aurel32 | return float_relation_unordered;
|
236 | b109f9f8 | bellard | } |
237 | b109f9f8 | bellard | } |
238 | 750afe93 | bellard | int float32_compare_quiet( float32 a, float32 b STATUS_PARAM )
|
239 | b109f9f8 | bellard | { |
240 | b109f9f8 | bellard | if (isless(a, b)) {
|
241 | 30e7a22e | aurel32 | return float_relation_less;
|
242 | b109f9f8 | bellard | } else if (a == b) { |
243 | 30e7a22e | aurel32 | return float_relation_equal;
|
244 | b109f9f8 | bellard | } else if (isgreater(a, b)) { |
245 | 30e7a22e | aurel32 | return float_relation_greater;
|
246 | b109f9f8 | bellard | } else {
|
247 | 30e7a22e | aurel32 | return float_relation_unordered;
|
248 | b109f9f8 | bellard | } |
249 | b109f9f8 | bellard | } |
250 | 750afe93 | bellard | int float32_is_signaling_nan( float32 a1)
|
251 | 158142c2 | bellard | { |
252 | 158142c2 | bellard | float32u u; |
253 | 158142c2 | bellard | uint32_t a; |
254 | 158142c2 | bellard | u.f = a1; |
255 | 158142c2 | bellard | a = u.i; |
256 | 158142c2 | bellard | return ( ( ( a>>22 ) & 0x1FF ) == 0x1FE ) && ( a & 0x003FFFFF ); |
257 | 158142c2 | bellard | } |
258 | 158142c2 | bellard | |
259 | 629bd74a | aurel32 | int float32_is_nan( float32 a1 )
|
260 | 629bd74a | aurel32 | { |
261 | 629bd74a | aurel32 | float32u u; |
262 | 629bd74a | aurel32 | uint64_t a; |
263 | 629bd74a | aurel32 | u.f = a1; |
264 | 629bd74a | aurel32 | a = u.i; |
265 | 629bd74a | aurel32 | return ( 0xFF800000 < ( a<<1 ) ); |
266 | 629bd74a | aurel32 | } |
267 | 629bd74a | aurel32 | |
268 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
269 | 158142c2 | bellard | | Software IEC/IEEE double-precision conversion routines.
|
270 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
271 | 158142c2 | bellard | int float64_to_int32( float64 a STATUS_PARAM)
|
272 | 158142c2 | bellard | { |
273 | 1b2b0af5 | bellard | return long_to_int32(lrint(a));
|
274 | 158142c2 | bellard | } |
275 | 158142c2 | bellard | int float64_to_int32_round_to_zero( float64 a STATUS_PARAM)
|
276 | 158142c2 | bellard | { |
277 | 158142c2 | bellard | return (int)a; |
278 | 158142c2 | bellard | } |
279 | 158142c2 | bellard | int64_t float64_to_int64( float64 a STATUS_PARAM) |
280 | 158142c2 | bellard | { |
281 | 158142c2 | bellard | return llrint(a);
|
282 | 158142c2 | bellard | } |
283 | 158142c2 | bellard | int64_t float64_to_int64_round_to_zero( float64 a STATUS_PARAM) |
284 | 158142c2 | bellard | { |
285 | 158142c2 | bellard | return (int64_t)a;
|
286 | 158142c2 | bellard | } |
287 | 158142c2 | bellard | float32 float64_to_float32( float64 a STATUS_PARAM) |
288 | 158142c2 | bellard | { |
289 | 158142c2 | bellard | return a;
|
290 | 158142c2 | bellard | } |
291 | 158142c2 | bellard | #ifdef FLOATX80
|
292 | 158142c2 | bellard | floatx80 float64_to_floatx80( float64 a STATUS_PARAM) |
293 | 158142c2 | bellard | { |
294 | 158142c2 | bellard | return a;
|
295 | 158142c2 | bellard | } |
296 | 158142c2 | bellard | #endif
|
297 | 158142c2 | bellard | #ifdef FLOAT128
|
298 | 158142c2 | bellard | float128 float64_to_float128( float64 a STATUS_PARAM) |
299 | 158142c2 | bellard | { |
300 | 158142c2 | bellard | return a;
|
301 | 158142c2 | bellard | } |
302 | 158142c2 | bellard | #endif
|
303 | 158142c2 | bellard | |
304 | 75d62a58 | j_mayer | unsigned int float64_to_uint32( float64 a STATUS_PARAM) |
305 | 75d62a58 | j_mayer | { |
306 | 75d62a58 | j_mayer | int64_t v; |
307 | 75d62a58 | j_mayer | unsigned int res; |
308 | 75d62a58 | j_mayer | |
309 | 75d62a58 | j_mayer | v = llrint(a); |
310 | 75d62a58 | j_mayer | if (v < 0) { |
311 | 75d62a58 | j_mayer | res = 0;
|
312 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
313 | 75d62a58 | j_mayer | res = 0xffffffff;
|
314 | 75d62a58 | j_mayer | } else {
|
315 | 75d62a58 | j_mayer | res = v; |
316 | 75d62a58 | j_mayer | } |
317 | 75d62a58 | j_mayer | return res;
|
318 | 75d62a58 | j_mayer | } |
319 | 75d62a58 | j_mayer | unsigned int float64_to_uint32_round_to_zero( float64 a STATUS_PARAM) |
320 | 75d62a58 | j_mayer | { |
321 | 75d62a58 | j_mayer | int64_t v; |
322 | 75d62a58 | j_mayer | unsigned int res; |
323 | 75d62a58 | j_mayer | |
324 | 75d62a58 | j_mayer | v = (int64_t)a; |
325 | 75d62a58 | j_mayer | if (v < 0) { |
326 | 75d62a58 | j_mayer | res = 0;
|
327 | 75d62a58 | j_mayer | } else if (v > 0xffffffff) { |
328 | 75d62a58 | j_mayer | res = 0xffffffff;
|
329 | 75d62a58 | j_mayer | } else {
|
330 | 75d62a58 | j_mayer | res = v; |
331 | 75d62a58 | j_mayer | } |
332 | 75d62a58 | j_mayer | return res;
|
333 | 75d62a58 | j_mayer | } |
334 | 75d62a58 | j_mayer | uint64_t float64_to_uint64 (float64 a STATUS_PARAM) |
335 | 75d62a58 | j_mayer | { |
336 | 75d62a58 | j_mayer | int64_t v; |
337 | 75d62a58 | j_mayer | |
338 | 75d62a58 | j_mayer | v = llrint(a + (float64)INT64_MIN); |
339 | 75d62a58 | j_mayer | |
340 | 75d62a58 | j_mayer | return v - INT64_MIN;
|
341 | 75d62a58 | j_mayer | } |
342 | 75d62a58 | j_mayer | uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM) |
343 | 75d62a58 | j_mayer | { |
344 | 75d62a58 | j_mayer | int64_t v; |
345 | 75d62a58 | j_mayer | |
346 | 75d62a58 | j_mayer | v = (int64_t)(a + (float64)INT64_MIN); |
347 | 75d62a58 | j_mayer | |
348 | 75d62a58 | j_mayer | return v - INT64_MIN;
|
349 | 75d62a58 | j_mayer | } |
350 | 75d62a58 | j_mayer | |
351 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
352 | 158142c2 | bellard | | Software IEC/IEEE double-precision operations.
|
353 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
354 | dfe5fff3 | Juan Quintela | #if defined(__sun__) && \
|
355 | dfe5fff3 | Juan Quintela | (defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10)
|
356 | 63a654bb | ths | static inline float64 trunc(float64 x) |
357 | 63a654bb | ths | { |
358 | 63a654bb | ths | return x < 0 ? -floor(-x) : floor(x); |
359 | 63a654bb | ths | } |
360 | 63a654bb | ths | #endif
|
361 | e6e5906b | pbrook | float64 float64_trunc_to_int( float64 a STATUS_PARAM ) |
362 | e6e5906b | pbrook | { |
363 | e6e5906b | pbrook | return trunc(a);
|
364 | e6e5906b | pbrook | } |
365 | e6e5906b | pbrook | |
366 | 158142c2 | bellard | float64 float64_round_to_int( float64 a STATUS_PARAM ) |
367 | 158142c2 | bellard | { |
368 | 158142c2 | bellard | #if defined(__arm__)
|
369 | 158142c2 | bellard | switch(STATUS(float_rounding_mode)) {
|
370 | 158142c2 | bellard | default:
|
371 | 158142c2 | bellard | case float_round_nearest_even:
|
372 | 158142c2 | bellard | asm("rndd %0, %1" : "=f" (a) : "f"(a)); |
373 | 158142c2 | bellard | break;
|
374 | 158142c2 | bellard | case float_round_down:
|
375 | 158142c2 | bellard | asm("rnddm %0, %1" : "=f" (a) : "f"(a)); |
376 | 158142c2 | bellard | break;
|
377 | 158142c2 | bellard | case float_round_up:
|
378 | 158142c2 | bellard | asm("rnddp %0, %1" : "=f" (a) : "f"(a)); |
379 | 158142c2 | bellard | break;
|
380 | 158142c2 | bellard | case float_round_to_zero:
|
381 | 158142c2 | bellard | asm("rnddz %0, %1" : "=f" (a) : "f"(a)); |
382 | 158142c2 | bellard | break;
|
383 | 158142c2 | bellard | } |
384 | 158142c2 | bellard | #else
|
385 | 158142c2 | bellard | return rint(a);
|
386 | 158142c2 | bellard | #endif
|
387 | 158142c2 | bellard | } |
388 | 158142c2 | bellard | |
389 | b109f9f8 | bellard | float64 float64_rem( float64 a, float64 b STATUS_PARAM) |
390 | b109f9f8 | bellard | { |
391 | b109f9f8 | bellard | return remainder(a, b);
|
392 | b109f9f8 | bellard | } |
393 | b109f9f8 | bellard | |
394 | 158142c2 | bellard | float64 float64_sqrt( float64 a STATUS_PARAM) |
395 | 158142c2 | bellard | { |
396 | 158142c2 | bellard | return sqrt(a);
|
397 | 158142c2 | bellard | } |
398 | 750afe93 | bellard | int float64_compare( float64 a, float64 b STATUS_PARAM )
|
399 | b109f9f8 | bellard | { |
400 | b109f9f8 | bellard | if (a < b) {
|
401 | 30e7a22e | aurel32 | return float_relation_less;
|
402 | b109f9f8 | bellard | } else if (a == b) { |
403 | 30e7a22e | aurel32 | return float_relation_equal;
|
404 | b109f9f8 | bellard | } else if (a > b) { |
405 | 30e7a22e | aurel32 | return float_relation_greater;
|
406 | b109f9f8 | bellard | } else {
|
407 | 30e7a22e | aurel32 | return float_relation_unordered;
|
408 | b109f9f8 | bellard | } |
409 | b109f9f8 | bellard | } |
410 | 750afe93 | bellard | int float64_compare_quiet( float64 a, float64 b STATUS_PARAM )
|
411 | b109f9f8 | bellard | { |
412 | b109f9f8 | bellard | if (isless(a, b)) {
|
413 | 30e7a22e | aurel32 | return float_relation_less;
|
414 | b109f9f8 | bellard | } else if (a == b) { |
415 | 30e7a22e | aurel32 | return float_relation_equal;
|
416 | b109f9f8 | bellard | } else if (isgreater(a, b)) { |
417 | 30e7a22e | aurel32 | return float_relation_greater;
|
418 | b109f9f8 | bellard | } else {
|
419 | 30e7a22e | aurel32 | return float_relation_unordered;
|
420 | b109f9f8 | bellard | } |
421 | b109f9f8 | bellard | } |
422 | 750afe93 | bellard | int float64_is_signaling_nan( float64 a1)
|
423 | 158142c2 | bellard | { |
424 | 158142c2 | bellard | float64u u; |
425 | 158142c2 | bellard | uint64_t a; |
426 | 158142c2 | bellard | u.f = a1; |
427 | 158142c2 | bellard | a = u.i; |
428 | 158142c2 | bellard | return
|
429 | 158142c2 | bellard | ( ( ( a>>51 ) & 0xFFF ) == 0xFFE ) |
430 | 158142c2 | bellard | && ( a & LIT64( 0x0007FFFFFFFFFFFF ) );
|
431 | 158142c2 | bellard | |
432 | 158142c2 | bellard | } |
433 | 158142c2 | bellard | |
434 | 750afe93 | bellard | int float64_is_nan( float64 a1 )
|
435 | e6e5906b | pbrook | { |
436 | e6e5906b | pbrook | float64u u; |
437 | e6e5906b | pbrook | uint64_t a; |
438 | e6e5906b | pbrook | u.f = a1; |
439 | e6e5906b | pbrook | a = u.i; |
440 | e6e5906b | pbrook | |
441 | 1b2ad2ec | aurel32 | return ( LIT64( 0xFFF0000000000000 ) < (bits64) ( a<<1 ) ); |
442 | e6e5906b | pbrook | |
443 | e6e5906b | pbrook | } |
444 | e6e5906b | pbrook | |
445 | 158142c2 | bellard | #ifdef FLOATX80
|
446 | 158142c2 | bellard | |
447 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
448 | 158142c2 | bellard | | Software IEC/IEEE extended double-precision conversion routines.
|
449 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
450 | 158142c2 | bellard | int floatx80_to_int32( floatx80 a STATUS_PARAM)
|
451 | 158142c2 | bellard | { |
452 | 1b2b0af5 | bellard | return long_to_int32(lrintl(a));
|
453 | 158142c2 | bellard | } |
454 | 158142c2 | bellard | int floatx80_to_int32_round_to_zero( floatx80 a STATUS_PARAM)
|
455 | 158142c2 | bellard | { |
456 | 158142c2 | bellard | return (int)a; |
457 | 158142c2 | bellard | } |
458 | 158142c2 | bellard | int64_t floatx80_to_int64( floatx80 a STATUS_PARAM) |
459 | 158142c2 | bellard | { |
460 | 158142c2 | bellard | return llrintl(a);
|
461 | 158142c2 | bellard | } |
462 | 158142c2 | bellard | int64_t floatx80_to_int64_round_to_zero( floatx80 a STATUS_PARAM) |
463 | 158142c2 | bellard | { |
464 | 158142c2 | bellard | return (int64_t)a;
|
465 | 158142c2 | bellard | } |
466 | 158142c2 | bellard | float32 floatx80_to_float32( floatx80 a STATUS_PARAM) |
467 | 158142c2 | bellard | { |
468 | 158142c2 | bellard | return a;
|
469 | 158142c2 | bellard | } |
470 | 158142c2 | bellard | float64 floatx80_to_float64( floatx80 a STATUS_PARAM) |
471 | 158142c2 | bellard | { |
472 | 158142c2 | bellard | return a;
|
473 | 158142c2 | bellard | } |
474 | 158142c2 | bellard | |
475 | 158142c2 | bellard | /*----------------------------------------------------------------------------
|
476 | 158142c2 | bellard | | Software IEC/IEEE extended double-precision operations.
|
477 | 158142c2 | bellard | *----------------------------------------------------------------------------*/
|
478 | 158142c2 | bellard | floatx80 floatx80_round_to_int( floatx80 a STATUS_PARAM) |
479 | 158142c2 | bellard | { |
480 | 158142c2 | bellard | return rintl(a);
|
481 | 158142c2 | bellard | } |
482 | b109f9f8 | bellard | floatx80 floatx80_rem( floatx80 a, floatx80 b STATUS_PARAM) |
483 | b109f9f8 | bellard | { |
484 | b109f9f8 | bellard | return remainderl(a, b);
|
485 | b109f9f8 | bellard | } |
486 | 158142c2 | bellard | floatx80 floatx80_sqrt( floatx80 a STATUS_PARAM) |
487 | 158142c2 | bellard | { |
488 | 158142c2 | bellard | return sqrtl(a);
|
489 | 158142c2 | bellard | } |
490 | 750afe93 | bellard | int floatx80_compare( floatx80 a, floatx80 b STATUS_PARAM )
|
491 | b109f9f8 | bellard | { |
492 | b109f9f8 | bellard | if (a < b) {
|
493 | 30e7a22e | aurel32 | return float_relation_less;
|
494 | b109f9f8 | bellard | } else if (a == b) { |
495 | 30e7a22e | aurel32 | return float_relation_equal;
|
496 | b109f9f8 | bellard | } else if (a > b) { |
497 | 30e7a22e | aurel32 | return float_relation_greater;
|
498 | b109f9f8 | bellard | } else {
|
499 | 30e7a22e | aurel32 | return float_relation_unordered;
|
500 | b109f9f8 | bellard | } |
501 | b109f9f8 | bellard | } |
502 | 750afe93 | bellard | int floatx80_compare_quiet( floatx80 a, floatx80 b STATUS_PARAM )
|
503 | b109f9f8 | bellard | { |
504 | b109f9f8 | bellard | if (isless(a, b)) {
|
505 | 30e7a22e | aurel32 | return float_relation_less;
|
506 | b109f9f8 | bellard | } else if (a == b) { |
507 | 30e7a22e | aurel32 | return float_relation_equal;
|
508 | b109f9f8 | bellard | } else if (isgreater(a, b)) { |
509 | 30e7a22e | aurel32 | return float_relation_greater;
|
510 | b109f9f8 | bellard | } else {
|
511 | 30e7a22e | aurel32 | return float_relation_unordered;
|
512 | b109f9f8 | bellard | } |
513 | b109f9f8 | bellard | } |
514 | 750afe93 | bellard | int floatx80_is_signaling_nan( floatx80 a1)
|
515 | 158142c2 | bellard | { |
516 | 158142c2 | bellard | floatx80u u; |
517 | 1b2ad2ec | aurel32 | uint64_t aLow; |
518 | 1b2ad2ec | aurel32 | u.f = a1; |
519 | 1b2ad2ec | aurel32 | |
520 | 1b2ad2ec | aurel32 | aLow = u.i.low & ~ LIT64( 0x4000000000000000 );
|
521 | 1b2ad2ec | aurel32 | return
|
522 | 1b2ad2ec | aurel32 | ( ( u.i.high & 0x7FFF ) == 0x7FFF ) |
523 | 1b2ad2ec | aurel32 | && (bits64) ( aLow<<1 )
|
524 | 1b2ad2ec | aurel32 | && ( u.i.low == aLow ); |
525 | 1b2ad2ec | aurel32 | } |
526 | 1b2ad2ec | aurel32 | |
527 | 1b2ad2ec | aurel32 | int floatx80_is_nan( floatx80 a1 )
|
528 | 1b2ad2ec | aurel32 | { |
529 | 1b2ad2ec | aurel32 | floatx80u u; |
530 | 158142c2 | bellard | u.f = a1; |
531 | 158142c2 | bellard | return ( ( u.i.high & 0x7FFF ) == 0x7FFF ) && (bits64) ( u.i.low<<1 ); |
532 | 158142c2 | bellard | } |
533 | 158142c2 | bellard | |
534 | 158142c2 | bellard | #endif |