Statistics
| Branch: | Revision:

root / fpu / softfloat-native.c @ 927e3a4e

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