Statistics
| Branch: | Revision:

root / fpu / softfloat-native.h @ 06ea77bc

History | View | Annotate | Download (14.8 kB)

1 158142c2 bellard
/* Native implementation of soft float functions */
2 158142c2 bellard
#include <math.h>
3 38cfa06c bellard
4 a167ba50 Aurelien Jarno
#if (defined(CONFIG_BSD) && !defined(__APPLE__) && !defined(__GLIBC__)) \
5 a167ba50 Aurelien Jarno
    || defined(CONFIG_SOLARIS)
6 158142c2 bellard
#include <ieeefp.h>
7 38cfa06c bellard
#define fabsf(f) ((float)fabs(f))
8 158142c2 bellard
#else
9 158142c2 bellard
#include <fenv.h>
10 158142c2 bellard
#endif
11 38cfa06c bellard
12 d07cca02 blueswir1
#if defined(__OpenBSD__) || defined(__NetBSD__)
13 7c2a9d09 blueswir1
#include <sys/param.h>
14 7c2a9d09 blueswir1
#endif
15 7c2a9d09 blueswir1
16 38cfa06c bellard
/*
17 38cfa06c bellard
 * Define some C99-7.12.3 classification macros and
18 38cfa06c bellard
 *        some C99-.12.4 for Solaris systems OS less than 10,
19 38cfa06c bellard
 *        or Solaris 10 systems running GCC 3.x or less.
20 38cfa06c bellard
 *   Solaris 10 with GCC4 does not need these macros as they
21 38cfa06c bellard
 *   are defined in <iso/math_c99.h> with a compiler directive
22 38cfa06c bellard
 */
23 dfe5fff3 Juan Quintela
#if defined(CONFIG_SOLARIS) && \
24 dfe5fff3 Juan Quintela
           ((CONFIG_SOLARIS_VERSION <= 9 ) || \
25 be45f068 Andreas Färber
           ((CONFIG_SOLARIS_VERSION == 10) && (__GNUC__ < 4))) \
26 7c2a9d09 blueswir1
    || (defined(__OpenBSD__) && (OpenBSD < 200811))
27 38cfa06c bellard
/*
28 38cfa06c bellard
 * C99 7.12.3 classification macros
29 38cfa06c bellard
 * and
30 38cfa06c bellard
 * C99 7.12.14 comparison macros
31 38cfa06c bellard
 *
32 38cfa06c bellard
 * ... do not work on Solaris 10 using GNU CC 3.4.x.
33 38cfa06c bellard
 * Try to workaround the missing / broken C99 math macros.
34 38cfa06c bellard
 */
35 128ab2ff blueswir1
#if defined(__OpenBSD__)
36 128ab2ff blueswir1
#define unordered(x, y) (isnan(x) || isnan(y))
37 128ab2ff blueswir1
#endif
38 38cfa06c bellard
39 d07cca02 blueswir1
#ifdef __NetBSD__
40 d07cca02 blueswir1
#ifndef isgreater
41 d07cca02 blueswir1
#define isgreater(x, y)                __builtin_isgreater(x, y)
42 d07cca02 blueswir1
#endif
43 d07cca02 blueswir1
#ifndef isgreaterequal
44 d07cca02 blueswir1
#define isgreaterequal(x, y)        __builtin_isgreaterequal(x, y)
45 d07cca02 blueswir1
#endif
46 d07cca02 blueswir1
#ifndef isless
47 d07cca02 blueswir1
#define isless(x, y)                __builtin_isless(x, y)
48 d07cca02 blueswir1
#endif
49 d07cca02 blueswir1
#ifndef islessequal
50 d07cca02 blueswir1
#define islessequal(x, y)        __builtin_islessequal(x, y)
51 d07cca02 blueswir1
#endif
52 d07cca02 blueswir1
#ifndef isunordered
53 d07cca02 blueswir1
#define isunordered(x, y)        __builtin_isunordered(x, y)
54 d07cca02 blueswir1
#endif
55 d07cca02 blueswir1
#endif
56 d07cca02 blueswir1
57 d07cca02 blueswir1
58 38cfa06c bellard
#define isnormal(x)             (fpclass(x) >= FP_NZERO)
59 38cfa06c bellard
#define isgreater(x, y)         ((!unordered(x, y)) && ((x) > (y)))
60 38cfa06c bellard
#define isgreaterequal(x, y)    ((!unordered(x, y)) && ((x) >= (y)))
61 38cfa06c bellard
#define isless(x, y)            ((!unordered(x, y)) && ((x) < (y)))
62 38cfa06c bellard
#define islessequal(x, y)       ((!unordered(x, y)) && ((x) <= (y)))
63 38cfa06c bellard
#define isunordered(x,y)        unordered(x, y)
64 ec530c81 bellard
#endif
65 158142c2 bellard
66 75b5a697 Juan Quintela
#if defined(__sun__) && !defined(CONFIG_NEEDS_LIBSUNMATH)
67 c94655b0 ths
68 c94655b0 ths
#ifndef isnan
69 c94655b0 ths
# define isnan(x) \
70 c94655b0 ths
    (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
71 c94655b0 ths
     : sizeof (x) == sizeof (double) ? isnan_d (x) \
72 c94655b0 ths
     : isnan_f (x))
