Statistics
| Branch: | Revision:

root / fpu / softfloat.h @ 8d725fac

History | View | Annotate | Download (24.9 kB)

1 8d725fac Andreas Färber
/*
2 8d725fac Andreas Färber
 * QEMU float support
3 8d725fac Andreas Färber
 *
4 8d725fac Andreas Färber
 * Derived from SoftFloat.
5 8d725fac Andreas Färber
 */
6 8d725fac Andreas Färber
7 158142c2 bellard
/*============================================================================
8 158142c2 bellard

9 158142c2 bellard
This C header file is part of the SoftFloat IEC/IEEE Floating-point Arithmetic
10 158142c2 bellard
Package, Release 2b.
11 158142c2 bellard

12 158142c2 bellard
Written by John R. Hauser.  This work was made possible in part by the
13 158142c2 bellard
International Computer Science Institute, located at Suite 600, 1947 Center
14 158142c2 bellard
Street, Berkeley, California 94704.  Funding was partially provided by the
15 158142c2 bellard
National Science Foundation under grant MIP-9311980.  The original version
16 158142c2 bellard
of this code was written as part of a project to build a fixed-point vector
17 158142c2 bellard
processor in collaboration with the University of California at Berkeley,
18 158142c2 bellard
overseen by Profs. Nelson Morgan and John Wawrzynek.  More information
19 158142c2 bellard
is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
20 158142c2 bellard
arithmetic/SoftFloat.html'.
21 158142c2 bellard

22 158142c2 bellard
THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort has
23 158142c2 bellard
been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
24 158142c2 bellard
RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
25 158142c2 bellard
AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
26 158142c2 bellard
COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
27 158142c2 bellard
EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
28 158142c2 bellard
INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
29 158142c2 bellard
OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
30 158142c2 bellard

31 158142c2 bellard
Derivative works are acceptable, even for commercial purposes, so long as
32 158142c2 bellard
(1) the source code for the derivative work includes prominent notice that
33 158142c2 bellard
the work is derivative, and (2) the source code includes prominent notice with
34 158142c2 bellard
these four paragraphs for those parts of this code that are retained.
35 158142c2 bellard

36 158142c2 bellard
=============================================================================*/
37 158142c2 bellard
38 158142c2 bellard
#ifndef SOFTFLOAT_H
39 158142c2 bellard
#define SOFTFLOAT_H
40 158142c2 bellard
41 75b5a697 Juan Quintela
#if defined(CONFIG_SOLARIS) && defined(CONFIG_NEEDS_LIBSUNMATH)
42 0475a5ca ths
#include <sunmath.h>
43 0475a5ca ths
#endif
44 0475a5ca ths
45 158142c2 bellard
#include <inttypes.h>
46 158142c2 bellard
#include "config.h"
47 158142c2 bellard
48 158142c2 bellard
/*----------------------------------------------------------------------------
49 158142c2 bellard
| Each of the following `typedef's defines the most convenient type that holds
50 158142c2 bellard
| integers of at least as many bits as specified.  For example, `uint8' should
51 158142c2 bellard
| be the most convenient type that can hold unsigned integers of as many as
52 158142c2 bellard
| 8 bits.  The `flag' type must be able to hold either a 0 or 1.  For most
53 158142c2 bellard
| implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
54 158142c2 bellard
| to the same as `int'.
55 158142c2 bellard
*----------------------------------------------------------------------------*/
56 750afe93 bellard
typedef uint8_t flag;
57 158142c2 bellard
typedef uint8_t uint8;
58 158142c2 bellard
typedef int8_t int8;
59 b29fe3ed malc
#ifndef _AIX
60 158142c2 bellard
typedef int uint16;
61 158142c2 bellard
typedef int int16;
62 b29fe3ed malc
#endif
63 158142c2 bellard
typedef unsigned int uint32;
64 158142c2 bellard
typedef signed int int32;
65 158142c2 bellard
typedef uint64_t uint64;
66 158142c2 bellard
typedef int64_t int64;
67 158142c2 bellard
68 158142c2 bellard
/*----------------------------------------------------------------------------
69 158142c2 bellard
| Each of the following `typedef's defines a type that holds integers
70 158142c2 bellard
| of _exactly_ the number of bits specified.  For instance, for most
71 158142c2 bellard
| implementation of C, `bits16' and `sbits16' should be `typedef'ed to
72 158142c2 bellard
| `unsigned short int' and `signed short int' (or `short int'), respectively.
73 158142c2 bellard
*----------------------------------------------------------------------------*/
74 158142c2 bellard
typedef uint8_t bits8;
75 158142c2 bellard
typedef int8_t sbits8;
76 158142c2 bellard
typedef uint16_t bits16;
77 158142c2 bellard
typedef int16_t sbits16;
78 158142c2 bellard
typedef uint32_t bits32;
79 158142c2 bellard
typedef int32_t sbits32;
80 158142c2 bellard
typedef uint64_t bits64;
81 158142c2 bellard
typedef int64_t sbits64;
82 158142c2 bellard
83 158142c2 bellard
#define LIT64( a ) a##LL
84 158142c2 bellard
#define INLINE static inline
85 158142c2 bellard
86 8559666d Christophe Lyon
#if defined(TARGET_MIPS) || defined(TARGET_SH4)
87 8559666d Christophe Lyon
#define SNAN_BIT_IS_ONE                1
88 8559666d Christophe Lyon
#else
89 8559666d Christophe Lyon
#define SNAN_BIT_IS_ONE                0
90 8559666d Christophe Lyon
#endif
91 8559666d Christophe Lyon
92 158142c2 bellard
/*----------------------------------------------------------------------------
93 158142c2 bellard
| The macro `FLOATX80' must be defined to enable the extended double-precision
94 158142c2 bellard
| floating-point format `floatx80'.  If this macro is not defined, the
95 158142c2 bellard
| `floatx80' type will not be defined, and none of the functions that either
96 158142c2 bellard
| input or output the `floatx80' type will be defined.  The same applies to
97 158142c2 bellard
| the `FLOAT128' macro and the quadruple-precision format `float128'.
98 158142c2 bellard
*----------------------------------------------------------------------------*/
99 158142c2 bellard
#ifdef CONFIG_SOFTFLOAT
100 158142c2 bellard
/* bit exact soft float support */
101 158142c2 bellard
#define FLOATX80
102 158142c2 bellard
#define FLOAT128
103 158142c2 bellard
#else
104 158142c2 bellard
/* native float support */
105 71e72a19 Juan Quintela
#if (defined(__i386__) || defined(__x86_64__)) && !defined(CONFIG_BSD)
106 158142c2 bellard
#define FLOATX80
107 158142c2 bellard
#endif
108 158142c2 bellard
#endif /* !CONFIG_SOFTFLOAT */
109 158142c2 bellard
110 158142c2 bellard
#define STATUS_PARAM , float_status *status
111 158142c2 bellard
#define STATUS(field) status->field
112 158142c2 bellard
#define STATUS_VAR , status
113 158142c2 bellard
114 1d6bda35 bellard
/*----------------------------------------------------------------------------
115 1d6bda35 bellard
| Software IEC/IEEE floating-point ordering relations
116 1d6bda35 bellard
*----------------------------------------------------------------------------*/
117 1d6bda35 bellard
enum {
118 1d6bda35 bellard
    float_relation_less      = -1,
119 1d6bda35 bellard
    float_relation_equal     =  0,
120 1d6bda35 bellard
    float_relation_greater   =  1,
121 1d6bda35 bellard
    float_relation_unordered =  2
122 1d6bda35 bellard
};
123 1d6bda35 bellard
124 158142c2 bellard
#ifdef CONFIG_SOFTFLOAT
125 158142c2 bellard
/*----------------------------------------------------------------------------
126 158142c2 bellard
| Software IEC/IEEE floating-point types.
127 158142c2 bellard
*----------------------------------------------------------------------------*/
128 f090c9d4 pbrook
/* Use structures for soft-float types.  This prevents accidentally mixing
129 f090c9d4 pbrook
   them with native int/float types.  A sufficiently clever compiler and
130 f090c9d4 pbrook
   sane ABI should be able to see though these structs.  However
131 f090c9d4 pbrook
   x86/gcc 3.x seems to struggle a bit, so leave them disabled by default.  */
