]> Git Repo - qemu.git/blame - include/fpu/softfloat.h
fpu: remove the LIT64 macro
[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
1d6bda35
FB
85/*----------------------------------------------------------------------------
86| Software IEC/IEEE floating-point ordering relations
87*----------------------------------------------------------------------------*/
88enum {
89 float_relation_less = -1,
90 float_relation_equal = 0,
91 float_relation_greater = 1,
92 float_relation_unordered = 2
93};
94
cfd88fc6 95#include "fpu/softfloat-types.h"
158142c2 96
e5a41ffa 97static inline void set_float_detect_tininess(int val, float_status *status)
c29aca44 98{
a2f2d288 99 status->float_detect_tininess = val;
c29aca44 100}
e5a41ffa 101static inline void set_float_rounding_mode(int val, float_status *status)
879d096b 102{
a2f2d288 103 status->float_rounding_mode = val;
879d096b 104}
e5a41ffa 105static inline void set_float_exception_flags(int val, float_status *status)
879d096b 106{
a2f2d288 107 status->float_exception_flags = val;
879d096b 108}
e5a41ffa
PM
109static inline void set_floatx80_rounding_precision(int val,
110 float_status *status)
879d096b 111{
a2f2d288 112 status->floatx80_rounding_precision = val;
879d096b 113}
e5a41ffa 114static inline void set_flush_to_zero(flag val, float_status *status)
fe76d976 115{
a2f2d288 116 status->flush_to_zero = val;
fe76d976 117}
e5a41ffa 118static inline void set_flush_inputs_to_zero(flag val, float_status *status)
37d18660 119{
a2f2d288 120 status->flush_inputs_to_zero = val;
37d18660 121}
e5a41ffa 122static inline void set_default_nan_mode(flag val, float_status *status)
5c7908ed 123{
a2f2d288 124 status->default_nan_mode = val;
5c7908ed 125}
af39bc8c
AM
126static inline void set_snan_bit_is_one(flag val, float_status *status)
127{
128 status->snan_bit_is_one = val;
129}
a49db98d 130static inline int get_float_detect_tininess(float_status *status)
879d096b 131{
a2f2d288 132 return status->float_detect_tininess;
879d096b 133}
a49db98d 134static inline int get_float_rounding_mode(float_status *status)
879d096b 135{
a2f2d288 136 return status->float_rounding_mode;
879d096b 137}
a49db98d 138static inline int get_float_exception_flags(float_status *status)
1d6bda35 139{
a2f2d288 140 return status->float_exception_flags;
1d6bda35 141}
a49db98d 142static inline int get_floatx80_rounding_precision(float_status *status)
879d096b 143{
a2f2d288 144 return status->floatx80_rounding_precision;
879d096b 145}
a49db98d 146static inline flag get_flush_to_zero(float_status *status)
879d096b 147{
a2f2d288 148 return status->flush_to_zero;
879d096b 149}
a49db98d 150static inline flag get_flush_inputs_to_zero(float_status *status)
879d096b 151{
a2f2d288 152 return status->flush_inputs_to_zero;
879d096b 153}
a49db98d 154static inline flag get_default_nan_mode(float_status *status)
879d096b 155{
a2f2d288 156 return status->default_nan_mode;
879d096b 157}
158142c2
FB
158
159/*----------------------------------------------------------------------------
160| Routine to raise any or all of the software IEC/IEEE floating-point
161| exception flags.
162*----------------------------------------------------------------------------*/
dfd60767 163void float_raise(uint8_t flags, float_status *status);
158142c2 164
7baeabce
AB
165/*----------------------------------------------------------------------------
166| If `a' is denormal and we are in flush-to-zero mode then set the
167| input-denormal exception and return zero. Otherwise just return the value.
168*----------------------------------------------------------------------------*/
210cbd49 169float16 float16_squash_input_denormal(float16 a, float_status *status);
e5a41ffa
PM
170float32 float32_squash_input_denormal(float32 a, float_status *status);
171float64 float64_squash_input_denormal(float64 a, float_status *status);
7baeabce 172
369be8f6
PM
173/*----------------------------------------------------------------------------
174| Options to indicate which negations to perform in float*_muladd()
175| Using these differs from negating an input or output before calling
176| the muladd function in that this means that a NaN doesn't have its
177| sign bit inverted before it is propagated.
67d43538
PM
178| We also support halving the result before rounding, as a special
179| case to support the ARM fused-sqrt-step instruction FRSQRTS.
369be8f6
PM
180*----------------------------------------------------------------------------*/
181enum {
182 float_muladd_negate_c = 1,
183 float_muladd_negate_product = 2,
66176802 184 float_muladd_negate_result = 4,
67d43538 185 float_muladd_halve_result = 8,
369be8f6
PM
186};
187
158142c2
FB
188/*----------------------------------------------------------------------------
189| Software IEC/IEEE integer-to-floating-point conversion routines.
190*----------------------------------------------------------------------------*/
2abdfe24
RH
191
192float16 int16_to_float16_scalbn(int16_t a, int, float_status *status);
193float16 int32_to_float16_scalbn(int32_t a, int, float_status *status);
194float16 int64_to_float16_scalbn(int64_t a, int, float_status *status);
195float16 uint16_to_float16_scalbn(uint16_t a, int, float_status *status);
196float16 uint32_to_float16_scalbn(uint32_t a, int, float_status *status);
197float16 uint64_to_float16_scalbn(uint64_t a, int, float_status *status);
198
199float16 int16_to_float16(int16_t a, float_status *status);
200float16 int32_to_float16(int32_t a, float_status *status);
201float16 int64_to_float16(int64_t a, float_status *status);
202float16 uint16_to_float16(uint16_t a, float_status *status);
203float16 uint32_to_float16(uint32_t a, float_status *status);
204float16 uint64_to_float16(uint64_t a, float_status *status);
205
206float32 int16_to_float32_scalbn(int16_t, int, float_status *status);
207float32 int32_to_float32_scalbn(int32_t, int, float_status *status);
208float32 int64_to_float32_scalbn(int64_t, int, float_status *status);
209float32 uint16_to_float32_scalbn(uint16_t, int, float_status *status);
210float32 uint32_to_float32_scalbn(uint32_t, int, float_status *status);
211float32 uint64_to_float32_scalbn(uint64_t, int, float_status *status);
212
c02e1fb8 213float32 int16_to_float32(int16_t, float_status *status);
e5a41ffa 214float32 int32_to_float32(int32_t, float_status *status);
2abdfe24 215float32 int64_to_float32(int64_t, float_status *status);
c02e1fb8 216float32 uint16_to_float32(uint16_t, float_status *status);
e5a41ffa 217float32 uint32_to_float32(uint32_t, float_status *status);
2abdfe24
RH
218float32 uint64_to_float32(uint64_t, float_status *status);
219
220float64 int16_to_float64_scalbn(int16_t, int, float_status *status);
221float64 int32_to_float64_scalbn(int32_t, int, float_status *status);
222float64 int64_to_float64_scalbn(int64_t, int, float_status *status);
223float64 uint16_to_float64_scalbn(uint16_t, int, float_status *status);
224float64 uint32_to_float64_scalbn(uint32_t, int, float_status *status);
225float64 uint64_to_float64_scalbn(uint64_t, int, float_status *status);
226
227float64 int16_to_float64(int16_t, float_status *status);
228float64 int32_to_float64(int32_t, float_status *status);
229float64 int64_to_float64(int64_t, float_status *status);
c02e1fb8 230float64 uint16_to_float64(uint16_t, float_status *status);
e5a41ffa 231float64 uint32_to_float64(uint32_t, float_status *status);
2abdfe24
RH
232float64 uint64_to_float64(uint64_t, float_status *status);
233
e5a41ffa 234floatx80 int32_to_floatx80(int32_t, float_status *status);
e5a41ffa 235floatx80 int64_to_floatx80(int64_t, float_status *status);
2abdfe24
RH
236
237float128 int32_to_float128(int32_t, float_status *status);
e5a41ffa 238float128 int64_to_float128(int64_t, float_status *status);
e5a41ffa 239float128 uint64_to_float128(uint64_t, float_status *status);
158142c2 240
60011498
PB
241/*----------------------------------------------------------------------------
242| Software half-precision conversion routines.
243*----------------------------------------------------------------------------*/
2f6c74be 244
6fed16b2
AB
245float16 float32_to_float16(float32, bool ieee, float_status *status);
246float32 float16_to_float32(float16, bool ieee, float_status *status);
247float16 float64_to_float16(float64 a, bool ieee, float_status *status);
248float64 float16_to_float64(float16 a, bool ieee, float_status *status);
2f6c74be
RH
249
250int16_t float16_to_int16_scalbn(float16, int, int, float_status *status);
251int32_t float16_to_int32_scalbn(float16, int, int, float_status *status);
252int64_t float16_to_int64_scalbn(float16, int, int, float_status *status);
253
ab52f973 254int16_t float16_to_int16(float16, float_status *status);
ab52f973 255int32_t float16_to_int32(float16, float_status *status);
ab52f973 256int64_t float16_to_int64(float16, float_status *status);
2f6c74be
RH
257
258int16_t float16_to_int16_round_to_zero(float16, float_status *status);
259int32_t float16_to_int32_round_to_zero(float16, float_status *status);
ab52f973 260int64_t float16_to_int64_round_to_zero(float16, float_status *status);
2f6c74be
RH
261
262uint16_t float16_to_uint16_scalbn(float16 a, int, int, float_status *status);
263uint32_t float16_to_uint32_scalbn(float16 a, int, int, float_status *status);
264uint64_t float16_to_uint64_scalbn(float16 a, int, int, float_status *status);
265
266uint16_t float16_to_uint16(float16 a, float_status *status);
267uint32_t float16_to_uint32(float16 a, float_status *status);
268uint64_t float16_to_uint64(float16 a, float_status *status);
269
270uint16_t float16_to_uint16_round_to_zero(float16 a, float_status *status);
271uint32_t float16_to_uint32_round_to_zero(float16 a, float_status *status);
ab52f973 272uint64_t float16_to_uint64_round_to_zero(float16 a, float_status *status);
bb4d4bb3
PM
273
274/*----------------------------------------------------------------------------
275| Software half-precision operations.
276*----------------------------------------------------------------------------*/
6fff2167 277
dbe4d53a 278float16 float16_round_to_int(float16, float_status *status);
6fff2167
AB
279float16 float16_add(float16, float16, float_status *status);
280float16 float16_sub(float16, float16, float_status *status);
74d707e2 281float16 float16_mul(float16, float16, float_status *status);
d446830a 282float16 float16_muladd(float16, float16, float16, int, float_status *status);
cf07323d 283float16 float16_div(float16, float16, float_status *status);
0bfc9f19 284float16 float16_scalbn(float16, int, float_status *status);
89360067
AB
285float16 float16_min(float16, float16, float_status *status);
286float16 float16_max(float16, float16, float_status *status);
287float16 float16_minnum(float16, float16, float_status *status);
288float16 float16_maxnum(float16, float16, float_status *status);
289float16 float16_minnummag(float16, float16, float_status *status);
290float16 float16_maxnummag(float16, float16, float_status *status);
c13bb2da 291float16 float16_sqrt(float16, float_status *status);
0c4c9092
AB
292int float16_compare(float16, float16, float_status *status);
293int float16_compare_quiet(float16, float16, float_status *status);
6fff2167 294
af39bc8c
AM
295int float16_is_quiet_nan(float16, float_status *status);
296int float16_is_signaling_nan(float16, float_status *status);
d619bb98 297float16 float16_silence_nan(float16, float_status *status);
60011498 298
a49db98d 299static inline int float16_is_any_nan(float16 a)
213ff4e6
MF
300{
301 return ((float16_val(a) & ~0x8000) > 0x7c00);
302}
303
f566c047
BR
304static inline int float16_is_neg(float16 a)
305{
306 return float16_val(a) >> 15;
307}
308
309static inline int float16_is_infinity(float16 a)
310{
311 return (float16_val(a) & 0x7fff) == 0x7c00;
312}
313
314static inline int float16_is_zero(float16 a)
315{
316 return (float16_val(a) & 0x7fff) == 0;
317}
318
319static inline int float16_is_zero_or_denormal(float16 a)
320{
321 return (float16_val(a) & 0x7c00) == 0;
322}
323
28136775
AB
324static inline float16 float16_abs(float16 a)
325{
326 /* Note that abs does *not* handle NaN specially, nor does
327 * it flush denormal inputs to zero.
328 */
329 return make_float16(float16_val(a) & 0x7fff);
330}
5f10aef5
AB
331
332static inline float16 float16_chs(float16 a)
333{
334 /* Note that chs does *not* handle NaN specially, nor does
335 * it flush denormal inputs to zero.
336 */
337 return make_float16(float16_val(a) ^ 0x8000);
338}
339
78b5a3e6
AB
340static inline float16 float16_set_sign(float16 a, int sign)
341{
342 return make_float16((float16_val(a) & 0x7fff) | (sign << 15));
343}
344
efd4829e 345#define float16_zero make_float16(0)
efd4829e 346#define float16_half make_float16(0x3800)
026e2d6e
AB
347#define float16_one make_float16(0x3c00)
348#define float16_one_point_five make_float16(0x3e00)
349#define float16_two make_float16(0x4000)
350#define float16_three make_float16(0x4200)
efd4829e
AB
351#define float16_infinity make_float16(0x7c00)
352
8559666d
CL
353/*----------------------------------------------------------------------------
354| The pattern for a default generated half-precision NaN.
355*----------------------------------------------------------------------------*/
af39bc8c 356float16 float16_default_nan(float_status *status);
8559666d 357
158142c2
FB
358/*----------------------------------------------------------------------------
359| Software IEC/IEEE single-precision conversion routines.
360*----------------------------------------------------------------------------*/
2f6c74be
RH
361
362int16_t float32_to_int16_scalbn(float32, int, int, float_status *status);
363int32_t float32_to_int32_scalbn(float32, int, int, float_status *status);
364int64_t float32_to_int64_scalbn(float32, int, int, float_status *status);
365
0bb721d7 366int16_t float32_to_int16(float32, float_status *status);
f4014512 367int32_t float32_to_int32(float32, float_status *status);
2f6c74be
RH
368int64_t float32_to_int64(float32, float_status *status);
369
370int16_t float32_to_int16_round_to_zero(float32, float_status *status);
f4014512 371int32_t float32_to_int32_round_to_zero(float32, float_status *status);
2f6c74be
RH
372int64_t float32_to_int64_round_to_zero(float32, float_status *status);
373
374uint16_t float32_to_uint16_scalbn(float32, int, int, float_status *status);
375uint32_t float32_to_uint32_scalbn(float32, int, int, float_status *status);
376uint64_t float32_to_uint64_scalbn(float32, int, int, float_status *status);
377
378uint16_t float32_to_uint16(float32, float_status *status);
3a87d009 379uint32_t float32_to_uint32(float32, float_status *status);
182f42fd 380uint64_t float32_to_uint64(float32, float_status *status);
2f6c74be
RH
381
382uint16_t float32_to_uint16_round_to_zero(float32, float_status *status);
383uint32_t float32_to_uint32_round_to_zero(float32, float_status *status);
182f42fd 384uint64_t float32_to_uint64_round_to_zero(float32, float_status *status);
2f6c74be 385
e5a41ffa
PM
386float64 float32_to_float64(float32, float_status *status);
387floatx80 float32_to_floatx80(float32, float_status *status);
388float128 float32_to_float128(float32, float_status *status);
158142c2
FB
389
390/*----------------------------------------------------------------------------
391| Software IEC/IEEE single-precision operations.
392*----------------------------------------------------------------------------*/
e5a41ffa
PM
393float32 float32_round_to_int(float32, float_status *status);
394float32 float32_add(float32, float32, float_status *status);
395float32 float32_sub(float32, float32, float_status *status);
396float32 float32_mul(float32, float32, float_status *status);
397float32 float32_div(float32, float32, float_status *status);
398float32 float32_rem(float32, float32, float_status *status);
399float32 float32_muladd(float32, float32, float32, int, float_status *status);
400float32 float32_sqrt(float32, float_status *status);
401float32 float32_exp2(float32, float_status *status);
402float32 float32_log2(float32, float_status *status);
403int float32_eq(float32, float32, float_status *status);
404int float32_le(float32, float32, float_status *status);
405int float32_lt(float32, float32, float_status *status);
406int float32_unordered(float32, float32, float_status *status);
407int float32_eq_quiet(float32, float32, float_status *status);
408int float32_le_quiet(float32, float32, float_status *status);
409int float32_lt_quiet(float32, float32, float_status *status);
410int float32_unordered_quiet(float32, float32, float_status *status);
411int float32_compare(float32, float32, float_status *status);
412int float32_compare_quiet(float32, float32, float_status *status);
413float32 float32_min(float32, float32, float_status *status);
414float32 float32_max(float32, float32, float_status *status);
415float32 float32_minnum(float32, float32, float_status *status);
416float32 float32_maxnum(float32, float32, float_status *status);
417float32 float32_minnummag(float32, float32, float_status *status);
418float32 float32_maxnummag(float32, float32, float_status *status);
af39bc8c
AM
419int float32_is_quiet_nan(float32, float_status *status);
420int float32_is_signaling_nan(float32, float_status *status);
d619bb98 421float32 float32_silence_nan(float32, float_status *status);
e5a41ffa 422float32 float32_scalbn(float32, int, float_status *status);
158142c2 423
a49db98d 424static inline float32 float32_abs(float32 a)
1d6bda35 425{
37d18660
PM
426 /* Note that abs does *not* handle NaN specially, nor does
427 * it flush denormal inputs to zero.
428 */
f090c9d4 429 return make_float32(float32_val(a) & 0x7fffffff);
1d6bda35
FB
430}
431
a49db98d 432static inline float32 float32_chs(float32 a)
1d6bda35 433{
37d18660
PM
434 /* Note that chs does *not* handle NaN specially, nor does
435 * it flush denormal inputs to zero.
436 */
f090c9d4 437 return make_float32(float32_val(a) ^ 0x80000000);
1d6bda35
FB
438}
439
a49db98d 440static inline int float32_is_infinity(float32 a)
c52ab6f5 441{
dadd71a7 442 return (float32_val(a) & 0x7fffffff) == 0x7f800000;
c52ab6f5
AJ
443}
444
a49db98d 445static inline int float32_is_neg(float32 a)
c52ab6f5
AJ
446{
447 return float32_val(a) >> 31;
448}
449
a49db98d 450static inline int float32_is_zero(float32 a)
c52ab6f5
AJ
451{
452 return (float32_val(a) & 0x7fffffff) == 0;
453}
454
a49db98d 455static inline int float32_is_any_nan(float32 a)
21d6ebde
PM
456{
457 return ((float32_val(a) & ~(1 << 31)) > 0x7f800000UL);
458}
459
a49db98d 460static inline int float32_is_zero_or_denormal(float32 a)
6f3300ad
PM
461{
462 return (float32_val(a) & 0x7f800000) == 0;
463}
464
588e6dfd
EC
465static inline bool float32_is_normal(float32 a)
466{
47393181 467 return (((float32_val(a) >> 23) + 1) & 0xff) >= 2;
588e6dfd
EC
468}
469
470static inline bool float32_is_denormal(float32 a)
471{
472 return float32_is_zero_or_denormal(a) && !float32_is_zero(a);
473}
474
315df0d1
EC
475static inline bool float32_is_zero_or_normal(float32 a)
476{
477 return float32_is_normal(a) || float32_is_zero(a);
478}
479
a49db98d 480static inline float32 float32_set_sign(float32 a, int sign)
c30fe7df
CL
481{
482 return make_float32((float32_val(a) & 0x7fffffff) | (sign << 31));
483}
484
f090c9d4 485#define float32_zero make_float32(0)
c30fe7df 486#define float32_half make_float32(0x3f000000)
026e2d6e
AB
487#define float32_one make_float32(0x3f800000)
488#define float32_one_point_five make_float32(0x3fc00000)
489#define float32_two make_float32(0x40000000)
490#define float32_three make_float32(0x40400000)
c30fe7df 491#define float32_infinity make_float32(0x7f800000)
f090c9d4 492
88857aca
LV
493/*----------------------------------------------------------------------------
494| Packs the sign `zSign', exponent `zExp', and significand `zSig' into a
495| single-precision floating-point value, returning the result. After being
496| shifted into the proper positions, the three fields are simply added
497| together to form the result. This means that any integer portion of `zSig'
498| will be added into the exponent. Since a properly normalized significand
499| will have an integer portion equal to 1, the `zExp' input should be 1 less
500| than the desired result exponent whenever `zSig' is a complete, normalized
501| significand.
502*----------------------------------------------------------------------------*/
503
504static inline float32 packFloat32(flag zSign, int zExp, uint32_t zSig)
505{
506 return make_float32(
507 (((uint32_t)zSign) << 31) + (((uint32_t)zExp) << 23) + zSig);
508}
509
8559666d
CL
510/*----------------------------------------------------------------------------
511| The pattern for a default generated single-precision NaN.
512*----------------------------------------------------------------------------*/
af39bc8c 513float32 float32_default_nan(float_status *status);
8559666d 514
158142c2
FB
515/*----------------------------------------------------------------------------
516| Software IEC/IEEE double-precision conversion routines.
517*----------------------------------------------------------------------------*/
2f6c74be
RH
518
519int16_t float64_to_int16_scalbn(float64, int, int, float_status *status);
520int32_t float64_to_int32_scalbn(float64, int, int, float_status *status);
521int64_t float64_to_int64_scalbn(float64, int, int, float_status *status);
522
0bb721d7 523int16_t float64_to_int16(float64, float_status *status);
f4014512 524int32_t float64_to_int32(float64, float_status *status);
2f6c74be
RH
525int64_t float64_to_int64(float64, float_status *status);
526
527int16_t float64_to_int16_round_to_zero(float64, float_status *status);
f4014512 528int32_t float64_to_int32_round_to_zero(float64, float_status *status);
2f6c74be
RH
529int64_t float64_to_int64_round_to_zero(float64, float_status *status);
530
531uint16_t float64_to_uint16_scalbn(float64, int, int, float_status *status);
532uint32_t float64_to_uint32_scalbn(float64, int, int, float_status *status);
533uint64_t float64_to_uint64_scalbn(float64, int, int, float_status *status);
534
535uint16_t float64_to_uint16(float64, float_status *status);
3a87d009 536uint32_t float64_to_uint32(float64, float_status *status);
2f6c74be
RH
537uint64_t float64_to_uint64(float64, float_status *status);
538
539uint16_t float64_to_uint16_round_to_zero(float64, float_status *status);
3a87d009 540uint32_t float64_to_uint32_round_to_zero(float64, float_status *status);
2f6c74be
RH
541uint64_t float64_to_uint64_round_to_zero(float64, float_status *status);
542
e5a41ffa
PM
543float32 float64_to_float32(float64, float_status *status);
544floatx80 float64_to_floatx80(float64, float_status *status);
545float128 float64_to_float128(float64, float_status *status);
158142c2
FB
546
547/*----------------------------------------------------------------------------
548| Software IEC/IEEE double-precision operations.
549*----------------------------------------------------------------------------*/
e5a41ffa 550float64 float64_round_to_int(float64, float_status *status);
e5a41ffa
PM
551float64 float64_add(float64, float64, float_status *status);
552float64 float64_sub(float64, float64, float_status *status);
553float64 float64_mul(float64, float64, float_status *status);
554float64 float64_div(float64, float64, float_status *status);
555float64 float64_rem(float64, float64, float_status *status);
556float64 float64_muladd(float64, float64, float64, int, float_status *status);
557float64 float64_sqrt(float64, float_status *status);
558float64 float64_log2(float64, float_status *status);
559int float64_eq(float64, float64, float_status *status);
560int float64_le(float64, float64, float_status *status);
561int float64_lt(float64, float64, float_status *status);
562int float64_unordered(float64, float64, float_status *status);
563int float64_eq_quiet(float64, float64, float_status *status);
564int float64_le_quiet(float64, float64, float_status *status);
565int float64_lt_quiet(float64, float64, float_status *status);
566int float64_unordered_quiet(float64, float64, float_status *status);
567int float64_compare(float64, float64, float_status *status);
568int float64_compare_quiet(float64, float64, float_status *status);
569float64 float64_min(float64, float64, float_status *status);
570float64 float64_max(float64, float64, float_status *status);
571float64 float64_minnum(float64, float64, float_status *status);
572float64 float64_maxnum(float64, float64, float_status *status);
573float64 float64_minnummag(float64, float64, float_status *status);
574float64 float64_maxnummag(float64, float64, float_status *status);
af39bc8c
AM
575int float64_is_quiet_nan(float64 a, float_status *status);
576int float64_is_signaling_nan(float64, float_status *status);
d619bb98 577float64 float64_silence_nan(float64, float_status *status);
e5a41ffa 578float64 float64_scalbn(float64, int, float_status *status);
158142c2 579
a49db98d 580static inline float64 float64_abs(float64 a)
1d6bda35 581{
37d18660
PM
582 /* Note that abs does *not* handle NaN specially, nor does
583 * it flush denormal inputs to zero.
584 */
f090c9d4 585 return make_float64(float64_val(a) & 0x7fffffffffffffffLL);
1d6bda35
FB
586}
587
a49db98d 588static inline float64 float64_chs(float64 a)
1d6bda35 589{
37d18660
PM
590 /* Note that chs does *not* handle NaN specially, nor does
591 * it flush denormal inputs to zero.
592 */
f090c9d4 593 return make_float64(float64_val(a) ^ 0x8000000000000000LL);
1d6bda35
FB
594}
595
a49db98d 596static inline int float64_is_infinity(float64 a)
c52ab6f5
AJ
597{
598 return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL;
599}
600
a49db98d 601static inline int float64_is_neg(float64 a)
c52ab6f5
AJ
602{
603 return float64_val(a) >> 63;
604}
605
a49db98d 606static inline int float64_is_zero(float64 a)
c52ab6f5
AJ
607{
608 return (float64_val(a) & 0x7fffffffffffffffLL) == 0;
609}
610
a49db98d 611static inline int float64_is_any_nan(float64 a)
21d6ebde
PM
612{
613 return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL);
614}
615
a49db98d 616static inline int float64_is_zero_or_denormal(float64 a)
587eabfa
AJ
617{
618 return (float64_val(a) & 0x7ff0000000000000LL) == 0;
619}
620
588e6dfd
EC
621static inline bool float64_is_normal(float64 a)
622{
47393181 623 return (((float64_val(a) >> 52) + 1) & 0x7ff) >= 2;
588e6dfd
EC
624}
625
626static inline bool float64_is_denormal(float64 a)
627{
628 return float64_is_zero_or_denormal(a) && !float64_is_zero(a);
629}
630
315df0d1
EC
631static inline bool float64_is_zero_or_normal(float64 a)
632{
633 return float64_is_normal(a) || float64_is_zero(a);
634}
635
a49db98d 636static inline float64 float64_set_sign(float64 a, int sign)
c30fe7df
CL
637{
638 return make_float64((float64_val(a) & 0x7fffffffffffffffULL)
639 | ((int64_t)sign << 63));
640}
641
f090c9d4 642#define float64_zero make_float64(0)
026e2d6e 643#define float64_half make_float64(0x3fe0000000000000LL)
196cfc89 644#define float64_one make_float64(0x3ff0000000000000LL)
026e2d6e
AB
645#define float64_one_point_five make_float64(0x3FF8000000000000ULL)
646#define float64_two make_float64(0x4000000000000000ULL)
647#define float64_three make_float64(0x4008000000000000ULL)
8229c991 648#define float64_ln2 make_float64(0x3fe62e42fefa39efLL)
c30fe7df 649#define float64_infinity make_float64(0x7ff0000000000000LL)
f090c9d4 650
8559666d
CL
651/*----------------------------------------------------------------------------
652| The pattern for a default generated double-precision NaN.
653*----------------------------------------------------------------------------*/
af39bc8c 654float64 float64_default_nan(float_status *status);
8559666d 655
158142c2
FB
656/*----------------------------------------------------------------------------
657| Software IEC/IEEE extended double-precision conversion routines.
658*----------------------------------------------------------------------------*/
f4014512
PM
659int32_t floatx80_to_int32(floatx80, float_status *status);
660int32_t floatx80_to_int32_round_to_zero(floatx80, float_status *status);
f42c2224
PM
661int64_t floatx80_to_int64(floatx80, float_status *status);
662int64_t floatx80_to_int64_round_to_zero(floatx80, float_status *status);
e5a41ffa
PM
663float32 floatx80_to_float32(floatx80, float_status *status);
664float64 floatx80_to_float64(floatx80, float_status *status);
665float128 floatx80_to_float128(floatx80, float_status *status);
158142c2 666
0f605c88
LV
667/*----------------------------------------------------------------------------
668| The pattern for an extended double-precision inf.
669*----------------------------------------------------------------------------*/
670extern const floatx80 floatx80_infinity;
671
158142c2
FB
672/*----------------------------------------------------------------------------
673| Software IEC/IEEE extended double-precision operations.
674*----------------------------------------------------------------------------*/
0f721292 675floatx80 floatx80_round(floatx80 a, float_status *status);
e5a41ffa
PM
676floatx80 floatx80_round_to_int(floatx80, float_status *status);
677floatx80 floatx80_add(floatx80, floatx80, float_status *status);
678floatx80 floatx80_sub(floatx80, floatx80, float_status *status);
679floatx80 floatx80_mul(floatx80, floatx80, float_status *status);
680floatx80 floatx80_div(floatx80, floatx80, float_status *status);
681floatx80 floatx80_rem(floatx80, floatx80, float_status *status);
682floatx80 floatx80_sqrt(floatx80, float_status *status);
683int floatx80_eq(floatx80, floatx80, float_status *status);
684int floatx80_le(floatx80, floatx80, float_status *status);
685int floatx80_lt(floatx80, floatx80, float_status *status);
686int floatx80_unordered(floatx80, floatx80, float_status *status);
687int floatx80_eq_quiet(floatx80, floatx80, float_status *status);
688int floatx80_le_quiet(floatx80, floatx80, float_status *status);
689int floatx80_lt_quiet(floatx80, floatx80, float_status *status);
690int floatx80_unordered_quiet(floatx80, floatx80, float_status *status);
691int floatx80_compare(floatx80, floatx80, float_status *status);
692int floatx80_compare_quiet(floatx80, floatx80, float_status *status);
af39bc8c
AM
693int floatx80_is_quiet_nan(floatx80, float_status *status);
694int floatx80_is_signaling_nan(floatx80, float_status *status);
d619bb98 695floatx80 floatx80_silence_nan(floatx80, float_status *status);
e5a41ffa 696floatx80 floatx80_scalbn(floatx80, int, float_status *status);
158142c2 697
a49db98d 698static inline floatx80 floatx80_abs(floatx80 a)
1d6bda35
FB
699{
700 a.high &= 0x7fff;
701 return a;
702}
703
a49db98d 704static inline floatx80 floatx80_chs(floatx80 a)
1d6bda35
FB
705{
706 a.high ^= 0x8000;
707 return a;
708}
709
a49db98d 710static inline int floatx80_is_infinity(floatx80 a)
c52ab6f5 711{
0f605c88
LV
712#if defined(TARGET_M68K)
713 return (a.high & 0x7fff) == floatx80_infinity.high && !(a.low << 1);
714#else
715 return (a.high & 0x7fff) == floatx80_infinity.high &&
716 a.low == floatx80_infinity.low;
717#endif
c52ab6f5
AJ
718}
719
a49db98d 720static inline int floatx80_is_neg(floatx80 a)
c52ab6f5
AJ
721{
722 return a.high >> 15;
723}
724
a49db98d 725static inline int floatx80_is_zero(floatx80 a)
c52ab6f5
AJ
726{
727 return (a.high & 0x7fff) == 0 && a.low == 0;
728}
729
a49db98d 730static inline int floatx80_is_zero_or_denormal(floatx80 a)
587eabfa
AJ
731{
732 return (a.high & 0x7fff) == 0;
733}
734
a49db98d 735static inline int floatx80_is_any_nan(floatx80 a)
2bed652f
PM
736{
737 return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1);
738}
739
d1eb8f2a
AD
740/*----------------------------------------------------------------------------
741| Return whether the given value is an invalid floatx80 encoding.
742| Invalid floatx80 encodings arise when the integer bit is not set, but
743| the exponent is not zero. The only times the integer bit is permitted to
744| be zero is in subnormal numbers and the value zero.
745| This includes what the Intel software developer's manual calls pseudo-NaNs,
746| pseudo-infinities and un-normal numbers. It does not include
747| pseudo-denormals, which must still be correctly handled as inputs even
748| if they are never generated as outputs.
749*----------------------------------------------------------------------------*/
750static inline bool floatx80_invalid_encoding(floatx80 a)
751{
752 return (a.low & (1ULL << 63)) == 0 && (a.high & 0x7FFF) != 0;
753}
754
f3218a8d
AJ
755#define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL)
756#define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL)
757#define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL)
c4b4c77a 758#define floatx80_pi make_floatx80(0x4000, 0xc90fdaa22168c235LL)
f3218a8d 759#define floatx80_half make_floatx80(0x3ffe, 0x8000000000000000LL)
f3218a8d 760
88857aca
LV
761/*----------------------------------------------------------------------------
762| Returns the fraction bits of the extended double-precision floating-point
763| value `a'.
764*----------------------------------------------------------------------------*/
765
766static inline uint64_t extractFloatx80Frac(floatx80 a)
767{
768 return a.low;
769}
770
771/*----------------------------------------------------------------------------
772| Returns the exponent bits of the extended double-precision floating-point
773| value `a'.
774*----------------------------------------------------------------------------*/
775
776static inline int32_t extractFloatx80Exp(floatx80 a)
777{
778 return a.high & 0x7FFF;
779}
780
781/*----------------------------------------------------------------------------
782| Returns the sign bit of the extended double-precision floating-point value
783| `a'.
784*----------------------------------------------------------------------------*/
785
786static inline flag extractFloatx80Sign(floatx80 a)
787{
788 return a.high >> 15;
789}
790
791/*----------------------------------------------------------------------------
792| Packs the sign `zSign', exponent `zExp', and significand `zSig' into an
793| extended double-precision floating-point value, returning the result.
794*----------------------------------------------------------------------------*/
795
796static inline floatx80 packFloatx80(flag zSign, int32_t zExp, uint64_t zSig)
797{
798 floatx80 z;
799
800 z.low = zSig;
801 z.high = (((uint16_t)zSign) << 15) + zExp;
802 return z;
803}
804
805/*----------------------------------------------------------------------------
806| Normalizes the subnormal extended double-precision floating-point value
807| represented by the denormalized significand `aSig'. The normalized exponent
808| and significand are stored at the locations pointed to by `zExpPtr' and
809| `zSigPtr', respectively.
810*----------------------------------------------------------------------------*/
811
812void normalizeFloatx80Subnormal(uint64_t aSig, int32_t *zExpPtr,
813 uint64_t *zSigPtr);
814
815/*----------------------------------------------------------------------------
816| Takes two extended double-precision floating-point values `a' and `b', one
817| of which is a NaN, and returns the appropriate NaN result. If either `a' or
818| `b' is a signaling NaN, the invalid exception is raised.
819*----------------------------------------------------------------------------*/
820
821floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, float_status *status);
822
823/*----------------------------------------------------------------------------
824| Takes an abstract floating-point value having sign `zSign', exponent `zExp',
825| and extended significand formed by the concatenation of `zSig0' and `zSig1',
826| and returns the proper extended double-precision floating-point value
827| corresponding to the abstract input. Ordinarily, the abstract value is
828| rounded and packed into the extended double-precision format, with the
829| inexact exception raised if the abstract input cannot be represented
830| exactly. However, if the abstract value is too large, the overflow and
831| inexact exceptions are raised and an infinity or maximal finite value is
832| returned. If the abstract value is too small, the input value is rounded to
833| a subnormal number, and the underflow and inexact exceptions are raised if
834| the abstract input cannot be represented exactly as a subnormal extended
835| double-precision floating-point number.
836| If `roundingPrecision' is 32 or 64, the result is rounded to the same
837| number of bits as single or double precision, respectively. Otherwise, the
838| result is rounded to the full precision of the extended double-precision
839| format.
840| The input significand must be normalized or smaller. If the input
841| significand is not normalized, `zExp' must be 0; in that case, the result
842| returned is a subnormal number, and it must not require rounding. The
843| handling of underflow and overflow follows the IEC/IEEE Standard for Binary
844| Floating-Point Arithmetic.
845*----------------------------------------------------------------------------*/
846
847floatx80 roundAndPackFloatx80(int8_t roundingPrecision, flag zSign,
848 int32_t zExp, uint64_t zSig0, uint64_t zSig1,
849 float_status *status);
850
851/*----------------------------------------------------------------------------
852| Takes an abstract floating-point value having sign `zSign', exponent
853| `zExp', and significand formed by the concatenation of `zSig0' and `zSig1',
854| and returns the proper extended double-precision floating-point value
855| corresponding to the abstract input. This routine is just like
856| `roundAndPackFloatx80' except that the input significand does not have to be
857| normalized.
858*----------------------------------------------------------------------------*/
859
860floatx80 normalizeRoundAndPackFloatx80(int8_t roundingPrecision,
861 flag zSign, int32_t zExp,
862 uint64_t zSig0, uint64_t zSig1,
863 float_status *status);
864
8559666d 865/*----------------------------------------------------------------------------
789ec7ce 866| The pattern for a default generated extended double-precision NaN.
8559666d 867*----------------------------------------------------------------------------*/
af39bc8c 868floatx80 floatx80_default_nan(float_status *status);
8559666d 869
158142c2
FB
870/*----------------------------------------------------------------------------
871| Software IEC/IEEE quadruple-precision conversion routines.
872*----------------------------------------------------------------------------*/
f4014512
PM
873int32_t float128_to_int32(float128, float_status *status);
874int32_t float128_to_int32_round_to_zero(float128, float_status *status);
f42c2224
PM
875int64_t float128_to_int64(float128, float_status *status);
876int64_t float128_to_int64_round_to_zero(float128, float_status *status);
2e6d8568
BR
877uint64_t float128_to_uint64(float128, float_status *status);
878uint64_t float128_to_uint64_round_to_zero(float128, float_status *status);
e45de992 879uint32_t float128_to_uint32(float128, float_status *status);
fd425037 880uint32_t float128_to_uint32_round_to_zero(float128, float_status *status);
e5a41ffa
PM
881float32 float128_to_float32(float128, float_status *status);
882float64 float128_to_float64(float128, float_status *status);
883floatx80 float128_to_floatx80(float128, float_status *status);
158142c2
FB
884
885/*----------------------------------------------------------------------------
886| Software IEC/IEEE quadruple-precision operations.
887*----------------------------------------------------------------------------*/
e5a41ffa
PM
888float128 float128_round_to_int(float128, float_status *status);
889float128 float128_add(float128, float128, float_status *status);
890float128 float128_sub(float128, float128, float_status *status);
891float128 float128_mul(float128, float128, float_status *status);
892float128 float128_div(float128, float128, float_status *status);
893float128 float128_rem(float128, float128, float_status *status);
894float128 float128_sqrt(float128, float_status *status);
895int float128_eq(float128, float128, float_status *status);
896int float128_le(float128, float128, float_status *status);
897int float128_lt(float128, float128, float_status *status);
898int float128_unordered(float128, float128, float_status *status);
899int float128_eq_quiet(float128, float128, float_status *status);
900int float128_le_quiet(float128, float128, float_status *status);
901int float128_lt_quiet(float128, float128, float_status *status);
902int float128_unordered_quiet(float128, float128, float_status *status);
903int float128_compare(float128, float128, float_status *status);
904int float128_compare_quiet(float128, float128, float_status *status);
af39bc8c
AM
905int float128_is_quiet_nan(float128, float_status *status);
906int float128_is_signaling_nan(float128, float_status *status);
d619bb98 907float128 float128_silence_nan(float128, float_status *status);
e5a41ffa 908float128 float128_scalbn(float128, int, float_status *status);
158142c2 909
a49db98d 910static inline float128 float128_abs(float128 a)
1d6bda35
FB
911{
912 a.high &= 0x7fffffffffffffffLL;
913 return a;
914}
915
a49db98d 916static inline float128 float128_chs(float128 a)
1d6bda35
FB
917{
918 a.high ^= 0x8000000000000000LL;
919 return a;
920}
921
a49db98d 922static inline int float128_is_infinity(float128 a)
c52ab6f5
AJ
923{
924 return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0;
925}
926
a49db98d 927static inline int float128_is_neg(float128 a)
c52ab6f5
AJ
928{
929 return a.high >> 63;
930}
931
a49db98d 932static inline int float128_is_zero(float128 a)
c52ab6f5
AJ
933{
934 return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0;
935}
936
a49db98d 937static inline int float128_is_zero_or_denormal(float128 a)
587eabfa
AJ
938{
939 return (a.high & 0x7fff000000000000LL) == 0;
940}
941
47393181
DH
942static inline bool float128_is_normal(float128 a)
943{
944 return (((a.high >> 48) + 1) & 0x7fff) >= 2;
945}
946
947static inline bool float128_is_denormal(float128 a)
948{
949 return float128_is_zero_or_denormal(a) && !float128_is_zero(a);
950}
951
a49db98d 952static inline int float128_is_any_nan(float128 a)
2bed652f
PM
953{
954 return ((a.high >> 48) & 0x7fff) == 0x7fff &&
955 ((a.low != 0) || ((a.high & 0xffffffffffffLL) != 0));
956}
957
1e397ead
RH
958#define float128_zero make_float128(0, 0)
959
8559666d 960/*----------------------------------------------------------------------------
789ec7ce 961| The pattern for a default generated quadruple-precision NaN.
8559666d 962*----------------------------------------------------------------------------*/
af39bc8c 963float128 float128_default_nan(float_status *status);
8559666d 964
175de524 965#endif /* SOFTFLOAT_H */
This page took 0.90953 seconds and 4 git commands to generate.