73 c94655b0 ths
static inline int isnan_f  (float       x) { return x != x; }
74 c94655b0 ths
static inline int isnan_d  (double      x) { return x != x; }
75 c94655b0 ths
static inline int isnan_ld (long double x) { return x != x; }
76 c94655b0 ths
#endif
77 c94655b0 ths
78 c94655b0 ths
#ifndef isinf
79 c94655b0 ths
# define isinf(x) \
80 c94655b0 ths
    (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
81 c94655b0 ths
     : sizeof (x) == sizeof (double) ? isinf_d (x) \
82 c94655b0 ths
     : isinf_f (x))
83 c94655b0 ths
static inline int isinf_f  (float       x) { return isnan (x - x); }
84 c94655b0 ths
static inline int isinf_d  (double      x) { return isnan (x - x); }
85 c94655b0 ths
static inline int isinf_ld (long double x) { return isnan (x - x); }
86 c94655b0 ths
#endif
87 c94655b0 ths
#endif
88 c94655b0 ths
89 158142c2 bellard
typedef float float32;
90 158142c2 bellard
typedef double float64;
91 158142c2 bellard
#ifdef FLOATX80
92 158142c2 bellard
typedef long double floatx80;
93 158142c2 bellard
#endif
94 158142c2 bellard
95 158142c2 bellard
typedef union {
96 158142c2 bellard
    float32 f;
97 158142c2 bellard
    uint32_t i;
98 158142c2 bellard
} float32u;
99 158142c2 bellard
typedef union {
100 158142c2 bellard
    float64 f;
101 158142c2 bellard
    uint64_t i;
102 158142c2 bellard
} float64u;
103 158142c2 bellard
#ifdef FLOATX80
104 158142c2 bellard
typedef union {
105 158142c2 bellard
    floatx80 f;
106 158142c2 bellard
    struct {
107 158142c2 bellard
        uint64_t low;
108 158142c2 bellard
        uint16_t high;
109 158142c2 bellard
    } i;
110 158142c2 bellard
} floatx80u;
111 158142c2 bellard
#endif
112 158142c2 bellard
113 158142c2 bellard
/*----------------------------------------------------------------------------
114 158142c2 bellard
| Software IEC/IEEE floating-point rounding mode.
115 158142c2 bellard
*----------------------------------------------------------------------------*/
116 a167ba50 Aurelien Jarno
#if (defined(CONFIG_BSD) && !defined(__APPLE__) && !defined(__GLIBC__)) \
117 a167ba50 Aurelien Jarno
    || defined(CONFIG_SOLARIS)