132 f090c9d4 pbrook
//#define USE_SOFTFLOAT_STRUCT_TYPES
133 f090c9d4 pbrook
#ifdef USE_SOFTFLOAT_STRUCT_TYPES
134 f090c9d4 pbrook
typedef struct {
135 bb4d4bb3 Peter Maydell
    uint16_t v;
136 bb4d4bb3 Peter Maydell
} float16;
137 bb4d4bb3 Peter Maydell
#define float16_val(x) (((float16)(x)).v)
138 bb4d4bb3 Peter Maydell
#define make_float16(x) __extension__ ({ float16 f16_val = {x}; f16_val; })
139 d5138cf4 Peter Maydell
#define const_float16(x) { x }
140 bb4d4bb3 Peter Maydell
typedef struct {
141 f090c9d4 pbrook
    uint32_t v;
142 f090c9d4 pbrook
} float32;
143 f090c9d4 pbrook
/* The cast ensures an error if the wrong type is passed.  */
144 f090c9d4 pbrook
#define float32_val(x) (((float32)(x)).v)
145 f090c9d4 pbrook
#define make_float32(x) __extension__ ({ float32 f32_val = {x}; f32_val; })
146 d5138cf4 Peter Maydell
#define const_float32(x) { x }
147 f090c9d4 pbrook
typedef struct {
148 f090c9d4 pbrook
    uint64_t v;
149 f090c9d4 pbrook
} float64;
150 f090c9d4 pbrook
#define float64_val(x) (((float64)(x)).v)
151 f090c9d4 pbrook
#define make_float64(x) __extension__ ({ float64 f64_val = {x}; f64_val; })
152 d5138cf4 Peter Maydell
#define const_float64(x) { x }
153 f090c9d4 pbrook
#else
154 bb4d4bb3 Peter Maydell
typedef uint16_t float16;
155 158142c2 bellard
typedef uint32_t float32;
156 158142c2 bellard
typedef uint64_t float64;
157 bb4d4bb3 Peter Maydell
#define float16_val(x) (x)
158 f090c9d4 pbrook
#define float32_val(x) (x)
159 f090c9d4 pbrook
#define float64_val(x) (x)
160 bb4d4bb3 Peter Maydell
#define make_float16(x) (x)
161 f090c9d4 pbrook
#define make_float32(x) (x)
162 f090c9d4 pbrook
#define make_float64(x) (x)
163 d5138cf4 Peter Maydell
#define const_float16(x) (x)
164 d5138cf4 Peter Maydell
#define const_float32(x) (x)
165 d5138cf4 Peter Maydell
#define const_float64(x) (x)
166 f090c9d4 pbrook
#endif
167 158142c2 bellard
#ifdef FLOATX80
168 158142c2 bellard
typedef struct {
169 158142c2 bellard
    uint64_t low;
170 158142c2 bellard
    uint16_t high;
171 158142c2 bellard
} floatx80;
172 158142c2 bellard
#endif
173 158142c2 bellard
#ifdef FLOAT128
174 158142c2 bellard
typedef struct {
175 e2542fe2 Juan Quintela
#ifdef HOST_WORDS_BIGENDIAN
176 158142c2 bellard
    uint64_t high, low;
177 158142c2 bellard
#else
178 158142c2 bellard
    uint64_t low, high;
179 158142c2 bellard
#endif
180 158142c2 bellard
} float128;
181 158142c2 bellard
#endif
182 158142c2 bellard
183 158142c2 bellard
/*----------------------------------------------------------------------------
184 158142c2 bellard
| Software IEC/IEEE floating-point underflow tininess-detection mode.
185 158142c2 bellard
*----------------------------------------------------------------------------*/
186 158142c2 bellard
enum {
187 158142c2 bellard
    float_tininess_after_rounding  = 0,
188 158142c2 bellard
    float_tininess_before_rounding = 1
189 158142c2 bellard
};
190 158142c2 bellard
191 158142c2 bellard
/*----------------------------------------------------------------------------
192 158142c2 bellard
| Software IEC/IEEE floating-point rounding mode.
193 158142c2 bellard
*----------------------------------------------------------------------------*/
194 158142c2 bellard
enum {
195 158142c2 bellard
    float_round_nearest_even = 0,
196 158142c2 bellard
    float_round_down         = 1,
197 158142c2 bellard
    float_round_up           = 2,
198 158142c2 bellard
    float_round_to_zero      = 3
199 158142c2 bellard
};
200 158142c2 bellard
201 158142c2 bellard
/*----------------------------------------------------------------------------
202 158142c2 bellard
| Software IEC/IEEE floating-point exception flags.
203 158142c2 bellard
*----------------------------------------------------------------------------*/
204 158142c2 bellard
enum {
205 158142c2 bellard
    float_flag_invalid   =  1,
206 158142c2 bellard
    float_flag_divbyzero =  4,
207 158142c2 bellard
    float_flag_overflow  =  8,
208 158142c2 bellard
    float_flag_underflow = 16,
209 37d18660 Peter Maydell
    float_flag_inexact   = 32,
210 37d18660 Peter Maydell
    float_flag_input_denormal = 64
211 158142c2 bellard
};
212 158142c2 bellard
213 158142c2 bellard
typedef struct float_status {
214 158142c2 bellard
    signed char float_detect_tininess;
215 158142c2 bellard
    signed char float_rounding_mode;
216 158142c2 bellard
    signed char float_exception_flags;
217 158142c2 bellard
#ifdef FLOATX80
218 158142c2 bellard
    signed char floatx80_rounding_precision;
219 158142c2 bellard
#endif
220 37d18660 Peter Maydell
    /* should denormalised results go to zero and set the inexact flag? */
221 fe76d976 pbrook
    flag flush_to_zero;
222 37d18660 Peter Maydell
    /* should denormalised inputs go to zero and set the input_denormal flag? */
223 37d18660 Peter Maydell
    flag flush_inputs_to_zero;
224 5c7908ed pbrook
    flag default_nan_mode;
225 158142c2 bellard
} float_status;
226 158142c2 bellard
227 158142c2 bellard
void set_float_rounding_mode(int val STATUS_PARAM);
228 1d6bda35 bellard
void set_float_exception_flags(int val STATUS_PARAM);
229 fe76d976 pbrook
INLINE void set_flush_to_zero(flag val STATUS_PARAM)
230 fe76d976 pbrook
{
231 fe76d976 pbrook
    STATUS(flush_to_zero) = val;
232 fe76d976 pbrook
}
233 37d18660 Peter Maydell
INLINE void set_flush_inputs_to_zero(flag val STATUS_PARAM)
234 37d18660 Peter Maydell
{
235 37d18660 Peter Maydell
    STATUS(flush_inputs_to_zero) = val;
236 37d18660 Peter Maydell
}
237 5c7908ed pbrook
INLINE void set_default_nan_mode(flag val STATUS_PARAM)
238 5c7908ed pbrook
{
239 5c7908ed pbrook
    STATUS(default_nan_mode) = val;
240 5c7908ed pbrook
}
241 1d6bda35 bellard
INLINE int get_float_exception_flags(float_status *status)
242 1d6bda35 bellard
{
243 1d6bda35 bellard
    return STATUS(float_exception_flags);
244 1d6bda35 bellard
}
245 158142c2 bellard
#ifdef FLOATX80
246 158142c2 bellard
void set_floatx80_rounding_precision(int val STATUS_PARAM);
247 158142c2 bellard
#endif
248 158142c2 bellard
249 158142c2 bellard
/*----------------------------------------------------------------------------
250 158142c2 bellard
| Routine to raise any or all of the software IEC/IEEE floating-point
251 158142c2 bellard
| exception flags.
252 158142c2 bellard
*----------------------------------------------------------------------------*/
253 ec530c81 bellard
void float_raise( int8 flags STATUS_PARAM);
254 158142c2 bellard
255 158142c2 bellard
/*----------------------------------------------------------------------------
256 158142c2 bellard
| Software IEC/IEEE integer-to-floating-point conversion routines.
257 158142c2 bellard
*----------------------------------------------------------------------------*/
258 158142c2 bellard
float32 int32_to_float32( int STATUS_PARAM );
259 158142c2 bellard
float64 int32_to_float64( int STATUS_PARAM );
260 1d6bda35 bellard
float32 uint32_to_float32( unsigned int STATUS_PARAM );
261 1d6bda35 bellard
float64 uint32_to_float64( unsigned int STATUS_PARAM );
262 158142c2 bellard
#ifdef FLOATX80
263 158142c2 bellard
floatx80 int32_to_floatx80( int STATUS_PARAM );
264 158142c2 bellard
#endif
265 158142c2 bellard
#ifdef FLOAT128
266 158142c2 bellard
float128 int32_to_float128( int STATUS_PARAM );
267 158142c2 bellard
#endif
268 158142c2 bellard
float32 int64_to_float32( int64_t STATUS_PARAM );
269 75d62a58 j_mayer
float32 uint64_to_float32( uint64_t STATUS_PARAM );
270 158142c2 bellard
float64 int64_to_float64( int64_t STATUS_PARAM );
271 75d62a58 j_mayer
float64 uint64_to_float64( uint64_t STATUS_PARAM );
272 158142c2 bellard
#ifdef FLOATX80
273 158142c2 bellard
floatx80 int64_to_floatx80( int64_t STATUS_PARAM );
274 158142c2 bellard
#endif
275 158142c2 bellard
#ifdef FLOAT128
276 158142c2 bellard
float128 int64_to_float128( int64_t STATUS_PARAM );
277 158142c2 bellard
#endif
278 158142c2 bellard
279 158142c2 bellard
/*----------------------------------------------------------------------------
280 60011498 Paul Brook
| Software half-precision conversion routines.
281 60011498 Paul Brook
*----------------------------------------------------------------------------*/
282 bb4d4bb3 Peter Maydell
float16 float32_to_float16( float32, flag STATUS_PARAM );
283 bb4d4bb3 Peter Maydell
float32 float16_to_float32( float16, flag STATUS_PARAM );
284 bb4d4bb3 Peter Maydell
285 bb4d4bb3 Peter Maydell
/*----------------------------------------------------------------------------
286 bb4d4bb3 Peter Maydell
| Software half-precision operations.
287 bb4d4bb3 Peter Maydell
*----------------------------------------------------------------------------*/
288 bb4d4bb3 Peter Maydell
int float16_is_quiet_nan( float16 );
289 bb4d4bb3 Peter Maydell
int float16_is_signaling_nan( float16 );
290 bb4d4bb3 Peter Maydell
float16 float16_maybe_silence_nan( float16 );
291 60011498 Paul Brook
292 60011498 Paul Brook
/*----------------------------------------------------------------------------
293 8559666d Christophe Lyon
| The pattern for a default generated half-precision NaN.
294 8559666d Christophe Lyon
*----------------------------------------------------------------------------*/
295 8559666d Christophe Lyon
#if defined(TARGET_ARM)
296 8559666d Christophe Lyon
#define float16_default_nan make_float16(0x7E00)
297 8559666d Christophe Lyon
#elif SNAN_BIT_IS_ONE
298 8559666d Christophe Lyon
#define float16_default_nan make_float16(0x7DFF)
299 8559666d Christophe Lyon
#else
300 8559666d Christophe Lyon
#define float16_default_nan make_float16(0xFE00)
301 8559666d Christophe Lyon
#endif
302 8559666d Christophe Lyon
303 8559666d Christophe Lyon
/*----------------------------------------------------------------------------
304 158142c2 bellard
| Software IEC/IEEE single-precision conversion routines.
305 158142c2 bellard
*----------------------------------------------------------------------------*/
306 cbcef455 Peter Maydell
int float32_to_int16_round_to_zero( float32 STATUS_PARAM );
307 cbcef455 Peter Maydell
unsigned int float32_to_uint16_round_to_zero( float32 STATUS_PARAM );
308 158142c2 bellard
int float32_to_int32( float32 STATUS_PARAM );
309 158142c2 bellard
int float32_to_int32_round_to_zero( float32 STATUS_PARAM );
310 1d6bda35 bellard
unsigned int float32_to_uint32( float32 STATUS_PARAM );
311 1d6bda35 bellard
unsigned int float32_to_uint32_round_to_zero( float32 STATUS_PARAM );
312 158142c2 bellard
int64_t float32_to_int64( float32 STATUS_PARAM );
313 158142c2 bellard
int64_t float32_to_int64_round_to_zero( float32 STATUS_PARAM );
314 158142c2 bellard
float64 float32_to_float64( float32 STATUS_PARAM );
315 158142c2 bellard
#ifdef FLOATX80
316 158142c2 bellard
floatx80 float32_to_floatx80( float32 STATUS_PARAM );
317 158142c2 bellard
#endif
318 158142c2 bellard
#ifdef FLOAT128
319 158142c2 bellard
float128 float32_to_float128( float32 STATUS_PARAM );
320 158142c2 bellard
#endif
321 158142c2 bellard
322 158142c2 bellard
/*----------------------------------------------------------------------------
323 158142c2 bellard
| Software IEC/IEEE single-precision operations.
324 158142c2 bellard
*----------------------------------------------------------------------------*/
325 158142c2 bellard
float32 float32_round_to_int( float32 STATUS_PARAM );
326 158142c2 bellard
float32 float32_add( float32, float32 STATUS_PARAM );
327 158142c2 bellard
float32 float32_sub( float32, float32 STATUS_PARAM );
328 158142c2 bellard
float32 float32_mul( float32, float32 STATUS_PARAM );
329 158142c2 bellard
float32 float32_div( float32, float32 STATUS_PARAM );
330 158142c2 bellard
float32 float32_rem( float32, float32 STATUS_PARAM );
331 158142c2 bellard
float32 float32_sqrt( float32 STATUS_PARAM );
332 8229c991 Aurelien Jarno
float32 float32_exp2( float32 STATUS_PARAM );
333 374dfc33 aurel32
float32 float32_log2( float32 STATUS_PARAM );
334 750afe93 bellard
int float32_eq( float32, float32 STATUS_PARAM );
335 750afe93 bellard
int float32_le( float32, float32 STATUS_PARAM );
336 750afe93 bellard
int float32_lt( float32, float32 STATUS_PARAM );
337 750afe93 bellard
int float32_eq_signaling( float32, float32 STATUS_PARAM );
338 750afe93 bellard
int float32_le_quiet( float32, float32 STATUS_PARAM );
339 750afe93 bellard
int float32_lt_quiet( float32, float32 STATUS_PARAM );
340 750afe93 bellard
int float32_compare( float32, float32 STATUS_PARAM );
341 750afe93 bellard
int float32_compare_quiet( float32, float32 STATUS_PARAM );
342 18569871 Peter Maydell
int float32_is_quiet_nan( float32 );
343 750afe93 bellard
int float32_is_signaling_nan( float32 );
344 b408dbde Peter Maydell
float32 float32_maybe_silence_nan( float32 );
345 9ee6e8bb pbrook
float32 float32_scalbn( float32, int STATUS_PARAM );
346 158142c2 bellard
347 1d6bda35 bellard
INLINE float32 float32_abs(float32 a)
348 1d6bda35 bellard
{
349 37d18660 Peter Maydell
    /* Note that abs does *not* handle NaN specially, nor does
350 37d18660 Peter Maydell
     * it flush denormal inputs to zero.
351 37d18660 Peter Maydell
     */
352 f090c9d4 pbrook
    return make_float32(float32_val(a) & 0x7fffffff);
353 1d6bda35 bellard
}
354 1d6bda35 bellard
355 1d6bda35 bellard
INLINE float32 float32_chs(float32 a)
356 1d6bda35 bellard
{
357 37d18660 Peter Maydell
    /* Note that chs does *not* handle NaN specially, nor does
358 37d18660 Peter Maydell
     * it flush denormal inputs to zero.
359 37d18660 Peter Maydell
     */
360 f090c9d4 pbrook
    return make_float32(float32_val(a) ^ 0x80000000);
361 1d6bda35 bellard
}
362 1d6bda35 bellard
363 c52ab6f5 aurel32
INLINE int float32_is_infinity(float32 a)
364 c52ab6f5 aurel32
{
365 dadd71a7 aurel32
    return (float32_val(a) & 0x7fffffff) == 0x7f800000;
366 c52ab6f5 aurel32
}
367 c52ab6f5 aurel32
368 c52ab6f5 aurel32
INLINE int float32_is_neg(float32 a)
369 c52ab6f5 aurel32
{
370 c52ab6f5 aurel32
    return float32_val(a) >> 31;
371 c52ab6f5 aurel32
}
372 c52ab6f5 aurel32
373 c52ab6f5 aurel32
INLINE int float32_is_zero(float32 a)
374 c52ab6f5 aurel32
{
375 c52ab6f5 aurel32
    return (float32_val(a) & 0x7fffffff) == 0;
376 c52ab6f5 aurel32
}
377 c52ab6f5 aurel32
378 21d6ebde Peter Maydell
INLINE int float32_is_any_nan(float32 a)
379 21d6ebde Peter Maydell
{
380 21d6ebde Peter Maydell
    return ((float32_val(a) & ~(1 << 31)) > 0x7f800000UL);
381 21d6ebde Peter Maydell
}
382 21d6ebde Peter Maydell
383 6f3300ad Peter Maydell
INLINE int float32_is_zero_or_denormal(float32 a)
384 6f3300ad Peter Maydell
{
385 6f3300ad Peter Maydell
    return (float32_val(a) & 0x7f800000) == 0;
386 6f3300ad Peter Maydell
}
387 6f3300ad Peter Maydell
388 c30fe7df Christophe Lyon
INLINE float32 float32_set_sign(float32 a, int sign)
389 c30fe7df Christophe Lyon
{
390 c30fe7df Christophe Lyon
    return make_float32((float32_val(a) & 0x7fffffff) | (sign << 31));
391 c30fe7df Christophe Lyon
}
392 c30fe7df Christophe Lyon
393 f090c9d4 pbrook
#define float32_zero make_float32(0)
394 196cfc89 aurel32
#define float32_one make_float32(0x3f800000)
395 8229c991 Aurelien Jarno
#define float32_ln2 make_float32(0x3f317218)
396 c30fe7df Christophe Lyon
#define float32_half make_float32(0x3f000000)
397 c30fe7df Christophe Lyon
#define float32_infinity make_float32(0x7f800000)
398 f090c9d4 pbrook
399 8559666d Christophe Lyon
400 8559666d Christophe Lyon
/*----------------------------------------------------------------------------
401 8559666d Christophe Lyon
| The pattern for a default generated single-precision NaN.
402 8559666d Christophe Lyon
*----------------------------------------------------------------------------*/
403 8559666d Christophe Lyon
#if defined(TARGET_SPARC)
404 8559666d Christophe Lyon
#define float32_default_nan make_float32(0x7FFFFFFF)
405 8559666d Christophe Lyon
#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
406 8559666d Christophe Lyon
#define float32_default_nan make_float32(0x7FC00000)
407 8559666d Christophe Lyon
#elif SNAN_BIT_IS_ONE
408 8559666d Christophe Lyon
#define float32_default_nan make_float32(0x7FBFFFFF)
409 8559666d Christophe Lyon
#else
410 8559666d Christophe Lyon
#define float32_default_nan make_float32(0xFFC00000)
411 8559666d Christophe Lyon
#endif
412 8559666d Christophe Lyon
413 158142c2 bellard
/*----------------------------------------------------------------------------
414 158142c2 bellard
| Software IEC/IEEE double-precision conversion routines.
415 158142c2 bellard
*----------------------------------------------------------------------------*/
416 cbcef455 Peter Maydell
int float64_to_int16_round_to_zero( float64 STATUS_PARAM );
417 cbcef455 Peter Maydell
unsigned int float64_to_uint16_round_to_zero( float64 STATUS_PARAM );
418 158142c2 bellard
int float64_to_int32( float64 STATUS_PARAM );
419 158142c2 bellard
int float64_to_int32_round_to_zero( float64 STATUS_PARAM );
420 1d6bda35 bellard
unsigned int float64_to_uint32( float64 STATUS_PARAM );
421 1d6bda35 bellard
unsigned int float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
422 158142c2 bellard
int64_t float64_to_int64( float64 STATUS_PARAM );
423 158142c2 bellard
int64_t float64_to_int64_round_to_zero( float64 STATUS_PARAM );
424 75d62a58 j_mayer
uint64_t float64_to_uint64 (float64 a STATUS_PARAM);
425 75d62a58 j_mayer
uint64_t float64_to_uint64_round_to_zero (float64 a STATUS_PARAM);
426 158142c2 bellard
float32 float64_to_float32( float64 STATUS_PARAM );
427 158142c2 bellard
#ifdef FLOATX80
428 158142c2 bellard
floatx80 float64_to_floatx80( float64 STATUS_PARAM );
429 158142c2 bellard
#endif
430 158142c2 bellard
#ifdef FLOAT128
431 158142c2 bellard
float128 float64_to_float128( float64 STATUS_PARAM );
432 158142c2 bellard
#endif
433 158142c2 bellard
434 158142c2 bellard
/*----------------------------------------------------------------------------
435 158142c2 bellard
| Software IEC/IEEE double-precision operations.
436 158142c2 bellard
*----------------------------------------------------------------------------*/
437 158142c2 bellard
float64 float64_round_to_int( float64 STATUS_PARAM );
438 e6e5906b pbrook
float64 float64_trunc_to_int( float64 STATUS_PARAM );
439 158142c2 bellard
float64 float64_add( float64, float64 STATUS_PARAM );
440 158142c2 bellard
float64 float64_sub( float64, float64 STATUS_PARAM );
441 158142c2 bellard
float64 float64_mul( float64, float64 STATUS_PARAM );
442 158142c2 bellard
float64 float64_div( float64, float64 STATUS_PARAM );
443 158142c2 bellard
float64 float64_rem( float64, float64 STATUS_PARAM );
444 158142c2 bellard
float64 float64_sqrt( float64 STATUS_PARAM );
445 374dfc33 aurel32
float64 float64_log2( float64 STATUS_PARAM );
446 750afe93 bellard
int float64_eq( float64, float64 STATUS_PARAM );
447 750afe93 bellard
int float64_le( float64, float64 STATUS_PARAM );
448 750afe93 bellard
int float64_lt( float64, float64 STATUS_PARAM );
449 750afe93 bellard
int float64_eq_signaling( float64, float64 STATUS_PARAM );
450 750afe93 bellard
int float64_le_quiet( float64, float64 STATUS_PARAM );
451 750afe93 bellard
int float64_lt_quiet( float64, float64 STATUS_PARAM );
452 750afe93 bellard
int float64_compare( float64, float64 STATUS_PARAM );
453 750afe93 bellard
int float64_compare_quiet( float64, float64 STATUS_PARAM );
454 18569871 Peter Maydell
int float64_is_quiet_nan( float64 a );
455 750afe93 bellard
int float64_is_signaling_nan( float64 );
456 b408dbde Peter Maydell
float64 float64_maybe_silence_nan( float64 );
457 9ee6e8bb pbrook
float64 float64_scalbn( float64, int STATUS_PARAM );
458 158142c2 bellard
459 1d6bda35 bellard
INLINE float64 float64_abs(float64 a)
460 1d6bda35 bellard
{
461 37d18660 Peter Maydell
    /* Note that abs does *not* handle NaN specially, nor does
462 37d18660 Peter Maydell
     * it flush denormal inputs to zero.
463 37d18660 Peter Maydell
     */
464 f090c9d4 pbrook
    return make_float64(float64_val(a) & 0x7fffffffffffffffLL);
465 1d6bda35 bellard
}
466 1d6bda35 bellard
467 1d6bda35 bellard
INLINE float64 float64_chs(float64 a)
468 1d6bda35 bellard
{
469 37d18660 Peter Maydell
    /* Note that chs does *not* handle NaN specially, nor does
470 37d18660 Peter Maydell
     * it flush denormal inputs to zero.
471 37d18660 Peter Maydell
     */
472 f090c9d4 pbrook
    return make_float64(float64_val(a) ^ 0x8000000000000000LL);
473 1d6bda35 bellard
}
474 1d6bda35 bellard
475 c52ab6f5 aurel32
INLINE int float64_is_infinity(float64 a)
476 c52ab6f5 aurel32
{
477 c52ab6f5 aurel32
    return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL;
478 c52ab6f5 aurel32
}
479 c52ab6f5 aurel32
480 c52ab6f5 aurel32
INLINE int float64_is_neg(float64 a)
481 c52ab6f5 aurel32
{
482 c52ab6f5 aurel32
    return float64_val(a) >> 63;
483 c52ab6f5 aurel32
}
484 c52ab6f5 aurel32
485 c52ab6f5 aurel32
INLINE int float64_is_zero(float64 a)
486 c52ab6f5 aurel32
{
487 c52ab6f5 aurel32
    return (float64_val(a) & 0x7fffffffffffffffLL) == 0;
488 c52ab6f5 aurel32
}
489 c52ab6f5 aurel32
490 21d6ebde Peter Maydell
INLINE int float64_is_any_nan(float64 a)
491 21d6ebde Peter Maydell
{
492 21d6ebde Peter Maydell
    return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL);
