]>
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 | ||
158142c2 | 85 | #define LIT64( a ) a##LL |
158142c2 | 86 | |
1d6bda35 FB |
87 | /*---------------------------------------------------------------------------- |
88 | | Software IEC/IEEE floating-point ordering relations | |
89 | *----------------------------------------------------------------------------*/ | |
90 | enum { | |
91 | float_relation_less = -1, | |
92 | float_relation_equal = 0, | |
93 | float_relation_greater = 1, | |
94 | float_relation_unordered = 2 | |
95 | }; | |
96 | ||
cfd88fc6 | 97 | #include "fpu/softfloat-types.h" |
158142c2 | 98 | |
e5a41ffa | 99 | static inline void set_float_detect_tininess(int val, float_status *status) |
c29aca44 | 100 | { |
a2f2d288 | 101 | status->float_detect_tininess = val; |
c29aca44 | 102 | } |
e5a41ffa | 103 | static inline void set_float_rounding_mode(int val, float_status *status) |
879d096b | 104 | { |
a2f2d288 | 105 | status->float_rounding_mode = val; |
879d096b | 106 | } |
e5a41ffa | 107 | static inline void set_float_exception_flags(int val, float_status *status) |
879d096b | 108 | { |
a2f2d288 | 109 | status->float_exception_flags = val; |
879d096b | 110 | } |
e5a41ffa PM |
111 | static inline void set_floatx80_rounding_precision(int val, |
112 | float_status *status) | |
879d096b | 113 | { |
a2f2d288 | 114 | status->floatx80_rounding_precision = val; |
879d096b | 115 | } |
e5a41ffa | 116 | static inline void set_flush_to_zero(flag val, float_status *status) |
fe76d976 | 117 | { |
a2f2d288 | 118 | status->flush_to_zero = val; |
fe76d976 | 119 | } |
e5a41ffa | 120 | static inline void set_flush_inputs_to_zero(flag val, float_status *status) |
37d18660 | 121 | { |
a2f2d288 | 122 | status->flush_inputs_to_zero = val; |
37d18660 | 123 | } |
e5a41ffa | 124 | static inline void set_default_nan_mode(flag val, float_status *status) |
5c7908ed | 125 | { |
a2f2d288 | 126 | status->default_nan_mode = val; |
5c7908ed | 127 | } |
af39bc8c AM |
128 | static inline void set_snan_bit_is_one(flag val, float_status *status) |
129 | { | |
130 | status->snan_bit_is_one = val; | |
131 | } | |
a49db98d | 132 | static inline int get_float_detect_tininess(float_status *status) |
879d096b | 133 | { |
a2f2d288 | 134 | return status->float_detect_tininess; |
879d096b | 135 | } |
a49db98d | 136 | static inline int get_float_rounding_mode(float_status *status) |
879d096b | 137 | { |
a2f2d288 | 138 | return status->float_rounding_mode; |
879d096b | 139 | } |
a49db98d | 140 | static inline int get_float_exception_flags(float_status *status) |
1d6bda35 | 141 | { |
a2f2d288 | 142 | return status->float_exception_flags; |
1d6bda35 | 143 | } |
a49db98d | 144 | static inline int get_floatx80_rounding_precision(float_status *status) |
879d096b | 145 | { |
a2f2d288 | 146 | return status->floatx80_rounding_precision; |
879d096b | 147 | } |
a49db98d | 148 | static inline flag get_flush_to_zero(float_status *status) |
879d096b | 149 | { |
a2f2d288 | 150 | return status->flush_to_zero; |
879d096b | 151 | } |
a49db98d | 152 | static inline flag get_flush_inputs_to_zero(float_status *status) |
879d096b | 153 | { |
a2f2d288 | 154 | return status->flush_inputs_to_zero; |
879d096b | 155 | } |
a49db98d | 156 | static inline flag get_default_nan_mode(float_status *status) |
879d096b | 157 | { |
a2f2d288 | 158 | return status->default_nan_mode; |
879d096b | 159 | } |
158142c2 FB |
160 | |
161 | /*---------------------------------------------------------------------------- | |
162 | | Routine to raise any or all of the software IEC/IEEE floating-point | |
163 | | exception flags. | |
164 | *----------------------------------------------------------------------------*/ | |
dfd60767 | 165 | void float_raise(uint8_t flags, float_status *status); |
158142c2 | 166 | |
7baeabce AB |
167 | /*---------------------------------------------------------------------------- |
168 | | If `a' is denormal and we are in flush-to-zero mode then set the | |
169 | | input-denormal exception and return zero. Otherwise just return the value. | |
170 | *----------------------------------------------------------------------------*/ | |
210cbd49 | 171 | float16 float16_squash_input_denormal(float16 a, float_status *status); |
e5a41ffa PM |
172 | float32 float32_squash_input_denormal(float32 a, float_status *status); |
173 | float64 float64_squash_input_denormal(float64 a, float_status *status); | |
7baeabce | 174 | |
369be8f6 PM |
175 | /*---------------------------------------------------------------------------- |
176 | | Options to indicate which negations to perform in float*_muladd() | |
177 | | Using these differs from negating an input or output before calling | |
178 | | the muladd function in that this means that a NaN doesn't have its | |
179 | | sign bit inverted before it is propagated. | |
67d43538 PM |
180 | | We also support halving the result before rounding, as a special |
181 | | case to support the ARM fused-sqrt-step instruction FRSQRTS. | |
369be8f6 PM |
182 | *----------------------------------------------------------------------------*/ |
183 | enum { | |
184 | float_muladd_negate_c = 1, | |
185 | float_muladd_negate_product = 2, | |
66176802 | 186 | float_muladd_negate_result = 4, |
67d43538 | 187 | float_muladd_halve_result = 8, |
369be8f6 PM |
188 | }; |
189 | ||
158142c2 FB |
190 | /*---------------------------------------------------------------------------- |
191 | | Software IEC/IEEE integer-to-floating-point conversion routines. | |
192 | *----------------------------------------------------------------------------*/ | |
c02e1fb8 | 193 | float32 int16_to_float32(int16_t, float_status *status); |
e5a41ffa | 194 | float32 int32_to_float32(int32_t, float_status *status); |
c02e1fb8 | 195 | float64 int16_to_float64(int16_t, float_status *status); |
e5a41ffa | 196 | float64 int32_to_float64(int32_t, float_status *status); |
c02e1fb8 | 197 | float32 uint16_to_float32(uint16_t, float_status *status); |
e5a41ffa | 198 | float32 uint32_to_float32(uint32_t, float_status *status); |
c02e1fb8 | 199 | float64 uint16_to_float64(uint16_t, float_status *status); |
e5a41ffa PM |
200 | float64 uint32_to_float64(uint32_t, float_status *status); |
201 | floatx80 int32_to_floatx80(int32_t, float_status *status); | |
202 | float128 int32_to_float128(int32_t, float_status *status); | |
203 | float32 int64_to_float32(int64_t, float_status *status); | |
204 | float64 int64_to_float64(int64_t, float_status *status); | |
205 | floatx80 int64_to_floatx80(int64_t, float_status *status); | |
206 | float128 int64_to_float128(int64_t, float_status *status); | |
207 | float32 uint64_to_float32(uint64_t, float_status *status); | |
208 | float64 uint64_to_float64(uint64_t, float_status *status); | |
209 | float128 uint64_to_float128(uint64_t, float_status *status); | |
158142c2 | 210 | |
60011498 PB |
211 | /*---------------------------------------------------------------------------- |
212 | | Software half-precision conversion routines. | |
213 | *----------------------------------------------------------------------------*/ | |
e5a41ffa PM |
214 | float16 float32_to_float16(float32, flag, float_status *status); |
215 | float32 float16_to_float32(float16, flag, float_status *status); | |
216 | float16 float64_to_float16(float64 a, flag ieee, float_status *status); | |
217 | float64 float16_to_float64(float16 a, flag ieee, float_status *status); | |
ab52f973 AB |
218 | int16_t float16_to_int16(float16, float_status *status); |
219 | uint16_t float16_to_uint16(float16 a, float_status *status); | |
220 | int16_t float16_to_int16_round_to_zero(float16, float_status *status); | |
221 | uint16_t float16_to_uint16_round_to_zero(float16 a, float_status *status); | |
222 | int32_t float16_to_int32(float16, float_status *status); | |
223 | uint32_t float16_to_uint32(float16 a, float_status *status); | |
224 | int32_t float16_to_int32_round_to_zero(float16, float_status *status); | |
225 | uint32_t float16_to_uint32_round_to_zero(float16 a, float_status *status); | |
226 | int64_t float16_to_int64(float16, float_status *status); | |
227 | uint64_t float16_to_uint64(float16 a, float_status *status); | |
228 | int64_t float16_to_int64_round_to_zero(float16, float_status *status); | |
229 | uint64_t float16_to_uint64_round_to_zero(float16 a, float_status *status); | |
230 | float16 int16_to_float16(int16_t a, float_status *status); | |
c02e1fb8 AB |
231 | float16 int32_to_float16(int32_t a, float_status *status); |
232 | float16 int64_to_float16(int64_t a, float_status *status); | |
233 | float16 uint16_to_float16(uint16_t a, float_status *status); | |
234 | float16 uint32_to_float16(uint32_t a, float_status *status); | |
235 | float16 uint64_to_float16(uint64_t a, float_status *status); | |
bb4d4bb3 PM |
236 | |
237 | /*---------------------------------------------------------------------------- | |
238 | | Software half-precision operations. | |
239 | *----------------------------------------------------------------------------*/ | |
6fff2167 | 240 | |
dbe4d53a | 241 | float16 float16_round_to_int(float16, float_status *status); |
6fff2167 AB |
242 | float16 float16_add(float16, float16, float_status *status); |
243 | float16 float16_sub(float16, float16, float_status *status); | |
74d707e2 | 244 | float16 float16_mul(float16, float16, float_status *status); |
d446830a | 245 | float16 float16_muladd(float16, float16, float16, int, float_status *status); |
cf07323d | 246 | float16 float16_div(float16, float16, float_status *status); |
0bfc9f19 | 247 | float16 float16_scalbn(float16, int, float_status *status); |
89360067 AB |
248 | float16 float16_min(float16, float16, float_status *status); |
249 | float16 float16_max(float16, float16, float_status *status); | |
250 | float16 float16_minnum(float16, float16, float_status *status); | |
251 | float16 float16_maxnum(float16, float16, float_status *status); | |
252 | float16 float16_minnummag(float16, float16, float_status *status); | |
253 | float16 float16_maxnummag(float16, float16, float_status *status); | |
c13bb2da | 254 | float16 float16_sqrt(float16, float_status *status); |
0c4c9092 AB |
255 | int float16_compare(float16, float16, float_status *status); |
256 | int float16_compare_quiet(float16, float16, float_status *status); | |
6fff2167 | 257 | |
af39bc8c AM |
258 | int float16_is_quiet_nan(float16, float_status *status); |
259 | int float16_is_signaling_nan(float16, float_status *status); | |
260 | float16 float16_maybe_silence_nan(float16, float_status *status); | |
60011498 | 261 | |
a49db98d | 262 | static inline int float16_is_any_nan(float16 a) |
213ff4e6 MF |
263 | { |
264 | return ((float16_val(a) & ~0x8000) > 0x7c00); | |
265 | } | |
266 | ||
f566c047 BR |
267 | static inline int float16_is_neg(float16 a) |
268 | { | |
269 | return float16_val(a) >> 15; | |
270 | } | |
271 | ||
272 | static inline int float16_is_infinity(float16 a) | |
273 | { | |
274 | return (float16_val(a) & 0x7fff) == 0x7c00; | |
275 | } | |
276 | ||
277 | static inline int float16_is_zero(float16 a) | |
278 | { | |
279 | return (float16_val(a) & 0x7fff) == 0; | |
280 | } | |
281 | ||
282 | static inline int float16_is_zero_or_denormal(float16 a) | |
283 | { | |
284 | return (float16_val(a) & 0x7c00) == 0; | |
285 | } | |
286 | ||
28136775 AB |
287 | static inline float16 float16_abs(float16 a) |
288 | { | |
289 | /* Note that abs does *not* handle NaN specially, nor does | |
290 | * it flush denormal inputs to zero. | |
291 | */ | |
292 | return make_float16(float16_val(a) & 0x7fff); | |
293 | } | |
5f10aef5 AB |
294 | |
295 | static inline float16 float16_chs(float16 a) | |
296 | { | |
297 | /* Note that chs does *not* handle NaN specially, nor does | |
298 | * it flush denormal inputs to zero. | |
299 | */ | |
300 | return make_float16(float16_val(a) ^ 0x8000); | |
301 | } | |
302 | ||
78b5a3e6 AB |
303 | static inline float16 float16_set_sign(float16 a, int sign) |
304 | { | |
305 | return make_float16((float16_val(a) & 0x7fff) | (sign << 15)); | |
306 | } | |
307 | ||
efd4829e | 308 | #define float16_zero make_float16(0) |
efd4829e | 309 | #define float16_half make_float16(0x3800) |
026e2d6e AB |
310 | #define float16_one make_float16(0x3c00) |
311 | #define float16_one_point_five make_float16(0x3e00) | |
312 | #define float16_two make_float16(0x4000) | |
313 | #define float16_three make_float16(0x4200) | |
efd4829e AB |
314 | #define float16_infinity make_float16(0x7c00) |
315 | ||
8559666d CL |
316 | /*---------------------------------------------------------------------------- |
317 | | The pattern for a default generated half-precision NaN. | |
318 | *----------------------------------------------------------------------------*/ | |
af39bc8c | 319 | float16 float16_default_nan(float_status *status); |
8559666d | 320 | |
158142c2 FB |
321 | /*---------------------------------------------------------------------------- |
322 | | Software IEC/IEEE single-precision conversion routines. | |
323 | *----------------------------------------------------------------------------*/ | |
0bb721d7 PM |
324 | int16_t float32_to_int16(float32, float_status *status); |
325 | uint16_t float32_to_uint16(float32, float_status *status); | |
326 | int16_t float32_to_int16_round_to_zero(float32, float_status *status); | |
327 | uint16_t float32_to_uint16_round_to_zero(float32, float_status *status); | |
f4014512 PM |
328 | int32_t float32_to_int32(float32, float_status *status); |
329 | int32_t float32_to_int32_round_to_zero(float32, float_status *status); | |
3a87d009 PM |
330 | uint32_t float32_to_uint32(float32, float_status *status); |
331 | uint32_t float32_to_uint32_round_to_zero(float32, float_status *status); | |
f42c2224 | 332 | int64_t float32_to_int64(float32, float_status *status); |
182f42fd PM |
333 | uint64_t float32_to_uint64(float32, float_status *status); |
334 | uint64_t float32_to_uint64_round_to_zero(float32, float_status *status); | |
f42c2224 | 335 | int64_t float32_to_int64_round_to_zero(float32, float_status *status); |
e5a41ffa PM |
336 | float64 float32_to_float64(float32, float_status *status); |
337 | floatx80 float32_to_floatx80(float32, float_status *status); | |
338 | float128 float32_to_float128(float32, float_status *status); | |
158142c2 FB |
339 | |
340 | /*---------------------------------------------------------------------------- | |
341 | | Software IEC/IEEE single-precision operations. | |
342 | *----------------------------------------------------------------------------*/ | |
e5a41ffa PM |
343 | float32 float32_round_to_int(float32, float_status *status); |
344 | float32 float32_add(float32, float32, float_status *status); | |
345 | float32 float32_sub(float32, float32, float_status *status); | |
346 | float32 float32_mul(float32, float32, float_status *status); | |
347 | float32 float32_div(float32, float32, float_status *status); | |
348 | float32 float32_rem(float32, float32, float_status *status); | |
349 | float32 float32_muladd(float32, float32, float32, int, float_status *status); | |
350 | float32 float32_sqrt(float32, float_status *status); | |
351 | float32 float32_exp2(float32, float_status *status); | |
352 | float32 float32_log2(float32, float_status *status); | |
353 | int float32_eq(float32, float32, float_status *status); | |
354 | int float32_le(float32, float32, float_status *status); | |
355 | int float32_lt(float32, float32, float_status *status); | |
356 | int float32_unordered(float32, float32, float_status *status); | |
357 | int float32_eq_quiet(float32, float32, float_status *status); | |
358 | int float32_le_quiet(float32, float32, float_status *status); | |
359 | int float32_lt_quiet(float32, float32, float_status *status); | |
360 | int float32_unordered_quiet(float32, float32, float_status *status); | |
361 | int float32_compare(float32, float32, float_status *status); | |
362 | int float32_compare_quiet(float32, float32, float_status *status); | |
363 | float32 float32_min(float32, float32, float_status *status); | |
364 | float32 float32_max(float32, float32, float_status *status); | |
365 | float32 float32_minnum(float32, float32, float_status *status); | |
366 | float32 float32_maxnum(float32, float32, float_status *status); | |
367 | float32 float32_minnummag(float32, float32, float_status *status); | |
368 | float32 float32_maxnummag(float32, float32, float_status *status); | |
af39bc8c AM |
369 | int float32_is_quiet_nan(float32, float_status *status); |
370 | int float32_is_signaling_nan(float32, float_status *status); | |
371 | float32 float32_maybe_silence_nan(float32, float_status *status); | |
e5a41ffa | 372 | float32 float32_scalbn(float32, int, float_status *status); |
158142c2 | 373 | |
a49db98d | 374 | static inline float32 float32_abs(float32 a) |
1d6bda35 | 375 | { |
37d18660 PM |
376 | /* Note that abs does *not* handle NaN specially, nor does |
377 | * it flush denormal inputs to zero. | |
378 | */ | |
f090c9d4 | 379 | return make_float32(float32_val(a) & 0x7fffffff); |
1d6bda35 FB |
380 | } |
381 | ||
a49db98d | 382 | static inline float32 float32_chs(float32 a) |
1d6bda35 | 383 | { |
37d18660 PM |
384 | /* Note that chs does *not* handle NaN specially, nor does |
385 | * it flush denormal inputs to zero. | |
386 | */ | |
f090c9d4 | 387 | return make_float32(float32_val(a) ^ 0x80000000); |
1d6bda35 FB |
388 | } |
389 | ||
a49db98d | 390 | static inline int float32_is_infinity(float32 a) |
c52ab6f5 | 391 | { |
dadd71a7 | 392 | return (float32_val(a) & 0x7fffffff) == 0x7f800000; |
c52ab6f5 AJ |
393 | } |
394 | ||
a49db98d | 395 | static inline int float32_is_neg(float32 a) |
c52ab6f5 AJ |
396 | { |
397 | return float32_val(a) >> 31; | |
398 | } | |
399 | ||
a49db98d | 400 | static inline int float32_is_zero(float32 a) |
c52ab6f5 AJ |
401 | { |
402 | return (float32_val(a) & 0x7fffffff) == 0; | |
403 | } | |
404 | ||
a49db98d | 405 | static inline int float32_is_any_nan(float32 a) |
21d6ebde PM |
406 | { |
407 | return ((float32_val(a) & ~(1 << 31)) > 0x7f800000UL); | |
408 | } | |
409 | ||
a49db98d | 410 | static inline int float32_is_zero_or_denormal(float32 a) |
6f3300ad PM |
411 | { |
412 | return (float32_val(a) & 0x7f800000) == 0; | |
413 | } | |
414 | ||
a49db98d | 415 | static inline float32 float32_set_sign(float32 a, int sign) |
c30fe7df CL |
416 | { |
417 | return make_float32((float32_val(a) & 0x7fffffff) | (sign << 31)); | |
418 | } | |
419 | ||
f090c9d4 | 420 | #define float32_zero make_float32(0) |
c30fe7df | 421 | #define float32_half make_float32(0x3f000000) |
026e2d6e AB |
422 | #define float32_one make_float32(0x3f800000) |
423 | #define float32_one_point_five make_float32(0x3fc00000) | |
424 | #define float32_two make_float32(0x40000000) | |
425 | #define float32_three make_float32(0x40400000) | |
c30fe7df | 426 | #define float32_infinity make_float32(0x7f800000) |
f090c9d4 | 427 | |
8559666d CL |
428 | /*---------------------------------------------------------------------------- |
429 | | The pattern for a default generated single-precision NaN. | |
430 | *----------------------------------------------------------------------------*/ | |
af39bc8c | 431 | float32 float32_default_nan(float_status *status); |
8559666d | 432 | |
158142c2 FB |
433 | /*---------------------------------------------------------------------------- |
434 | | Software IEC/IEEE double-precision conversion routines. | |
435 | *----------------------------------------------------------------------------*/ | |
0bb721d7 PM |
436 | int16_t float64_to_int16(float64, float_status *status); |
437 | uint16_t float64_to_uint16(float64, float_status *status); | |
438 | int16_t float64_to_int16_round_to_zero(float64, float_status *status); | |
439 | uint16_t float64_to_uint16_round_to_zero(float64, float_status *status); | |
f4014512 PM |
440 | int32_t float64_to_int32(float64, float_status *status); |
441 | int32_t float64_to_int32_round_to_zero(float64, float_status *status); | |
3a87d009 PM |
442 | uint32_t float64_to_uint32(float64, float_status *status); |
443 | uint32_t float64_to_uint32_round_to_zero(float64, float_status *status); | |
f42c2224 PM |
444 | int64_t float64_to_int64(float64, float_status *status); |
445 | int64_t float64_to_int64_round_to_zero(float64, float_status *status); | |
182f42fd PM |
446 | uint64_t float64_to_uint64(float64 a, float_status *status); |
447 | uint64_t float64_to_uint64_round_to_zero(float64 a, float_status *status); | |
e5a41ffa PM |
448 | float32 float64_to_float32(float64, float_status *status); |
449 | floatx80 float64_to_floatx80(float64, float_status *status); | |
450 | float128 float64_to_float128(float64, float_status *status); | |
158142c2 FB |
451 | |
452 | /*---------------------------------------------------------------------------- | |
453 | | Software IEC/IEEE double-precision operations. | |
454 | *----------------------------------------------------------------------------*/ | |
e5a41ffa PM |
455 | float64 float64_round_to_int(float64, float_status *status); |
456 | float64 float64_trunc_to_int(float64, float_status *status); | |
457 | float64 float64_add(float64, float64, float_status *status); | |
458 | float64 float64_sub(float64, float64, float_status *status); | |
459 | float64 float64_mul(float64, float64, float_status *status); | |
460 | float64 float64_div(float64, float64, float_status *status); | |
461 | float64 float64_rem(float64, float64, float_status *status); | |
462 | float64 float64_muladd(float64, float64, float64, int, float_status *status); | |
463 | float64 float64_sqrt(float64, float_status *status); | |
464 | float64 float64_log2(float64, float_status *status); | |
465 | int float64_eq(float64, float64, float_status *status); | |
466 | int float64_le(float64, float64, float_status *status); | |
467 | int float64_lt(float64, float64, float_status *status); | |
468 | int float64_unordered(float64, float64, float_status *status); | |
469 | int float64_eq_quiet(float64, float64, float_status *status); | |
470 | int float64_le_quiet(float64, float64, float_status *status); | |
471 | int float64_lt_quiet(float64, float64, float_status *status); | |
472 | int float64_unordered_quiet(float64, float64, float_status *status); | |
473 | int float64_compare(float64, float64, float_status *status); | |
474 | int float64_compare_quiet(float64, float64, float_status *status); | |
475 | float64 float64_min(float64, float64, float_status *status); | |
476 | float64 float64_max(float64, float64, float_status *status); | |
477 | float64 float64_minnum(float64, float64, float_status *status); | |
478 | float64 float64_maxnum(float64, float64, float_status *status); | |
479 | float64 float64_minnummag(float64, float64, float_status *status); | |
480 | float64 float64_maxnummag(float64, float64, float_status *status); | |
af39bc8c AM |
481 | int float64_is_quiet_nan(float64 a, float_status *status); |
482 | int float64_is_signaling_nan(float64, float_status *status); | |
483 | float64 float64_maybe_silence_nan(float64, float_status *status); | |
e5a41ffa | 484 | float64 float64_scalbn(float64, int, float_status *status); |
158142c2 | 485 | |
a49db98d | 486 | static inline float64 float64_abs(float64 a) |
1d6bda35 | 487 | { |
37d18660 PM |
488 | /* Note that abs does *not* handle NaN specially, nor does |
489 | * it flush denormal inputs to zero. | |
490 | */ | |
f090c9d4 | 491 | return make_float64(float64_val(a) & 0x7fffffffffffffffLL); |
1d6bda35 FB |
492 | } |
493 | ||
a49db98d | 494 | static inline float64 float64_chs(float64 a) |
1d6bda35 | 495 | { |
37d18660 PM |
496 | /* Note that chs does *not* handle NaN specially, nor does |
497 | * it flush denormal inputs to zero. | |
498 | */ | |
f090c9d4 | 499 | return make_float64(float64_val(a) ^ 0x8000000000000000LL); |
1d6bda35 FB |
500 | } |
501 | ||
a49db98d | 502 | static inline int float64_is_infinity(float64 a) |
c52ab6f5 AJ |
503 | { |
504 | return (float64_val(a) & 0x7fffffffffffffffLL ) == 0x7ff0000000000000LL; | |
505 | } | |
506 | ||
a49db98d | 507 | static inline int float64_is_neg(float64 a) |
c52ab6f5 AJ |
508 | { |
509 | return float64_val(a) >> 63; | |
510 | } | |
511 | ||
a49db98d | 512 | static inline int float64_is_zero(float64 a) |
c52ab6f5 AJ |
513 | { |
514 | return (float64_val(a) & 0x7fffffffffffffffLL) == 0; | |
515 | } | |
516 | ||
a49db98d | 517 | static inline int float64_is_any_nan(float64 a) |
21d6ebde PM |
518 | { |
519 | return ((float64_val(a) & ~(1ULL << 63)) > 0x7ff0000000000000ULL); | |
520 | } | |
521 | ||
a49db98d | 522 | static inline int float64_is_zero_or_denormal(float64 a) |
587eabfa AJ |
523 | { |
524 | return (float64_val(a) & 0x7ff0000000000000LL) == 0; | |
525 | } | |
526 | ||
a49db98d | 527 | static inline float64 float64_set_sign(float64 a, int sign) |
c30fe7df CL |
528 | { |
529 | return make_float64((float64_val(a) & 0x7fffffffffffffffULL) | |
530 | | ((int64_t)sign << 63)); | |
531 | } | |
532 | ||
f090c9d4 | 533 | #define float64_zero make_float64(0) |
026e2d6e | 534 | #define float64_half make_float64(0x3fe0000000000000LL) |
196cfc89 | 535 | #define float64_one make_float64(0x3ff0000000000000LL) |
026e2d6e AB |
536 | #define float64_one_point_five make_float64(0x3FF8000000000000ULL) |
537 | #define float64_two make_float64(0x4000000000000000ULL) | |
538 | #define float64_three make_float64(0x4008000000000000ULL) | |
8229c991 | 539 | #define float64_ln2 make_float64(0x3fe62e42fefa39efLL) |
c30fe7df | 540 | #define float64_infinity make_float64(0x7ff0000000000000LL) |
f090c9d4 | 541 | |
8559666d CL |
542 | /*---------------------------------------------------------------------------- |
543 | | The pattern for a default generated double-precision NaN. | |
544 | *----------------------------------------------------------------------------*/ | |
af39bc8c | 545 | float64 float64_default_nan(float_status *status); |
8559666d | 546 | |
158142c2 FB |
547 | /*---------------------------------------------------------------------------- |
548 | | Software IEC/IEEE extended double-precision conversion routines. | |
549 | *----------------------------------------------------------------------------*/ | |
f4014512 PM |
550 | int32_t floatx80_to_int32(floatx80, float_status *status); |
551 | int32_t floatx80_to_int32_round_to_zero(floatx80, float_status *status); | |
f42c2224 PM |
552 | int64_t floatx80_to_int64(floatx80, float_status *status); |
553 | int64_t floatx80_to_int64_round_to_zero(floatx80, float_status *status); | |
e5a41ffa PM |
554 | float32 floatx80_to_float32(floatx80, float_status *status); |
555 | float64 floatx80_to_float64(floatx80, float_status *status); | |
556 | float128 floatx80_to_float128(floatx80, float_status *status); | |
158142c2 FB |
557 | |
558 | /*---------------------------------------------------------------------------- | |
559 | | Software IEC/IEEE extended double-precision operations. | |
560 | *----------------------------------------------------------------------------*/ | |
0f721292 | 561 | floatx80 floatx80_round(floatx80 a, float_status *status); |
e5a41ffa PM |
562 | floatx80 floatx80_round_to_int(floatx80, float_status *status); |
563 | floatx80 floatx80_add(floatx80, floatx80, float_status *status); | |
564 | floatx80 floatx80_sub(floatx80, floatx80, float_status *status); | |
565 | floatx80 floatx80_mul(floatx80, floatx80, float_status *status); | |
566 | floatx80 floatx80_div(floatx80, floatx80, float_status *status); | |
567 | floatx80 floatx80_rem(floatx80, floatx80, float_status *status); | |
568 | floatx80 floatx80_sqrt(floatx80, float_status *status); | |
569 | int floatx80_eq(floatx80, floatx80, float_status *status); | |
570 | int floatx80_le(floatx80, floatx80, float_status *status); | |
571 | int floatx80_lt(floatx80, floatx80, float_status *status); | |
572 | int floatx80_unordered(floatx80, floatx80, float_status *status); | |
573 | int floatx80_eq_quiet(floatx80, floatx80, float_status *status); | |
574 | int floatx80_le_quiet(floatx80, floatx80, float_status *status); | |
575 | int floatx80_lt_quiet(floatx80, floatx80, float_status *status); | |
576 | int floatx80_unordered_quiet(floatx80, floatx80, float_status *status); | |
577 | int floatx80_compare(floatx80, floatx80, float_status *status); | |
578 | int floatx80_compare_quiet(floatx80, floatx80, float_status *status); | |
af39bc8c AM |
579 | int floatx80_is_quiet_nan(floatx80, float_status *status); |
580 | int floatx80_is_signaling_nan(floatx80, float_status *status); | |
581 | floatx80 floatx80_maybe_silence_nan(floatx80, float_status *status); | |
e5a41ffa | 582 | floatx80 floatx80_scalbn(floatx80, int, float_status *status); |
158142c2 | 583 | |
a49db98d | 584 | static inline floatx80 floatx80_abs(floatx80 a) |
1d6bda35 FB |
585 | { |
586 | a.high &= 0x7fff; | |
587 | return a; | |
588 | } | |
589 | ||
a49db98d | 590 | static inline floatx80 floatx80_chs(floatx80 a) |
1d6bda35 FB |
591 | { |
592 | a.high ^= 0x8000; | |
593 | return a; | |
594 | } | |
595 | ||
a49db98d | 596 | static inline int floatx80_is_infinity(floatx80 a) |
c52ab6f5 | 597 | { |
b76235e4 | 598 | return (a.high & 0x7fff) == 0x7fff && a.low == 0x8000000000000000LL; |
c52ab6f5 AJ |
599 | } |
600 | ||
a49db98d | 601 | static inline int floatx80_is_neg(floatx80 a) |
c52ab6f5 AJ |
602 | { |
603 | return a.high >> 15; | |
604 | } | |
605 | ||
a49db98d | 606 | static inline int floatx80_is_zero(floatx80 a) |
c52ab6f5 AJ |
607 | { |
608 | return (a.high & 0x7fff) == 0 && a.low == 0; | |
609 | } | |
610 | ||
a49db98d | 611 | static inline int floatx80_is_zero_or_denormal(floatx80 a) |
587eabfa AJ |
612 | { |
613 | return (a.high & 0x7fff) == 0; | |
614 | } | |
615 | ||
a49db98d | 616 | static inline int floatx80_is_any_nan(floatx80 a) |
2bed652f PM |
617 | { |
618 | return ((a.high & 0x7fff) == 0x7fff) && (a.low<<1); | |
619 | } | |
620 | ||
d1eb8f2a AD |
621 | /*---------------------------------------------------------------------------- |
622 | | Return whether the given value is an invalid floatx80 encoding. | |
623 | | Invalid floatx80 encodings arise when the integer bit is not set, but | |
624 | | the exponent is not zero. The only times the integer bit is permitted to | |
625 | | be zero is in subnormal numbers and the value zero. | |
626 | | This includes what the Intel software developer's manual calls pseudo-NaNs, | |
627 | | pseudo-infinities and un-normal numbers. It does not include | |
628 | | pseudo-denormals, which must still be correctly handled as inputs even | |
629 | | if they are never generated as outputs. | |
630 | *----------------------------------------------------------------------------*/ | |
631 | static inline bool floatx80_invalid_encoding(floatx80 a) | |
632 | { | |
633 | return (a.low & (1ULL << 63)) == 0 && (a.high & 0x7FFF) != 0; | |
634 | } | |
635 | ||
f3218a8d AJ |
636 | #define floatx80_zero make_floatx80(0x0000, 0x0000000000000000LL) |
637 | #define floatx80_one make_floatx80(0x3fff, 0x8000000000000000LL) | |
638 | #define floatx80_ln2 make_floatx80(0x3ffe, 0xb17217f7d1cf79acLL) | |
c4b4c77a | 639 | #define floatx80_pi make_floatx80(0x4000, 0xc90fdaa22168c235LL) |
f3218a8d AJ |
640 | #define floatx80_half make_floatx80(0x3ffe, 0x8000000000000000LL) |
641 | #define floatx80_infinity make_floatx80(0x7fff, 0x8000000000000000LL) | |
642 | ||
8559666d | 643 | /*---------------------------------------------------------------------------- |
789ec7ce | 644 | | The pattern for a default generated extended double-precision NaN. |
8559666d | 645 | *----------------------------------------------------------------------------*/ |
af39bc8c | 646 | floatx80 floatx80_default_nan(float_status *status); |
8559666d | 647 | |
158142c2 FB |
648 | /*---------------------------------------------------------------------------- |
649 | | Software IEC/IEEE quadruple-precision conversion routines. | |
650 | *----------------------------------------------------------------------------*/ | |
f4014512 PM |
651 | int32_t float128_to_int32(float128, float_status *status); |
652 | int32_t float128_to_int32_round_to_zero(float128, float_status *status); | |
f42c2224 PM |
653 | int64_t float128_to_int64(float128, float_status *status); |
654 | int64_t float128_to_int64_round_to_zero(float128, float_status *status); | |
2e6d8568 BR |
655 | uint64_t float128_to_uint64(float128, float_status *status); |
656 | uint64_t float128_to_uint64_round_to_zero(float128, float_status *status); | |
fd425037 | 657 | uint32_t float128_to_uint32_round_to_zero(float128, float_status *status); |
e5a41ffa PM |
658 | float32 float128_to_float32(float128, float_status *status); |
659 | float64 float128_to_float64(float128, float_status *status); | |
660 | floatx80 float128_to_floatx80(float128, float_status *status); | |
158142c2 FB |
661 | |
662 | /*---------------------------------------------------------------------------- | |
663 | | Software IEC/IEEE quadruple-precision operations. | |
664 | *----------------------------------------------------------------------------*/ | |
e5a41ffa PM |
665 | float128 float128_round_to_int(float128, float_status *status); |
666 | float128 float128_add(float128, float128, float_status *status); | |
667 | float128 float128_sub(float128, float128, float_status *status); | |
668 | float128 float128_mul(float128, float128, float_status *status); | |
669 | float128 float128_div(float128, float128, float_status *status); | |
670 | float128 float128_rem(float128, float128, float_status *status); | |
671 | float128 float128_sqrt(float128, float_status *status); | |
672 | int float128_eq(float128, float128, float_status *status); | |
673 | int float128_le(float128, float128, float_status *status); | |
674 | int float128_lt(float128, float128, float_status *status); | |
675 | int float128_unordered(float128, float128, float_status *status); | |
676 | int float128_eq_quiet(float128, float128, float_status *status); | |
677 | int float128_le_quiet(float128, float128, float_status *status); | |
678 | int float128_lt_quiet(float128, float128, float_status *status); | |
679 | int float128_unordered_quiet(float128, float128, float_status *status); | |
680 | int float128_compare(float128, float128, float_status *status); | |
681 | int float128_compare_quiet(float128, float128, float_status *status); | |
af39bc8c AM |
682 | int float128_is_quiet_nan(float128, float_status *status); |
683 | int float128_is_signaling_nan(float128, float_status *status); | |
684 | float128 float128_maybe_silence_nan(float128, float_status *status); | |
e5a41ffa | 685 | float128 float128_scalbn(float128, int, float_status *status); |
158142c2 | 686 | |
a49db98d | 687 | static inline float128 float128_abs(float128 a) |
1d6bda35 FB |
688 | { |
689 | a.high &= 0x7fffffffffffffffLL; | |
690 | return a; | |
691 | } | |
692 | ||
a49db98d | 693 | static inline float128 float128_chs(float128 a) |
1d6bda35 FB |
694 | { |
695 | a.high ^= 0x8000000000000000LL; | |
696 | return a; | |
697 | } | |
698 | ||
a49db98d | 699 | static inline int float128_is_infinity(float128 a) |
c52ab6f5 AJ |
700 | { |
701 | return (a.high & 0x7fffffffffffffffLL) == 0x7fff000000000000LL && a.low == 0; | |
702 | } | |
703 | ||
a49db98d | 704 | static inline int float128_is_neg(float128 a) |
c52ab6f5 AJ |
705 | { |
706 | return a.high >> 63; | |
707 | } | |
708 | ||
a49db98d | 709 | static inline int float128_is_zero(float128 a) |
c52ab6f5 AJ |
710 | { |
711 | return (a.high & 0x7fffffffffffffffLL) == 0 && a.low == 0; | |
712 | } | |
713 | ||
a49db98d | 714 | static inline int float128_is_zero_or_denormal(float128 a) |
587eabfa AJ |
715 | { |
716 | return (a.high & 0x7fff000000000000LL) == 0; | |
717 | } | |
718 | ||
a49db98d | 719 | static inline int float128_is_any_nan(float128 a) |
2bed652f PM |
720 | { |
721 | return ((a.high >> 48) & 0x7fff) == 0x7fff && | |
722 | ((a.low != 0) || ((a.high & 0xffffffffffffLL) != 0)); | |
723 | } | |
724 | ||
1e397ead RH |
725 | #define float128_zero make_float128(0, 0) |
726 | ||
8559666d | 727 | /*---------------------------------------------------------------------------- |
789ec7ce | 728 | | The pattern for a default generated quadruple-precision NaN. |
8559666d | 729 | *----------------------------------------------------------------------------*/ |
af39bc8c | 730 | float128 float128_default_nan(float_status *status); |
8559666d | 731 | |
175de524 | 732 | #endif /* SOFTFLOAT_H */ |