118 128ab2ff blueswir1
#if defined(__OpenBSD__)
119 128ab2ff blueswir1
#define FE_RM FP_RM
120 128ab2ff blueswir1
#define FE_RP FP_RP
121 128ab2ff blueswir1
#define FE_RZ FP_RZ
122 128ab2ff blueswir1
#endif
123 158142c2 bellard
enum {
124 158142c2 bellard
    float_round_nearest_even = FP_RN,
125 7918bf47 pbrook
    float_round_down         = FP_RM,
126 7918bf47 pbrook
    float_round_up           = FP_RP,
127 7918bf47 pbrook
    float_round_to_zero      = FP_RZ
128 158142c2 bellard
};
129 158142c2 bellard
#else
130 158142c2 bellard
enum {
131 158142c2 bellard
    float_round_nearest_even = FE_TONEAREST,
132 158142c2 bellard
    float_round_down         = FE_DOWNWARD,
133 158142c2 bellard
    float_round_up           = FE_UPWARD,
134 158142c2 bellard
    float_round_to_zero      = FE_TOWARDZERO
135 158142c2 bellard
};
136 158142c2 bellard
#endif
137 158142c2 bellard
138 158142c2 bellard
typedef struct float_status {
139 e872aa81 aurel32
    int float_rounding_mode;
140 158142c2 bellard
#ifdef FLOATX80
141 e872aa81 aurel32
    int floatx80_rounding_precision;
142 158142c2 bellard
#endif
143 158142c2 bellard
} float_status;
144 158142c2 bellard
145 158142c2 bellard
void set_float_rounding_mode(int val STATUS_PARAM);
146 158142c2 bellard
#ifdef FLOATX80
147 158142c2 bellard
void set_floatx80_rounding_precision(int val STATUS_PARAM);
148 158142c2 bellard
#endif
149 158142c2 bellard
150 158142c2 bellard
/*----------------------------------------------------------------------------
151 158142c2 bellard
| Software IEC/IEEE integer-to-floating-point conversion routines.
152 158142c2 bellard
*----------------------------------------------------------------------------*/
153 158142c2 bellard
float32 int32_to_float32( int STATUS_PARAM);
154 75d62a58 j_mayer
float32 uint32_to_float32( unsigned int STATUS_PARAM);
155 158142c2 bellard
float64 int32_to_float64( int STATUS_PARAM);
156 75d62a58 j_mayer
float64 uint32_to_float64( unsigned int STATUS_PARAM);
157 158142c2 bellard
#ifdef FLOATX80
158 158142c2 bellard
floatx80 int32_to_floatx80( int STATUS_PARAM);
159 158142c2 bellard
#endif
160 158142c2 bellard
#ifdef FLOAT128
161 158142c2 bellard
float128 int32_to_float128( int STATUS_PARAM);
162 158142c2 bellard
#endif
163 158142c2 bellard
float32 int64_to_float32( int64_t STATUS_PARAM);
164 75d62a58 j_mayer
float32 uint64_to_float32( uint64_t STATUS_PARAM);
165 158142c2 bellard
float64 int64_to_float64( int64_t STATUS_PARAM);
166 75d62a58 j_mayer
float64 uint64_to_float64( uint64_t v STATUS_PARAM);
167 158142c2 bellard
#ifdef FLOATX80
168 158142c2 bellard
floatx80 int64_to_floatx80( int64_t STATUS_PARAM);
169 158142c2 bellard
#endif
170 158142c2 bellard
#ifdef FLOAT128
171 158142c2 bellard
float128 int64_to_float128( int64_t STATUS_PARAM);
172 158142c2 bellard
#endif
173 158142c2 bellard
174 158142c2 bellard
/*----------------------------------------------------------------------------
175 d2b1027d Aurelien Jarno
| Software IEC/IEEE single-precision conversion constants.
176 d2b1027d Aurelien Jarno
*----------------------------------------------------------------------------*/
177 d2b1027d Aurelien Jarno
#define float32_zero (0.0)
178 d2b1027d Aurelien Jarno
#define float32_one (1.0)
179 d2b1027d Aurelien Jarno
#define float32_ln2 (0.6931471)
180 d2b1027d Aurelien Jarno
#define float32_pi (3.1415926)
181 d2b1027d Aurelien Jarno
#define float32_half (0.5)
182 d2b1027d Aurelien Jarno
183 d2b1027d Aurelien Jarno
/*----------------------------------------------------------------------------
184 158142c2 bellard
| Software IEC/IEEE single-precision conversion routines.
185 158142c2 bellard
*----------------------------------------------------------------------------*/
186 158142c2 bellard
int float32_to_int32( float32  STATUS_PARAM);
187 158142c2 bellard
int float32_to_int32_round_to_zero( float32  STATUS_PARAM);
188 75d62a58 j_mayer
unsigned int float32_to_uint32( float32 a STATUS_PARAM);
189 75d62a58 j_mayer
unsigned int float32_to_uint32_round_to_zero( float32 a STATUS_PARAM);
190 158142c2 bellard
int64_t float32_to_int64( float32  STATUS_PARAM);
191 158142c2 bellard
int64_t float32_to_int64_round_to_zero( float32  STATUS_PARAM);
192 158142c2 bellard
float64 float32_to_float64( float32  STATUS_PARAM);
193 158142c2 bellard
#ifdef FLOATX80
194 158142c2 bellard
floatx80 float32_to_floatx80( float32  STATUS_PARAM);
195 158142c2 bellard
#endif
196 158142c2 bellard
#ifdef FLOAT128
197 158142c2 bellard
float128 float32_to_float128( float32  STATUS_PARAM);
198 158142c2 bellard
#endif
199 158142c2 bellard
200 158142c2 bellard
/*----------------------------------------------------------------------------
201 158142c2 bellard
| Software IEC/IEEE single-precision operations.
202 158142c2 bellard
*----------------------------------------------------------------------------*/
203 158142c2 bellard
float32 float32_round_to_int( float32  STATUS_PARAM);
204 158142c2 bellard
INLINE float32 float32_add( float32 a, float32 b STATUS_PARAM)
205 158142c2 bellard
{
206 158142c2 bellard
    return a + b;
207 158142c2 bellard
}
208 158142c2 bellard
INLINE float32 float32_sub( float32 a, float32 b STATUS_PARAM)
209 158142c2 bellard
{
210 158142c2 bellard
    return a - b;
211 158142c2 bellard
}
212 158142c2 bellard
INLINE float32 float32_mul( float32 a, float32 b STATUS_PARAM)
213 158142c2 bellard
{
214 158142c2 bellard
    return a * b;
215 158142c2 bellard
}
216 158142c2 bellard
INLINE float32 float32_div( float32 a, float32 b STATUS_PARAM)
217 158142c2 bellard
{
218 158142c2 bellard
    return a / b;
219 158142c2 bellard
}
220 158142c2 bellard
float32 float32_rem( float32, float32  STATUS_PARAM);
221 158142c2 bellard
float32 float32_sqrt( float32  STATUS_PARAM);
222 211315fb Aurelien Jarno
INLINE int float32_eq_quiet( float32 a, float32 b STATUS_PARAM)
223 158142c2 bellard
{
224 158142c2 bellard
    return a == b;
225 158142c2 bellard
}
226 750afe93 bellard
INLINE int float32_le( float32 a, float32 b STATUS_PARAM)
227 158142c2 bellard
{
228 158142c2 bellard
    return a <= b;
229 158142c2 bellard
}
230 750afe93 bellard
INLINE int float32_lt( float32 a, float32 b STATUS_PARAM)
231 158142c2 bellard
{
232 158142c2 bellard
    return a < b;
233 158142c2 bellard
}
234 2657d0ff Aurelien Jarno
INLINE int float32_eq( float32 a, float32 b STATUS_PARAM)
235 158142c2 bellard
{
236 b109f9f8 bellard
    return a <= b && a >= b;
237 158142c2 bellard
}
238 750afe93 bellard
INLINE int float32_le_quiet( float32 a, float32 b STATUS_PARAM)
239 158142c2 bellard
{
240 158142c2 bellard
    return islessequal(a, b);
241 158142c2 bellard
}
242 750afe93 bellard
INLINE int float32_lt_quiet( float32 a, float32 b STATUS_PARAM)
243 158142c2 bellard
{
244 158142c2 bellard
    return isless(a, b);
245 158142c2 bellard
}
246 750afe93 bellard
INLINE int float32_unordered( float32 a, float32 b STATUS_PARAM)
247 b109f9f8 bellard
{
248 b109f9f8 bellard
    return isunordered(a, b);
249 b4a0ef79 Aurelien Jarno
}
250 b4a0ef79 Aurelien Jarno
INLINE int float32_unordered_quiet( float32 a, float32 b STATUS_PARAM)
251 b4a0ef79 Aurelien Jarno
{
252 b4a0ef79 Aurelien Jarno
    return isunordered(a, b);
253 b109f9f8 bellard
}
254 750afe93 bellard
int float32_compare( float32, float32 STATUS_PARAM );
255 750afe93 bellard
int float32_compare_quiet( float32, float32 STATUS_PARAM );
256 750afe93 bellard
int float32_is_signaling_nan( float32 );
257 18569871 Peter Maydell
int float32_is_quiet_nan( float32 );
258 4cc5383f Aurelien Jarno
int float32_is_any_nan( float32 );
259 158142c2 bellard
260 158142c2 bellard
INLINE float32 float32_abs(float32 a)
261 158142c2 bellard
{
262 158142c2 bellard
    return fabsf(a);
263 158142c2 bellard
}
264 158142c2 bellard
265 158142c2 bellard
INLINE float32 float32_chs(float32 a)
266 158142c2 bellard
{
267 158142c2 bellard
    return -a;
268 158142c2 bellard
}
269 158142c2 bellard
270 c52ab6f5 aurel32
INLINE float32 float32_is_infinity(float32 a)
271 c52ab6f5 aurel32
{
272 c52ab6f5 aurel32
    return fpclassify(a) == FP_INFINITE;
273 c52ab6f5 aurel32
}
274 c52ab6f5 aurel32
275 c52ab6f5 aurel32
INLINE float32 float32_is_neg(float32 a)
276 c52ab6f5 aurel32
{
277 8d6c92b6 aurel32
    float32u u;
278 8d6c92b6 aurel32
    u.f = a;
279 8d6c92b6 aurel32
    return u.i >> 31;
280 c52ab6f5 aurel32
}
281 c52ab6f5 aurel32
282 c52ab6f5 aurel32
INLINE float32 float32_is_zero(float32 a)
283 c52ab6f5 aurel32
{
284 c52ab6f5 aurel32
    return fpclassify(a) == FP_ZERO;
285 c52ab6f5 aurel32
}
286 c52ab6f5 aurel32
287 d6882cf0 Aurelien Jarno
INLINE float32 float32_scalbn(float32 a, int n STATUS_PARAM)
288 9ee6e8bb pbrook
{
289 9ee6e8bb pbrook
    return scalbnf(a, n);
290 9ee6e8bb pbrook
}
291 9ee6e8bb pbrook
292 158142c2 bellard
/*----------------------------------------------------------------------------
293 d2b1027d Aurelien Jarno
| Software IEC/IEEE double-precision conversion constants.
294 d2b1027d Aurelien Jarno
*----------------------------------------------------------------------------*/
295 d2b1027d Aurelien Jarno
#define float64_zero (0.0)
296 d2b1027d Aurelien Jarno
#define float64_one (1.0)
297 d2b1027d Aurelien Jarno
#define float64_ln2 (0.693147180559945)
298 d2b1027d Aurelien Jarno
#define float64_pi (3.141592653589793)
299 d2b1027d Aurelien Jarno
#define float64_half (0.5)
300 d2b1027d Aurelien Jarno
301 d2b1027d Aurelien Jarno
/*----------------------------------------------------------------------------
302 158142c2 bellard
| Software IEC/IEEE double-precision conversion routines.
303 158142c2 bellard
*----------------------------------------------------------------------------*/
304 158142c2 bellard
int float64_to_int32( float64 STATUS_PARAM );
305 158142c2 bellard
int float64_to_int32_round_to_zero( float64 STATUS_PARAM );
306 75d62a58 j_mayer
unsigned int float64_to_uint32( float64 STATUS_PARAM );
307 75d62a58 j_mayer
unsigned int float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
308 158142c2 bellard
int64_t float64_to_int64( float64 STATUS_PARAM );
309 158142c2 bellard
int64_t float64_to_int64_round_to_zero( float64 STATUS_PARAM );
310 75d62a58 j_mayer
uint64_t float64_to_uint64( float64 STATUS_PARAM );
311 75d62a58 j_mayer
uint64_t float64_to_uint64_round_to_zero( float64 STATUS_PARAM );
312 158142c2 bellard
float32 float64_to_float32( float64 STATUS_PARAM );
313 158142c2 bellard
#ifdef FLOATX80
314 158142c2 bellard
floatx80 float64_to_floatx80( float64 STATUS_PARAM );
315 158142c2 bellard
#endif
316 158142c2 bellard
#ifdef FLOAT128
317 158142c2 bellard
float128 float64_to_float128( float64 STATUS_PARAM );
318 158142c2 bellard
#endif
319 158142c2 bellard
320 158142c2 bellard
/*----------------------------------------------------------------------------
321 158142c2 bellard
| Software IEC/IEEE double-precision operations.
322 158142c2 bellard
*----------------------------------------------------------------------------*/
323 158142c2 bellard
float64 float64_round_to_int( float64 STATUS_PARAM );
324 e6e5906b pbrook
float64 float64_trunc_to_int( float64 STATUS_PARAM );
325 158142c2 bellard
INLINE float64 float64_add( float64 a, float64 b STATUS_PARAM)
326 158142c2 bellard
{
327 158142c2 bellard
    return a + b;
328 158142c2 bellard
}
329 158142c2 bellard
INLINE float64 float64_sub( float64 a, float64 b STATUS_PARAM)
330 158142c2 bellard
{
331 158142c2 bellard
    return a - b;
332 158142c2 bellard
}
333 158142c2 bellard
INLINE float64 float64_mul( float64 a, float64 b STATUS_PARAM)
334 158142c2 bellard
{
335 158142c2 bellard
    return a * b;
336 158142c2 bellard
}
337 158142c2 bellard
INLINE float64 float64_div( float64 a, float64 b STATUS_PARAM)
338 158142c2 bellard
{
339 158142c2 bellard
    return a / b;
340 158142c2 bellard
}
341 158142c2 bellard
float64 float64_rem( float64, float64 STATUS_PARAM );
342 158142c2 bellard
float64 float64_sqrt( float64 STATUS_PARAM );
343 211315fb Aurelien Jarno
INLINE int float64_eq_quiet( float64 a, float64 b STATUS_PARAM)
344 158142c2 bellard
{
345 158142c2 bellard
    return a == b;
346 158142c2 bellard
}
347 750afe93 bellard
INLINE int float64_le( float64 a, float64 b STATUS_PARAM)
348 158142c2 bellard
{
349 158142c2 bellard
    return a <= b;
350 158142c2 bellard
}
351 750afe93 bellard
INLINE int float64_lt( float64 a, float64 b STATUS_PARAM)
352 158142c2 bellard
{
353 158142c2 bellard
    return a < b;
354 158142c2 bellard
}
355 2657d0ff Aurelien Jarno
INLINE int float64_eq( float64 a, float64 b STATUS_PARAM)
356 158142c2 bellard
{
357 b109f9f8 bellard
    return a <= b && a >= b;
358 158142c2 bellard
}
359 750afe93 bellard
INLINE int float64_le_quiet( float64 a, float64 b STATUS_PARAM)
360 158142c2 bellard
{
361 158142c2 bellard
    return islessequal(a, b);
362 158142c2 bellard
}
363 750afe93 bellard
INLINE int float64_lt_quiet( float64 a, float64 b STATUS_PARAM)
364 158142c2 bellard
{
365 158142c2 bellard
    return isless(a, b);
366 158142c2 bellard
367 158142c2 bellard
}
368 750afe93 bellard
INLINE int float64_unordered( float64 a, float64 b STATUS_PARAM)
369 b109f9f8 bellard
{
370 b109f9f8 bellard
    return isunordered(a, b);
371 b4a0ef79 Aurelien Jarno
}
372 b4a0ef79 Aurelien Jarno
INLINE int float64_unordered_quiet( float64 a, float64 b STATUS_PARAM)
373 b4a0ef79 Aurelien Jarno
{
374 b4a0ef79 Aurelien Jarno
    return isunordered(a, b);
375 b109f9f8 bellard
}
376 750afe93 bellard
int float64_compare( float64, float64 STATUS_PARAM );
377 750afe93 bellard
int float64_compare_quiet( float64, float64 STATUS_PARAM );
378 750afe93 bellard
int float64_is_signaling_nan( float64 );
379 4cc5383f Aurelien Jarno
int float64_is_any_nan( float64 );
380 18569871 Peter Maydell
int float64_is_quiet_nan( float64 );
381 158142c2 bellard
382 158142c2 bellard
INLINE float64 float64_abs(float64 a)
383 158142c2 bellard
{
384 158142c2 bellard
    return fabs(a);
385 158142c2 bellard
}
386 158142c2 bellard
387 158142c2 bellard
INLINE float64 float64_chs(float64 a)
388 158142c2 bellard
{
389 158142c2 bellard
    return -a;
390 158142c2 bellard
}
391 158142c2 bellard
392 c52ab6f5 aurel32
INLINE float64 float64_is_infinity(float64 a)
393 c52ab6f5 aurel32
{
394 c52ab6f5 aurel32
    return fpclassify(a) == FP_INFINITE;
395 c52ab6f5 aurel32
}
396 c52ab6f5 aurel32
397 c52ab6f5 aurel32
INLINE float64 float64_is_neg(float64 a)
398 c52ab6f5 aurel32
{
399 8d6c92b6 aurel32
    float64u u;
400 8d6c92b6 aurel32
    u.f = a;
401 8d6c92b6 aurel32
    return u.i >> 63;
402 c52ab6f5 aurel32
}
403 c52ab6f5 aurel32
404 c52ab6f5 aurel32
INLINE float64 float64_is_zero(float64 a)
405 c52ab6f5 aurel32
{
406 c52ab6f5 aurel32
    return fpclassify(a) == FP_ZERO;
407 c52ab6f5 aurel32
}
408 c52ab6f5 aurel32
409 d6882cf0 Aurelien Jarno
INLINE float64 float64_scalbn(float64 a, int n STATUS_PARAM)
410 9ee6e8bb pbrook
{
411 9ee6e8bb pbrook
    return scalbn(a, n);
412 9ee6e8bb pbrook
}
413 9ee6e8bb pbrook
414 158142c2 bellard
#ifdef FLOATX80
415 158142c2 bellard
416 158142c2 bellard
/*----------------------------------------------------------------------------
417 d2b1027d Aurelien Jarno
| Software IEC/IEEE extended double-precision conversion constants.
418 d2b1027d Aurelien Jarno
*----------------------------------------------------------------------------*/
419 d2b1027d Aurelien Jarno
#define floatx80_zero (0.0L)
420 d2b1027d Aurelien Jarno
#define floatx80_one (1.0L)
421 d2b1027d Aurelien Jarno
#define floatx80_ln2 (0.69314718055994530943L)
422 d2b1027d Aurelien Jarno
#define floatx80_pi (3.14159265358979323851L)
423 d2b1027d Aurelien Jarno
#define floatx80_half (0.5L)
424 d2b1027d Aurelien Jarno
425 d2b1027d Aurelien Jarno
/*----------------------------------------------------------------------------
426 158142c2 bellard
| Software IEC/IEEE extended double-precision conversion routines.
427 158142c2 bellard
*----------------------------------------------------------------------------*/
428 158142c2 bellard
int floatx80_to_int32( floatx80 STATUS_PARAM );
429 158142c2 bellard
int floatx80_to_int32_round_to_zero( floatx80 STATUS_PARAM );
430 158142c2 bellard
int64_t floatx80_to_int64( floatx80 STATUS_PARAM);
431 158142c2 bellard
int64_t floatx80_to_int64_round_to_zero( floatx80 STATUS_PARAM);
432 158142c2 bellard
float32 floatx80_to_float32( floatx80 STATUS_PARAM );
433 158142c2 bellard
float64 floatx80_to_float64( floatx80 STATUS_PARAM );
434 158142c2 bellard
#ifdef FLOAT128
435 158142c2 bellard
float128 floatx80_to_float128( floatx80 STATUS_PARAM );
436 158142c2 bellard
#endif
437 158142c2 bellard
438 158142c2 bellard
/*----------------------------------------------------------------------------
439 158142c2 bellard
| Software IEC/IEEE extended double-precision operations.
440 158142c2 bellard
*----------------------------------------------------------------------------*/
441 158142c2 bellard
floatx80 floatx80_round_to_int( floatx80 STATUS_PARAM );
442 158142c2 bellard
INLINE floatx80 floatx80_add( floatx80 a, floatx80 b STATUS_PARAM)
443 158142c2 bellard
{
444 158142c2 bellard
    return a + b;
445 158142c2 bellard
}
446 158142c2 bellard
INLINE floatx80 floatx80_sub( floatx80 a, floatx80 b STATUS_PARAM)
447 158142c2 bellard
{
448 158142c2 bellard
    return a - b;
449 158142c2 bellard
}
450 158142c2 bellard
INLINE floatx80 floatx80_mul( floatx80 a, floatx80 b STATUS_PARAM)
451 158142c2 bellard
{
452 158142c2 bellard
    return a * b;
453 158142c2 bellard
}
454 158142c2 bellard
INLINE floatx80 floatx80_div( floatx80 a, floatx80 b STATUS_PARAM)
455 158142c2 bellard
{
456 158142c2 bellard
    return a / b;
457 158142c2 bellard
}
458 158142c2 bellard
floatx80 floatx80_rem( floatx80, floatx80 STATUS_PARAM );
459 158142c2 bellard
floatx80 floatx80_sqrt( floatx80 STATUS_PARAM );
460 211315fb Aurelien Jarno
INLINE int floatx80_eq_quiet( floatx80 a, floatx80 b STATUS_PARAM)
461 158142c2 bellard
{
462 158142c2 bellard
    return a == b;
463 158142c2 bellard
}
464 750afe93 bellard
INLINE int floatx80_le( floatx80 a, floatx80 b STATUS_PARAM)
465 158142c2 bellard
{
466 158142c2 bellard
    return a <= b;
467 158142c2 bellard
}
468 750afe93 bellard
INLINE int floatx80_lt( floatx80 a, floatx80 b STATUS_PARAM)
469 158142c2 bellard
{
470 158142c2 bellard
    return a < b;
471 158142c2 bellard
}
472 2657d0ff Aurelien Jarno
INLINE int floatx80_eq( floatx80 a, floatx80 b STATUS_PARAM)
473 158142c2 bellard
{
474 b109f9f8 bellard
    return a <= b && a >= b;
475 158142c2 bellard
}
476 750afe93 bellard
INLINE int floatx80_le_quiet( floatx80 a, floatx80 b STATUS_PARAM)
477 158142c2 bellard
{
478 158142c2 bellard
    return islessequal(a, b);
479 158142c2 bellard
}
480 750afe93 bellard
INLINE int floatx80_lt_quiet( floatx80 a, floatx80 b STATUS_PARAM)
481 158142c2 bellard
{
482 158142c2 bellard
    return isless(a, b);
483 158142c2 bellard
484 158142c2 bellard
}
485 750afe93 bellard
INLINE int floatx80_unordered( floatx80 a, floatx80 b STATUS_PARAM)
486 b109f9f8 bellard
{
487 b109f9f8 bellard
    return isunordered(a, b);
488 b4a0ef79 Aurelien Jarno
}
489 b4a0ef79 Aurelien Jarno
INLINE int floatx80_unordered_quiet( floatx80 a, floatx80 b STATUS_PARAM)
490 b4a0ef79 Aurelien Jarno
{
491 b4a0ef79 Aurelien Jarno
    return isunordered(a, b);
492 b109f9f8 bellard
}
493 750afe93 bellard
int floatx80_compare( floatx80, floatx80 STATUS_PARAM );
494 750afe93 bellard
int floatx80_compare_quiet( floatx80, floatx80 STATUS_PARAM );
495 750afe93 bellard
int floatx80_is_signaling_nan( floatx80 );
496 18569871 Peter Maydell
int floatx80_is_quiet_nan( floatx80 );
497 4cc5383f Aurelien Jarno
int floatx80_is_any_nan( floatx80 );
498 158142c2 bellard
499 158142c2 bellard
INLINE floatx80 floatx80_abs(floatx80 a)
500 158142c2 bellard
{
501 158142c2 bellard
    return fabsl(a);
502 158142c2 bellard
}
503 158142c2 bellard
504 158142c2 bellard
INLINE floatx80 floatx80_chs(floatx80 a)
505 158142c2 bellard
{
506 158142c2 bellard
    return -a;
507 158142c2 bellard
}
508 9ee6e8bb pbrook
509 c52ab6f5 aurel32
INLINE floatx80 floatx80_is_infinity(floatx80 a)
510 c52ab6f5 aurel32
{
511 c52ab6f5 aurel32
    return fpclassify(a) == FP_INFINITE;
512 c52ab6f5 aurel32
}
513 c52ab6f5 aurel32
514 c52ab6f5 aurel32
INLINE floatx80 floatx80_is_neg(floatx80 a)
515 c52ab6f5 aurel32
{
516 8d6c92b6 aurel32
    floatx80u u;
517 8d6c92b6 aurel32
    u.f = a;
518 8d6c92b6 aurel32
    return u.i.high >> 15;
519 c52ab6f5 aurel32
}
520 c52ab6f5 aurel32
521 c52ab6f5 aurel32
INLINE floatx80 floatx80_is_zero(floatx80 a)
522 c52ab6f5 aurel32
{
523 c52ab6f5 aurel32
    return fpclassify(a) == FP_ZERO;
524 c52ab6f5 aurel32
}
525 c52ab6f5 aurel32
526 d6882cf0 Aurelien Jarno
INLINE floatx80 floatx80_scalbn(floatx80 a, int n STATUS_PARAM)
527 9ee6e8bb pbrook
{
528 9ee6e8bb pbrook
    return scalbnl(a, n);
529 9ee6e8bb pbrook
}
530 9ee6e8bb pbrook
531 158142c2 bellard
#endif