]> git.proxmox.com Git - mirror_qemu.git/blame - include/fpu/softfloat.h
softfloat: Clarify license status
[mirror_qemu.git] / include / fpu / softfloat.h
CommitLineData
8d725fac
AF
1/*
2 * QEMU float support
3 *
16017c48
PM
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.
8d725fac
AF
16 */
17
a7d1ac78
PM
18/*
19===============================================================================
20This C header file is part of the SoftFloat IEC/IEEE Floating-point
21Arithmetic Package, Release 2a.
158142c2
FB
22
23Written by John R. Hauser. This work was made possible in part by the
24International Computer Science Institute, located at Suite 600, 1947 Center
25Street, Berkeley, California 94704. Funding was partially provided by the
26National Science Foundation under grant MIP-9311980. The original version
27of this code was written as part of a project to build a fixed-point vector
28processor in collaboration with the University of California at Berkeley,
29overseen by Profs. Nelson Morgan and John Wawrzynek. More information
a7d1ac78 30is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/
158142c2
FB
31arithmetic/SoftFloat.html'.
32
a7d1ac78
PM
33THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort
34has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
35TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO
36PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
37AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
158142c2
FB
38
39Derivative works are acceptable, even for commercial purposes, so long as
a7d1ac78
PM
40(1) they include prominent notice that the work is derivative, and (2) they
41include prominent notice akin to these four paragraphs for those parts of
42this code that are retained.
158142c2 43
a7d1ac78
PM
44===============================================================================
45*/
158142c2 46
16017c48
PM
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
158142c2
FB
82#ifndef SOFTFLOAT_H
83#define SOFTFLOAT_H
84
75b5a697 85#if defined(CONFIG_SOLARIS) && defined(CONFIG_NEEDS_LIBSUNMATH)
0475a5ca
TS
86#include <sunmath.h>
87#endif
88
158142c2 89#include <inttypes.h>
789ec7ce 90#include "config-host.h"
1de7afc9 91#include "qemu/osdep.h"
158142c2
FB
92
93/*----------------------------------------------------------------------------
94| Each of the following `typedef's defines the most convenient type that holds
95| integers of at least as many bits as specified. For example, `uint8' should
96| be the most convenient type that can hold unsigned integers of as many as
97| 8 bits. The `flag' type must be able to hold either a 0 or 1. For most
98| implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
99| to the same as `int'.
100*----------------------------------------------------------------------------*/
750afe93 101typedef uint8_t flag;
158142c2
FB
102typedef uint8_t uint8;
103typedef int8_t int8;
158142c2
FB
104typedef unsigned int uint32;
105typedef signed int int32;
106typedef uint64_t uint64;
107typedef int64_t int64;
108
158142c2 109#define LIT64( a ) a##LL
158142c2 110
158142c2
FB
111#define STATUS_PARAM , float_status *status
112#define STATUS(field) status->field
113#define STATUS_VAR , status
114
1d6bda35
FB
115/*----------------------------------------------------------------------------
116| Software IEC/IEEE floating-point ordering relations
117*----------------------------------------------------------------------------*/
118enum {
119 float_relation_less = -1,
120 float_relation_equal = 0,
121 float_relation_greater = 1,
122 float_relation_unordered = 2
123};
124
158142c2
FB
125/*----------------------------------------------------------------------------
126| Software IEC/IEEE floating-point types.
127*----------------------------------------------------------------------------*/
f090c9d4
PB
128/* Use structures for soft-float types. This prevents accidentally mixing
129 them with native int/float types. A sufficiently clever compiler and
130 sane ABI should be able to see though these structs. However
131 x86/gcc 3.x seems to struggle a bit, so leave them disabled by default. */
132//#define USE_SOFTFLOAT_STRUCT_TYPES
133#ifdef USE_SOFTFLOAT_STRUCT_TYPES
bb4d4bb3
PM
134typedef struct {
135 uint16_t v;
136} float16;
137#define float16_val(x) (((float16)(x)).v)
138#define make_float16(x) __extension__ ({ float16 f16_val = {x}; f16_val; })
d5138cf4 139#define const_float16(x) { x }
f090c9d4
PB
140typedef struct {
141 uint32_t v;
142} float32;
143/* The cast ensures an error if the wrong type is passed. */
144#define float32_val(x) (((float32)(x)).v)
145#define make_float32(x) __extension__ ({ float32 f32_val = {x}; f32_val; })
d5138cf4 146#define const_float32(x) { x }
f090c9d4
PB
147typedef struct {
148 uint64_t v;
149} float64;
150#define float64_val(x) (((float64)(x)).v)
151#define make_float64(x) __extension__ ({ float64 f64_val = {x}; f64_val; })
d5138cf4 152#define const_float64(x) { x }
f090c9d4 153#else
bb4d4bb3 154typedef uint16_t float16;
158142c2
FB
155typedef uint32_t float32;
156typedef uint64_t float64;
bb4d4bb3 157#define float16_val(x) (x)
f090c9d4
PB
158#define float32_val(x) (x)
159#define float64_val(x) (x)
bb4d4bb3 160#define make_float16(x) (x)
f090c9d4
PB
161#define make_float32(x) (x)
162#define make_float64(x) (x)
d5138cf4
PM
163#define const_float16(x) (x)
164#define const_float32(x) (x)
165#define const_float64(x) (x)
f090c9d4 166#endif
158142c2
FB
167typedef struct {
168 uint64_t low;
169 uint16_t high;
170} floatx80;
f3218a8d 171#define make_floatx80(exp, mant) ((floatx80) { mant, exp })
3bf7e40a 172#define make_floatx80_init(exp, mant) { .low = mant, .high = exp }
158142c2 173typedef struct {
e2542fe2 174#ifdef HOST_WORDS_BIGENDIAN
158142c2
FB
175 uint64_t high, low;
176#else
177 uint64_t low, high;
178#endif
179} float128;
789ec7ce 180#define make_float128(high_, low_) ((float128) { .high = high_, .low = low_ })
3bf7e40a 181#define make_float128_init(high_, low_) { .high = high_, .low = low_ }
158142c2
FB
182
183/*----------------------------------------------------------------------------
184| Software IEC/IEEE floating-point underflow tininess-detection mode.
185*----------------------------------------------------------------------------*/
186enum {
187 float_tininess_after_rounding = 0,
188 float_tininess_before_rounding = 1
189};
190
191/*----------------------------------------------------------------------------
192| Software IEC/IEEE floating-point rounding mode.
193*----------------------------------------------------------------------------*/
194enum {
195 float_round_nearest_even = 0,
196 float_round_down = 1,
197 float_round_up = 2,
f9288a76
PM
198 float_round_to_zero = 3,
199 float_round_ties_away = 4,
158142c2
FB
200};
201
202/*----------------------------------------------------------------------------
203| Software IEC/IEEE floating-point exception flags.
204*----------------------------------------------------------------------------*/
205enum {
206 float_flag_invalid = 1,
207 float_flag_divbyzero = 4,
208 float_flag_overflow = 8,
209 float_flag_underflow = 16,
37d18660 210 float_flag_inexact = 32,
e6afc87f
PM
211 float_flag_input_denormal = 64,
212 float_flag_output_denormal = 128
158142c2
FB
213};
214
215typedef struct float_status {
216 signed char float_detect_tininess;
217 signed char float_rounding_mode;
218 signed char float_exception_flags;
158142c2 219 signed char floatx80_rounding_precision;
37d18660 220 /* should denormalised results go to zero and set the inexact flag? */
fe76d976 221 flag flush_to_zero;
37d18660
PM
222 /* should denormalised inputs go to zero and set the input_denormal flag? */
223 flag flush_inputs_to_zero;
5c7908ed 224 flag default_nan_mode;
158142c2
FB
225} float_status;
226
a49db98d 227static inline void set_float_detect_tininess(int val STATUS_PARAM)
c29aca44
PM
228{
229 STATUS(float_detect_tininess) = val;
230}
a49db98d 231static inline void set_float_rounding_mode(int val STATUS_PARAM)
879d096b
PM
232{
233 STATUS(float_rounding_mode) = val;
234}
a49db98d 235static inline void set_float_exception_flags(int val STATUS_PARAM)
879d096b
PM
236{
237 STATUS(float_exception_flags) = val;
238}
a49db98d 239static inline void set_floatx80_rounding_precision(int val STATUS_PARAM)
879d096b
PM
240{
241 STATUS(floatx80_rounding_precision) = val;
242}
a49db98d 243static inline void set_flush_to_zero(flag val STATUS_PARAM)
fe76d976
PB
244{
245 STATUS(flush_to_zero) = val;
246}
a49db98d 247static inline void set_flush_inputs_to_zero(flag val STATUS_PARAM)
37d18660
PM
248{
249 STATUS(flush_inputs_to_zero) = val;
250}
a49db98d 251static inline void set_default_nan_mode(flag val STATUS_PARAM)
5c7908ed
PB
252{
253 STATUS(default_nan_mode) = val;
254}
a49db98d 255static inline int get_float_detect_tininess(float_status *status)
879d096b
PM
256{
257 return STATUS(float_detect_tininess);
258}
a49db98d 259static inline int get_float_rounding_mode(float_status *status)
879d096b
PM
260{
261 return STATUS(float_rounding_mode);
262}
a49db98d 263static inline int get_float_exception_flags(float_status *status)
1d6bda35
FB
264{
265 return STATUS(float_exception_flags);
266}
a49db98d 267static inline int get_floatx80_rounding_precision(float_status *status)
879d096b
PM
268{
269 return STATUS(floatx80_rounding_precision);
270}
a49db98d 271static inline flag get_flush_to_zero(float_status *status)
879d096b
PM
272{
273 return STATUS(flush_to_zero);
274}
a49db98d 275static inline flag get_flush_inputs_to_zero(float_status *status)
879d096b
PM
276{
277 return STATUS(flush_inputs_to_zero);
278}
a49db98d 279static inline flag get_default_nan_mode(float_status *status)
879d096b
PM
280{
281 return STATUS(default_nan_mode);
282}
158142c2
FB
283
284/*----------------------------------------------------------------------------
285| Routine to raise any or all of the software IEC/IEEE floating-point
286| exception flags.
287*----------------------------------------------------------------------------*/
ec530c81 288void float_raise( int8 flags STATUS_PARAM);
158142c2 289
7baeabce
AB
290/*----------------------------------------------------------------------------
291| If `a' is denormal and we are in flush-to-zero mode then set the
292| input-denormal exception and return zero. Otherwise just return the value.
293*----------------------------------------------------------------------------*/
294float32 float32_squash_input_denormal(float32 a STATUS_PARAM);
295float64 float64_squash_input_denormal(float64 a STATUS_PARAM);
296
369be8f6
PM
297/*----------------------------------------------------------------------------
298| Options to indicate which negations to perform in float*_muladd()
299| Using these differs from negating an input or output before calling
300| the muladd function in that this means that a NaN doesn't have its
301| sign bit inverted before it is propagated.
67d43538
PM
302| We also support halving the result before rounding, as a special
303| case to support the ARM fused-sqrt-step instruction FRSQRTS.
369be8f6
PM
304*----------------------------------------------------------------------------*/
305enum {
306 float_muladd_negate_c = 1,
307 float_muladd_negate_product = 2,
66176802 308 float_muladd_negate_result = 4,
67d43538 309 float_muladd_halve_result = 8,
369be8f6
PM
310};
311
158142c2
FB
312/*----------------------------------------------------------------------------
313| Software IEC/IEEE integer-to-floating-point conversion routines.
314*----------------------------------------------------------------------------*/
c4850f9e
PM
315float32 int32_to_float32(int32_t STATUS_PARAM);
316float64 int32_to_float64(int32_t STATUS_PARAM);
317float32 uint32_to_float32(uint32_t STATUS_PARAM);
318float64 uint32_to_float64(uint32_t STATUS_PARAM);
319floatx80 int32_to_floatx80(int32_t STATUS_PARAM);
320float128 int32_to_float128(int32_t STATUS_PARAM);
321float32 int64_to_float32(int64_t STATUS_PARAM);
c4850f9e 322float64 int64_to_float64(int64_t STATUS_PARAM);
c4850f9e
PM
323floatx80 int64_to_floatx80(int64_t STATUS_PARAM);
324float128 int64_to_float128(int64_t STATUS_PARAM);
6bb8e0f1
PM
325float32 uint64_to_float32(uint64_t STATUS_PARAM);
326float64 uint64_to_float64(uint64_t STATUS_PARAM);
c4850f9e 327float128 uint64_to_float128(uint64_t STATUS_PARAM);
158142c2 328
8afbdaba 329/* We provide the int16 versions for symmetry of API with float-to-int */
a49db98d 330static inline float32 int16_to_float32(int16_t v STATUS_PARAM)
8afbdaba
PM
331{
332 return int32_to_float32(v STATUS_VAR);
333}
334
a49db98d 335static inline float32 uint16_to_float32(uint16_t v STATUS_PARAM)
8afbdaba
PM
336{
337 return uint32_to_float32(v STATUS_VAR);
338}
339
a49db98d 340static inline float64 int16_to_float64(int16_t v STATUS_PARAM)
8afbdaba
PM
341{
342 return int32_to_float64(v STATUS_VAR);
343}
344
a49db98d 345static inline float64 uint16_to_float64(uint16_t v STATUS_PARAM)
8afbdaba
PM
346{
347 return uint32_to_float64(v STATUS_VAR);
348}
349
60011498
PB
350/*----------------------------------------------------------------------------
351| Software half-precision conversion routines.
352*----------------------------------------------------------------------------*/
bb4d4bb3
PM
353float16 float32_to_float16( float32, flag STATUS_PARAM );
354float32 float16_to_float32( float16, flag STATUS_PARAM );
14c9a07e
PM
355float16 float64_to_float16(float64 a, flag ieee STATUS_PARAM);
356float64 float16_to_float64(float16 a, flag ieee STATUS_PARAM);
bb4d4bb3
PM
357
358/*----------------------------------------------------------------------------
359| Software half-precision operations.
360*----------------------------------------------------------------------------*/
361int float16_is_quiet_nan( float16 );
362int float16_is_signaling_nan( float16 );
363float16 float16_maybe_silence_nan( float16 );
60011498 364
a49db98d 365static inline int float16_is_any_nan(float16 a)
213ff4e6
MF
366{
367 return ((float16_val(a) & ~0x8000) > 0x7c00);
368}
369
8559666d
CL
370/*----------------------------------------------------------------------------
371| The pattern for a default generated half-precision NaN.
372*----------------------------------------------------------------------------*/
789ec7ce 373extern const float16 float16_default_nan;
8559666d 374
158142c2
FB
375/*----------------------------------------------------------------------------
376| Software IEC/IEEE single-precision conversion routines.
377*----------------------------------------------------------------------------*/
f581bf54
WN
378int_fast16_t float32_to_int16(float32 STATUS_PARAM);
379uint_fast16_t float32_to_uint16(float32 STATUS_PARAM);
94a49d86 380int_fast16_t float32_to_int16_round_to_zero(float32 STATUS_PARAM);
5aea4c58 381uint_fast16_t float32_to_uint16_round_to_zero(float32 STATUS_PARAM);
87b8cc3c
AF
382int32 float32_to_int32( float32 STATUS_PARAM );
383int32 float32_to_int32_round_to_zero( float32 STATUS_PARAM );
384uint32 float32_to_uint32( float32 STATUS_PARAM );
385uint32 float32_to_uint32_round_to_zero( float32 STATUS_PARAM );
386int64 float32_to_int64( float32 STATUS_PARAM );
2f18bbf9 387uint64 float32_to_uint64(float32 STATUS_PARAM);
a13d4489 388uint64 float32_to_uint64_round_to_zero(float32 STATUS_PARAM);
87b8cc3c 389int64 float32_to_int64_round_to_zero( float32 STATUS_PARAM );
158142c2 390float64 float32_to_float64( float32 STATUS_PARAM );
158142c2 391floatx80 float32_to_floatx80( float32 STATUS_PARAM );
158142c2 392float128 float32_to_float128( float32 STATUS_PARAM );
158142c2
FB
393
394/*----------------------------------------------------------------------------
395| Software IEC/IEEE single-precision operations.
396*----------------------------------------------------------------------------*/
397float32 float32_round_to_int( float32 STATUS_PARAM );
398float32 float32_add( float32, float32 STATUS_PARAM );
399float32 float32_sub( float32, float32 STATUS_PARAM );
400float32 float32_mul( float32, float32 STATUS_PARAM );
401float32 float32_div( float32, float32 STATUS_PARAM );
402float32 float32_rem( float32, float32 STATUS_PARAM );
369be8f6 403float32 float32_muladd(float32, float32, float32, int STATUS_PARAM);
158142c2 404float32 float32_sqrt( float32 STATUS_PARAM );
8229c991 405float32 float32_exp2( float32 STATUS_PARAM );
374dfc33 406float32 float32_log2( float32 STATUS_PARAM );
b689362d 407int float32_eq( float32, float32 STATUS_PARAM );
750afe93
FB
408int float32_le( float32, float32 STATUS_PARAM );
409int float32_lt( float32, float32 STATUS_PARAM );
67b7861d 410int float32_unordered( float32, float32 STATUS_PARAM );
b689362d 411int float32_eq_quiet( float32, float32 STATUS_PARAM );
750afe93
FB
412int float32_le_quiet( float32, float32 STATUS_PARAM );
413int float32_lt_quiet( float32, float32 STATUS_PARAM );
67b7861d 414int float32_unordered_quiet( float32, float32 STATUS_PARAM );
750afe93
FB
415int float32_compare( float32, float32 STATUS_PARAM );
416int float32_compare_quiet( float32, float32 STATUS_PARAM );
274f1b04
PM
417float32 float32_min(float32, float32 STATUS_PARAM);
418float32 float32_max(float32, float32 STATUS_PARAM);
e17ab310
WN
419float32 float32_minnum(float32, float32 STATUS_PARAM);
420float32 float32_maxnum(float32, float32 STATUS_PARAM);
2d31e060
LA
421float32 float32_minnummag(float32, float32 STATUS_PARAM);
422float32 float32_maxnummag(float32, float32 STATUS_PARAM);
18569871 423int float32_is_quiet_nan( float32 );
750afe93 424int float32_is_signaling_nan( float32 );
b408dbde 425float32 float32_maybe_silence_nan( float32 );
9ee6e8bb 426float32 float32_scalbn( float32, int STATUS_PARAM );
158142c2 427
a49db98d 428static inline float32 float32_abs(float32 a)
1d6bda35 429{
37d18660
PM
430 /* Note that abs does *not* handle NaN specially, nor does
431 * it flush denormal inputs to zero.
432 */
f090c9d4 433 return make_float32(float32_val(a) & 0x7fffffff);
1d6bda35
FB
434}
435
a49db98d 436static inline float32 float32_chs(float32 a)
1d6bda35 437{
37d18660
PM
438 /* Note that chs does *not* handle NaN specially, nor does
439 * it flush denormal inputs to zero.
440 */
f090c9d4 441 return make_float32(float32_val(a) ^ 0x80000000);
1d6bda35
FB
442}
443
a49db98d 444static inline int float32_is_infinity(float32 a)
c52ab6f5 445{
dadd71a7 446 return (float32_val(a) & 0x7fffffff) == 0x7f800000;
c52ab6f5
AJ
447}
448
a49db98d 449static inline int float32_is_neg(float32 a)
c52ab6f5
AJ
450{
451 return float32_val(a) >> 31;
452}
453
a49db98d 454static inline int float32_is_zero(float32 a)
c52ab6f5
AJ
455{
456 return (float32_val(a) & 0x7fffffff) == 0;
457}
458
a49db98d 459static inline int float32_is_any_nan(float32 a)
21d6ebde
PM
460{
461 return ((float32_val(a) & ~(1 << 31)) > 0x7f800000UL);
462}
463
a49db98d 464static inline int float32_is_zero_or_denormal(float32 a)
6f3300ad
PM
465{
466 return (float32_val(a) & 0x7f800000) == 0;
467}
468
a49db98d 469static inline float32 float32_set_sign(float32 a, int sign)
c30fe7df
CL
470{
471 return make_float32((float32_val(a) & 0x7fffffff) | (sign << 31));
472}
473
f090c9d4 474#define float32_zero make_float32(0)
196cfc89 475#define float32_one make_float32(0x3f800000)
8229c991 476#define float32_ln2 make_float32(0x3f317218)
c4b4c77a 477#define float32_pi make_float32(0x40490fdb)
c30fe7df
CL
478#define float32_half make_float32(0x3f000000)
479#define float32_infinity make_float32(0x7f800000)
f090c9d4 480
8559666d
CL
481
482/*----------------------------------------------------------------------------
483| The pattern for a default generated single-precision NaN.
484*----------------------------------------------------------------------------*/
789ec7ce 485extern const float32 float32_default_nan;
8559666d 486
158142c2
FB
487/*----------------------------------------------------------------------------
488| Software IEC/IEEE double-precision conversion routines.
489*----------------------------------------------------------------------------*/
f581bf54
WN
490int_fast16_t float64_to_int16(float64 STATUS_PARAM);
491uint_fast16_t float64_to_uint16(float64 STATUS_PARAM);
94a49d86 492int_fast16_t float64_to_int16_round_to_zero(float64 STATUS_PARAM);
5aea4c58 493uint_fast16_t float64_to_uint16_round_to_zero(float64 STATUS_PARAM);
87b8cc3c
AF
494int32 float64_to_int32( float64 STATUS_PARAM );
495int32 float64_to_int32_round_to_zero( float64 STATUS_PARAM );
496uint32 float64_to_uint32( float64 STATUS_PARAM );
497uint32 float64_to_uint32_round_to_zero( float64 STATUS_PARAM );
498int64 float64_to_int64( float64 STATUS_PARAM );
499int64 float64_to_int64_round_to_zero( float64 STATUS_PARAM );
500uint64 float64_to_uint64 (float64 a STATUS_PARAM);
501uint64 float64_to_uint64_round_to_zero (float64 a STATUS_PARAM);
158142c2 502float32 float64_to_float32( float64 STATUS_PARAM );
158142c2 503floatx80 float64_to_floatx80( float64 STATUS_PARAM );
158142c2 504float128 float64_to_float128( float64 STATUS_PARAM );
158142c2
FB
505
506/*----------------------------------------------------------------------------
507| Software IEC/IEEE double-precision operations.
508*----------------------------------------------------------------------------*/
509float64 float64_round_to_int( float64 STATUS_PARAM );
e6e5906b 510float64 float64_trunc_to_int( float64 STATUS_PARAM );
158142c2
FB
511float64 float64_add( float64, float64 STATUS_PARAM );
512float64 float64_sub( float64, float64 STATUS_PARAM );
513float64 float64_mul( float64, float64 STATUS_PARAM );
514float64 float64_div( float64, float64 STATUS_PARAM );
515float64 float64_rem( float64, float64 STATUS_PARAM );
369be8f6 516float64 float64_muladd(float64, float64, float64, int STATUS_PARAM);
158142c2 517float64 float64_sqrt( float64 STATUS_PARAM );
374dfc33 518float64 float64_log2( float64 STATUS_PARAM );
b689362d 519int float64_eq( float64, float64 STATUS_PARAM );
750afe93
FB
520int float64_le( float64, float64 STATUS_PARAM );
521int float64_lt( float64, float64 STATUS_PARAM );
67b7861d 522int float64_unordered( float64, float64 STATUS_PARAM );
b689362d 523int float64_eq_quiet( float64, float64 STATUS_PARAM );
750afe93
FB
524int float64_le_quiet( float64, float64 STATUS_PARAM );
525int float64_lt_quiet( float64, float64 STATUS_PARAM );
67b7861d 526int float64_unordered_quiet( float64, float64 STATUS_PARAM );
750afe93
FB
527int float64_compare( float64, float64 STATUS_PARAM );
528int float64_compare_quiet( float64, float64 STATUS_PARAM );
274f1b04
PM
529float64 float64_min(float64, float64 STATUS_PARAM);
530float64 float64_max(float64, float64 STATUS_PARAM);
e17ab310
WN
531float64 float64_minnum(float64, float64 STATUS_PARAM);
532float64 float64_maxnum(float64, float64 STATUS_PARAM);
2d31e060
LA
533float64 float64_minnummag(float64, float64 STATUS_PARAM);
534float64 float64_maxnummag(float64, float64 STATUS_PARAM);
18569871 535int float64_is_quiet_nan( float64 a );
750afe93 536int float64_is_signaling_nan( float64 );
b408dbde 537float64 float64_maybe_silence_nan( float64 );
9ee6e8bb 538float64 float64_scalbn( float64, int STATUS_PARAM );
158142c2 539
a49db98d 540static inline float64 float64_abs(float64 a)
1d6bda35 541{
37d18660
PM
542 /* Note that abs does *not* handle NaN specially, nor does
543 * it flush denormal inputs to zero.
544 */
f090c9d4 545 return make_float64(float64_val(a) & 0x7fffffffffffffffLL);
1d6bda35
FB
546}
547
a49db98d 548static inline float64 float64_chs(float64 a)
1d6bda35 549{
37d18660
PM
550 /* Note that chs does *not* handle NaN specially, nor does
551 * it flush denormal inputs to zero.
552 */
f090c9d4 553 return make_float64(float64_val(a) ^ 0x8000000000000000LL);
1d6bda35
FB
554}
555
a49db98d 556static inline int float64_is_infinity(float64 a)
c52ab6f5
AJ
557{
558 return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL;
559}
560
a49db98d 561static inline int float64_is_neg(float64 a)
c52ab6f5
AJ
562{
563 return float64_val(a) >> 63;
564}
565
a49db98d 566static inline int float64_is_zero(float64 a)
c52ab6f5
AJ
567{
568 return (float64_val(a) & 0x7fffffffffffffffLL) == 0;
569}
570
a49db98d 571static inline int float64_is_any_nan(float64 a)
21d6ebde
PM
572{
573 return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL);
574}
575
a49db98d 576static inline int float64_is_zero_or_denormal(float64 a)
587eabfa
AJ
577{
578 return (float64_val(a) & 0x7ff0000000000000LL) == 0;
579}
580
a49db98d 581static inline float64 float64_set_sign(float64 a, int sign)
c30fe7df
CL
582{
583 return make_float64((float64_val(a) & 0x7fffffffffffffffULL)
584 | ((int64_t)sign << 63));
585}
586
f090c9d4 587#define float64_zero make_float64(0)
196cfc89 588#define float64_one make_float64(0x3ff0000000000000LL)
8229c991 589#define float64_ln2 make_float64(0x3fe62e42fefa39efLL)
c4b4c77a 590#define float64_pi make_float64(0x400921fb54442d18LL)
c30fe7df
CL
591#define float64_half make_float64(0x3fe0000000000000LL)
592#define float64_infinity make_float64(0x7ff0000000000000LL)
f090c9d4 593
8559666d
CL
594/*----------------------------------------------------------------------------
595| The pattern for a default generated double-precision NaN.
596*----------------------------------------------------------------------------*/
789ec7ce 597extern const float64 float64_default_nan;
8559666d 598
158142c2
FB
599/*----------------------------------------------------------------------------
600| Software IEC/IEEE extended double-precision conversion routines.
601*----------------------------------------------------------------------------*/
87b8cc3c
AF
602int32 floatx80_to_int32( floatx80 STATUS_PARAM );
603int32 floatx80_to_int32_round_to_zero( floatx80 STATUS_PARAM );
604int64 floatx80_to_int64( floatx80 STATUS_PARAM );
605int64 floatx80_to_int64_round_to_zero( floatx80 STATUS_PARAM );
158142c2
FB
606float32 floatx80_to_float32( floatx80 STATUS_PARAM );
607float64 floatx80_to_float64( floatx80 STATUS_PARAM );
158142c2 608float128 floatx80_to_float128( floatx80 STATUS_PARAM );
158142c2
FB
609
610/*----------------------------------------------------------------------------
611| Software IEC/IEEE extended double-precision operations.
612*----------------------------------------------------------------------------*/
613floatx80 floatx80_round_to_int( floatx80 STATUS_PARAM );
614floatx80 floatx80_add( floatx80, floatx80 STATUS_PARAM );
615floatx80 floatx80_sub( floatx80, floatx80 STATUS_PARAM );
616floatx80 floatx80_mul( floatx80, floatx80 STATUS_PARAM );
617floatx80 floatx80_div( floatx80, floatx80 STATUS_PARAM );
618floatx80 floatx80_rem( floatx80, floatx80 STATUS_PARAM );
619floatx80 floatx80_sqrt( floatx80 STATUS_PARAM );
b689362d 620int floatx80_eq( floatx80, floatx80 STATUS_PARAM );
750afe93
FB
621int floatx80_le( floatx80, floatx80 STATUS_PARAM );
622int floatx80_lt( floatx80, floatx80 STATUS_PARAM );
67b7861d 623int floatx80_unordered( floatx80, floatx80 STATUS_PARAM );
b689362d 624int floatx80_eq_quiet( floatx80, floatx80 STATUS_PARAM );
750afe93
FB
625int floatx80_le_quiet( floatx80, floatx80 STATUS_PARAM );
626int floatx80_lt_quiet( floatx80, floatx80 STATUS_PARAM );
67b7861d 627int floatx80_unordered_quiet( floatx80, floatx80 STATUS_PARAM );
f6714d36
AJ
628int floatx80_compare( floatx80, floatx80 STATUS_PARAM );
629int floatx80_compare_quiet( floatx80, floatx80 STATUS_PARAM );
18569871 630int floatx80_is_quiet_nan( floatx80 );
750afe93 631int floatx80_is_signaling_nan( floatx80 );
f6a7d92a 632floatx80 floatx80_maybe_silence_nan( floatx80 );
9ee6e8bb 633floatx80 floatx80_scalbn( floatx80, int STATUS_PARAM );
158142c2 634
a49db98d 635static inline floatx80 floatx80_abs(floatx80 a)
1d6bda35
FB
636{
637 a.high &= 0x7fff;
638 return a;
639}
640
a49db98d 641static inline floatx80 floatx80_chs(floatx80 a)
1d6bda35
FB
642{
643 a.high ^= 0x8000;
644 return a;
645}
646
a49db98d 647static inline int floatx80_is_infinity(floatx80 a)
c52ab6f5 648{
b76235e4 649 return (a.high & 0x7fff) == 0x7fff && a.low == 0x8000000000000000LL;
c52ab6f5
AJ
650}
651
a49db98d 652static inline int floatx80_is_neg(floatx80 a)
c52ab6f5
AJ
653{
654 return a.high >> 15;
655}
656
a49db98d 657static inline int floatx80_is_zero(floatx80 a)
c52ab6f5
AJ
658{
659 return (a.high & 0x7fff) == 0 && a.low == 0;
660}
661
a49db98d 662static inline int floatx80_is_zero_or_denormal(floatx80 a)
587eabfa
AJ
663{
664 return (a.high & 0x7fff) == 0;
665}
666
a49db98d 667static inline int floatx80_is_any_nan(floatx80 a)
2bed652f
PM
668{
669 return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1);
670}
671
f3218a8d
AJ
672#define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL)
673#define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)
674#define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)
c4b4c77a 675#define floatx80_pi make_floatx80(0x4000, 0xc90fdaa22168c235LL)
f3218a8d
AJ
676#define floatx80_half make_floatx80(0x3ffe, 0x8000000000000000LL)
677#define floatx80_infinity make_floatx80(0x7fff, 0x8000000000000000LL)
678
8559666d 679/*----------------------------------------------------------------------------
789ec7ce 680| The pattern for a default generated extended double-precision NaN.
8559666d 681*----------------------------------------------------------------------------*/
789ec7ce 682extern const floatx80 floatx80_default_nan;
8559666d 683
158142c2
FB
684/*----------------------------------------------------------------------------
685| Software IEC/IEEE quadruple-precision conversion routines.
686*----------------------------------------------------------------------------*/
87b8cc3c
AF
687int32 float128_to_int32( float128 STATUS_PARAM );
688int32 float128_to_int32_round_to_zero( float128 STATUS_PARAM );
689int64 float128_to_int64( float128 STATUS_PARAM );
690int64 float128_to_int64_round_to_zero( float128 STATUS_PARAM );
158142c2
FB
691float32 float128_to_float32( float128 STATUS_PARAM );
692float64 float128_to_float64( float128 STATUS_PARAM );
158142c2 693floatx80 float128_to_floatx80( float128 STATUS_PARAM );
158142c2
FB
694
695/*----------------------------------------------------------------------------
696| Software IEC/IEEE quadruple-precision operations.
697*----------------------------------------------------------------------------*/
698float128 float128_round_to_int( float128 STATUS_PARAM );
699float128 float128_add( float128, float128 STATUS_PARAM );
700float128 float128_sub( float128, float128 STATUS_PARAM );
701float128 float128_mul( float128, float128 STATUS_PARAM );
702float128 float128_div( float128, float128 STATUS_PARAM );
703float128 float128_rem( float128, float128 STATUS_PARAM );
704float128 float128_sqrt( float128 STATUS_PARAM );
b689362d 705int float128_eq( float128, float128 STATUS_PARAM );
750afe93
FB
706int float128_le( float128, float128 STATUS_PARAM );
707int float128_lt( float128, float128 STATUS_PARAM );
67b7861d 708int float128_unordered( float128, float128 STATUS_PARAM );
b689362d 709int float128_eq_quiet( float128, float128 STATUS_PARAM );
750afe93
FB
710int float128_le_quiet( float128, float128 STATUS_PARAM );
711int float128_lt_quiet( float128, float128 STATUS_PARAM );
67b7861d 712int float128_unordered_quiet( float128, float128 STATUS_PARAM );
1f587329
BS
713int float128_compare( float128, float128 STATUS_PARAM );
714int float128_compare_quiet( float128, float128 STATUS_PARAM );
18569871 715int float128_is_quiet_nan( float128 );
750afe93 716int float128_is_signaling_nan( float128 );
f6a7d92a 717float128 float128_maybe_silence_nan( float128 );
9ee6e8bb 718float128 float128_scalbn( float128, int STATUS_PARAM );
158142c2 719
a49db98d 720static inline float128 float128_abs(float128 a)
1d6bda35
FB
721{
722 a.high &= 0x7fffffffffffffffLL;
723 return a;
724}
725
a49db98d 726static inline float128 float128_chs(float128 a)
1d6bda35
FB
727{
728 a.high ^= 0x8000000000000000LL;
729 return a;
730}
731
a49db98d 732static inline int float128_is_infinity(float128 a)
c52ab6f5
AJ
733{
734 return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0;
735}
736
a49db98d 737static inline int float128_is_neg(float128 a)
c52ab6f5
AJ
738{
739 return a.high >> 63;
740}
741
a49db98d 742static inline int float128_is_zero(float128 a)
c52ab6f5
AJ
743{
744 return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0;
745}
746
a49db98d 747static inline int float128_is_zero_or_denormal(float128 a)
587eabfa
AJ
748{
749 return (a.high & 0x7fff000000000000LL) == 0;
750}
751
a49db98d 752static inline int float128_is_any_nan(float128 a)
2bed652f
PM
753{
754 return ((a.high >> 48) & 0x7fff) == 0x7fff &&
755 ((a.low != 0) || ((a.high & 0xffffffffffffLL) != 0));
756}
757
1e397ead
RH
758#define float128_zero make_float128(0, 0)
759
8559666d 760/*----------------------------------------------------------------------------
789ec7ce 761| The pattern for a default generated quadruple-precision NaN.
8559666d 762*----------------------------------------------------------------------------*/
789ec7ce 763extern const float128 float128_default_nan;
8559666d 764
158142c2 765#endif /* !SOFTFLOAT_H */