493 21d6ebde Peter Maydell
}
494 21d6ebde Peter Maydell
495 c30fe7df Christophe Lyon
INLINE float64 float64_set_sign(float64 a, int sign)
496 c30fe7df Christophe Lyon
{
497 c30fe7df Christophe Lyon
    return make_float64((float64_val(a) & 0x7fffffffffffffffULL)
498 c30fe7df Christophe Lyon
                        | ((int64_t)sign << 63));
499 c30fe7df Christophe Lyon
}
500 c30fe7df Christophe Lyon
501 f090c9d4 pbrook
#define float64_zero make_float64(0)
502 196cfc89 aurel32
#define float64_one make_float64(0x3ff0000000000000LL)
503 8229c991 Aurelien Jarno
#define float64_ln2 make_float64(0x3fe62e42fefa39efLL)
504 c30fe7df Christophe Lyon
#define float64_half make_float64(0x3fe0000000000000LL)
505 c30fe7df Christophe Lyon
#define float64_infinity make_float64(0x7ff0000000000000LL)
506 f090c9d4 pbrook
507 8559666d Christophe Lyon
/*----------------------------------------------------------------------------
508 8559666d Christophe Lyon
| The pattern for a default generated double-precision NaN.
509 8559666d Christophe Lyon
*----------------------------------------------------------------------------*/
510 8559666d Christophe Lyon
#if defined(TARGET_SPARC)
511 8559666d Christophe Lyon
#define float64_default_nan make_float64(LIT64( 0x7FFFFFFFFFFFFFFF ))
512 8559666d Christophe Lyon
#elif defined(TARGET_PPC) || defined(TARGET_ARM) || defined(TARGET_ALPHA)
513 8559666d Christophe Lyon
#define float64_default_nan make_float64(LIT64( 0x7FF8000000000000 ))
514 8559666d Christophe Lyon
#elif SNAN_BIT_IS_ONE
515 8559666d Christophe Lyon
#define float64_default_nan make_float64(LIT64( 0x7FF7FFFFFFFFFFFF ))
516 8559666d Christophe Lyon
#else
517 8559666d Christophe Lyon
#define float64_default_nan make_float64(LIT64( 0xFFF8000000000000 ))
518 8559666d Christophe Lyon
#endif
519 8559666d Christophe Lyon
520 158142c2 bellard
#ifdef FLOATX80
521 158142c2 bellard
522 158142c2 bellard
/*----------------------------------------------------------------------------
523 158142c2 bellard
| Software IEC/IEEE extended double-precision conversion routines.
524 158142c2 bellard
*----------------------------------------------------------------------------*/
525 158142c2 bellard
int floatx80_to_int32( floatx80 STATUS_PARAM );
526 158142c2 bellard
int floatx80_to_int32_round_to_zero( floatx80 STATUS_PARAM );
527 158142c2 bellard
int64_t floatx80_to_int64( floatx80 STATUS_PARAM );
528 158142c2 bellard
int64_t floatx80_to_int64_round_to_zero( floatx80 STATUS_PARAM );
529 158142c2 bellard
float32 floatx80_to_float32( floatx80 STATUS_PARAM );
530 158142c2 bellard
float64 floatx80_to_float64( floatx80 STATUS_PARAM );
531 158142c2 bellard
#ifdef FLOAT128
532 158142c2 bellard
float128 floatx80_to_float128( floatx80 STATUS_PARAM );
533 158142c2 bellard
#endif
534 158142c2 bellard
535 158142c2 bellard
/*----------------------------------------------------------------------------
536 158142c2 bellard
| Software IEC/IEEE extended double-precision operations.
537 158142c2 bellard
*----------------------------------------------------------------------------*/
538 158142c2 bellard
floatx80 floatx80_round_to_int( floatx80 STATUS_PARAM );
539 158142c2 bellard
floatx80 floatx80_add( floatx80, floatx80 STATUS_PARAM );
540 158142c2 bellard
floatx80 floatx80_sub( floatx80, floatx80 STATUS_PARAM );
541 158142c2 bellard
floatx80 floatx80_mul( floatx80, floatx80 STATUS_PARAM );
542 158142c2 bellard
floatx80 floatx80_div( floatx80, floatx80 STATUS_PARAM );
543 158142c2 bellard
floatx80 floatx80_rem( floatx80, floatx80 STATUS_PARAM );
544 158142c2 bellard
floatx80 floatx80_sqrt( floatx80 STATUS_PARAM );
545 750afe93 bellard
int floatx80_eq( floatx80, floatx80 STATUS_PARAM );
546 750afe93 bellard
int floatx80_le( floatx80, floatx80 STATUS_PARAM );
547 750afe93 bellard
int floatx80_lt( floatx80, floatx80 STATUS_PARAM );
548 750afe93 bellard
int floatx80_eq_signaling( floatx80, floatx80 STATUS_PARAM );
549 750afe93 bellard
int floatx80_le_quiet( floatx80, floatx80 STATUS_PARAM );
550 750afe93 bellard
int floatx80_lt_quiet( floatx80, floatx80 STATUS_PARAM );
551 18569871 Peter Maydell
int floatx80_is_quiet_nan( floatx80 );
552 750afe93 bellard
int floatx80_is_signaling_nan( floatx80 );
553 f6a7d92a Aurelien Jarno
floatx80 floatx80_maybe_silence_nan( floatx80 );
554 9ee6e8bb pbrook
floatx80 floatx80_scalbn( floatx80, int STATUS_PARAM );
555 158142c2 bellard
556 1d6bda35 bellard
INLINE floatx80 floatx80_abs(floatx80 a)
557 1d6bda35 bellard
{
558 1d6bda35 bellard
    a.high &= 0x7fff;
559 1d6bda35 bellard
    return a;
560 1d6bda35 bellard
}
561 1d6bda35 bellard
562 1d6bda35 bellard
INLINE floatx80 floatx80_chs(floatx80 a)
563 1d6bda35 bellard
{
564 1d6bda35 bellard
    a.high ^= 0x8000;
565 1d6bda35 bellard
    return a;
566 1d6bda35 bellard
}
567 1d6bda35 bellard
568 c52ab6f5 aurel32
INLINE int floatx80_is_infinity(floatx80 a)
569 c52ab6f5 aurel32
{
570 c52ab6f5 aurel32
    return (a.high & 0x7fff) == 0x7fff && a.low == 0;
571 c52ab6f5 aurel32
}
572 c52ab6f5 aurel32
573 c52ab6f5 aurel32
INLINE int floatx80_is_neg(floatx80 a)
574 c52ab6f5 aurel32
{
575 c52ab6f5 aurel32
    return a.high >> 15;
576 c52ab6f5 aurel32
}
577 c52ab6f5 aurel32
578 c52ab6f5 aurel32
INLINE int floatx80_is_zero(floatx80 a)
579 c52ab6f5 aurel32
{
580 c52ab6f5 aurel32
    return (a.high & 0x7fff) == 0 && a.low == 0;
581 c52ab6f5 aurel32
}
582 c52ab6f5 aurel32
583 2bed652f Peter Maydell
INLINE int floatx80_is_any_nan(floatx80 a)
584 2bed652f Peter Maydell
{
585 2bed652f Peter Maydell
    return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1);
