monitor: Fix tracepoint crash on JSON syntax error
[qemu/armbru.git] / include / fpu / softfloat.h
blob69f4dbc4db7d904b992925ee7ff1970949e4bfe1
1 /*
2 * QEMU float support
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
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 ===============================================================================
47 /* BSD licensing:
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.
82 #ifndef SOFTFLOAT_H
83 #define SOFTFLOAT_H
85 #define LIT64( a ) a##LL
87 /*----------------------------------------------------------------------------
88 | Software IEC/IEEE floating-point ordering relations
89 *----------------------------------------------------------------------------*/
90 enum {
91 float_relation_less = -1,
92 float_relation_equal = 0,
93 float_relation_greater = 1,
94 float_relation_unordered = 2
97 #include "fpu/softfloat-types.h"
99 static inline void set_float_detect_tininess(int val, float_status *status)
101 status->float_detect_tininess = val;
103 static inline void set_float_rounding_mode(int val, float_status *status)
105 status->float_rounding_mode = val;
107 static inline void set_float_exception_flags(int val, float_status *status)
109 status->float_exception_flags = val;
111 static inline void set_floatx80_rounding_precision(int val,
112 float_status *status)
114 status->floatx80_rounding_precision = val;
116 static inline void set_flush_to_zero(flag val, float_status *status)
118 status->flush_to_zero = val;
120 static inline void set_flush_inputs_to_zero(flag val, float_status *status)
122 status->flush_inputs_to_zero = val;
124 static inline void set_default_nan_mode(flag val, float_status *status)
126 status->default_nan_mode = val;
128 static inline void set_snan_bit_is_one(flag val, float_status *status)
130 status->snan_bit_is_one = val;
132 static inline int get_float_detect_tininess(float_status *status)
134 return status->float_detect_tininess;
136 static inline int get_float_rounding_mode(float_status *status)
138 return status->float_rounding_mode;
140 static inline int get_float_exception_flags(float_status *status)
142 return status->float_exception_flags;
144 static inline int get_floatx80_rounding_precision(float_status *status)
146 return status->floatx80_rounding_precision;
148 static inline flag get_flush_to_zero(float_status *status)
150 return status->flush_to_zero;
152 static inline flag get_flush_inputs_to_zero(float_status *status)
154 return status->flush_inputs_to_zero;
156 static inline flag get_default_nan_mode(float_status *status)
158 return status->default_nan_mode;
161 /*----------------------------------------------------------------------------
162 | Routine to raise any or all of the software IEC/IEEE floating-point
163 | exception flags.
164 *----------------------------------------------------------------------------*/
165 void float_raise(uint8_t flags, float_status *status);
167 /*----------------------------------------------------------------------------
168 | If `a' is denormal and we are in flush-to-zero mode then set the
169 | input-denormal exception and return zero. Otherwise just return the value.
170 *----------------------------------------------------------------------------*/
171 float16 float16_squash_input_denormal(float16 a, float_status *status);
172 float32 float32_squash_input_denormal(float32 a, float_status *status);
173 float64 float64_squash_input_denormal(float64 a, float_status *status);
175 /*----------------------------------------------------------------------------
176 | Options to indicate which negations to perform in float*_muladd()
177 | Using these differs from negating an input or output before calling
178 | the muladd function in that this means that a NaN doesn't have its
179 | sign bit inverted before it is propagated.
180 | We also support halving the result before rounding, as a special
181 | case to support the ARM fused-sqrt-step instruction FRSQRTS.
182 *----------------------------------------------------------------------------*/
183 enum {
184 float_muladd_negate_c = 1,
185 float_muladd_negate_product = 2,
186 float_muladd_negate_result = 4,
187 float_muladd_halve_result = 8,
190 /*----------------------------------------------------------------------------
191 | Software IEC/IEEE integer-to-floating-point conversion routines.
192 *----------------------------------------------------------------------------*/
193 float32 int16_to_float32(int16_t, float_status *status);
194 float32 int32_to_float32(int32_t, float_status *status);
195 float64 int16_to_float64(int16_t, float_status *status);
196 float64 int32_to_float64(int32_t, float_status *status);
197 float32 uint16_to_float32(uint16_t, float_status *status);
198 float32 uint32_to_float32(uint32_t, float_status *status);
199 float64 uint16_to_float64(uint16_t, float_status *status);
200 float64 uint32_to_float64(uint32_t, float_status *status);
201 floatx80 int32_to_floatx80(int32_t, float_status *status);
202 float128 int32_to_float128(int32_t, float_status *status);
203 float32 int64_to_float32(int64_t, float_status *status);
204 float64 int64_to_float64(int64_t, float_status *status);
205 floatx80 int64_to_floatx80(int64_t, float_status *status);
206 float128 int64_to_float128(int64_t, float_status *status);
207 float32 uint64_to_float32(uint64_t, float_status *status);
208 float64 uint64_to_float64(uint64_t, float_status *status);
209 float128 uint64_to_float128(uint64_t, float_status *status);
211 /*----------------------------------------------------------------------------
212 | Software half-precision conversion routines.
213 *----------------------------------------------------------------------------*/
214 float16 float32_to_float16(float32, bool ieee, float_status *status);
215 float32 float16_to_float32(float16, bool ieee, float_status *status);
216 float16 float64_to_float16(float64 a, bool ieee, float_status *status);
217 float64 float16_to_float64(float16 a, bool ieee, float_status *status);
218 int16_t float16_to_int16(float16, float_status *status);
219 uint16_t float16_to_uint16(float16 a, float_status *status);
220 int16_t float16_to_int16_round_to_zero(float16, float_status *status);
221 uint16_t float16_to_uint16_round_to_zero(float16 a, float_status *status);
222 int32_t float16_to_int32(float16, float_status *status);
223 uint32_t float16_to_uint32(float16 a, float_status *status);
224 int32_t float16_to_int32_round_to_zero(float16, float_status *status);
225 uint32_t float16_to_uint32_round_to_zero(float16 a, float_status *status);
226 int64_t float16_to_int64(float16, float_status *status);
227 uint64_t float16_to_uint64(float16 a, float_status *status);
228 int64_t float16_to_int64_round_to_zero(float16, float_status *status);
229 uint64_t float16_to_uint64_round_to_zero(float16 a, float_status *status);
230 float16 int16_to_float16(int16_t a, float_status *status);
231 float16 int32_to_float16(int32_t a, float_status *status);
232 float16 int64_to_float16(int64_t a, float_status *status);
233 float16 uint16_to_float16(uint16_t a, float_status *status);
234 float16 uint32_to_float16(uint32_t a, float_status *status);
235 float16 uint64_to_float16(uint64_t a, float_status *status);
237 /*----------------------------------------------------------------------------
238 | Software half-precision operations.
239 *----------------------------------------------------------------------------*/
241 float16 float16_round_to_int(float16, float_status *status);
242 float16 float16_add(float16, float16, float_status *status);
243 float16 float16_sub(float16, float16, float_status *status);
244 float16 float16_mul(float16, float16, float_status *status);
245 float16 float16_muladd(float16, float16, float16, int, float_status *status);
246 float16 float16_div(float16, float16, float_status *status);
247 float16 float16_scalbn(float16, int, float_status *status);
248 float16 float16_min(float16, float16, float_status *status);
249 float16 float16_max(float16, float16, float_status *status);
250 float16 float16_minnum(float16, float16, float_status *status);
251 float16 float16_maxnum(float16, float16, float_status *status);
252 float16 float16_minnummag(float16, float16, float_status *status);
253 float16 float16_maxnummag(float16, float16, float_status *status);
254 float16 float16_sqrt(float16, float_status *status);
255 int float16_compare(float16, float16, float_status *status);
256 int float16_compare_quiet(float16, float16, float_status *status);
258 int float16_is_quiet_nan(float16, float_status *status);
259 int float16_is_signaling_nan(float16, float_status *status);
260 float16 float16_silence_nan(float16, float_status *status);
262 static inline int float16_is_any_nan(float16 a)
264 return ((float16_val(a) & ~0x8000) > 0x7c00);
267 static inline int float16_is_neg(float16 a)
269 return float16_val(a) >> 15;
272 static inline int float16_is_infinity(float16 a)
274 return (float16_val(a) & 0x7fff) == 0x7c00;
277 static inline int float16_is_zero(float16 a)
279 return (float16_val(a) & 0x7fff) == 0;
282 static inline int float16_is_zero_or_denormal(float16 a)
284 return (float16_val(a) & 0x7c00) == 0;
287 static inline float16 float16_abs(float16 a)
289 /* Note that abs does *not* handle NaN specially, nor does
290 * it flush denormal inputs to zero.
292 return make_float16(float16_val(a) & 0x7fff);
295 static inline float16 float16_chs(float16 a)
297 /* Note that chs does *not* handle NaN specially, nor does
298 * it flush denormal inputs to zero.
300 return make_float16(float16_val(a) ^ 0x8000);
303 static inline float16 float16_set_sign(float16 a, int sign)
305 return make_float16((float16_val(a) & 0x7fff) | (sign << 15));
308 #define float16_zero make_float16(0)
309 #define float16_half make_float16(0x3800)
310 #define float16_one make_float16(0x3c00)
311 #define float16_one_point_five make_float16(0x3e00)
312 #define float16_two make_float16(0x4000)
313 #define float16_three make_float16(0x4200)
314 #define float16_infinity make_float16(0x7c00)
316 /*----------------------------------------------------------------------------
317 | The pattern for a default generated half-precision NaN.
318 *----------------------------------------------------------------------------*/
319 float16 float16_default_nan(float_status *status);
321 /*----------------------------------------------------------------------------
322 | Software IEC/IEEE single-precision conversion routines.
323 *----------------------------------------------------------------------------*/
324 int16_t float32_to_int16(float32, float_status *status);
325 uint16_t float32_to_uint16(float32, float_status *status);
326 int16_t float32_to_int16_round_to_zero(float32, float_status *status);
327 uint16_t float32_to_uint16_round_to_zero(float32, float_status *status);
328 int32_t float32_to_int32(float32, float_status *status);
329 int32_t float32_to_int32_round_to_zero(float32, float_status *status);
330 uint32_t float32_to_uint32(float32, float_status *status);
331 uint32_t float32_to_uint32_round_to_zero(float32, float_status *status);
332 int64_t float32_to_int64(float32, float_status *status);
333 uint64_t float32_to_uint64(float32, float_status *status);
334 uint64_t float32_to_uint64_round_to_zero(float32, float_status *status);
335 int64_t float32_to_int64_round_to_zero(float32, float_status *status);
336 float64 float32_to_float64(float32, float_status *status);
337 floatx80 float32_to_floatx80(float32, float_status *status);
338 float128 float32_to_float128(float32, float_status *status);
340 /*----------------------------------------------------------------------------
341 | Software IEC/IEEE single-precision operations.
342 *----------------------------------------------------------------------------*/
343 float32 float32_round_to_int(float32, float_status *status);
344 float32 float32_add(float32, float32, float_status *status);
345 float32 float32_sub(float32, float32, float_status *status);
346 float32 float32_mul(float32, float32, float_status *status);
347 float32 float32_div(float32, float32, float_status *status);
348 float32 float32_rem(float32, float32, float_status *status);
349 float32 float32_muladd(float32, float32, float32, int, float_status *status);
350 float32 float32_sqrt(float32, float_status *status);
351 float32 float32_exp2(float32, float_status *status);
352 float32 float32_log2(float32, float_status *status);
353 int float32_eq(float32, float32, float_status *status);
354 int float32_le(float32, float32, float_status *status);
355 int float32_lt(float32, float32, float_status *status);
356 int float32_unordered(float32, float32, float_status *status);
357 int float32_eq_quiet(float32, float32, float_status *status);
358 int float32_le_quiet(float32, float32, float_status *status);
359 int float32_lt_quiet(float32, float32, float_status *status);
360 int float32_unordered_quiet(float32, float32, float_status *status);
361 int float32_compare(float32, float32, float_status *status);
362 int float32_compare_quiet(float32, float32, float_status *status);
363 float32 float32_min(float32, float32, float_status *status);
364 float32 float32_max(float32, float32, float_status *status);
365 float32 float32_minnum(float32, float32, float_status *status);
366 float32 float32_maxnum(float32, float32, float_status *status);
367 float32 float32_minnummag(float32, float32, float_status *status);
368 float32 float32_maxnummag(float32, float32, float_status *status);
369 int float32_is_quiet_nan(float32, float_status *status);
370 int float32_is_signaling_nan(float32, float_status *status);
371 float32 float32_silence_nan(float32, float_status *status);
372 float32 float32_scalbn(float32, int, float_status *status);
374 static inline float32 float32_abs(float32 a)
376 /* Note that abs does *not* handle NaN specially, nor does
377 * it flush denormal inputs to zero.
379 return make_float32(float32_val(a) & 0x7fffffff);
382 static inline float32 float32_chs(float32 a)
384 /* Note that chs does *not* handle NaN specially, nor does
385 * it flush denormal inputs to zero.
387 return make_float32(float32_val(a) ^ 0x80000000);
390 static inline int float32_is_infinity(float32 a)
392 return (float32_val(a) & 0x7fffffff) == 0x7f800000;
395 static inline int float32_is_neg(float32 a)
397 return float32_val(a) >> 31;
400 static inline int float32_is_zero(float32 a)
402 return (float32_val(a) & 0x7fffffff) == 0;
405 static inline int float32_is_any_nan(float32 a)
407 return ((float32_val(a) & ~(1 << 31)) > 0x7f800000UL);
410 static inline int float32_is_zero_or_denormal(float32 a)
412 return (float32_val(a) & 0x7f800000) == 0;
415 static inline float32 float32_set_sign(float32 a, int sign)
417 return make_float32((float32_val(a) & 0x7fffffff) | (sign << 31));
420 #define float32_zero make_float32(0)
421 #define float32_half make_float32(0x3f000000)
422 #define float32_one make_float32(0x3f800000)
423 #define float32_one_point_five make_float32(0x3fc00000)
424 #define float32_two make_float32(0x40000000)
425 #define float32_three make_float32(0x40400000)
426 #define float32_infinity make_float32(0x7f800000)
428 /*----------------------------------------------------------------------------
429 | Packs the sign `zSign', exponent `zExp', and significand `zSig' into a
430 | single-precision floating-point value, returning the result. After being
431 | shifted into the proper positions, the three fields are simply added
432 | together to form the result. This means that any integer portion of `zSig'
433 | will be added into the exponent. Since a properly normalized significand
434 | will have an integer portion equal to 1, the `zExp' input should be 1 less
435 | than the desired result exponent whenever `zSig' is a complete, normalized
436 | significand.
437 *----------------------------------------------------------------------------*/
439 static inline float32 packFloat32(flag zSign, int zExp, uint32_t zSig)
441 return make_float32(
442 (((uint32_t)zSign) << 31) + (((uint32_t)zExp) << 23) + zSig);
445 /*----------------------------------------------------------------------------
446 | The pattern for a default generated single-precision NaN.
447 *----------------------------------------------------------------------------*/
448 float32 float32_default_nan(float_status *status);
450 /*----------------------------------------------------------------------------
451 | Software IEC/IEEE double-precision conversion routines.
452 *----------------------------------------------------------------------------*/
453 int16_t float64_to_int16(float64, float_status *status);
454 uint16_t float64_to_uint16(float64, float_status *status);
455 int16_t float64_to_int16_round_to_zero(float64, float_status *status);
456 uint16_t float64_to_uint16_round_to_zero(float64, float_status *status);
457 int32_t float64_to_int32(float64, float_status *status);
458 int32_t float64_to_int32_round_to_zero(float64, float_status *status);
459 uint32_t float64_to_uint32(float64, float_status *status);
460 uint32_t float64_to_uint32_round_to_zero(float64, float_status *status);
461 int64_t float64_to_int64(float64, float_status *status);
462 int64_t float64_to_int64_round_to_zero(float64, float_status *status);
463 uint64_t float64_to_uint64(float64 a, float_status *status);
464 uint64_t float64_to_uint64_round_to_zero(float64 a, float_status *status);
465 float32 float64_to_float32(float64, float_status *status);
466 floatx80 float64_to_floatx80(float64, float_status *status);
467 float128 float64_to_float128(float64, float_status *status);
469 /*----------------------------------------------------------------------------
470 | Software IEC/IEEE double-precision operations.
471 *----------------------------------------------------------------------------*/
472 float64 float64_round_to_int(float64, float_status *status);
473 float64 float64_trunc_to_int(float64, float_status *status);
474 float64 float64_add(float64, float64, float_status *status);
475 float64 float64_sub(float64, float64, float_status *status);
476 float64 float64_mul(float64, float64, float_status *status);
477 float64 float64_div(float64, float64, float_status *status);
478 float64 float64_rem(float64, float64, float_status *status);
479 float64 float64_muladd(float64, float64, float64, int, float_status *status);
480 float64 float64_sqrt(float64, float_status *status);
481 float64 float64_log2(float64, float_status *status);
482 int float64_eq(float64, float64, float_status *status);
483 int float64_le(float64, float64, float_status *status);
484 int float64_lt(float64, float64, float_status *status);
485 int float64_unordered(float64, float64, float_status *status);
486 int float64_eq_quiet(float64, float64, float_status *status);
487 int float64_le_quiet(float64, float64, float_status *status);
488 int float64_lt_quiet(float64, float64, float_status *status);
489 int float64_unordered_quiet(float64, float64, float_status *status);
490 int float64_compare(float64, float64, float_status *status);
491 int float64_compare_quiet(float64, float64, float_status *status);
492 float64 float64_min(float64, float64, float_status *status);
493 float64 float64_max(float64, float64, float_status *status);
494 float64 float64_minnum(float64, float64, float_status *status);
495 float64 float64_maxnum(float64, float64, float_status *status);
496 float64 float64_minnummag(float64, float64, float_status *status);
497 float64 float64_maxnummag(float64, float64, float_status *status);
498 int float64_is_quiet_nan(float64 a, float_status *status);
499 int float64_is_signaling_nan(float64, float_status *status);
500 float64 float64_silence_nan(float64, float_status *status);
501 float64 float64_scalbn(float64, int, float_status *status);
503 static inline float64 float64_abs(float64 a)
505 /* Note that abs does *not* handle NaN specially, nor does
506 * it flush denormal inputs to zero.
508 return make_float64(float64_val(a) & 0x7fffffffffffffffLL);
511 static inline float64 float64_chs(float64 a)
513 /* Note that chs does *not* handle NaN specially, nor does
514 * it flush denormal inputs to zero.
516 return make_float64(float64_val(a) ^ 0x8000000000000000LL);
519 static inline int float64_is_infinity(float64 a)
521 return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL;
524 static inline int float64_is_neg(float64 a)
526 return float64_val(a) >> 63;
529 static inline int float64_is_zero(float64 a)
531 return (float64_val(a) & 0x7fffffffffffffffLL) == 0;
534 static inline int float64_is_any_nan(float64 a)
536 return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL);
539 static inline int float64_is_zero_or_denormal(float64 a)
541 return (float64_val(a) & 0x7ff0000000000000LL) == 0;
544 static inline float64 float64_set_sign(float64 a, int sign)
546 return make_float64((float64_val(a) & 0x7fffffffffffffffULL)
547 | ((int64_t)sign << 63));
550 #define float64_zero make_float64(0)
551 #define float64_half make_float64(0x3fe0000000000000LL)
552 #define float64_one make_float64(0x3ff0000000000000LL)
553 #define float64_one_point_five make_float64(0x3FF8000000000000ULL)
554 #define float64_two make_float64(0x4000000000000000ULL)
555 #define float64_three make_float64(0x4008000000000000ULL)
556 #define float64_ln2 make_float64(0x3fe62e42fefa39efLL)
557 #define float64_infinity make_float64(0x7ff0000000000000LL)
559 /*----------------------------------------------------------------------------
560 | The pattern for a default generated double-precision NaN.
561 *----------------------------------------------------------------------------*/
562 float64 float64_default_nan(float_status *status);
564 /*----------------------------------------------------------------------------
565 | Software IEC/IEEE extended double-precision conversion routines.
566 *----------------------------------------------------------------------------*/
567 int32_t floatx80_to_int32(floatx80, float_status *status);
568 int32_t floatx80_to_int32_round_to_zero(floatx80, float_status *status);
569 int64_t floatx80_to_int64(floatx80, float_status *status);
570 int64_t floatx80_to_int64_round_to_zero(floatx80, float_status *status);
571 float32 floatx80_to_float32(floatx80, float_status *status);
572 float64 floatx80_to_float64(floatx80, float_status *status);
573 float128 floatx80_to_float128(floatx80, float_status *status);
575 /*----------------------------------------------------------------------------
576 | The pattern for an extended double-precision inf.
577 *----------------------------------------------------------------------------*/
578 extern const floatx80 floatx80_infinity;
580 /*----------------------------------------------------------------------------
581 | Software IEC/IEEE extended double-precision operations.
582 *----------------------------------------------------------------------------*/
583 floatx80 floatx80_round(floatx80 a, float_status *status);
584 floatx80 floatx80_round_to_int(floatx80, float_status *status);
585 floatx80 floatx80_add(floatx80, floatx80, float_status *status);
586 floatx80 floatx80_sub(floatx80, floatx80, float_status *status);
587 floatx80 floatx80_mul(floatx80, floatx80, float_status *status);
588 floatx80 floatx80_div(floatx80, floatx80, float_status *status);
589 floatx80 floatx80_rem(floatx80, floatx80, float_status *status);
590 floatx80 floatx80_sqrt(floatx80, float_status *status);
591 int floatx80_eq(floatx80, floatx80, float_status *status);
592 int floatx80_le(floatx80, floatx80, float_status *status);
593 int floatx80_lt(floatx80, floatx80, float_status *status);
594 int floatx80_unordered(floatx80, floatx80, float_status *status);
595 int floatx80_eq_quiet(floatx80, floatx80, float_status *status);
596 int floatx80_le_quiet(floatx80, floatx80, float_status *status);
597 int floatx80_lt_quiet(floatx80, floatx80, float_status *status);
598 int floatx80_unordered_quiet(floatx80, floatx80, float_status *status);
599 int floatx80_compare(floatx80, floatx80, float_status *status);
600 int floatx80_compare_quiet(floatx80, floatx80, float_status *status);
601 int floatx80_is_quiet_nan(floatx80, float_status *status);
602 int floatx80_is_signaling_nan(floatx80, float_status *status);
603 floatx80 floatx80_silence_nan(floatx80, float_status *status);
604 floatx80 floatx80_scalbn(floatx80, int, float_status *status);
606 static inline floatx80 floatx80_abs(floatx80 a)
608 a.high &= 0x7fff;
609 return a;
612 static inline floatx80 floatx80_chs(floatx80 a)
614 a.high ^= 0x8000;
615 return a;
618 static inline int floatx80_is_infinity(floatx80 a)
620 #if defined(TARGET_M68K)
621 return (a.high & 0x7fff) == floatx80_infinity.high && !(a.low << 1);
622 #else
623 return (a.high & 0x7fff) == floatx80_infinity.high &&
624 a.low == floatx80_infinity.low;
625 #endif
628 static inline int floatx80_is_neg(floatx80 a)
630 return a.high >> 15;
633 static inline int floatx80_is_zero(floatx80 a)
635 return (a.high & 0x7fff) == 0 && a.low == 0;
638 static inline int floatx80_is_zero_or_denormal(floatx80 a)
640 return (a.high & 0x7fff) == 0;
643 static inline int floatx80_is_any_nan(floatx80 a)
645 return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1);
648 /*----------------------------------------------------------------------------
649 | Return whether the given value is an invalid floatx80 encoding.
650 | Invalid floatx80 encodings arise when the integer bit is not set, but
651 | the exponent is not zero. The only times the integer bit is permitted to
652 | be zero is in subnormal numbers and the value zero.
653 | This includes what the Intel software developer's manual calls pseudo-NaNs,
654 | pseudo-infinities and un-normal numbers. It does not include
655 | pseudo-denormals, which must still be correctly handled as inputs even
656 | if they are never generated as outputs.
657 *----------------------------------------------------------------------------*/
658 static inline bool floatx80_invalid_encoding(floatx80 a)
660 return (a.low & (1ULL << 63)) == 0 && (a.high & 0x7FFF) != 0;
663 #define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL)
664 #define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)
665 #define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)
666 #define floatx80_pi make_floatx80(0x4000, 0xc90fdaa22168c235LL)
667 #define floatx80_half make_floatx80(0x3ffe, 0x8000000000000000LL)
669 /*----------------------------------------------------------------------------
670 | Returns the fraction bits of the extended double-precision floating-point
671 | value `a'.
672 *----------------------------------------------------------------------------*/
674 static inline uint64_t extractFloatx80Frac(floatx80 a)
676 return a.low;
679 /*----------------------------------------------------------------------------
680 | Returns the exponent bits of the extended double-precision floating-point
681 | value `a'.
682 *----------------------------------------------------------------------------*/
684 static inline int32_t extractFloatx80Exp(floatx80 a)
686 return a.high & 0x7FFF;
689 /*----------------------------------------------------------------------------
690 | Returns the sign bit of the extended double-precision floating-point value
691 | `a'.
692 *----------------------------------------------------------------------------*/
694 static inline flag extractFloatx80Sign(floatx80 a)
696 return a.high >> 15;
699 /*----------------------------------------------------------------------------
700 | Packs the sign `zSign', exponent `zExp', and significand `zSig' into an
701 | extended double-precision floating-point value, returning the result.
702 *----------------------------------------------------------------------------*/
704 static inline floatx80 packFloatx80(flag zSign, int32_t zExp, uint64_t zSig)
706 floatx80 z;
708 z.low = zSig;
709 z.high = (((uint16_t)zSign) << 15) + zExp;
710 return z;
713 /*----------------------------------------------------------------------------
714 | Normalizes the subnormal extended double-precision floating-point value
715 | represented by the denormalized significand `aSig'. The normalized exponent
716 | and significand are stored at the locations pointed to by `zExpPtr' and
717 | `zSigPtr', respectively.
718 *----------------------------------------------------------------------------*/
720 void normalizeFloatx80Subnormal(uint64_t aSig, int32_t *zExpPtr,
721 uint64_t *zSigPtr);
723 /*----------------------------------------------------------------------------
724 | Takes two extended double-precision floating-point values `a' and `b', one
725 | of which is a NaN, and returns the appropriate NaN result. If either `a' or
726 | `b' is a signaling NaN, the invalid exception is raised.
727 *----------------------------------------------------------------------------*/
729 floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, float_status *status);
731 /*----------------------------------------------------------------------------
732 | Takes an abstract floating-point value having sign `zSign', exponent `zExp',
733 | and extended significand formed by the concatenation of `zSig0' and `zSig1',
734 | and returns the proper extended double-precision floating-point value
735 | corresponding to the abstract input. Ordinarily, the abstract value is
736 | rounded and packed into the extended double-precision format, with the
737 | inexact exception raised if the abstract input cannot be represented
738 | exactly. However, if the abstract value is too large, the overflow and
739 | inexact exceptions are raised and an infinity or maximal finite value is
740 | returned. If the abstract value is too small, the input value is rounded to
741 | a subnormal number, and the underflow and inexact exceptions are raised if
742 | the abstract input cannot be represented exactly as a subnormal extended
743 | double-precision floating-point number.
744 | If `roundingPrecision' is 32 or 64, the result is rounded to the same
745 | number of bits as single or double precision, respectively. Otherwise, the
746 | result is rounded to the full precision of the extended double-precision
747 | format.
748 | The input significand must be normalized or smaller. If the input
749 | significand is not normalized, `zExp' must be 0; in that case, the result
750 | returned is a subnormal number, and it must not require rounding. The
751 | handling of underflow and overflow follows the IEC/IEEE Standard for Binary
752 | Floating-Point Arithmetic.
753 *----------------------------------------------------------------------------*/
755 floatx80 roundAndPackFloatx80(int8_t roundingPrecision, flag zSign,
756 int32_t zExp, uint64_t zSig0, uint64_t zSig1,
757 float_status *status);
759 /*----------------------------------------------------------------------------
760 | Takes an abstract floating-point value having sign `zSign', exponent
761 | `zExp', and significand formed by the concatenation of `zSig0' and `zSig1',
762 | and returns the proper extended double-precision floating-point value
763 | corresponding to the abstract input. This routine is just like
764 | `roundAndPackFloatx80' except that the input significand does not have to be
765 | normalized.
766 *----------------------------------------------------------------------------*/
768 floatx80 normalizeRoundAndPackFloatx80(int8_t roundingPrecision,
769 flag zSign, int32_t zExp,
770 uint64_t zSig0, uint64_t zSig1,
771 float_status *status);
773 /*----------------------------------------------------------------------------
774 | The pattern for a default generated extended double-precision NaN.
775 *----------------------------------------------------------------------------*/
776 floatx80 floatx80_default_nan(float_status *status);
778 /*----------------------------------------------------------------------------
779 | Software IEC/IEEE quadruple-precision conversion routines.
780 *----------------------------------------------------------------------------*/
781 int32_t float128_to_int32(float128, float_status *status);
782 int32_t float128_to_int32_round_to_zero(float128, float_status *status);
783 int64_t float128_to_int64(float128, float_status *status);
784 int64_t float128_to_int64_round_to_zero(float128, float_status *status);
785 uint64_t float128_to_uint64(float128, float_status *status);
786 uint64_t float128_to_uint64_round_to_zero(float128, float_status *status);
787 uint32_t float128_to_uint32_round_to_zero(float128, float_status *status);
788 float32 float128_to_float32(float128, float_status *status);
789 float64 float128_to_float64(float128, float_status *status);
790 floatx80 float128_to_floatx80(float128, float_status *status);
792 /*----------------------------------------------------------------------------
793 | Software IEC/IEEE quadruple-precision operations.
794 *----------------------------------------------------------------------------*/
795 float128 float128_round_to_int(float128, float_status *status);
796 float128 float128_add(float128, float128, float_status *status);
797 float128 float128_sub(float128, float128, float_status *status);
798 float128 float128_mul(float128, float128, float_status *status);
799 float128 float128_div(float128, float128, float_status *status);
800 float128 float128_rem(float128, float128, float_status *status);
801 float128 float128_sqrt(float128, float_status *status);
802 int float128_eq(float128, float128, float_status *status);
803 int float128_le(float128, float128, float_status *status);
804 int float128_lt(float128, float128, float_status *status);
805 int float128_unordered(float128, float128, float_status *status);
806 int float128_eq_quiet(float128, float128, float_status *status);
807 int float128_le_quiet(float128, float128, float_status *status);
808 int float128_lt_quiet(float128, float128, float_status *status);
809 int float128_unordered_quiet(float128, float128, float_status *status);
810 int float128_compare(float128, float128, float_status *status);
811 int float128_compare_quiet(float128, float128, float_status *status);
812 int float128_is_quiet_nan(float128, float_status *status);
813 int float128_is_signaling_nan(float128, float_status *status);
814 float128 float128_silence_nan(float128, float_status *status);
815 float128 float128_scalbn(float128, int, float_status *status);
817 static inline float128 float128_abs(float128 a)
819 a.high &= 0x7fffffffffffffffLL;
820 return a;
823 static inline float128 float128_chs(float128 a)
825 a.high ^= 0x8000000000000000LL;
826 return a;
829 static inline int float128_is_infinity(float128 a)
831 return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0;
834 static inline int float128_is_neg(float128 a)
836 return a.high >> 63;
839 static inline int float128_is_zero(float128 a)
841 return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0;
844 static inline int float128_is_zero_or_denormal(float128 a)
846 return (a.high & 0x7fff000000000000LL) == 0;
849 static inline int float128_is_any_nan(float128 a)
851 return ((a.high >> 48) & 0x7fff) == 0x7fff &&
852 ((a.low != 0) || ((a.high & 0xffffffffffffLL) != 0));
855 #define float128_zero make_float128(0, 0)
857 /*----------------------------------------------------------------------------
858 | The pattern for a default generated quadruple-precision NaN.
859 *----------------------------------------------------------------------------*/
860 float128 float128_default_nan(float_status *status);
862 #endif /* SOFTFLOAT_H */