4 * The code in this source file is derived from release 2a of the SoftFloat
5 * IEC/IEEE Floating-point Arithmetic Package. Those parts of the code (and
6 * some later contributions) are provided under that license, as detailed below.
7 * It has subsequently been modified by contributors to the QEMU Project,
8 * so some portions are provided under:
9 * the SoftFloat-2a license
13 * Any future contributions to this file after December 1st 2014 will be
14 * taken to be licensed under the Softfloat-2a license unless specifically
15 * indicated otherwise.
19 ===============================================================================
20 This C header file is part of the SoftFloat IEC/IEEE Floating-point
21 Arithmetic Package, Release 2a.
23 Written by John R. Hauser. This work was made possible in part by the
24 International Computer Science Institute, located at Suite 600, 1947 Center
25 Street, Berkeley, California 94704. Funding was partially provided by the
26 National Science Foundation under grant MIP-9311980. The original version
27 of this code was written as part of a project to build a fixed-point vector
28 processor in collaboration with the University of California at Berkeley,
29 overseen by Profs. Nelson Morgan and John Wawrzynek. More information
30 is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/
31 arithmetic/SoftFloat.html'.
33 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
34 has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
35 TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
36 PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
37 AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
39 Derivative works are acceptable, even for commercial purposes, so long as
40 (1) they include prominent notice that the work is derivative, and (2) they
41 include prominent notice akin to these four paragraphs for those parts of
42 this code that are retained.
44 ===============================================================================
48 * Copyright (c) 2006, Fabrice Bellard
49 * All rights reserved.
51 * Redistribution and use in source and binary forms, with or without
52 * modification, are permitted provided that the following conditions are met:
54 * 1. Redistributions of source code must retain the above copyright notice,
55 * this list of conditions and the following disclaimer.
57 * 2. Redistributions in binary form must reproduce the above copyright notice,
58 * this list of conditions and the following disclaimer in the documentation
59 * and/or other materials provided with the distribution.
61 * 3. Neither the name of the copyright holder nor the names of its contributors
62 * may be used to endorse or promote products derived from this software without
63 * specific prior written permission.
65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
66 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
69 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
70 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
71 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
72 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
73 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
74 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
75 * THE POSSIBILITY OF SUCH DAMAGE.
78 /* Portions of this work are licensed under the terms of the GNU GPL,
79 * version 2 or later. See the COPYING file in the top-level directory.
85 #if defined(CONFIG_SOLARIS) && defined(CONFIG_NEEDS_LIBSUNMATH)
90 /* This 'flag' type must be able to hold at least 0 and 1. It should
91 * probably be replaced with 'bool' but the uses would need to be audited
92 * to check that they weren't accidentally relying on it being a larger type.
96 #define LIT64( a ) a##LL
98 /*----------------------------------------------------------------------------
99 | Software IEC/IEEE floating-point ordering relations
100 *----------------------------------------------------------------------------*/
102 float_relation_less
= -1,
103 float_relation_equal
= 0,
104 float_relation_greater
= 1,
105 float_relation_unordered
= 2
108 /*----------------------------------------------------------------------------
109 | Software IEC/IEEE floating-point types.
110 *----------------------------------------------------------------------------*/
111 /* Use structures for soft-float types. This prevents accidentally mixing
112 them with native int/float types. A sufficiently clever compiler and
113 sane ABI should be able to see though these structs. However
114 x86/gcc 3.x seems to struggle a bit, so leave them disabled by default. */
115 //#define USE_SOFTFLOAT_STRUCT_TYPES
116 #ifdef USE_SOFTFLOAT_STRUCT_TYPES
120 #define float16_val(x) (((float16)(x)).v)
121 #define make_float16(x) __extension__ ({ float16 f16_val = {x}; f16_val; })
122 #define const_float16(x) { x }
126 /* The cast ensures an error if the wrong type is passed. */
127 #define float32_val(x) (((float32)(x)).v)
128 #define make_float32(x) __extension__ ({ float32 f32_val = {x}; f32_val; })
129 #define const_float32(x) { x }
133 #define float64_val(x) (((float64)(x)).v)
134 #define make_float64(x) __extension__ ({ float64 f64_val = {x}; f64_val; })
135 #define const_float64(x) { x }
137 typedef uint16_t float16
;
138 typedef uint32_t float32
;
139 typedef uint64_t float64
;
140 #define float16_val(x) (x)
141 #define float32_val(x) (x)
142 #define float64_val(x) (x)
143 #define make_float16(x) (x)
144 #define make_float32(x) (x)
145 #define make_float64(x) (x)
146 #define const_float16(x) (x)
147 #define const_float32(x) (x)
148 #define const_float64(x) (x)
154 #define make_floatx80(exp, mant) ((floatx80) { mant, exp })
155 #define make_floatx80_init(exp, mant) { .low = mant, .high = exp }
157 #ifdef HOST_WORDS_BIGENDIAN
163 #define make_float128(high_, low_) ((float128) { .high = high_, .low = low_ })
164 #define make_float128_init(high_, low_) { .high = high_, .low = low_ }
166 /*----------------------------------------------------------------------------
167 | Software IEC/IEEE floating-point underflow tininess-detection mode.
168 *----------------------------------------------------------------------------*/
170 float_tininess_after_rounding
= 0,
171 float_tininess_before_rounding
= 1
174 /*----------------------------------------------------------------------------
175 | Software IEC/IEEE floating-point rounding mode.
176 *----------------------------------------------------------------------------*/
178 float_round_nearest_even
= 0,
179 float_round_down
= 1,
181 float_round_to_zero
= 3,
182 float_round_ties_away
= 4,
183 /* Not an IEEE rounding mode: round to the closest odd mantissa value */
184 float_round_to_odd
= 5,
187 /*----------------------------------------------------------------------------
188 | Software IEC/IEEE floating-point exception flags.
189 *----------------------------------------------------------------------------*/
191 float_flag_invalid
= 1,
192 float_flag_divbyzero
= 4,
193 float_flag_overflow
= 8,
194 float_flag_underflow
= 16,
195 float_flag_inexact
= 32,
196 float_flag_input_denormal
= 64,
197 float_flag_output_denormal
= 128
200 typedef struct float_status
{
201 signed char float_detect_tininess
;
202 signed char float_rounding_mode
;
203 uint8_t float_exception_flags
;
204 signed char floatx80_rounding_precision
;
205 /* should denormalised results go to zero and set the inexact flag? */
207 /* should denormalised inputs go to zero and set the input_denormal flag? */
208 flag flush_inputs_to_zero
;
209 flag default_nan_mode
;
210 flag snan_bit_is_one
;
213 static inline void set_float_detect_tininess(int val
, float_status
*status
)
215 status
->float_detect_tininess
= val
;
217 static inline void set_float_rounding_mode(int val
, float_status
*status
)
219 status
->float_rounding_mode
= val
;
221 static inline void set_float_exception_flags(int val
, float_status
*status
)
223 status
->float_exception_flags
= val
;
225 static inline void set_floatx80_rounding_precision(int val
,
226 float_status
*status
)
228 status
->floatx80_rounding_precision
= val
;
230 static inline void set_flush_to_zero(flag val
, float_status
*status
)
232 status
->flush_to_zero
= val
;
234 static inline void set_flush_inputs_to_zero(flag val
, float_status
*status
)
236 status
->flush_inputs_to_zero
= val
;
238 static inline void set_default_nan_mode(flag val
, float_status
*status
)
240 status
->default_nan_mode
= val
;
242 static inline void set_snan_bit_is_one(flag val
, float_status
*status
)
244 status
->snan_bit_is_one
= val
;
246 static inline int get_float_detect_tininess(float_status
*status
)
248 return status
->float_detect_tininess
;
250 static inline int get_float_rounding_mode(float_status
*status
)
252 return status
->float_rounding_mode
;
254 static inline int get_float_exception_flags(float_status
*status
)
256 return status
->float_exception_flags
;
258 static inline int get_floatx80_rounding_precision(float_status
*status
)
260 return status
->floatx80_rounding_precision
;
262 static inline flag
get_flush_to_zero(float_status
*status
)
264 return status
->flush_to_zero
;
266 static inline flag
get_flush_inputs_to_zero(float_status
*status
)
268 return status
->flush_inputs_to_zero
;
270 static inline flag
get_default_nan_mode(float_status
*status
)
272 return status
->default_nan_mode
;
275 /*----------------------------------------------------------------------------
276 | Routine to raise any or all of the software IEC/IEEE floating-point
278 *----------------------------------------------------------------------------*/
279 void float_raise(uint8_t flags
, float_status
*status
);
281 /*----------------------------------------------------------------------------
282 | If `a' is denormal and we are in flush-to-zero mode then set the
283 | input-denormal exception and return zero. Otherwise just return the value.
284 *----------------------------------------------------------------------------*/
285 float32
float32_squash_input_denormal(float32 a
, float_status
*status
);
286 float64
float64_squash_input_denormal(float64 a
, float_status
*status
);
288 /*----------------------------------------------------------------------------
289 | Options to indicate which negations to perform in float*_muladd()
290 | Using these differs from negating an input or output before calling
291 | the muladd function in that this means that a NaN doesn't have its
292 | sign bit inverted before it is propagated.
293 | We also support halving the result before rounding, as a special
294 | case to support the ARM fused-sqrt-step instruction FRSQRTS.
295 *----------------------------------------------------------------------------*/
297 float_muladd_negate_c
= 1,
298 float_muladd_negate_product
= 2,
299 float_muladd_negate_result
= 4,
300 float_muladd_halve_result
= 8,
303 /*----------------------------------------------------------------------------
304 | Software IEC/IEEE integer-to-floating-point conversion routines.
305 *----------------------------------------------------------------------------*/
306 float32
int32_to_float32(int32_t, float_status
*status
);
307 float64
int32_to_float64(int32_t, float_status
*status
);
308 float32
uint32_to_float32(uint32_t, float_status
*status
);
309 float64
uint32_to_float64(uint32_t, float_status
*status
);
310 floatx80
int32_to_floatx80(int32_t, float_status
*status
);
311 float128
int32_to_float128(int32_t, float_status
*status
);
312 float32
int64_to_float32(int64_t, float_status
*status
);
313 float64
int64_to_float64(int64_t, float_status
*status
);
314 floatx80
int64_to_floatx80(int64_t, float_status
*status
);
315 float128
int64_to_float128(int64_t, float_status
*status
);
316 float32
uint64_to_float32(uint64_t, float_status
*status
);
317 float64
uint64_to_float64(uint64_t, float_status
*status
);
318 float128
uint64_to_float128(uint64_t, float_status
*status
);
320 /* We provide the int16 versions for symmetry of API with float-to-int */
321 static inline float32
int16_to_float32(int16_t v
, float_status
*status
)
323 return int32_to_float32(v
, status
);
326 static inline float32
uint16_to_float32(uint16_t v
, float_status
*status
)
328 return uint32_to_float32(v
, status
);
331 static inline float64
int16_to_float64(int16_t v
, float_status
*status
)
333 return int32_to_float64(v
, status
);
336 static inline float64
uint16_to_float64(uint16_t v
, float_status
*status
)
338 return uint32_to_float64(v
, status
);
341 /*----------------------------------------------------------------------------
342 | Software half-precision conversion routines.
343 *----------------------------------------------------------------------------*/
344 float16
float32_to_float16(float32
, flag
, float_status
*status
);
345 float32
float16_to_float32(float16
, flag
, float_status
*status
);
346 float16
float64_to_float16(float64 a
, flag ieee
, float_status
*status
);
347 float64
float16_to_float64(float16 a
, flag ieee
, float_status
*status
);
349 /*----------------------------------------------------------------------------
350 | Software half-precision operations.
351 *----------------------------------------------------------------------------*/
352 int float16_is_quiet_nan(float16
, float_status
*status
);
353 int float16_is_signaling_nan(float16
, float_status
*status
);
354 float16
float16_maybe_silence_nan(float16
, float_status
*status
);
356 static inline int float16_is_any_nan(float16 a
)
358 return ((float16_val(a
) & ~0x8000) > 0x7c00);
361 static inline int float16_is_neg(float16 a
)
363 return float16_val(a
) >> 15;
366 static inline int float16_is_infinity(float16 a
)
368 return (float16_val(a
) & 0x7fff) == 0x7c00;
371 static inline int float16_is_zero(float16 a
)
373 return (float16_val(a
) & 0x7fff) == 0;
376 static inline int float16_is_zero_or_denormal(float16 a
)
378 return (float16_val(a
) & 0x7c00) == 0;
381 /*----------------------------------------------------------------------------
382 | The pattern for a default generated half-precision NaN.
383 *----------------------------------------------------------------------------*/
384 float16
float16_default_nan(float_status
*status
);
386 /*----------------------------------------------------------------------------
387 | Software IEC/IEEE single-precision conversion routines.
388 *----------------------------------------------------------------------------*/
389 int16_t float32_to_int16(float32
, float_status
*status
);
390 uint16_t float32_to_uint16(float32
, float_status
*status
);
391 int16_t float32_to_int16_round_to_zero(float32
, float_status
*status
);
392 uint16_t float32_to_uint16_round_to_zero(float32
, float_status
*status
);
393 int32_t float32_to_int32(float32
, float_status
*status
);
394 int32_t float32_to_int32_round_to_zero(float32
, float_status
*status
);
395 uint32_t float32_to_uint32(float32
, float_status
*status
);
396 uint32_t float32_to_uint32_round_to_zero(float32
, float_status
*status
);
397 int64_t float32_to_int64(float32
, float_status
*status
);
398 uint64_t float32_to_uint64(float32
, float_status
*status
);
399 uint64_t float32_to_uint64_round_to_zero(float32
, float_status
*status
);
400 int64_t float32_to_int64_round_to_zero(float32
, float_status
*status
);
401 float64
float32_to_float64(float32
, float_status
*status
);
402 floatx80
float32_to_floatx80(float32
, float_status
*status
);
403 float128
float32_to_float128(float32
, float_status
*status
);
405 /*----------------------------------------------------------------------------
406 | Software IEC/IEEE single-precision operations.
407 *----------------------------------------------------------------------------*/
408 float32
float32_round_to_int(float32
, float_status
*status
);
409 float32
float32_add(float32
, float32
, float_status
*status
);
410 float32
float32_sub(float32
, float32
, float_status
*status
);
411 float32
float32_mul(float32
, float32
, float_status
*status
);
412 float32
float32_div(float32
, float32
, float_status
*status
);
413 float32
float32_rem(float32
, float32
, float_status
*status
);
414 float32
float32_muladd(float32
, float32
, float32
, int, float_status
*status
);
415 float32
float32_sqrt(float32
, float_status
*status
);
416 float32
float32_exp2(float32
, float_status
*status
);
417 float32
float32_log2(float32
, float_status
*status
);
418 int float32_eq(float32
, float32
, float_status
*status
);
419 int float32_le(float32
, float32
, float_status
*status
);
420 int float32_lt(float32
, float32
, float_status
*status
);
421 int float32_unordered(float32
, float32
, float_status
*status
);
422 int float32_eq_quiet(float32
, float32
, float_status
*status
);
423 int float32_le_quiet(float32
, float32
, float_status
*status
);
424 int float32_lt_quiet(float32
, float32
, float_status
*status
);
425 int float32_unordered_quiet(float32
, float32
, float_status
*status
);
426 int float32_compare(float32
, float32
, float_status
*status
);
427 int float32_compare_quiet(float32
, float32
, float_status
*status
);
428 float32
float32_min(float32
, float32
, float_status
*status
);
429 float32
float32_max(float32
, float32
, float_status
*status
);
430 float32
float32_minnum(float32
, float32
, float_status
*status
);
431 float32
float32_maxnum(float32
, float32
, float_status
*status
);
432 float32
float32_minnummag(float32
, float32
, float_status
*status
);
433 float32
float32_maxnummag(float32
, float32
, float_status
*status
);
434 int float32_is_quiet_nan(float32
, float_status
*status
);
435 int float32_is_signaling_nan(float32
, float_status
*status
);
436 float32
float32_maybe_silence_nan(float32
, float_status
*status
);
437 float32
float32_scalbn(float32
, int, float_status
*status
);
439 static inline float32
float32_abs(float32 a
)
441 /* Note that abs does *not* handle NaN specially, nor does
442 * it flush denormal inputs to zero.
444 return make_float32(float32_val(a
) & 0x7fffffff);
447 static inline float32
float32_chs(float32 a
)
449 /* Note that chs does *not* handle NaN specially, nor does
450 * it flush denormal inputs to zero.
452 return make_float32(float32_val(a
) ^ 0x80000000);
455 static inline int float32_is_infinity(float32 a
)
457 return (float32_val(a
) & 0x7fffffff) == 0x7f800000;
460 static inline int float32_is_neg(float32 a
)
462 return float32_val(a
) >> 31;
465 static inline int float32_is_zero(float32 a
)
467 return (float32_val(a
) & 0x7fffffff) == 0;
470 static inline int float32_is_any_nan(float32 a
)
472 return ((float32_val(a
) & ~(1 << 31)) > 0x7f800000UL
);
475 static inline int float32_is_zero_or_denormal(float32 a
)
477 return (float32_val(a
) & 0x7f800000) == 0;
480 static inline float32
float32_set_sign(float32 a
, int sign
)
482 return make_float32((float32_val(a
) & 0x7fffffff) | (sign
<< 31));
485 #define float32_zero make_float32(0)
486 #define float32_one make_float32(0x3f800000)
487 #define float32_ln2 make_float32(0x3f317218)
488 #define float32_pi make_float32(0x40490fdb)
489 #define float32_half make_float32(0x3f000000)
490 #define float32_infinity make_float32(0x7f800000)
493 /*----------------------------------------------------------------------------
494 | The pattern for a default generated single-precision NaN.
495 *----------------------------------------------------------------------------*/
496 float32
float32_default_nan(float_status
*status
);
498 /*----------------------------------------------------------------------------
499 | Software IEC/IEEE double-precision conversion routines.
500 *----------------------------------------------------------------------------*/
501 int16_t float64_to_int16(float64
, float_status
*status
);
502 uint16_t float64_to_uint16(float64
, float_status
*status
);
503 int16_t float64_to_int16_round_to_zero(float64
, float_status
*status
);
504 uint16_t float64_to_uint16_round_to_zero(float64
, float_status
*status
);
505 int32_t float64_to_int32(float64
, float_status
*status
);
506 int32_t float64_to_int32_round_to_zero(float64
, float_status
*status
);
507 uint32_t float64_to_uint32(float64
, float_status
*status
);
508 uint32_t float64_to_uint32_round_to_zero(float64
, float_status
*status
);
509 int64_t float64_to_int64(float64
, float_status
*status
);
510 int64_t float64_to_int64_round_to_zero(float64
, float_status
*status
);
511 uint64_t float64_to_uint64(float64 a
, float_status
*status
);
512 uint64_t float64_to_uint64_round_to_zero(float64 a
, float_status
*status
);
513 float32
float64_to_float32(float64
, float_status
*status
);
514 floatx80
float64_to_floatx80(float64
, float_status
*status
);
515 float128
float64_to_float128(float64
, float_status
*status
);
517 /*----------------------------------------------------------------------------
518 | Software IEC/IEEE double-precision operations.
519 *----------------------------------------------------------------------------*/
520 float64
float64_round_to_int(float64
, float_status
*status
);
521 float64
float64_trunc_to_int(float64
, float_status
*status
);
522 float64
float64_add(float64
, float64
, float_status
*status
);
523 float64
float64_sub(float64
, float64
, float_status
*status
);
524 float64
float64_mul(float64
, float64
, float_status
*status
);
525 float64
float64_div(float64
, float64
, float_status
*status
);
526 float64
float64_rem(float64
, float64
, float_status
*status
);
527 float64
float64_muladd(float64
, float64
, float64
, int, float_status
*status
);
528 float64
float64_sqrt(float64
, float_status
*status
);
529 float64
float64_log2(float64
, float_status
*status
);
530 int float64_eq(float64
, float64
, float_status
*status
);
531 int float64_le(float64
, float64
, float_status
*status
);
532 int float64_lt(float64
, float64
, float_status
*status
);
533 int float64_unordered(float64
, float64
, float_status
*status
);
534 int float64_eq_quiet(float64
, float64
, float_status
*status
);
535 int float64_le_quiet(float64
, float64
, float_status
*status
);
536 int float64_lt_quiet(float64
, float64
, float_status
*status
);
537 int float64_unordered_quiet(float64
, float64
, float_status
*status
);
538 int float64_compare(float64
, float64
, float_status
*status
);
539 int float64_compare_quiet(float64
, float64
, float_status
*status
);
540 float64
float64_min(float64
, float64
, float_status
*status
);
541 float64
float64_max(float64
, float64
, float_status
*status
);
542 float64
float64_minnum(float64
, float64
, float_status
*status
);
543 float64
float64_maxnum(float64
, float64
, float_status
*status
);
544 float64
float64_minnummag(float64
, float64
, float_status
*status
);
545 float64
float64_maxnummag(float64
, float64
, float_status
*status
);
546 int float64_is_quiet_nan(float64 a
, float_status
*status
);
547 int float64_is_signaling_nan(float64
, float_status
*status
);
548 float64
float64_maybe_silence_nan(float64
, float_status
*status
);
549 float64
float64_scalbn(float64
, int, float_status
*status
);
551 static inline float64
float64_abs(float64 a
)
553 /* Note that abs does *not* handle NaN specially, nor does
554 * it flush denormal inputs to zero.
556 return make_float64(float64_val(a
) & 0x7fffffffffffffffLL
);
559 static inline float64
float64_chs(float64 a
)
561 /* Note that chs does *not* handle NaN specially, nor does
562 * it flush denormal inputs to zero.
564 return make_float64(float64_val(a
) ^ 0x8000000000000000LL
);
567 static inline int float64_is_infinity(float64 a
)
569 return (float64_val(a
) & 0x7fffffffffffffffLL
) == 0x7ff0000000000000LL
;
572 static inline int float64_is_neg(float64 a
)
574 return float64_val(a
) >> 63;
577 static inline int float64_is_zero(float64 a
)
579 return (float64_val(a
) & 0x7fffffffffffffffLL
) == 0;
582 static inline int float64_is_any_nan(float64 a
)
584 return ((float64_val(a
) & ~(1ULL << 63)) > 0x7ff0000000000000ULL
);
587 static inline int float64_is_zero_or_denormal(float64 a
)
589 return (float64_val(a
) & 0x7ff0000000000000LL
) == 0;
592 static inline float64
float64_set_sign(float64 a
, int sign
)
594 return make_float64((float64_val(a
) & 0x7fffffffffffffffULL
)
595 | ((int64_t)sign
<< 63));
598 #define float64_zero make_float64(0)
599 #define float64_one make_float64(0x3ff0000000000000LL)
600 #define float64_ln2 make_float64(0x3fe62e42fefa39efLL)
601 #define float64_pi make_float64(0x400921fb54442d18LL)
602 #define float64_half make_float64(0x3fe0000000000000LL)
603 #define float64_infinity make_float64(0x7ff0000000000000LL)
605 /*----------------------------------------------------------------------------
606 | The pattern for a default generated double-precision NaN.
607 *----------------------------------------------------------------------------*/
608 float64
float64_default_nan(float_status
*status
);
610 /*----------------------------------------------------------------------------
611 | Software IEC/IEEE extended double-precision conversion routines.
612 *----------------------------------------------------------------------------*/
613 int32_t floatx80_to_int32(floatx80
, float_status
*status
);
614 int32_t floatx80_to_int32_round_to_zero(floatx80
, float_status
*status
);
615 int64_t floatx80_to_int64(floatx80
, float_status
*status
);
616 int64_t floatx80_to_int64_round_to_zero(floatx80
, float_status
*status
);
617 float32
floatx80_to_float32(floatx80
, float_status
*status
);
618 float64
floatx80_to_float64(floatx80
, float_status
*status
);
619 float128
floatx80_to_float128(floatx80
, float_status
*status
);
621 /*----------------------------------------------------------------------------
622 | Software IEC/IEEE extended double-precision operations.
623 *----------------------------------------------------------------------------*/
624 floatx80
floatx80_round_to_int(floatx80
, float_status
*status
);
625 floatx80
floatx80_add(floatx80
, floatx80
, float_status
*status
);
626 floatx80
floatx80_sub(floatx80
, floatx80
, float_status
*status
);
627 floatx80
floatx80_mul(floatx80
, floatx80
, float_status
*status
);
628 floatx80
floatx80_div(floatx80
, floatx80
, float_status
*status
);
629 floatx80
floatx80_rem(floatx80
, floatx80
, float_status
*status
);
630 floatx80
floatx80_sqrt(floatx80
, float_status
*status
);
631 int floatx80_eq(floatx80
, floatx80
, float_status
*status
);
632 int floatx80_le(floatx80
, floatx80
, float_status
*status
);
633 int floatx80_lt(floatx80
, floatx80
, float_status
*status
);
634 int floatx80_unordered(floatx80
, floatx80
, float_status
*status
);
635 int floatx80_eq_quiet(floatx80
, floatx80
, float_status
*status
);
636 int floatx80_le_quiet(floatx80
, floatx80
, float_status
*status
);
637 int floatx80_lt_quiet(floatx80
, floatx80
, float_status
*status
);
638 int floatx80_unordered_quiet(floatx80
, floatx80
, float_status
*status
);
639 int floatx80_compare(floatx80
, floatx80
, float_status
*status
);
640 int floatx80_compare_quiet(floatx80
, floatx80
, float_status
*status
);
641 int floatx80_is_quiet_nan(floatx80
, float_status
*status
);
642 int floatx80_is_signaling_nan(floatx80
, float_status
*status
);
643 floatx80
floatx80_maybe_silence_nan(floatx80
, float_status
*status
);
644 floatx80
floatx80_scalbn(floatx80
, int, float_status
*status
);
646 static inline floatx80
floatx80_abs(floatx80 a
)
652 static inline floatx80
floatx80_chs(floatx80 a
)
658 static inline int floatx80_is_infinity(floatx80 a
)
660 return (a
.high
& 0x7fff) == 0x7fff && a
.low
== 0x8000000000000000LL
;
663 static inline int floatx80_is_neg(floatx80 a
)
668 static inline int floatx80_is_zero(floatx80 a
)
670 return (a
.high
& 0x7fff) == 0 && a
.low
== 0;
673 static inline int floatx80_is_zero_or_denormal(floatx80 a
)
675 return (a
.high
& 0x7fff) == 0;
678 static inline int floatx80_is_any_nan(floatx80 a
)
680 return ((a
.high
& 0x7fff) == 0x7fff) && (a
.low
<<1);
683 /*----------------------------------------------------------------------------
684 | Return whether the given value is an invalid floatx80 encoding.
685 | Invalid floatx80 encodings arise when the integer bit is not set, but
686 | the exponent is not zero. The only times the integer bit is permitted to
687 | be zero is in subnormal numbers and the value zero.
688 | This includes what the Intel software developer's manual calls pseudo-NaNs,
689 | pseudo-infinities and un-normal numbers. It does not include
690 | pseudo-denormals, which must still be correctly handled as inputs even
691 | if they are never generated as outputs.
692 *----------------------------------------------------------------------------*/
693 static inline bool floatx80_invalid_encoding(floatx80 a
)
695 return (a
.low
& (1ULL << 63)) == 0 && (a
.high
& 0x7FFF) != 0;
698 #define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL)
699 #define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)
700 #define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)
701 #define floatx80_pi make_floatx80(0x4000, 0xc90fdaa22168c235LL)
702 #define floatx80_half make_floatx80(0x3ffe, 0x8000000000000000LL)
703 #define floatx80_infinity make_floatx80(0x7fff, 0x8000000000000000LL)
705 /*----------------------------------------------------------------------------
706 | The pattern for a default generated extended double-precision NaN.
707 *----------------------------------------------------------------------------*/
708 floatx80
floatx80_default_nan(float_status
*status
);
710 /*----------------------------------------------------------------------------
711 | Software IEC/IEEE quadruple-precision conversion routines.
712 *----------------------------------------------------------------------------*/
713 int32_t float128_to_int32(float128
, float_status
*status
);
714 int32_t float128_to_int32_round_to_zero(float128
, float_status
*status
);
715 int64_t float128_to_int64(float128
, float_status
*status
);
716 int64_t float128_to_int64_round_to_zero(float128
, float_status
*status
);
717 uint64_t float128_to_uint64(float128
, float_status
*status
);
718 uint64_t float128_to_uint64_round_to_zero(float128
, float_status
*status
);
719 uint32_t float128_to_uint32_round_to_zero(float128
, float_status
*status
);
720 float32
float128_to_float32(float128
, float_status
*status
);
721 float64
float128_to_float64(float128
, float_status
*status
);
722 floatx80
float128_to_floatx80(float128
, float_status
*status
);
724 /*----------------------------------------------------------------------------
725 | Software IEC/IEEE quadruple-precision operations.
726 *----------------------------------------------------------------------------*/
727 float128
float128_round_to_int(float128
, float_status
*status
);
728 float128
float128_add(float128
, float128
, float_status
*status
);
729 float128
float128_sub(float128
, float128
, float_status
*status
);
730 float128
float128_mul(float128
, float128
, float_status
*status
);
731 float128
float128_div(float128
, float128
, float_status
*status
);
732 float128
float128_rem(float128
, float128
, float_status
*status
);
733 float128
float128_sqrt(float128
, float_status
*status
);
734 int float128_eq(float128
, float128
, float_status
*status
);
735 int float128_le(float128
, float128
, float_status
*status
);
736 int float128_lt(float128
, float128
, float_status
*status
);
737 int float128_unordered(float128
, float128
, float_status
*status
);
738 int float128_eq_quiet(float128
, float128
, float_status
*status
);
739 int float128_le_quiet(float128
, float128
, float_status
*status
);
740 int float128_lt_quiet(float128
, float128
, float_status
*status
);
741 int float128_unordered_quiet(float128
, float128
, float_status
*status
);
742 int float128_compare(float128
, float128
, float_status
*status
);
743 int float128_compare_quiet(float128
, float128
, float_status
*status
);
744 int float128_is_quiet_nan(float128
, float_status
*status
);
745 int float128_is_signaling_nan(float128
, float_status
*status
);
746 float128
float128_maybe_silence_nan(float128
, float_status
*status
);
747 float128
float128_scalbn(float128
, int, float_status
*status
);
749 static inline float128
float128_abs(float128 a
)
751 a
.high
&= 0x7fffffffffffffffLL
;
755 static inline float128
float128_chs(float128 a
)
757 a
.high
^= 0x8000000000000000LL
;
761 static inline int float128_is_infinity(float128 a
)
763 return (a
.high
& 0x7fffffffffffffffLL
) == 0x7fff000000000000LL
&& a
.low
== 0;
766 static inline int float128_is_neg(float128 a
)
771 static inline int float128_is_zero(float128 a
)
773 return (a
.high
& 0x7fffffffffffffffLL
) == 0 && a
.low
== 0;
776 static inline int float128_is_zero_or_denormal(float128 a
)
778 return (a
.high
& 0x7fff000000000000LL
) == 0;
781 static inline int float128_is_any_nan(float128 a
)
783 return ((a
.high
>> 48) & 0x7fff) == 0x7fff &&
784 ((a
.low
!= 0) || ((a
.high
& 0xffffffffffffLL
) != 0));
787 #define float128_zero make_float128(0, 0)
789 /*----------------------------------------------------------------------------
790 | The pattern for a default generated quadruple-precision NaN.
791 *----------------------------------------------------------------------------*/
792 float128
float128_default_nan(float_status
*status
);
794 #endif /* SOFTFLOAT_H */