586 2bed652f Peter Maydell
}
587 2bed652f Peter Maydell
588 8559666d Christophe Lyon
/*----------------------------------------------------------------------------
589 8559666d Christophe Lyon
| The pattern for a default generated extended double-precision NaN.  The
590 8559666d Christophe Lyon
| `high' and `low' values hold the most- and least-significant bits,
591 8559666d Christophe Lyon
| respectively.
592 8559666d Christophe Lyon
*----------------------------------------------------------------------------*/
593 8559666d Christophe Lyon
#if SNAN_BIT_IS_ONE
594 8559666d Christophe Lyon
#define floatx80_default_nan_high 0x7FFF
595 8559666d Christophe Lyon
#define floatx80_default_nan_low  LIT64( 0xBFFFFFFFFFFFFFFF )
596 8559666d Christophe Lyon
#else
597 8559666d Christophe Lyon
#define floatx80_default_nan_high 0xFFFF
598 8559666d Christophe Lyon
#define floatx80_default_nan_low  LIT64( 0xC000000000000000 )
599 8559666d Christophe Lyon
#endif
600 8559666d Christophe Lyon
601 158142c2 bellard
#endif
602 158142c2 bellard
603 158142c2 bellard
#ifdef FLOAT128
604 158142c2 bellard
605 158142c2 bellard
/*----------------------------------------------------------------------------
606 158142c2 bellard
| Software IEC/IEEE quadruple-precision conversion routines.
607 158142c2 bellard
*----------------------------------------------------------------------------*/
608 158142c2 bellard
int float128_to_int32( float128 STATUS_PARAM );
609 158142c2 bellard
int float128_to_int32_round_to_zero( float128 STATUS_PARAM );
610 158142c2 bellard
int64_t float128_to_int64( float128 STATUS_PARAM );
611 158142c2 bellard
int64_t float128_to_int64_round_to_zero( float128 STATUS_PARAM );
612 158142c2 bellard
float32 float128_to_float32( float128 STATUS_PARAM );
613 158142c2 bellard
float64 float128_to_float64( float128 STATUS_PARAM );
614 158142c2 bellard
#ifdef FLOATX80
615 158142c2 bellard
floatx80 float128_to_floatx80( float128 STATUS_PARAM );
616 158142c2 bellard
#endif
617 158142c2 bellard
618 158142c2 bellard
/*----------------------------------------------------------------------------
619 158142c2 bellard
| Software IEC/IEEE quadruple-precision operations.
620 158142c2 bellard
*----------------------------------------------------------------------------*/
621 158142c2 bellard
float128 float128_round_to_int( float128 STATUS_PARAM );
622 158142c2 bellard
float128 float128_add( float128, float128 STATUS_PARAM );
623 158142c2 bellard
float128 float128_sub( float128, float128 STATUS_PARAM );
624 158142c2 bellard
float128 float128_mul( float128, float128 STATUS_PARAM );
625 158142c2 bellard
float128 float128_div( float128, float128 STATUS_PARAM );
626 158142c2 bellard
float128 float128_rem( float128, float128 STATUS_PARAM );
627 158142c2 bellard
float128 float128_sqrt( float128 STATUS_PARAM );
628 750afe93 bellard
int float128_eq( float128, float128 STATUS_PARAM );
629 750afe93 bellard
int float128_le( float128, float128 STATUS_PARAM );
630 750afe93 bellard
int float128_lt( float128, float128 STATUS_PARAM );
631 750afe93 bellard
int float128_eq_signaling( float128, float128 STATUS_PARAM );
632 750afe93 bellard
int float128_le_quiet( float128, float128 STATUS_PARAM );
633 750afe93 bellard
int float128_lt_quiet( float128, float128 STATUS_PARAM );
634 1f587329 blueswir1
int float128_compare( float128, float128 STATUS_PARAM );
635 1f587329 blueswir1
int float128_compare_quiet( float128, float128 STATUS_PARAM );
636 18569871 Peter Maydell
int float128_is_quiet_nan( float128 );
637 750afe93 bellard
int float128_is_signaling_nan( float128 );
638 f6a7d92a Aurelien Jarno
float128 float128_maybe_silence_nan( float128 );
639 9ee6e8bb pbrook
float128 float128_scalbn( float128, int STATUS_PARAM );
640 158142c2 bellard
641 1d6bda35 bellard
INLINE float128 float128_abs(float128 a)
642 1d6bda35 bellard
{
643 1d6bda35 bellard
    a.high &= 0x7fffffffffffffffLL;
644 1d6bda35 bellard
    return a;
645 1d6bda35 bellard
}
646 1d6bda35 bellard
647 1d6bda35 bellard
INLINE float128 float128_chs(float128 a)
648 1d6bda35 bellard
{
649 1d6bda35 bellard
    a.high ^= 0x8000000000000000LL;
650 1d6bda35 bellard
    return a;
651 1d6bda35 bellard
}
652 1d6bda35 bellard
653 c52ab6f5 aurel32
INLINE int float128_is_infinity(float128 a)
654 c52ab6f5 aurel32
{
655 c52ab6f5 aurel32
    return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0;
656 c52ab6f5 aurel32
}
657 c52ab6f5 aurel32
658 c52ab6f5 aurel32
INLINE int float128_is_neg(float128 a)
659 c52ab6f5 aurel32
{
660 c52ab6f5 aurel32
    return a.high >> 63;
661 c52ab6f5 aurel32
}
662 c52ab6f5 aurel32
663 c52ab6f5 aurel32
INLINE int float128_is_zero(float128 a)
664 c52ab6f5 aurel32
{
665 c52ab6f5 aurel32
    return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0;
666 c52ab6f5 aurel32
}
667 c52ab6f5 aurel32
668 2bed652f Peter Maydell
INLINE int float128_is_any_nan(float128 a)
669 2bed652f Peter Maydell
{
670 2bed652f Peter Maydell
    return ((a.high >> 48) & 0x7fff) == 0x7fff &&
671 2bed652f Peter Maydell
        ((a.low != 0) || ((a.high & 0xffffffffffffLL) != 0));
672 2bed652f Peter Maydell
}
673 2bed652f Peter Maydell
674 8559666d Christophe Lyon
/*----------------------------------------------------------------------------
675 8559666d Christophe Lyon
| The pattern for a default generated quadruple-precision NaN.  The `high' and
676 8559666d Christophe Lyon
| `low' values hold the most- and least-significant bits, respectively.
677 8559666d Christophe Lyon
*----------------------------------------------------------------------------*/
678 8559666d Christophe Lyon
#if SNAN_BIT_IS_ONE
679 8559666d Christophe Lyon
#define float128_default_nan_high LIT64( 0x7FFF7FFFFFFFFFFF )
680 8559666d Christophe Lyon
#define float128_default_nan_low  LIT64( 0xFFFFFFFFFFFFFFFF )
681 8559666d Christophe Lyon
#else
682 8559666d Christophe Lyon
#define float128_default_nan_high LIT64( 0xFFFF800000000000 )
683 8559666d Christophe Lyon
#define float128_default_nan_low  LIT64( 0x0000000000000000 )
684 8559666d Christophe Lyon
#endif
685 8559666d Christophe Lyon
686 158142c2 bellard
#endif
687 158142c2 bellard
688 158142c2 bellard
#else /* CONFIG_SOFTFLOAT */
689 158142c2 bellard
690 158142c2 bellard
#include "softfloat-native.h"
691 158142c2 bellard
692 158142c2 bellard
#endif /* !CONFIG_SOFTFLOAT */
693 158142c2 bellard
694 158142c2 bellard
#endif /* !SOFTFLOAT_H */