]>
Commit | Line | Data |
---|---|---|
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 | =============================================================================== | |
20 | This C header file is part of the SoftFloat IEC/IEEE Floating-point | |
21 | Arithmetic Package, Release 2a. | |
158142c2 FB |
22 | |
23 | Written by John R. Hauser. This work was made possible in part by the | |
24 | International Computer Science Institute, located at Suite 600, 1947 Center | |
25 | Street, Berkeley, California 94704. Funding was partially provided by the | |
26 | National Science Foundation under grant MIP-9311980. The original version | |
27 | of this code was written as part of a project to build a fixed-point vector | |
28 | processor in collaboration with the University of California at Berkeley, | |
29 | overseen by Profs. Nelson Morgan and John Wawrzynek. More information | |
a7d1ac78 | 30 | is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ |
158142c2 FB |
31 | arithmetic/SoftFloat.html'. |
32 | ||
a7d1ac78 PM |
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. | |
158142c2 FB |
38 | |
39 | Derivative 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 |
41 | include prominent notice akin to these four paragraphs for those parts of | |
42 | this 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 | *----------------------------------------------------------------------------*/ | |
88 | enum { | |
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 | 97 | static inline void set_float_detect_tininess(int val, float_status *status) |
c29aca44 | 98 | { |
a2f2d288 | 99 | status->float_detect_tininess = val; |
c29aca44 | 100 | } |
e5a41ffa | 101 | static inline void set_float_rounding_mode(int val, float_status *status) |
879d096b | 102 | { |
a2f2d288 | 103 | status->float_rounding_mode = val; |
879d096b | 104 | } |
e5a41ffa | 105 | static inline void set_float_exception_flags(int val, float_status *status) |
879d096b | 106 | { |
a2f2d288 | 107 | status->float_exception_flags = val; |
879d096b | 108 | } |
e5a41ffa PM |
109 | static inline void set_floatx80_rounding_precision(int val, |
110 | float_status *status) | |
879d096b | 111 | { |
a2f2d288 | 112 | status->floatx80_rounding_precision = val; |
879d096b | 113 | } |
e5a41ffa | 114 | static inline void set_flush_to_zero(flag val, float_status *status) |
fe76d976 | 115 | { |
a2f2d288 | 116 | status->flush_to_zero = val; |
fe76d976 | 117 | } |
e5a41ffa | 118 | static 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 | 122 | static inline void set_default_nan_mode(flag val, float_status *status) |
5c7908ed | 123 | { |
a2f2d288 | 124 | status->default_nan_mode = val; |
5c7908ed | 125 | } |
af39bc8c AM |
126 | static inline void set_snan_bit_is_one(flag val, float_status *status) |
127 | { | |
128 | status->snan_bit_is_one = val; | |
129 | } | |
a49db98d | 130 | static inline int get_float_detect_tininess(float_status *status) |
879d096b | 131 | { |
a2f2d288 | 132 | return status->float_detect_tininess; |
879d096b | 133 | } |
a49db98d | 134 | static inline int get_float_rounding_mode(float_status *status) |
879d096b | 135 | { |
a2f2d288 | 136 | return status->float_rounding_mode; |
879d096b | 137 | } |
a49db98d | 138 | static inline int get_float_exception_flags(float_status *status) |
1d6bda35 | 139 | { |
a2f2d288 | 140 | return status->float_exception_flags; |
1d6bda35 | 141 | } |
a49db98d | 142 | static inline int get_floatx80_rounding_precision(float_status *status) |
879d096b | 143 | { |
a2f2d288 | 144 | return status->floatx80_rounding_precision; |
879d096b | 145 | } |
a49db98d | 146 | static inline flag get_flush_to_zero(float_status *status) |
879d096b | 147 | { |
a2f2d288 | 148 | return status->flush_to_zero; |
879d096b | 149 | } |
a49db98d | 150 | static inline flag get_flush_inputs_to_zero(float_status *status) |
879d096b | 151 | { |
a2f2d288 | 152 | return status->flush_inputs_to_zero; |
879d096b | 153 | } |
a49db98d | 154 | static 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 | 163 | void 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 | 169 | float16 float16_squash_input_denormal(float16 a, float_status *status); |
e5a41ffa PM |
170 | float32 float32_squash_input_denormal(float32 a, float_status *status); |
171 | float64 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 | *----------------------------------------------------------------------------*/ |
181 | enum { | |
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 | |
192 | float16 int16_to_float16_scalbn(int16_t a, int, float_status *status); | |
193 | float16 int32_to_float16_scalbn(int32_t a, int, float_status *status); | |
194 | float16 int64_to_float16_scalbn(int64_t a, int, float_status *status); | |
195 | float16 uint16_to_float16_scalbn(uint16_t a, int, float_status *status); | |
196 | float16 uint32_to_float16_scalbn(uint32_t a, int, float_status *status); | |
197 | float16 uint64_to_float16_scalbn(uint64_t a, int, float_status *status); | |
198 | ||
199 | float16 int16_to_float16(int16_t a, float_status *status); | |
200 | float16 int32_to_float16(int32_t a, float_status *status); | |
201 | float16 int64_to_float16(int64_t a, float_status *status); | |
202 | float16 uint16_to_float16(uint16_t a, float_status *status); | |
203 | float16 uint32_to_float16(uint32_t a, float_status *status); | |
204 | float16 uint64_to_float16(uint64_t a, float_status *status); | |
205 | ||
206 | float32 int16_to_float32_scalbn(int16_t, int, float_status *status); | |
207 | float32 int32_to_float32_scalbn(int32_t, int, float_status *status); | |
208 | float32 int64_to_float32_scalbn(int64_t, int, float_status *status); | |
209 | float32 uint16_to_float32_scalbn(uint16_t, int, float_status *status); | |
210 | float32 uint32_to_float32_scalbn(uint32_t, int, float_status *status); | |
211 | float32 uint64_to_float32_scalbn(uint64_t, int, float_status *status); | |
212 | ||
c02e1fb8 | 213 | float32 int16_to_float32(int16_t, float_status *status); |
e5a41ffa | 214 | float32 int32_to_float32(int32_t, float_status *status); |
2abdfe24 | 215 | float32 int64_to_float32(int64_t, float_status *status); |
c02e1fb8 | 216 | float32 uint16_to_float32(uint16_t, float_status *status); |
e5a41ffa | 217 | float32 uint32_to_float32(uint32_t, float_status *status); |
2abdfe24 RH |
218 | float32 uint64_to_float32(uint64_t, float_status *status); |
219 | ||
220 | float64 int16_to_float64_scalbn(int16_t, int, float_status *status); | |
221 | float64 int32_to_float64_scalbn(int32_t, int, float_status *status); | |
222 | float64 int64_to_float64_scalbn(int64_t, int, float_status *status); | |
223 | float64 uint16_to_float64_scalbn(uint16_t, int, float_status *status); | |
224 | float64 uint32_to_float64_scalbn(uint32_t, int, float_status *status); | |
225 | float64 uint64_to_float64_scalbn(uint64_t, int, float_status *status); | |
226 | ||
227 | float64 int16_to_float64(int16_t, float_status *status); | |
228 | float64 int32_to_float64(int32_t, float_status *status); | |
229 | float64 int64_to_float64(int64_t, float_status *status); | |
c02e1fb8 | 230 | float64 uint16_to_float64(uint16_t, float_status *status); |
e5a41ffa | 231 | float64 uint32_to_float64(uint32_t, float_status *status); |
2abdfe24 RH |
232 | float64 uint64_to_float64(uint64_t, float_status *status); |
233 | ||
e5a41ffa | 234 | floatx80 int32_to_floatx80(int32_t, float_status *status); |
e5a41ffa | 235 | floatx80 int64_to_floatx80(int64_t, float_status *status); |
2abdfe24 RH |
236 | |
237 | float128 int32_to_float128(int32_t, float_status *status); | |
e5a41ffa | 238 | float128 int64_to_float128(int64_t, float_status *status); |
e5a41ffa | 239 | float128 uint64_to_float128(uint64_t, float_status *status); |
158142c2 | 240 | |
60011498 PB |
241 | /*---------------------------------------------------------------------------- |
242 | | Software half-precision conversion routines. | |
243 | *----------------------------------------------------------------------------*/ | |
2f6c74be | 244 | |
6fed16b2 AB |
245 | float16 float32_to_float16(float32, bool ieee, float_status *status); |
246 | float32 float16_to_float32(float16, bool ieee, float_status *status); | |
247 | float16 float64_to_float16(float64 a, bool ieee, float_status *status); | |
248 | float64 float16_to_float64(float16 a, bool ieee, float_status *status); | |
2f6c74be RH |
249 | |
250 | int16_t float16_to_int16_scalbn(float16, int, int, float_status *status); | |
251 | int32_t float16_to_int32_scalbn(float16, int, int, float_status *status); | |
252 | int64_t float16_to_int64_scalbn(float16, int, int, float_status *status); | |
253 | ||
ab52f973 | 254 | int16_t float16_to_int16(float16, float_status *status); |
ab52f973 | 255 | int32_t float16_to_int32(float16, float_status *status); |
ab52f973 | 256 | int64_t float16_to_int64(float16, float_status *status); |
2f6c74be RH |
257 | |
258 | int16_t float16_to_int16_round_to_zero(float16, float_status *status); | |
259 | int32_t float16_to_int32_round_to_zero(float16, float_status *status); | |
ab52f973 | 260 | int64_t float16_to_int64_round_to_zero(float16, float_status *status); |
2f6c74be RH |
261 | |
262 | uint16_t float16_to_uint16_scalbn(float16 a, int, int, float_status *status); | |
263 | uint32_t float16_to_uint32_scalbn(float16 a, int, int, float_status *status); | |
264 | uint64_t float16_to_uint64_scalbn(float16 a, int, int, float_status *status); | |
265 | ||
266 | uint16_t float16_to_uint16(float16 a, float_status *status); | |
267 | uint32_t float16_to_uint32(float16 a, float_status *status); | |
268 | uint64_t float16_to_uint64(float16 a, float_status *status); | |
269 | ||
270 | uint16_t float16_to_uint16_round_to_zero(float16 a, float_status *status); | |
271 | uint32_t float16_to_uint32_round_to_zero(float16 a, float_status *status); | |
ab52f973 | 272 | uint64_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 | 278 | float16 float16_round_to_int(float16, float_status *status); |
6fff2167 AB |
279 | float16 float16_add(float16, float16, float_status *status); |
280 | float16 float16_sub(float16, float16, float_status *status); | |
74d707e2 | 281 | float16 float16_mul(float16, float16, float_status *status); |
d446830a | 282 | float16 float16_muladd(float16, float16, float16, int, float_status *status); |
cf07323d | 283 | float16 float16_div(float16, float16, float_status *status); |
0bfc9f19 | 284 | float16 float16_scalbn(float16, int, float_status *status); |
89360067 AB |
285 | float16 float16_min(float16, float16, float_status *status); |
286 | float16 float16_max(float16, float16, float_status *status); | |
287 | float16 float16_minnum(float16, float16, float_status *status); | |
288 | float16 float16_maxnum(float16, float16, float_status *status); | |
289 | float16 float16_minnummag(float16, float16, float_status *status); | |
290 | float16 float16_maxnummag(float16, float16, float_status *status); | |
c13bb2da | 291 | float16 float16_sqrt(float16, float_status *status); |
0c4c9092 AB |
292 | int float16_compare(float16, float16, float_status *status); |
293 | int float16_compare_quiet(float16, float16, float_status *status); | |
6fff2167 | 294 | |
af39bc8c AM |
295 | int float16_is_quiet_nan(float16, float_status *status); |
296 | int float16_is_signaling_nan(float16, float_status *status); | |
d619bb98 | 297 | float16 float16_silence_nan(float16, float_status *status); |
60011498 | 298 | |
a49db98d | 299 | static inline int float16_is_any_nan(float16 a) |
213ff4e6 MF |
300 | { |
301 | return ((float16_val(a) & ~0x8000) > 0x7c00); | |
302 | } | |
303 | ||
f566c047 BR |
304 | static inline int float16_is_neg(float16 a) |
305 | { | |
306 | return float16_val(a) >> 15; | |
307 | } | |
308 | ||
309 | static inline int float16_is_infinity(float16 a) | |
310 | { | |
311 | return (float16_val(a) & 0x7fff) == 0x7c00; | |
312 | } | |
313 | ||
314 | static inline int float16_is_zero(float16 a) | |
315 | { | |
316 | return (float16_val(a) & 0x7fff) == 0; | |
317 | } | |
318 | ||
319 | static inline int float16_is_zero_or_denormal(float16 a) | |
320 | { | |
321 | return (float16_val(a) & 0x7c00) == 0; | |
322 | } | |
323 | ||
28136775 AB |
324 | static 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 | |
332 | static 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 |
340 | static 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 | 356 | float16 float16_default_nan(float_status *status); |
8559666d | 357 | |
158142c2 FB |
358 | /*---------------------------------------------------------------------------- |
359 | | Software IEC/IEEE single-precision conversion routines. | |
360 | *----------------------------------------------------------------------------*/ | |
2f6c74be RH |
361 | |
362 | int16_t float32_to_int16_scalbn(float32, int, int, float_status *status); | |
363 | int32_t float32_to_int32_scalbn(float32, int, int, float_status *status); | |
364 | int64_t float32_to_int64_scalbn(float32, int, int, float_status *status); | |
365 | ||
0bb721d7 | 366 | int16_t float32_to_int16(float32, float_status *status); |
f4014512 | 367 | int32_t float32_to_int32(float32, float_status *status); |
2f6c74be RH |
368 | int64_t float32_to_int64(float32, float_status *status); |
369 | ||
370 | int16_t float32_to_int16_round_to_zero(float32, float_status *status); | |
f4014512 | 371 | int32_t float32_to_int32_round_to_zero(float32, float_status *status); |
2f6c74be RH |
372 | int64_t float32_to_int64_round_to_zero(float32, float_status *status); |
373 | ||
374 | uint16_t float32_to_uint16_scalbn(float32, int, int, float_status *status); | |
375 | uint32_t float32_to_uint32_scalbn(float32, int, int, float_status *status); | |
376 | uint64_t float32_to_uint64_scalbn(float32, int, int, float_status *status); | |
377 | ||
378 | uint16_t float32_to_uint16(float32, float_status *status); | |
3a87d009 | 379 | uint32_t float32_to_uint32(float32, float_status *status); |
182f42fd | 380 | uint64_t float32_to_uint64(float32, float_status *status); |
2f6c74be RH |
381 | |
382 | uint16_t float32_to_uint16_round_to_zero(float32, float_status *status); | |
383 | uint32_t float32_to_uint32_round_to_zero(float32, float_status *status); | |
182f42fd | 384 | uint64_t float32_to_uint64_round_to_zero(float32, float_status *status); |
2f6c74be | 385 | |
e5a41ffa PM |
386 | float64 float32_to_float64(float32, float_status *status); |
387 | floatx80 float32_to_floatx80(float32, float_status *status); | |
388 | float128 float32_to_float128(float32, float_status *status); | |
158142c2 FB |
389 | |
390 | /*---------------------------------------------------------------------------- | |
391 | | Software IEC/IEEE single-precision operations. | |
392 | *----------------------------------------------------------------------------*/ | |
e5a41ffa PM |
393 | float32 float32_round_to_int(float32, float_status *status); |
394 | float32 float32_add(float32, float32, float_status *status); | |
395 | float32 float32_sub(float32, float32, float_status *status); | |
396 | float32 float32_mul(float32, float32, float_status *status); | |
397 | float32 float32_div(float32, float32, float_status *status); | |
398 | float32 float32_rem(float32, float32, float_status *status); | |
399 | float32 float32_muladd(float32, float32, float32, int, float_status *status); | |
400 | float32 float32_sqrt(float32, float_status *status); | |
401 | float32 float32_exp2(float32, float_status *status); | |
402 | float32 float32_log2(float32, float_status *status); | |
403 | int float32_eq(float32, float32, float_status *status); | |
404 | int float32_le(float32, float32, float_status *status); | |
405 | int float32_lt(float32, float32, float_status *status); | |
406 | int float32_unordered(float32, float32, float_status *status); | |
407 | int float32_eq_quiet(float32, float32, float_status *status); | |
408 | int float32_le_quiet(float32, float32, float_status *status); | |
409 | int float32_lt_quiet(float32, float32, float_status *status); | |
410 | int float32_unordered_quiet(float32, float32, float_status *status); | |
411 | int float32_compare(float32, float32, float_status *status); | |
412 | int float32_compare_quiet(float32, float32, float_status *status); | |
413 | float32 float32_min(float32, float32, float_status *status); | |
414 | float32 float32_max(float32, float32, float_status *status); | |
415 | float32 float32_minnum(float32, float32, float_status *status); | |
416 | float32 float32_maxnum(float32, float32, float_status *status); | |
417 | float32 float32_minnummag(float32, float32, float_status *status); | |
418 | float32 float32_maxnummag(float32, float32, float_status *status); | |
af39bc8c AM |
419 | int float32_is_quiet_nan(float32, float_status *status); |
420 | int float32_is_signaling_nan(float32, float_status *status); | |
d619bb98 | 421 | float32 float32_silence_nan(float32, float_status *status); |
e5a41ffa | 422 | float32 float32_scalbn(float32, int, float_status *status); |
158142c2 | 423 | |
a49db98d | 424 | static 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 | 432 | static 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 | 440 | static inline int float32_is_infinity(float32 a) |
c52ab6f5 | 441 | { |
dadd71a7 | 442 | return (float32_val(a) & 0x7fffffff) == 0x7f800000; |
c52ab6f5 AJ |
443 | } |
444 | ||
a49db98d | 445 | static inline int float32_is_neg(float32 a) |
c52ab6f5 AJ |
446 | { |
447 | return float32_val(a) >> 31; | |
448 | } | |
449 | ||
a49db98d | 450 | static inline int float32_is_zero(float32 a) |
c52ab6f5 AJ |
451 | { |
452 | return (float32_val(a) & 0x7fffffff) == 0; | |
453 | } | |
454 | ||
a49db98d | 455 | static inline int float32_is_any_nan(float32 a) |
21d6ebde PM |
456 | { |
457 | return ((float32_val(a) & ~(1 << 31)) > 0x7f800000UL); | |
458 | } | |
459 | ||
a49db98d | 460 | static inline int float32_is_zero_or_denormal(float32 a) |
6f3300ad PM |
461 | { |
462 | return (float32_val(a) & 0x7f800000) == 0; | |
463 | } | |
464 | ||
588e6dfd EC |
465 | static inline bool float32_is_normal(float32 a) |
466 | { | |
47393181 | 467 | return (((float32_val(a) >> 23) + 1) & 0xff) >= 2; |
588e6dfd EC |
468 | } |
469 | ||
470 | static inline bool float32_is_denormal(float32 a) | |
471 | { | |
472 | return float32_is_zero_or_denormal(a) && !float32_is_zero(a); | |
473 | } | |
474 | ||
315df0d1 EC |
475 | static inline bool float32_is_zero_or_normal(float32 a) |
476 | { | |
477 | return float32_is_normal(a) || float32_is_zero(a); | |
478 | } | |
479 | ||
a49db98d | 480 | static 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 | ||
504 | static 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 | 513 | float32 float32_default_nan(float_status *status); |
8559666d | 514 | |
158142c2 FB |
515 | /*---------------------------------------------------------------------------- |
516 | | Software IEC/IEEE double-precision conversion routines. | |
517 | *----------------------------------------------------------------------------*/ | |
2f6c74be RH |
518 | |
519 | int16_t float64_to_int16_scalbn(float64, int, int, float_status *status); | |
520 | int32_t float64_to_int32_scalbn(float64, int, int, float_status *status); | |
521 | int64_t float64_to_int64_scalbn(float64, int, int, float_status *status); | |
522 | ||
0bb721d7 | 523 | int16_t float64_to_int16(float64, float_status *status); |
f4014512 | 524 | int32_t float64_to_int32(float64, float_status *status); |
2f6c74be RH |
525 | int64_t float64_to_int64(float64, float_status *status); |
526 | ||
527 | int16_t float64_to_int16_round_to_zero(float64, float_status *status); | |
f4014512 | 528 | int32_t float64_to_int32_round_to_zero(float64, float_status *status); |
2f6c74be RH |
529 | int64_t float64_to_int64_round_to_zero(float64, float_status *status); |
530 | ||
531 | uint16_t float64_to_uint16_scalbn(float64, int, int, float_status *status); | |
532 | uint32_t float64_to_uint32_scalbn(float64, int, int, float_status *status); | |
533 | uint64_t float64_to_uint64_scalbn(float64, int, int, float_status *status); | |
534 | ||
535 | uint16_t float64_to_uint16(float64, float_status *status); | |
3a87d009 | 536 | uint32_t float64_to_uint32(float64, float_status *status); |
2f6c74be RH |
537 | uint64_t float64_to_uint64(float64, float_status *status); |
538 | ||
539 | uint16_t float64_to_uint16_round_to_zero(float64, float_status *status); | |
3a87d009 | 540 | uint32_t float64_to_uint32_round_to_zero(float64, float_status *status); |
2f6c74be RH |
541 | uint64_t float64_to_uint64_round_to_zero(float64, float_status *status); |
542 | ||
e5a41ffa PM |
543 | float32 float64_to_float32(float64, float_status *status); |
544 | floatx80 float64_to_floatx80(float64, float_status *status); | |
545 | float128 float64_to_float128(float64, float_status *status); | |
158142c2 FB |
546 | |
547 | /*---------------------------------------------------------------------------- | |
548 | | Software IEC/IEEE double-precision operations. | |
549 | *----------------------------------------------------------------------------*/ | |
e5a41ffa | 550 | float64 float64_round_to_int(float64, float_status *status); |
e5a41ffa PM |
551 | float64 float64_add(float64, float64, float_status *status); |
552 | float64 float64_sub(float64, float64, float_status *status); | |
553 | float64 float64_mul(float64, float64, float_status *status); | |
554 | float64 float64_div(float64, float64, float_status *status); | |
555 | float64 float64_rem(float64, float64, float_status *status); | |
556 | float64 float64_muladd(float64, float64, float64, int, float_status *status); | |
557 | float64 float64_sqrt(float64, float_status *status); | |
558 | float64 float64_log2(float64, float_status *status); | |
559 | int float64_eq(float64, float64, float_status *status); | |
560 | int float64_le(float64, float64, float_status *status); | |
561 | int float64_lt(float64, float64, float_status *status); | |
562 | int float64_unordered(float64, float64, float_status *status); | |
563 | int float64_eq_quiet(float64, float64, float_status *status); | |
564 | int float64_le_quiet(float64, float64, float_status *status); | |
565 | int float64_lt_quiet(float64, float64, float_status *status); | |
566 | int float64_unordered_quiet(float64, float64, float_status *status); | |
567 | int float64_compare(float64, float64, float_status *status); | |
568 | int float64_compare_quiet(float64, float64, float_status *status); | |
569 | float64 float64_min(float64, float64, float_status *status); | |
570 | float64 float64_max(float64, float64, float_status *status); | |
571 | float64 float64_minnum(float64, float64, float_status *status); | |
572 | float64 float64_maxnum(float64, float64, float_status *status); | |
573 | float64 float64_minnummag(float64, float64, float_status *status); | |
574 | float64 float64_maxnummag(float64, float64, float_status *status); | |
af39bc8c AM |
575 | int float64_is_quiet_nan(float64 a, float_status *status); |
576 | int float64_is_signaling_nan(float64, float_status *status); | |
d619bb98 | 577 | float64 float64_silence_nan(float64, float_status *status); |
e5a41ffa | 578 | float64 float64_scalbn(float64, int, float_status *status); |
158142c2 | 579 | |
a49db98d | 580 | static 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 | 588 | static 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 | 596 | static inline int float64_is_infinity(float64 a) |
c52ab6f5 AJ |
597 | { |
598 | return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL; | |
599 | } | |
600 | ||
a49db98d | 601 | static inline int float64_is_neg(float64 a) |
c52ab6f5 AJ |
602 | { |
603 | return float64_val(a) >> 63; | |
604 | } | |
605 | ||
a49db98d | 606 | static inline int float64_is_zero(float64 a) |
c52ab6f5 AJ |
607 | { |
608 | return (float64_val(a) & 0x7fffffffffffffffLL) == 0; | |
609 | } | |
610 | ||
a49db98d | 611 | static inline int float64_is_any_nan(float64 a) |
21d6ebde PM |
612 | { |
613 | return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL); | |
614 | } | |
615 | ||
a49db98d | 616 | static inline int float64_is_zero_or_denormal(float64 a) |
587eabfa AJ |
617 | { |
618 | return (float64_val(a) & 0x7ff0000000000000LL) == 0; | |
619 | } | |
620 | ||
588e6dfd EC |
621 | static inline bool float64_is_normal(float64 a) |
622 | { | |
47393181 | 623 | return (((float64_val(a) >> 52) + 1) & 0x7ff) >= 2; |
588e6dfd EC |
624 | } |
625 | ||
626 | static inline bool float64_is_denormal(float64 a) | |
627 | { | |
628 | return float64_is_zero_or_denormal(a) && !float64_is_zero(a); | |
629 | } | |
630 | ||
315df0d1 EC |
631 | static inline bool float64_is_zero_or_normal(float64 a) |
632 | { | |
633 | return float64_is_normal(a) || float64_is_zero(a); | |
634 | } | |
635 | ||
a49db98d | 636 | static 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 | 654 | float64 float64_default_nan(float_status *status); |
8559666d | 655 | |
158142c2 FB |
656 | /*---------------------------------------------------------------------------- |
657 | | Software IEC/IEEE extended double-precision conversion routines. | |
658 | *----------------------------------------------------------------------------*/ | |
f4014512 PM |
659 | int32_t floatx80_to_int32(floatx80, float_status *status); |
660 | int32_t floatx80_to_int32_round_to_zero(floatx80, float_status *status); | |
f42c2224 PM |
661 | int64_t floatx80_to_int64(floatx80, float_status *status); |
662 | int64_t floatx80_to_int64_round_to_zero(floatx80, float_status *status); | |
e5a41ffa PM |
663 | float32 floatx80_to_float32(floatx80, float_status *status); |
664 | float64 floatx80_to_float64(floatx80, float_status *status); | |
665 | float128 floatx80_to_float128(floatx80, float_status *status); | |
158142c2 | 666 | |
0f605c88 LV |
667 | /*---------------------------------------------------------------------------- |
668 | | The pattern for an extended double-precision inf. | |
669 | *----------------------------------------------------------------------------*/ | |
670 | extern const floatx80 floatx80_infinity; | |
671 | ||
158142c2 FB |
672 | /*---------------------------------------------------------------------------- |
673 | | Software IEC/IEEE extended double-precision operations. | |
674 | *----------------------------------------------------------------------------*/ | |
0f721292 | 675 | floatx80 floatx80_round(floatx80 a, float_status *status); |
e5a41ffa PM |
676 | floatx80 floatx80_round_to_int(floatx80, float_status *status); |
677 | floatx80 floatx80_add(floatx80, floatx80, float_status *status); | |
678 | floatx80 floatx80_sub(floatx80, floatx80, float_status *status); | |
679 | floatx80 floatx80_mul(floatx80, floatx80, float_status *status); | |
680 | floatx80 floatx80_div(floatx80, floatx80, float_status *status); | |
681 | floatx80 floatx80_rem(floatx80, floatx80, float_status *status); | |
682 | floatx80 floatx80_sqrt(floatx80, float_status *status); | |
683 | int floatx80_eq(floatx80, floatx80, float_status *status); | |
684 | int floatx80_le(floatx80, floatx80, float_status *status); | |
685 | int floatx80_lt(floatx80, floatx80, float_status *status); | |
686 | int floatx80_unordered(floatx80, floatx80, float_status *status); | |
687 | int floatx80_eq_quiet(floatx80, floatx80, float_status *status); | |
688 | int floatx80_le_quiet(floatx80, floatx80, float_status *status); | |
689 | int floatx80_lt_quiet(floatx80, floatx80, float_status *status); | |
690 | int floatx80_unordered_quiet(floatx80, floatx80, float_status *status); | |
691 | int floatx80_compare(floatx80, floatx80, float_status *status); | |
692 | int floatx80_compare_quiet(floatx80, floatx80, float_status *status); | |
af39bc8c AM |
693 | int floatx80_is_quiet_nan(floatx80, float_status *status); |
694 | int floatx80_is_signaling_nan(floatx80, float_status *status); | |
d619bb98 | 695 | floatx80 floatx80_silence_nan(floatx80, float_status *status); |
e5a41ffa | 696 | floatx80 floatx80_scalbn(floatx80, int, float_status *status); |
158142c2 | 697 | |
a49db98d | 698 | static inline floatx80 floatx80_abs(floatx80 a) |
1d6bda35 FB |
699 | { |
700 | a.high &= 0x7fff; | |
701 | return a; | |
702 | } | |
703 | ||
a49db98d | 704 | static inline floatx80 floatx80_chs(floatx80 a) |
1d6bda35 FB |
705 | { |
706 | a.high ^= 0x8000; | |
707 | return a; | |
708 | } | |
709 | ||
a49db98d | 710 | static 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 | 720 | static inline int floatx80_is_neg(floatx80 a) |
c52ab6f5 AJ |
721 | { |
722 | return a.high >> 15; | |
723 | } | |
724 | ||
a49db98d | 725 | static inline int floatx80_is_zero(floatx80 a) |
c52ab6f5 AJ |
726 | { |
727 | return (a.high & 0x7fff) == 0 && a.low == 0; | |
728 | } | |
729 | ||
a49db98d | 730 | static inline int floatx80_is_zero_or_denormal(floatx80 a) |
587eabfa AJ |
731 | { |
732 | return (a.high & 0x7fff) == 0; | |
733 | } | |
734 | ||
a49db98d | 735 | static 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 | *----------------------------------------------------------------------------*/ | |
750 | static 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 | ||
766 | static 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 | ||
776 | static 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 | ||
786 | static 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 | ||
796 | static 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 | ||
812 | void 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 | ||
821 | floatx80 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 | ||
847 | floatx80 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 | ||
860 | floatx80 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 | 868 | floatx80 floatx80_default_nan(float_status *status); |
8559666d | 869 | |
158142c2 FB |
870 | /*---------------------------------------------------------------------------- |
871 | | Software IEC/IEEE quadruple-precision conversion routines. | |
872 | *----------------------------------------------------------------------------*/ | |
f4014512 PM |
873 | int32_t float128_to_int32(float128, float_status *status); |
874 | int32_t float128_to_int32_round_to_zero(float128, float_status *status); | |
f42c2224 PM |
875 | int64_t float128_to_int64(float128, float_status *status); |
876 | int64_t float128_to_int64_round_to_zero(float128, float_status *status); | |
2e6d8568 BR |
877 | uint64_t float128_to_uint64(float128, float_status *status); |
878 | uint64_t float128_to_uint64_round_to_zero(float128, float_status *status); | |
e45de992 | 879 | uint32_t float128_to_uint32(float128, float_status *status); |
fd425037 | 880 | uint32_t float128_to_uint32_round_to_zero(float128, float_status *status); |
e5a41ffa PM |
881 | float32 float128_to_float32(float128, float_status *status); |
882 | float64 float128_to_float64(float128, float_status *status); | |
883 | floatx80 float128_to_floatx80(float128, float_status *status); | |
158142c2 FB |
884 | |
885 | /*---------------------------------------------------------------------------- | |
886 | | Software IEC/IEEE quadruple-precision operations. | |
887 | *----------------------------------------------------------------------------*/ | |
e5a41ffa PM |
888 | float128 float128_round_to_int(float128, float_status *status); |
889 | float128 float128_add(float128, float128, float_status *status); | |
890 | float128 float128_sub(float128, float128, float_status *status); | |
891 | float128 float128_mul(float128, float128, float_status *status); | |
892 | float128 float128_div(float128, float128, float_status *status); | |
893 | float128 float128_rem(float128, float128, float_status *status); | |
894 | float128 float128_sqrt(float128, float_status *status); | |
895 | int float128_eq(float128, float128, float_status *status); | |
896 | int float128_le(float128, float128, float_status *status); | |
897 | int float128_lt(float128, float128, float_status *status); | |
898 | int float128_unordered(float128, float128, float_status *status); | |
899 | int float128_eq_quiet(float128, float128, float_status *status); | |
900 | int float128_le_quiet(float128, float128, float_status *status); | |
901 | int float128_lt_quiet(float128, float128, float_status *status); | |
902 | int float128_unordered_quiet(float128, float128, float_status *status); | |
903 | int float128_compare(float128, float128, float_status *status); | |
904 | int float128_compare_quiet(float128, float128, float_status *status); | |
af39bc8c AM |
905 | int float128_is_quiet_nan(float128, float_status *status); |
906 | int float128_is_signaling_nan(float128, float_status *status); | |
d619bb98 | 907 | float128 float128_silence_nan(float128, float_status *status); |
e5a41ffa | 908 | float128 float128_scalbn(float128, int, float_status *status); |
158142c2 | 909 | |
a49db98d | 910 | static inline float128 float128_abs(float128 a) |
1d6bda35 FB |
911 | { |
912 | a.high &= 0x7fffffffffffffffLL; | |
913 | return a; | |
914 | } | |
915 | ||
a49db98d | 916 | static inline float128 float128_chs(float128 a) |
1d6bda35 FB |
917 | { |
918 | a.high ^= 0x8000000000000000LL; | |
919 | return a; | |
920 | } | |
921 | ||
a49db98d | 922 | static inline int float128_is_infinity(float128 a) |
c52ab6f5 AJ |
923 | { |
924 | return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0; | |
925 | } | |
926 | ||
a49db98d | 927 | static inline int float128_is_neg(float128 a) |
c52ab6f5 AJ |
928 | { |
929 | return a.high >> 63; | |
930 | } | |
931 | ||
a49db98d | 932 | static inline int float128_is_zero(float128 a) |
c52ab6f5 AJ |
933 | { |
934 | return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0; | |
935 | } | |
936 | ||
a49db98d | 937 | static inline int float128_is_zero_or_denormal(float128 a) |
587eabfa AJ |
938 | { |
939 | return (a.high & 0x7fff000000000000LL) == 0; | |
940 | } | |
941 | ||
47393181 DH |
942 | static inline bool float128_is_normal(float128 a) |
943 | { | |
944 | return (((a.high >> 48) + 1) & 0x7fff) >= 2; | |
945 | } | |
946 | ||
947 | static inline bool float128_is_denormal(float128 a) | |
948 | { | |
949 | return float128_is_zero_or_denormal(a) && !float128_is_zero(a); | |
950 | } | |
951 | ||
a49db98d | 952 | static 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 | 963 | float128 float128_default_nan(float_status *status); |
8559666d | 964 | |
175de524 | 965 | #endif /* SOFTFLOAT_H */ |