xref: /openbmc/qemu/include/fpu/softfloat.h (revision 7ef295ea)
1 /*
2  * QEMU float support
3  *
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
10  *  the BSD license
11  *  GPL-v2-or-later
12  *
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.
16  */
17 
18 /*
19 ===============================================================================
20 This C header file is part of the SoftFloat IEC/IEEE Floating-point
21 Arithmetic Package, Release 2a.
22 
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'.
32 
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.
38 
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.
43 
44 ===============================================================================
45 */
46 
47 /* BSD licensing:
48  * Copyright (c) 2006, Fabrice Bellard
49  * All rights reserved.
50  *
51  * Redistribution and use in source and binary forms, with or without
52  * modification, are permitted provided that the following conditions are met:
53  *
54  * 1. Redistributions of source code must retain the above copyright notice,
55  * this list of conditions and the following disclaimer.
56  *
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.
60  *
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.
64  *
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.
76  */
77 
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.
80  */
81 
82 #ifndef SOFTFLOAT_H
83 #define SOFTFLOAT_H
84 
85 #if defined(CONFIG_SOLARIS) && defined(CONFIG_NEEDS_LIBSUNMATH)
86 #include <sunmath.h>
87 #endif
88 
89 
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.
93  */
94 typedef uint8_t flag;
95 
96 #define LIT64( a ) a##LL
97 
98 /*----------------------------------------------------------------------------
99 | Software IEC/IEEE floating-point ordering relations
100 *----------------------------------------------------------------------------*/
101 enum {
102     float_relation_less      = -1,
103     float_relation_equal     =  0,
104     float_relation_greater   =  1,
105     float_relation_unordered =  2
106 };
107 
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
117 typedef struct {
118     uint16_t v;
119 } float16;
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 }
123 typedef struct {
124     uint32_t v;
125 } float32;
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 }
130 typedef struct {
131     uint64_t v;
132 } float64;
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 }
136 #else
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)
149 #endif
150 typedef struct {
151     uint64_t low;
152     uint16_t high;
153 } floatx80;
154 #define make_floatx80(exp, mant) ((floatx80) { mant, exp })
155 #define make_floatx80_init(exp, mant) { .low = mant, .high = exp }
156 typedef struct {
157 #ifdef HOST_WORDS_BIGENDIAN
158     uint64_t high, low;
159 #else
160     uint64_t low, high;
161 #endif
162 } float128;
163 #define make_float128(high_, low_) ((float128) { .high = high_, .low = low_ })
164 #define make_float128_init(high_, low_) { .high = high_, .low = low_ }
165 
166 /*----------------------------------------------------------------------------
167 | Software IEC/IEEE floating-point underflow tininess-detection mode.
168 *----------------------------------------------------------------------------*/
169 enum {
170     float_tininess_after_rounding  = 0,
171     float_tininess_before_rounding = 1
172 };
173 
174 /*----------------------------------------------------------------------------
175 | Software IEC/IEEE floating-point rounding mode.
176 *----------------------------------------------------------------------------*/
177 enum {
178     float_round_nearest_even = 0,
179     float_round_down         = 1,
180     float_round_up           = 2,
181     float_round_to_zero      = 3,
182     float_round_ties_away    = 4,
183 };
184 
185 /*----------------------------------------------------------------------------
186 | Software IEC/IEEE floating-point exception flags.
187 *----------------------------------------------------------------------------*/
188 enum {
189     float_flag_invalid   =  1,
190     float_flag_divbyzero =  4,
191     float_flag_overflow  =  8,
192     float_flag_underflow = 16,
193     float_flag_inexact   = 32,
194     float_flag_input_denormal = 64,
195     float_flag_output_denormal = 128
196 };
197 
198 typedef struct float_status {
199     signed char float_detect_tininess;
200     signed char float_rounding_mode;
201     signed char float_exception_flags;
202     signed char floatx80_rounding_precision;
203     /* should denormalised results go to zero and set the inexact flag? */
204     flag flush_to_zero;
205     /* should denormalised inputs go to zero and set the input_denormal flag? */
206     flag flush_inputs_to_zero;
207     flag default_nan_mode;
208 } float_status;
209 
210 static inline void set_float_detect_tininess(int val, float_status *status)
211 {
212     status->float_detect_tininess = val;
213 }
214 static inline void set_float_rounding_mode(int val, float_status *status)
215 {
216     status->float_rounding_mode = val;
217 }
218 static inline void set_float_exception_flags(int val, float_status *status)
219 {
220     status->float_exception_flags = val;
221 }
222 static inline void set_floatx80_rounding_precision(int val,
223                                                    float_status *status)
224 {
225     status->floatx80_rounding_precision = val;
226 }
227 static inline void set_flush_to_zero(flag val, float_status *status)
228 {
229     status->flush_to_zero = val;
230 }
231 static inline void set_flush_inputs_to_zero(flag val, float_status *status)
232 {
233     status->flush_inputs_to_zero = val;
234 }
235 static inline void set_default_nan_mode(flag val, float_status *status)
236 {
237     status->default_nan_mode = val;
238 }
239 static inline int get_float_detect_tininess(float_status *status)
240 {
241     return status->float_detect_tininess;
242 }
243 static inline int get_float_rounding_mode(float_status *status)
244 {
245     return status->float_rounding_mode;
246 }
247 static inline int get_float_exception_flags(float_status *status)
248 {
249     return status->float_exception_flags;
250 }
251 static inline int get_floatx80_rounding_precision(float_status *status)
252 {
253     return status->floatx80_rounding_precision;
254 }
255 static inline flag get_flush_to_zero(float_status *status)
256 {
257     return status->flush_to_zero;
258 }
259 static inline flag get_flush_inputs_to_zero(float_status *status)
260 {
261     return status->flush_inputs_to_zero;
262 }
263 static inline flag get_default_nan_mode(float_status *status)
264 {
265     return status->default_nan_mode;
266 }
267 
268 /*----------------------------------------------------------------------------
269 | Routine to raise any or all of the software IEC/IEEE floating-point
270 | exception flags.
271 *----------------------------------------------------------------------------*/
272 void float_raise(int8_t flags, float_status *status);
273 
274 /*----------------------------------------------------------------------------
275 | If `a' is denormal and we are in flush-to-zero mode then set the
276 | input-denormal exception and return zero. Otherwise just return the value.
277 *----------------------------------------------------------------------------*/
278 float32 float32_squash_input_denormal(float32 a, float_status *status);
279 float64 float64_squash_input_denormal(float64 a, float_status *status);
280 
281 /*----------------------------------------------------------------------------
282 | Options to indicate which negations to perform in float*_muladd()
283 | Using these differs from negating an input or output before calling
284 | the muladd function in that this means that a NaN doesn't have its
285 | sign bit inverted before it is propagated.
286 | We also support halving the result before rounding, as a special
287 | case to support the ARM fused-sqrt-step instruction FRSQRTS.
288 *----------------------------------------------------------------------------*/
289 enum {
290     float_muladd_negate_c = 1,
291     float_muladd_negate_product = 2,
292     float_muladd_negate_result = 4,
293     float_muladd_halve_result = 8,
294 };
295 
296 /*----------------------------------------------------------------------------
297 | Software IEC/IEEE integer-to-floating-point conversion routines.
298 *----------------------------------------------------------------------------*/
299 float32 int32_to_float32(int32_t, float_status *status);
300 float64 int32_to_float64(int32_t, float_status *status);
301 float32 uint32_to_float32(uint32_t, float_status *status);
302 float64 uint32_to_float64(uint32_t, float_status *status);
303 floatx80 int32_to_floatx80(int32_t, float_status *status);
304 float128 int32_to_float128(int32_t, float_status *status);
305 float32 int64_to_float32(int64_t, float_status *status);
306 float64 int64_to_float64(int64_t, float_status *status);
307 floatx80 int64_to_floatx80(int64_t, float_status *status);
308 float128 int64_to_float128(int64_t, float_status *status);
309 float32 uint64_to_float32(uint64_t, float_status *status);
310 float64 uint64_to_float64(uint64_t, float_status *status);
311 float128 uint64_to_float128(uint64_t, float_status *status);
312 
313 /* We provide the int16 versions for symmetry of API with float-to-int */
314 static inline float32 int16_to_float32(int16_t v, float_status *status)
315 {
316     return int32_to_float32(v, status);
317 }
318 
319 static inline float32 uint16_to_float32(uint16_t v, float_status *status)
320 {
321     return uint32_to_float32(v, status);
322 }
323 
324 static inline float64 int16_to_float64(int16_t v, float_status *status)
325 {
326     return int32_to_float64(v, status);
327 }
328 
329 static inline float64 uint16_to_float64(uint16_t v, float_status *status)
330 {
331     return uint32_to_float64(v, status);
332 }
333 
334 /*----------------------------------------------------------------------------
335 | Software half-precision conversion routines.
336 *----------------------------------------------------------------------------*/
337 float16 float32_to_float16(float32, flag, float_status *status);
338 float32 float16_to_float32(float16, flag, float_status *status);
339 float16 float64_to_float16(float64 a, flag ieee, float_status *status);
340 float64 float16_to_float64(float16 a, flag ieee, float_status *status);
341 
342 /*----------------------------------------------------------------------------
343 | Software half-precision operations.
344 *----------------------------------------------------------------------------*/
345 int float16_is_quiet_nan( float16 );
346 int float16_is_signaling_nan( float16 );
347 float16 float16_maybe_silence_nan( float16 );
348 
349 static inline int float16_is_any_nan(float16 a)
350 {
351     return ((float16_val(a) & ~0x8000) > 0x7c00);
352 }
353 
354 /*----------------------------------------------------------------------------
355 | The pattern for a default generated half-precision NaN.
356 *----------------------------------------------------------------------------*/
357 extern const float16 float16_default_nan;
358 
359 /*----------------------------------------------------------------------------
360 | Software IEC/IEEE single-precision conversion routines.
361 *----------------------------------------------------------------------------*/
362 int16_t float32_to_int16(float32, float_status *status);
363 uint16_t float32_to_uint16(float32, float_status *status);
364 int16_t float32_to_int16_round_to_zero(float32, float_status *status);
365 uint16_t float32_to_uint16_round_to_zero(float32, float_status *status);
366 int32_t float32_to_int32(float32, float_status *status);
367 int32_t float32_to_int32_round_to_zero(float32, float_status *status);
368 uint32_t float32_to_uint32(float32, float_status *status);
369 uint32_t float32_to_uint32_round_to_zero(float32, float_status *status);
370 int64_t float32_to_int64(float32, float_status *status);
371 uint64_t float32_to_uint64(float32, float_status *status);
372 uint64_t float32_to_uint64_round_to_zero(float32, float_status *status);
373 int64_t float32_to_int64_round_to_zero(float32, float_status *status);
374 float64 float32_to_float64(float32, float_status *status);
375 floatx80 float32_to_floatx80(float32, float_status *status);
376 float128 float32_to_float128(float32, float_status *status);
377 
378 /*----------------------------------------------------------------------------
379 | Software IEC/IEEE single-precision operations.
380 *----------------------------------------------------------------------------*/
381 float32 float32_round_to_int(float32, float_status *status);
382 float32 float32_add(float32, float32, float_status *status);
383 float32 float32_sub(float32, float32, float_status *status);
384 float32 float32_mul(float32, float32, float_status *status);
385 float32 float32_div(float32, float32, float_status *status);
386 float32 float32_rem(float32, float32, float_status *status);
387 float32 float32_muladd(float32, float32, float32, int, float_status *status);
388 float32 float32_sqrt(float32, float_status *status);
389 float32 float32_exp2(float32, float_status *status);
390 float32 float32_log2(float32, float_status *status);
391 int float32_eq(float32, float32, float_status *status);
392 int float32_le(float32, float32, float_status *status);
393 int float32_lt(float32, float32, float_status *status);
394 int float32_unordered(float32, float32, float_status *status);
395 int float32_eq_quiet(float32, float32, float_status *status);
396 int float32_le_quiet(float32, float32, float_status *status);
397 int float32_lt_quiet(float32, float32, float_status *status);
398 int float32_unordered_quiet(float32, float32, float_status *status);
399 int float32_compare(float32, float32, float_status *status);
400 int float32_compare_quiet(float32, float32, float_status *status);
401 float32 float32_min(float32, float32, float_status *status);
402 float32 float32_max(float32, float32, float_status *status);
403 float32 float32_minnum(float32, float32, float_status *status);
404 float32 float32_maxnum(float32, float32, float_status *status);
405 float32 float32_minnummag(float32, float32, float_status *status);
406 float32 float32_maxnummag(float32, float32, float_status *status);
407 int float32_is_quiet_nan( float32 );
408 int float32_is_signaling_nan( float32 );
409 float32 float32_maybe_silence_nan( float32 );
410 float32 float32_scalbn(float32, int, float_status *status);
411 
412 static inline float32 float32_abs(float32 a)
413 {
414     /* Note that abs does *not* handle NaN specially, nor does
415      * it flush denormal inputs to zero.
416      */
417     return make_float32(float32_val(a) & 0x7fffffff);
418 }
419 
420 static inline float32 float32_chs(float32 a)
421 {
422     /* Note that chs does *not* handle NaN specially, nor does
423      * it flush denormal inputs to zero.
424      */
425     return make_float32(float32_val(a) ^ 0x80000000);
426 }
427 
428 static inline int float32_is_infinity(float32 a)
429 {
430     return (float32_val(a) & 0x7fffffff) == 0x7f800000;
431 }
432 
433 static inline int float32_is_neg(float32 a)
434 {
435     return float32_val(a) >> 31;
436 }
437 
438 static inline int float32_is_zero(float32 a)
439 {
440     return (float32_val(a) & 0x7fffffff) == 0;
441 }
442 
443 static inline int float32_is_any_nan(float32 a)
444 {
445     return ((float32_val(a) & ~(1 << 31)) > 0x7f800000UL);
446 }
447 
448 static inline int float32_is_zero_or_denormal(float32 a)
449 {
450     return (float32_val(a) & 0x7f800000) == 0;
451 }
452 
453 static inline float32 float32_set_sign(float32 a, int sign)
454 {
455     return make_float32((float32_val(a) & 0x7fffffff) | (sign << 31));
456 }
457 
458 #define float32_zero make_float32(0)
459 #define float32_one make_float32(0x3f800000)
460 #define float32_ln2 make_float32(0x3f317218)
461 #define float32_pi make_float32(0x40490fdb)
462 #define float32_half make_float32(0x3f000000)
463 #define float32_infinity make_float32(0x7f800000)
464 
465 
466 /*----------------------------------------------------------------------------
467 | The pattern for a default generated single-precision NaN.
468 *----------------------------------------------------------------------------*/
469 extern const float32 float32_default_nan;
470 
471 /*----------------------------------------------------------------------------
472 | Software IEC/IEEE double-precision conversion routines.
473 *----------------------------------------------------------------------------*/
474 int16_t float64_to_int16(float64, float_status *status);
475 uint16_t float64_to_uint16(float64, float_status *status);
476 int16_t float64_to_int16_round_to_zero(float64, float_status *status);
477 uint16_t float64_to_uint16_round_to_zero(float64, float_status *status);
478 int32_t float64_to_int32(float64, float_status *status);
479 int32_t float64_to_int32_round_to_zero(float64, float_status *status);
480 uint32_t float64_to_uint32(float64, float_status *status);
481 uint32_t float64_to_uint32_round_to_zero(float64, float_status *status);
482 int64_t float64_to_int64(float64, float_status *status);
483 int64_t float64_to_int64_round_to_zero(float64, float_status *status);
484 uint64_t float64_to_uint64(float64 a, float_status *status);
485 uint64_t float64_to_uint64_round_to_zero(float64 a, float_status *status);
486 float32 float64_to_float32(float64, float_status *status);
487 floatx80 float64_to_floatx80(float64, float_status *status);
488 float128 float64_to_float128(float64, float_status *status);
489 
490 /*----------------------------------------------------------------------------
491 | Software IEC/IEEE double-precision operations.
492 *----------------------------------------------------------------------------*/
493 float64 float64_round_to_int(float64, float_status *status);
494 float64 float64_trunc_to_int(float64, float_status *status);
495 float64 float64_add(float64, float64, float_status *status);
496 float64 float64_sub(float64, float64, float_status *status);
497 float64 float64_mul(float64, float64, float_status *status);
498 float64 float64_div(float64, float64, float_status *status);
499 float64 float64_rem(float64, float64, float_status *status);
500 float64 float64_muladd(float64, float64, float64, int, float_status *status);
501 float64 float64_sqrt(float64, float_status *status);
502 float64 float64_log2(float64, float_status *status);
503 int float64_eq(float64, float64, float_status *status);
504 int float64_le(float64, float64, float_status *status);
505 int float64_lt(float64, float64, float_status *status);
506 int float64_unordered(float64, float64, float_status *status);
507 int float64_eq_quiet(float64, float64, float_status *status);
508 int float64_le_quiet(float64, float64, float_status *status);
509 int float64_lt_quiet(float64, float64, float_status *status);
510 int float64_unordered_quiet(float64, float64, float_status *status);
511 int float64_compare(float64, float64, float_status *status);
512 int float64_compare_quiet(float64, float64, float_status *status);
513 float64 float64_min(float64, float64, float_status *status);
514 float64 float64_max(float64, float64, float_status *status);
515 float64 float64_minnum(float64, float64, float_status *status);
516 float64 float64_maxnum(float64, float64, float_status *status);
517 float64 float64_minnummag(float64, float64, float_status *status);
518 float64 float64_maxnummag(float64, float64, float_status *status);
519 int float64_is_quiet_nan( float64 a );
520 int float64_is_signaling_nan( float64 );
521 float64 float64_maybe_silence_nan( float64 );
522 float64 float64_scalbn(float64, int, float_status *status);
523 
524 static inline float64 float64_abs(float64 a)
525 {
526     /* Note that abs does *not* handle NaN specially, nor does
527      * it flush denormal inputs to zero.
528      */
529     return make_float64(float64_val(a) & 0x7fffffffffffffffLL);
530 }
531 
532 static inline float64 float64_chs(float64 a)
533 {
534     /* Note that chs does *not* handle NaN specially, nor does
535      * it flush denormal inputs to zero.
536      */
537     return make_float64(float64_val(a) ^ 0x8000000000000000LL);
538 }
539 
540 static inline int float64_is_infinity(float64 a)
541 {
542     return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL;
543 }
544 
545 static inline int float64_is_neg(float64 a)
546 {
547     return float64_val(a) >> 63;
548 }
549 
550 static inline int float64_is_zero(float64 a)
551 {
552     return (float64_val(a) & 0x7fffffffffffffffLL) == 0;
553 }
554 
555 static inline int float64_is_any_nan(float64 a)
556 {
557     return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL);
558 }
559 
560 static inline int float64_is_zero_or_denormal(float64 a)
561 {
562     return (float64_val(a) & 0x7ff0000000000000LL) == 0;
563 }
564 
565 static inline float64 float64_set_sign(float64 a, int sign)
566 {
567     return make_float64((float64_val(a) & 0x7fffffffffffffffULL)
568                         | ((int64_t)sign << 63));
569 }
570 
571 #define float64_zero make_float64(0)
572 #define float64_one make_float64(0x3ff0000000000000LL)
573 #define float64_ln2 make_float64(0x3fe62e42fefa39efLL)
574 #define float64_pi make_float64(0x400921fb54442d18LL)
575 #define float64_half make_float64(0x3fe0000000000000LL)
576 #define float64_infinity make_float64(0x7ff0000000000000LL)
577 
578 /*----------------------------------------------------------------------------
579 | The pattern for a default generated double-precision NaN.
580 *----------------------------------------------------------------------------*/
581 extern const float64 float64_default_nan;
582 
583 /*----------------------------------------------------------------------------
584 | Software IEC/IEEE extended double-precision conversion routines.
585 *----------------------------------------------------------------------------*/
586 int32_t floatx80_to_int32(floatx80, float_status *status);
587 int32_t floatx80_to_int32_round_to_zero(floatx80, float_status *status);
588 int64_t floatx80_to_int64(floatx80, float_status *status);
589 int64_t floatx80_to_int64_round_to_zero(floatx80, float_status *status);
590 float32 floatx80_to_float32(floatx80, float_status *status);
591 float64 floatx80_to_float64(floatx80, float_status *status);
592 float128 floatx80_to_float128(floatx80, float_status *status);
593 
594 /*----------------------------------------------------------------------------
595 | Software IEC/IEEE extended double-precision operations.
596 *----------------------------------------------------------------------------*/
597 floatx80 floatx80_round_to_int(floatx80, float_status *status);
598 floatx80 floatx80_add(floatx80, floatx80, float_status *status);
599 floatx80 floatx80_sub(floatx80, floatx80, float_status *status);
600 floatx80 floatx80_mul(floatx80, floatx80, float_status *status);
601 floatx80 floatx80_div(floatx80, floatx80, float_status *status);
602 floatx80 floatx80_rem(floatx80, floatx80, float_status *status);
603 floatx80 floatx80_sqrt(floatx80, float_status *status);
604 int floatx80_eq(floatx80, floatx80, float_status *status);
605 int floatx80_le(floatx80, floatx80, float_status *status);
606 int floatx80_lt(floatx80, floatx80, float_status *status);
607 int floatx80_unordered(floatx80, floatx80, float_status *status);
608 int floatx80_eq_quiet(floatx80, floatx80, float_status *status);
609 int floatx80_le_quiet(floatx80, floatx80, float_status *status);
610 int floatx80_lt_quiet(floatx80, floatx80, float_status *status);
611 int floatx80_unordered_quiet(floatx80, floatx80, float_status *status);
612 int floatx80_compare(floatx80, floatx80, float_status *status);
613 int floatx80_compare_quiet(floatx80, floatx80, float_status *status);
614 int floatx80_is_quiet_nan( floatx80 );
615 int floatx80_is_signaling_nan( floatx80 );
616 floatx80 floatx80_maybe_silence_nan( floatx80 );
617 floatx80 floatx80_scalbn(floatx80, int, float_status *status);
618 
619 static inline floatx80 floatx80_abs(floatx80 a)
620 {
621     a.high &= 0x7fff;
622     return a;
623 }
624 
625 static inline floatx80 floatx80_chs(floatx80 a)
626 {
627     a.high ^= 0x8000;
628     return a;
629 }
630 
631 static inline int floatx80_is_infinity(floatx80 a)
632 {
633     return (a.high & 0x7fff) == 0x7fff && a.low == 0x8000000000000000LL;
634 }
635 
636 static inline int floatx80_is_neg(floatx80 a)
637 {
638     return a.high >> 15;
639 }
640 
641 static inline int floatx80_is_zero(floatx80 a)
642 {
643     return (a.high & 0x7fff) == 0 && a.low == 0;
644 }
645 
646 static inline int floatx80_is_zero_or_denormal(floatx80 a)
647 {
648     return (a.high & 0x7fff) == 0;
649 }
650 
651 static inline int floatx80_is_any_nan(floatx80 a)
652 {
653     return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1);
654 }
655 
656 #define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL)
657 #define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)
658 #define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)
659 #define floatx80_pi make_floatx80(0x4000, 0xc90fdaa22168c235LL)
660 #define floatx80_half make_floatx80(0x3ffe, 0x8000000000000000LL)
661 #define floatx80_infinity make_floatx80(0x7fff, 0x8000000000000000LL)
662 
663 /*----------------------------------------------------------------------------
664 | The pattern for a default generated extended double-precision NaN.
665 *----------------------------------------------------------------------------*/
666 extern const floatx80 floatx80_default_nan;
667 
668 /*----------------------------------------------------------------------------
669 | Software IEC/IEEE quadruple-precision conversion routines.
670 *----------------------------------------------------------------------------*/
671 int32_t float128_to_int32(float128, float_status *status);
672 int32_t float128_to_int32_round_to_zero(float128, float_status *status);
673 int64_t float128_to_int64(float128, float_status *status);
674 int64_t float128_to_int64_round_to_zero(float128, float_status *status);
675 float32 float128_to_float32(float128, float_status *status);
676 float64 float128_to_float64(float128, float_status *status);
677 floatx80 float128_to_floatx80(float128, float_status *status);
678 
679 /*----------------------------------------------------------------------------
680 | Software IEC/IEEE quadruple-precision operations.
681 *----------------------------------------------------------------------------*/
682 float128 float128_round_to_int(float128, float_status *status);
683 float128 float128_add(float128, float128, float_status *status);
684 float128 float128_sub(float128, float128, float_status *status);
685 float128 float128_mul(float128, float128, float_status *status);
686 float128 float128_div(float128, float128, float_status *status);
687 float128 float128_rem(float128, float128, float_status *status);
688 float128 float128_sqrt(float128, float_status *status);
689 int float128_eq(float128, float128, float_status *status);
690 int float128_le(float128, float128, float_status *status);
691 int float128_lt(float128, float128, float_status *status);
692 int float128_unordered(float128, float128, float_status *status);
693 int float128_eq_quiet(float128, float128, float_status *status);
694 int float128_le_quiet(float128, float128, float_status *status);
695 int float128_lt_quiet(float128, float128, float_status *status);
696 int float128_unordered_quiet(float128, float128, float_status *status);
697 int float128_compare(float128, float128, float_status *status);
698 int float128_compare_quiet(float128, float128, float_status *status);
699 int float128_is_quiet_nan( float128 );
700 int float128_is_signaling_nan( float128 );
701 float128 float128_maybe_silence_nan( float128 );
702 float128 float128_scalbn(float128, int, float_status *status);
703 
704 static inline float128 float128_abs(float128 a)
705 {
706     a.high &= 0x7fffffffffffffffLL;
707     return a;
708 }
709 
710 static inline float128 float128_chs(float128 a)
711 {
712     a.high ^= 0x8000000000000000LL;
713     return a;
714 }
715 
716 static inline int float128_is_infinity(float128 a)
717 {
718     return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0;
719 }
720 
721 static inline int float128_is_neg(float128 a)
722 {
723     return a.high >> 63;
724 }
725 
726 static inline int float128_is_zero(float128 a)
727 {
728     return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0;
729 }
730 
731 static inline int float128_is_zero_or_denormal(float128 a)
732 {
733     return (a.high & 0x7fff000000000000LL) == 0;
734 }
735 
736 static inline int float128_is_any_nan(float128 a)
737 {
738     return ((a.high >> 48) & 0x7fff) == 0x7fff &&
739         ((a.low != 0) || ((a.high & 0xffffffffffffLL) != 0));
740 }
741 
742 #define float128_zero make_float128(0, 0)
743 
744 /*----------------------------------------------------------------------------
745 | The pattern for a default generated quadruple-precision NaN.
746 *----------------------------------------------------------------------------*/
747 extern const float128 float128_default_nan;
748 
749 #endif /* !SOFTFLOAT_H */
750