Andreas Färber | 8d725fa | 2011-03-07 01:34:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * QEMU float support |
| 3 | * |
Peter Maydell | 16017c4 | 2015-01-12 14:38:28 +0000 | [diff] [blame] | 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. |
Andreas Färber | 8d725fa | 2011-03-07 01:34:04 +0100 | [diff] [blame] | 16 | */ |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 17 | |
Peter Maydell | a7d1ac7 | 2015-01-12 14:38:25 +0000 | [diff] [blame] | 18 | /* |
| 19 | =============================================================================== |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 20 | This C source fragment is part of the SoftFloat IEC/IEEE Floating-point |
Peter Maydell | a7d1ac7 | 2015-01-12 14:38:25 +0000 | [diff] [blame] | 21 | Arithmetic Package, Release 2a. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 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 |
Peter Maydell | a7d1ac7 | 2015-01-12 14:38:25 +0000 | [diff] [blame] | 30 | is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 31 | arithmetic/SoftFloat.html'. |
| 32 | |
Peter Maydell | a7d1ac7 | 2015-01-12 14:38:25 +0000 | [diff] [blame] | 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. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 38 | |
| 39 | Derivative works are acceptable, even for commercial purposes, so long as |
Peter Maydell | a7d1ac7 | 2015-01-12 14:38:25 +0000 | [diff] [blame] | 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. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 43 | |
Peter Maydell | a7d1ac7 | 2015-01-12 14:38:25 +0000 | [diff] [blame] | 44 | =============================================================================== |
| 45 | */ |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 46 | |
Peter Maydell | 16017c4 | 2015-01-12 14:38:28 +0000 | [diff] [blame] | 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 | |
Max Filippov | 213ff4e | 2012-09-19 04:23:51 +0400 | [diff] [blame] | 82 | /* Define for architectures which deviate from IEEE in not supporting |
| 83 | * signaling NaNs (so all NaNs are treated as quiet). |
| 84 | */ |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 85 | #if defined(TARGET_XTENSA) |
Max Filippov | 213ff4e | 2012-09-19 04:23:51 +0400 | [diff] [blame] | 86 | #define NO_SIGNALING_NANS 1 |
| 87 | #endif |
| 88 | |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 89 | /* Define how the architecture discriminates signaling NaNs. |
| 90 | * This done with the most significant bit of the fraction. |
| 91 | * In IEEE 754-1985 this was implementation defined, but in IEEE 754-2008 |
| 92 | * the msb must be zero. MIPS is (so far) unique in supporting both the |
| 93 | * 2008 revision and backward compatibility with their original choice. |
| 94 | * Thus for MIPS we must make the choice at runtime. |
| 95 | */ |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 96 | static inline bool snan_bit_is_one(float_status *status) |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 97 | { |
| 98 | #if defined(TARGET_MIPS) |
| 99 | return status->snan_bit_is_one; |
| 100 | #elif defined(TARGET_HPPA) || defined(TARGET_UNICORE32) || defined(TARGET_SH4) |
| 101 | return 1; |
| 102 | #else |
| 103 | return 0; |
| 104 | #endif |
| 105 | } |
| 106 | |
Paolo Bonzini | 789ec7c | 2011-07-28 12:10:29 +0200 | [diff] [blame] | 107 | /*---------------------------------------------------------------------------- |
Richard Henderson | 298b468 | 2018-05-10 12:45:29 -0700 | [diff] [blame] | 108 | | For the deconstructed floating-point with fraction FRAC, return true |
| 109 | | if the fraction represents a signalling NaN; otherwise false. |
| 110 | *----------------------------------------------------------------------------*/ |
| 111 | |
| 112 | static bool parts_is_snan_frac(uint64_t frac, float_status *status) |
| 113 | { |
| 114 | #ifdef NO_SIGNALING_NANS |
| 115 | return false; |
| 116 | #else |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 117 | bool msb = extract64(frac, DECOMPOSED_BINARY_POINT - 1, 1); |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 118 | return msb == snan_bit_is_one(status); |
Richard Henderson | 298b468 | 2018-05-10 12:45:29 -0700 | [diff] [blame] | 119 | #endif |
| 120 | } |
| 121 | |
| 122 | /*---------------------------------------------------------------------------- |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 123 | | The pattern for a default generated deconstructed floating-point NaN. |
| 124 | *----------------------------------------------------------------------------*/ |
| 125 | |
| 126 | static FloatParts parts_default_nan(float_status *status) |
| 127 | { |
| 128 | bool sign = 0; |
| 129 | uint64_t frac; |
| 130 | |
| 131 | #if defined(TARGET_SPARC) || defined(TARGET_M68K) |
Richard Henderson | 8fb3d90 | 2018-05-14 13:12:14 -0700 | [diff] [blame] | 132 | /* !snan_bit_is_one, set all bits */ |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 133 | frac = (1ULL << DECOMPOSED_BINARY_POINT) - 1; |
Richard Henderson | 8fb3d90 | 2018-05-14 13:12:14 -0700 | [diff] [blame] | 134 | #elif defined(TARGET_I386) || defined(TARGET_X86_64) \ |
| 135 | || defined(TARGET_MICROBLAZE) |
| 136 | /* !snan_bit_is_one, set sign and msb */ |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 137 | frac = 1ULL << (DECOMPOSED_BINARY_POINT - 1); |
Richard Henderson | 8fb3d90 | 2018-05-14 13:12:14 -0700 | [diff] [blame] | 138 | sign = 1; |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 139 | #elif defined(TARGET_HPPA) |
Richard Henderson | 8fb3d90 | 2018-05-14 13:12:14 -0700 | [diff] [blame] | 140 | /* snan_bit_is_one, set msb-1. */ |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 141 | frac = 1ULL << (DECOMPOSED_BINARY_POINT - 2); |
| 142 | #else |
Richard Henderson | 8fb3d90 | 2018-05-14 13:12:14 -0700 | [diff] [blame] | 143 | /* This case is true for Alpha, ARM, MIPS, OpenRISC, PPC, RISC-V, |
| 144 | * S390, SH4, TriCore, and Xtensa. I cannot find documentation |
| 145 | * for Unicore32; the choice from the original commit is unchanged. |
| 146 | * Our other supported targets, CRIS, LM32, Moxie, Nios2, and Tile, |
| 147 | * do not have floating-point. |
| 148 | */ |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 149 | if (snan_bit_is_one(status)) { |
Richard Henderson | 8fb3d90 | 2018-05-14 13:12:14 -0700 | [diff] [blame] | 150 | /* set all bits other than msb */ |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 151 | frac = (1ULL << (DECOMPOSED_BINARY_POINT - 1)) - 1; |
| 152 | } else { |
Richard Henderson | 8fb3d90 | 2018-05-14 13:12:14 -0700 | [diff] [blame] | 153 | /* set msb */ |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 154 | frac = 1ULL << (DECOMPOSED_BINARY_POINT - 1); |
Richard Henderson | f7e598e | 2018-05-10 13:09:49 -0700 | [diff] [blame] | 155 | } |
| 156 | #endif |
| 157 | |
| 158 | return (FloatParts) { |
| 159 | .cls = float_class_qnan, |
| 160 | .sign = sign, |
| 161 | .exp = INT_MAX, |
| 162 | .frac = frac |
| 163 | }; |
| 164 | } |
| 165 | |
| 166 | /*---------------------------------------------------------------------------- |
Richard Henderson | 0bcfbcb | 2018-05-10 13:32:53 -0700 | [diff] [blame] | 167 | | Returns a quiet NaN from a signalling NaN for the deconstructed |
| 168 | | floating-point parts. |
| 169 | *----------------------------------------------------------------------------*/ |
| 170 | |
| 171 | static FloatParts parts_silence_nan(FloatParts a, float_status *status) |
| 172 | { |
| 173 | #ifdef NO_SIGNALING_NANS |
| 174 | g_assert_not_reached(); |
| 175 | #elif defined(TARGET_HPPA) |
| 176 | a.frac &= ~(1ULL << (DECOMPOSED_BINARY_POINT - 1)); |
| 177 | a.frac |= 1ULL << (DECOMPOSED_BINARY_POINT - 2); |
| 178 | #else |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 179 | if (snan_bit_is_one(status)) { |
Richard Henderson | 0bcfbcb | 2018-05-10 13:32:53 -0700 | [diff] [blame] | 180 | return parts_default_nan(status); |
| 181 | } else { |
| 182 | a.frac |= 1ULL << (DECOMPOSED_BINARY_POINT - 1); |
| 183 | } |
| 184 | #endif |
| 185 | a.cls = float_class_qnan; |
| 186 | return a; |
| 187 | } |
| 188 | |
| 189 | /*---------------------------------------------------------------------------- |
Paolo Bonzini | 789ec7c | 2011-07-28 12:10:29 +0200 | [diff] [blame] | 190 | | The pattern for a default generated extended double-precision NaN. |
| 191 | *----------------------------------------------------------------------------*/ |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 192 | floatx80 floatx80_default_nan(float_status *status) |
| 193 | { |
| 194 | floatx80 r; |
Richard Henderson | 0218a16 | 2018-05-14 13:56:44 -0700 | [diff] [blame] | 195 | |
| 196 | /* None of the targets that have snan_bit_is_one use floatx80. */ |
| 197 | assert(!snan_bit_is_one(status)); |
Laurent Vivier | e5b0cbe | 2017-06-12 01:16:27 +0200 | [diff] [blame] | 198 | #if defined(TARGET_M68K) |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 199 | r.low = UINT64_C(0xFFFFFFFFFFFFFFFF); |
Laurent Vivier | e5b0cbe | 2017-06-12 01:16:27 +0200 | [diff] [blame] | 200 | r.high = 0x7FFF; |
| 201 | #else |
Richard Henderson | 0218a16 | 2018-05-14 13:56:44 -0700 | [diff] [blame] | 202 | /* X86 */ |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 203 | r.low = UINT64_C(0xC000000000000000); |
Richard Henderson | 0218a16 | 2018-05-14 13:56:44 -0700 | [diff] [blame] | 204 | r.high = 0xFFFF; |
Laurent Vivier | e5b0cbe | 2017-06-12 01:16:27 +0200 | [diff] [blame] | 205 | #endif |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 206 | return r; |
| 207 | } |
Paolo Bonzini | 789ec7c | 2011-07-28 12:10:29 +0200 | [diff] [blame] | 208 | |
| 209 | /*---------------------------------------------------------------------------- |
Laurent Vivier | 0f605c8 | 2018-02-24 21:18:01 +0100 | [diff] [blame] | 210 | | The pattern for a default generated extended double-precision inf. |
| 211 | *----------------------------------------------------------------------------*/ |
| 212 | |
| 213 | #define floatx80_infinity_high 0x7FFF |
| 214 | #if defined(TARGET_M68K) |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 215 | #define floatx80_infinity_low UINT64_C(0x0000000000000000) |
Laurent Vivier | 0f605c8 | 2018-02-24 21:18:01 +0100 | [diff] [blame] | 216 | #else |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 217 | #define floatx80_infinity_low UINT64_C(0x8000000000000000) |
Laurent Vivier | 0f605c8 | 2018-02-24 21:18:01 +0100 | [diff] [blame] | 218 | #endif |
| 219 | |
| 220 | const floatx80 floatx80_infinity |
| 221 | = make_floatx80_init(floatx80_infinity_high, floatx80_infinity_low); |
| 222 | |
| 223 | /*---------------------------------------------------------------------------- |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 224 | | Raises the exceptions specified by `flags'. Floating-point traps can be |
| 225 | | defined here if desired. It is currently not possible for such a trap |
| 226 | | to substitute a result value. If traps are not implemented, this routine |
| 227 | | should be simply `float_exception_flags |= flags;'. |
| 228 | *----------------------------------------------------------------------------*/ |
| 229 | |
Pranith Kumar | dfd6076 | 2016-08-10 14:55:02 -0400 | [diff] [blame] | 230 | void float_raise(uint8_t flags, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 231 | { |
Peter Maydell | a2f2d28 | 2015-02-02 18:57:35 +0000 | [diff] [blame] | 232 | status->float_exception_flags |= flags; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /*---------------------------------------------------------------------------- |
| 236 | | Internal canonical NaN format. |
| 237 | *----------------------------------------------------------------------------*/ |
| 238 | typedef struct { |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 239 | bool sign; |
Andreas Färber | bb98fe4 | 2011-03-07 01:34:06 +0100 | [diff] [blame] | 240 | uint64_t high, low; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 241 | } commonNaNT; |
| 242 | |
| 243 | /*---------------------------------------------------------------------------- |
Peter Maydell | bb4d4bb | 2011-02-10 11:28:56 +0000 | [diff] [blame] | 244 | | Returns 1 if the half-precision floating-point value `a' is a quiet |
| 245 | | NaN; otherwise returns 0. |
| 246 | *----------------------------------------------------------------------------*/ |
| 247 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 248 | bool float16_is_quiet_nan(float16 a_, float_status *status) |
Peter Maydell | bb4d4bb | 2011-02-10 11:28:56 +0000 | [diff] [blame] | 249 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 250 | #ifdef NO_SIGNALING_NANS |
| 251 | return float16_is_any_nan(a_); |
| 252 | #else |
Peter Maydell | bb4d4bb | 2011-02-10 11:28:56 +0000 | [diff] [blame] | 253 | uint16_t a = float16_val(a_); |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 254 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 255 | return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF); |
| 256 | } else { |
LIU Zhiwei | 8cdf912 | 2020-07-13 21:04:08 +0100 | [diff] [blame] | 257 | return ((a >> 9) & 0x3F) == 0x3F; |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 258 | } |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 259 | #endif |
Peter Maydell | bb4d4bb | 2011-02-10 11:28:56 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /*---------------------------------------------------------------------------- |
| 263 | | Returns 1 if the half-precision floating-point value `a' is a signaling |
| 264 | | NaN; otherwise returns 0. |
| 265 | *----------------------------------------------------------------------------*/ |
| 266 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 267 | bool float16_is_signaling_nan(float16 a_, float_status *status) |
Peter Maydell | bb4d4bb | 2011-02-10 11:28:56 +0000 | [diff] [blame] | 268 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 269 | #ifdef NO_SIGNALING_NANS |
| 270 | return 0; |
| 271 | #else |
Peter Maydell | bb4d4bb | 2011-02-10 11:28:56 +0000 | [diff] [blame] | 272 | uint16_t a = float16_val(a_); |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 273 | if (snan_bit_is_one(status)) { |
LIU Zhiwei | 8cdf912 | 2020-07-13 21:04:08 +0100 | [diff] [blame] | 274 | return ((a >> 9) & 0x3F) == 0x3F; |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 275 | } else { |
| 276 | return (((a >> 9) & 0x3F) == 0x3E) && (a & 0x1FF); |
| 277 | } |
Max Filippov | 213ff4e | 2012-09-19 04:23:51 +0400 | [diff] [blame] | 278 | #endif |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 279 | } |
Peter Maydell | bb4d4bb | 2011-02-10 11:28:56 +0000 | [diff] [blame] | 280 | |
| 281 | /*---------------------------------------------------------------------------- |
ths | 5a6932d | 2007-11-16 14:57:36 +0000 | [diff] [blame] | 282 | | Returns 1 if the single-precision floating-point value `a' is a quiet |
| 283 | | NaN; otherwise returns 0. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 284 | *----------------------------------------------------------------------------*/ |
| 285 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 286 | bool float32_is_quiet_nan(float32 a_, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 287 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 288 | #ifdef NO_SIGNALING_NANS |
| 289 | return float32_is_any_nan(a_); |
| 290 | #else |
pbrook | f090c9d | 2007-11-18 14:33:24 +0000 | [diff] [blame] | 291 | uint32_t a = float32_val(a_); |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 292 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 293 | return (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF); |
| 294 | } else { |
| 295 | return ((uint32_t)(a << 1) >= 0xFF800000); |
| 296 | } |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 297 | #endif |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /*---------------------------------------------------------------------------- |
| 301 | | Returns 1 if the single-precision floating-point value `a' is a signaling |
| 302 | | NaN; otherwise returns 0. |
| 303 | *----------------------------------------------------------------------------*/ |
| 304 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 305 | bool float32_is_signaling_nan(float32 a_, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 306 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 307 | #ifdef NO_SIGNALING_NANS |
| 308 | return 0; |
| 309 | #else |
pbrook | f090c9d | 2007-11-18 14:33:24 +0000 | [diff] [blame] | 310 | uint32_t a = float32_val(a_); |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 311 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 312 | return ((uint32_t)(a << 1) >= 0xFF800000); |
| 313 | } else { |
| 314 | return (((a >> 22) & 0x1FF) == 0x1FE) && (a & 0x003FFFFF); |
| 315 | } |
Max Filippov | 213ff4e | 2012-09-19 04:23:51 +0400 | [diff] [blame] | 316 | #endif |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 317 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 318 | |
| 319 | /*---------------------------------------------------------------------------- |
| 320 | | Returns the result of converting the single-precision floating-point NaN |
| 321 | | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid |
| 322 | | exception is raised. |
| 323 | *----------------------------------------------------------------------------*/ |
| 324 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 325 | static commonNaNT float32ToCommonNaN(float32 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 326 | { |
| 327 | commonNaNT z; |
| 328 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 329 | if (float32_is_signaling_nan(a, status)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 330 | float_raise(float_flag_invalid, status); |
| 331 | } |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 332 | z.sign = float32_val(a) >> 31; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 333 | z.low = 0; |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 334 | z.high = ((uint64_t)float32_val(a)) << 41; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 335 | return z; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | /*---------------------------------------------------------------------------- |
| 339 | | Returns the result of converting the canonical NaN `a' to the single- |
| 340 | | precision floating-point format. |
| 341 | *----------------------------------------------------------------------------*/ |
| 342 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 343 | static float32 commonNaNToFloat32(commonNaNT a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 344 | { |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 345 | uint32_t mantissa = a.high >> 41; |
Christophe Lyon | bcd4d9a | 2011-02-10 11:28:57 +0000 | [diff] [blame] | 346 | |
Peter Maydell | a2f2d28 | 2015-02-02 18:57:35 +0000 | [diff] [blame] | 347 | if (status->default_nan_mode) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 348 | return float32_default_nan(status); |
Christophe Lyon | bcd4d9a | 2011-02-10 11:28:57 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 351 | if (mantissa) { |
ths | 85016c9 | 2007-12-25 23:59:51 +0000 | [diff] [blame] | 352 | return make_float32( |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 353 | (((uint32_t)a.sign) << 31) | 0x7F800000 | (a.high >> 41)); |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 354 | } else { |
| 355 | return float32_default_nan(status); |
| 356 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /*---------------------------------------------------------------------------- |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 360 | | Select which NaN to propagate for a two-input operation. |
| 361 | | IEEE754 doesn't specify all the details of this, so the |
| 362 | | algorithm is target-specific. |
| 363 | | The routine is passed various bits of information about the |
| 364 | | two NaNs and should return 0 to select NaN a and 1 for NaN b. |
| 365 | | Note that signalling NaNs are always squashed to quiet NaNs |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 366 | | by the caller, by calling floatXX_silence_nan() before |
Aurelien Jarno | 1f398e0 | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 367 | | returning them. |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 368 | | |
| 369 | | aIsLargerSignificand is only valid if both a and b are NaNs |
| 370 | | of some kind, and is true if a has the larger significand, |
| 371 | | or if both a and b have the same significand but a is |
| 372 | | positive but b is negative. It is only needed for the x87 |
| 373 | | tie-break rule. |
| 374 | *----------------------------------------------------------------------------*/ |
| 375 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 376 | static int pickNaN(FloatClass a_cls, FloatClass b_cls, |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 377 | bool aIsLargerSignificand) |
Peter Maydell | 011da61 | 2010-12-16 11:51:18 +0000 | [diff] [blame] | 378 | { |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 379 | #if defined(TARGET_ARM) || defined(TARGET_MIPS) || defined(TARGET_HPPA) |
Alex Bennée | 1389452 | 2017-07-19 11:49:42 +0100 | [diff] [blame] | 380 | /* ARM mandated NaN propagation rules (see FPProcessNaNs()), take |
| 381 | * the first of: |
Peter Maydell | 011da61 | 2010-12-16 11:51:18 +0000 | [diff] [blame] | 382 | * 1. A if it is signaling |
| 383 | * 2. B if it is signaling |
| 384 | * 3. A (quiet) |
| 385 | * 4. B (quiet) |
| 386 | * A signaling NaN is always quietened before returning it. |
| 387 | */ |
Aurelien Jarno | 084d19b | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 388 | /* According to MIPS specifications, if one of the two operands is |
| 389 | * a sNaN, a new qNaN has to be generated. This is done in |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 390 | * floatXX_silence_nan(). For qNaN inputs the specifications |
Aurelien Jarno | 084d19b | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 391 | * says: "When possible, this QNaN result is one of the operand QNaN |
| 392 | * values." In practice it seems that most implementations choose |
| 393 | * the first operand if both operands are qNaN. In short this gives |
| 394 | * the following rules: |
| 395 | * 1. A if it is signaling |
| 396 | * 2. B if it is signaling |
| 397 | * 3. A (quiet) |
| 398 | * 4. B (quiet) |
| 399 | * A signaling NaN is always silenced before returning it. |
| 400 | */ |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 401 | if (is_snan(a_cls)) { |
Aurelien Jarno | 084d19b | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 402 | return 0; |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 403 | } else if (is_snan(b_cls)) { |
Aurelien Jarno | 084d19b | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 404 | return 1; |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 405 | } else if (is_qnan(a_cls)) { |
Aurelien Jarno | 084d19b | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 406 | return 0; |
| 407 | } else { |
| 408 | return 1; |
| 409 | } |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 410 | #elif defined(TARGET_PPC) || defined(TARGET_XTENSA) || defined(TARGET_M68K) |
Aurelien Jarno | e024e88 | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 411 | /* PowerPC propagation rules: |
| 412 | * 1. A if it sNaN or qNaN |
| 413 | * 2. B if it sNaN or qNaN |
| 414 | * A signaling NaN is always silenced before returning it. |
| 415 | */ |
Laurent Vivier | e5b0cbe | 2017-06-12 01:16:27 +0200 | [diff] [blame] | 416 | /* M68000 FAMILY PROGRAMMER'S REFERENCE MANUAL |
| 417 | * 3.4 FLOATING-POINT INSTRUCTION DETAILS |
| 418 | * If either operand, but not both operands, of an operation is a |
| 419 | * nonsignaling NaN, then that NaN is returned as the result. If both |
| 420 | * operands are nonsignaling NaNs, then the destination operand |
| 421 | * nonsignaling NaN is returned as the result. |
| 422 | * If either operand to an operation is a signaling NaN (SNaN), then the |
| 423 | * SNaN bit is set in the FPSR EXC byte. If the SNaN exception enable bit |
| 424 | * is set in the FPCR ENABLE byte, then the exception is taken and the |
| 425 | * destination is not modified. If the SNaN exception enable bit is not |
| 426 | * set, setting the SNaN bit in the operand to a one converts the SNaN to |
| 427 | * a nonsignaling NaN. The operation then continues as described in the |
| 428 | * preceding paragraph for nonsignaling NaNs. |
| 429 | */ |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 430 | if (is_nan(a_cls)) { |
| 431 | return 0; |
Laurent Vivier | e5b0cbe | 2017-06-12 01:16:27 +0200 | [diff] [blame] | 432 | } else { |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 433 | return 1; |
Laurent Vivier | e5b0cbe | 2017-06-12 01:16:27 +0200 | [diff] [blame] | 434 | } |
Peter Maydell | 011da61 | 2010-12-16 11:51:18 +0000 | [diff] [blame] | 435 | #else |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 436 | /* This implements x87 NaN propagation rules: |
| 437 | * SNaN + QNaN => return the QNaN |
| 438 | * two SNaNs => return the one with the larger significand, silenced |
| 439 | * two QNaNs => return the one with the larger significand |
| 440 | * SNaN and a non-NaN => return the SNaN, silenced |
| 441 | * QNaN and a non-NaN => return the QNaN |
| 442 | * |
| 443 | * If we get down to comparing significands and they are the same, |
| 444 | * return the NaN with the positive sign bit (if any). |
| 445 | */ |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 446 | if (is_snan(a_cls)) { |
| 447 | if (is_snan(b_cls)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 448 | return aIsLargerSignificand ? 0 : 1; |
| 449 | } |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 450 | return is_qnan(b_cls) ? 1 : 0; |
| 451 | } else if (is_qnan(a_cls)) { |
| 452 | if (is_snan(b_cls) || !is_qnan(b_cls)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 453 | return 0; |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 454 | } else { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 455 | return aIsLargerSignificand ? 0 : 1; |
| 456 | } |
| 457 | } else { |
| 458 | return 1; |
| 459 | } |
Peter Maydell | 011da61 | 2010-12-16 11:51:18 +0000 | [diff] [blame] | 460 | #endif |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 461 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 462 | |
| 463 | /*---------------------------------------------------------------------------- |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 464 | | Select which NaN to propagate for a three-input operation. |
| 465 | | For the moment we assume that no CPU needs the 'larger significand' |
| 466 | | information. |
| 467 | | Return values : 0 : a; 1 : b; 2 : c; 3 : default-NaN |
| 468 | *----------------------------------------------------------------------------*/ |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 469 | static int pickNaNMulAdd(FloatClass a_cls, FloatClass b_cls, FloatClass c_cls, |
| 470 | bool infzero, float_status *status) |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 471 | { |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 472 | #if defined(TARGET_ARM) |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 473 | /* For ARM, the (inf,zero,qnan) case sets InvalidOp and returns |
| 474 | * the default NaN |
| 475 | */ |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 476 | if (infzero && is_qnan(c_cls)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 477 | float_raise(float_flag_invalid, status); |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 478 | return 3; |
| 479 | } |
| 480 | |
| 481 | /* This looks different from the ARM ARM pseudocode, because the ARM ARM |
| 482 | * puts the operands to a fused mac operation (a*b)+c in the order c,a,b. |
| 483 | */ |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 484 | if (is_snan(c_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 485 | return 2; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 486 | } else if (is_snan(a_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 487 | return 0; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 488 | } else if (is_snan(b_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 489 | return 1; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 490 | } else if (is_qnan(c_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 491 | return 2; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 492 | } else if (is_qnan(a_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 493 | return 0; |
| 494 | } else { |
| 495 | return 1; |
| 496 | } |
Aurelien Jarno | bbc1ded | 2012-10-09 21:53:20 +0200 | [diff] [blame] | 497 | #elif defined(TARGET_MIPS) |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 498 | if (snan_bit_is_one(status)) { |
Mateja Marjanovic | 7ca96e1 | 2019-03-19 16:21:56 +0100 | [diff] [blame] | 499 | /* |
| 500 | * For MIPS systems that conform to IEEE754-1985, the (inf,zero,nan) |
| 501 | * case sets InvalidOp and returns the default NaN |
| 502 | */ |
| 503 | if (infzero) { |
| 504 | float_raise(float_flag_invalid, status); |
| 505 | return 3; |
| 506 | } |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 507 | /* Prefer sNaN over qNaN, in the a, b, c order. */ |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 508 | if (is_snan(a_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 509 | return 0; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 510 | } else if (is_snan(b_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 511 | return 1; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 512 | } else if (is_snan(c_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 513 | return 2; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 514 | } else if (is_qnan(a_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 515 | return 0; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 516 | } else if (is_qnan(b_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 517 | return 1; |
| 518 | } else { |
| 519 | return 2; |
| 520 | } |
Aurelien Jarno | bbc1ded | 2012-10-09 21:53:20 +0200 | [diff] [blame] | 521 | } else { |
Mateja Marjanovic | 7ca96e1 | 2019-03-19 16:21:56 +0100 | [diff] [blame] | 522 | /* |
| 523 | * For MIPS systems that conform to IEEE754-2008, the (inf,zero,nan) |
| 524 | * case sets InvalidOp and returns the input value 'c' |
| 525 | */ |
| 526 | if (infzero) { |
| 527 | float_raise(float_flag_invalid, status); |
| 528 | return 2; |
| 529 | } |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 530 | /* Prefer sNaN over qNaN, in the c, a, b order. */ |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 531 | if (is_snan(c_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 532 | return 2; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 533 | } else if (is_snan(a_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 534 | return 0; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 535 | } else if (is_snan(b_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 536 | return 1; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 537 | } else if (is_qnan(c_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 538 | return 2; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 539 | } else if (is_qnan(a_cls)) { |
Aleksandar Markovic | c27644f | 2016-06-10 11:57:31 +0200 | [diff] [blame] | 540 | return 0; |
| 541 | } else { |
| 542 | return 1; |
| 543 | } |
Aurelien Jarno | bbc1ded | 2012-10-09 21:53:20 +0200 | [diff] [blame] | 544 | } |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 545 | #elif defined(TARGET_PPC) |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 546 | /* For PPC, the (inf,zero,qnan) case sets InvalidOp, but we prefer |
| 547 | * to return an input NaN if we have one (ie c) rather than generating |
| 548 | * a default NaN |
| 549 | */ |
| 550 | if (infzero) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 551 | float_raise(float_flag_invalid, status); |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 552 | return 2; |
| 553 | } |
| 554 | |
| 555 | /* If fRA is a NaN return it; otherwise if fRB is a NaN return it; |
| 556 | * otherwise return fRC. Note that muladd on PPC is (fRA * fRC) + frB |
| 557 | */ |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 558 | if (is_nan(a_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 559 | return 0; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 560 | } else if (is_nan(c_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 561 | return 2; |
| 562 | } else { |
| 563 | return 1; |
| 564 | } |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 565 | #else |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 566 | /* A default implementation: prefer a to b to c. |
| 567 | * This is unlikely to actually match any real implementation. |
| 568 | */ |
| 569 | if (is_nan(a_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 570 | return 0; |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 571 | } else if (is_nan(b_cls)) { |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 572 | return 1; |
| 573 | } else { |
| 574 | return 2; |
| 575 | } |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 576 | #endif |
Richard Henderson | 3bd2dec | 2018-05-10 15:38:08 -0700 | [diff] [blame] | 577 | } |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 578 | |
| 579 | /*---------------------------------------------------------------------------- |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 580 | | Takes two single-precision floating-point values `a' and `b', one of which |
| 581 | | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a |
| 582 | | signaling NaN, the invalid exception is raised. |
| 583 | *----------------------------------------------------------------------------*/ |
| 584 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 585 | static float32 propagateFloat32NaN(float32 a, float32 b, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 586 | { |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 587 | bool aIsLargerSignificand; |
Andreas Färber | bb98fe4 | 2011-03-07 01:34:06 +0100 | [diff] [blame] | 588 | uint32_t av, bv; |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 589 | FloatClass a_cls, b_cls; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 590 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 591 | /* This is not complete, but is good enough for pickNaN. */ |
| 592 | a_cls = (!float32_is_any_nan(a) |
| 593 | ? float_class_normal |
| 594 | : float32_is_signaling_nan(a, status) |
| 595 | ? float_class_snan |
| 596 | : float_class_qnan); |
| 597 | b_cls = (!float32_is_any_nan(b) |
| 598 | ? float_class_normal |
| 599 | : float32_is_signaling_nan(b, status) |
| 600 | ? float_class_snan |
| 601 | : float_class_qnan); |
| 602 | |
pbrook | f090c9d | 2007-11-18 14:33:24 +0000 | [diff] [blame] | 603 | av = float32_val(a); |
| 604 | bv = float32_val(b); |
Aurelien Jarno | 1f398e0 | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 605 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 606 | if (is_snan(a_cls) || is_snan(b_cls)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 607 | float_raise(float_flag_invalid, status); |
| 608 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 609 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 610 | if (status->default_nan_mode) { |
| 611 | return float32_default_nan(status); |
| 612 | } |
Aurelien Jarno | 1020160 | 2011-01-14 20:39:17 +0100 | [diff] [blame] | 613 | |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 614 | if ((uint32_t)(av << 1) < (uint32_t)(bv << 1)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 615 | aIsLargerSignificand = 0; |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 616 | } else if ((uint32_t)(bv << 1) < (uint32_t)(av << 1)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 617 | aIsLargerSignificand = 1; |
| 618 | } else { |
| 619 | aIsLargerSignificand = (av < bv) ? 1 : 0; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 620 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 621 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 622 | if (pickNaN(a_cls, b_cls, aIsLargerSignificand)) { |
| 623 | if (is_snan(b_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 624 | return float32_silence_nan(b, status); |
| 625 | } |
| 626 | return b; |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 627 | } else { |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 628 | if (is_snan(a_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 629 | return float32_silence_nan(a, status); |
| 630 | } |
| 631 | return a; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 632 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 633 | } |
| 634 | |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 635 | /*---------------------------------------------------------------------------- |
ths | 5a6932d | 2007-11-16 14:57:36 +0000 | [diff] [blame] | 636 | | Returns 1 if the double-precision floating-point value `a' is a quiet |
| 637 | | NaN; otherwise returns 0. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 638 | *----------------------------------------------------------------------------*/ |
| 639 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 640 | bool float64_is_quiet_nan(float64 a_, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 641 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 642 | #ifdef NO_SIGNALING_NANS |
| 643 | return float64_is_any_nan(a_); |
| 644 | #else |
Andreas Färber | bb98fe4 | 2011-03-07 01:34:06 +0100 | [diff] [blame] | 645 | uint64_t a = float64_val(a_); |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 646 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 647 | return (((a >> 51) & 0xFFF) == 0xFFE) |
| 648 | && (a & 0x0007FFFFFFFFFFFFULL); |
| 649 | } else { |
| 650 | return ((a << 1) >= 0xFFF0000000000000ULL); |
| 651 | } |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 652 | #endif |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | /*---------------------------------------------------------------------------- |
| 656 | | Returns 1 if the double-precision floating-point value `a' is a signaling |
| 657 | | NaN; otherwise returns 0. |
| 658 | *----------------------------------------------------------------------------*/ |
| 659 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 660 | bool float64_is_signaling_nan(float64 a_, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 661 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 662 | #ifdef NO_SIGNALING_NANS |
| 663 | return 0; |
| 664 | #else |
Andreas Färber | bb98fe4 | 2011-03-07 01:34:06 +0100 | [diff] [blame] | 665 | uint64_t a = float64_val(a_); |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 666 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 667 | return ((a << 1) >= 0xFFF0000000000000ULL); |
| 668 | } else { |
| 669 | return (((a >> 51) & 0xFFF) == 0xFFE) |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 670 | && (a & UINT64_C(0x0007FFFFFFFFFFFF)); |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 671 | } |
Max Filippov | 213ff4e | 2012-09-19 04:23:51 +0400 | [diff] [blame] | 672 | #endif |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 673 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 674 | |
| 675 | /*---------------------------------------------------------------------------- |
| 676 | | Returns the result of converting the double-precision floating-point NaN |
| 677 | | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid |
| 678 | | exception is raised. |
| 679 | *----------------------------------------------------------------------------*/ |
| 680 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 681 | static commonNaNT float64ToCommonNaN(float64 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 682 | { |
| 683 | commonNaNT z; |
| 684 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 685 | if (float64_is_signaling_nan(a, status)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 686 | float_raise(float_flag_invalid, status); |
| 687 | } |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 688 | z.sign = float64_val(a) >> 63; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 689 | z.low = 0; |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 690 | z.high = float64_val(a) << 12; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 691 | return z; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /*---------------------------------------------------------------------------- |
| 695 | | Returns the result of converting the canonical NaN `a' to the double- |
| 696 | | precision floating-point format. |
| 697 | *----------------------------------------------------------------------------*/ |
| 698 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 699 | static float64 commonNaNToFloat64(commonNaNT a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 700 | { |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 701 | uint64_t mantissa = a.high >> 12; |
ths | 85016c9 | 2007-12-25 23:59:51 +0000 | [diff] [blame] | 702 | |
Peter Maydell | a2f2d28 | 2015-02-02 18:57:35 +0000 | [diff] [blame] | 703 | if (status->default_nan_mode) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 704 | return float64_default_nan(status); |
Christophe Lyon | bcd4d9a | 2011-02-10 11:28:57 +0000 | [diff] [blame] | 705 | } |
| 706 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 707 | if (mantissa) { |
ths | 85016c9 | 2007-12-25 23:59:51 +0000 | [diff] [blame] | 708 | return make_float64( |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 709 | (((uint64_t) a.sign) << 63) |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 710 | | UINT64_C(0x7FF0000000000000) |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 711 | | (a.high >> 12)); |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 712 | } else { |
| 713 | return float64_default_nan(status); |
| 714 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | /*---------------------------------------------------------------------------- |
| 718 | | Takes two double-precision floating-point values `a' and `b', one of which |
| 719 | | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a |
| 720 | | signaling NaN, the invalid exception is raised. |
| 721 | *----------------------------------------------------------------------------*/ |
| 722 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 723 | static float64 propagateFloat64NaN(float64 a, float64 b, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 724 | { |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 725 | bool aIsLargerSignificand; |
Andreas Färber | bb98fe4 | 2011-03-07 01:34:06 +0100 | [diff] [blame] | 726 | uint64_t av, bv; |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 727 | FloatClass a_cls, b_cls; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 728 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 729 | /* This is not complete, but is good enough for pickNaN. */ |
| 730 | a_cls = (!float64_is_any_nan(a) |
| 731 | ? float_class_normal |
| 732 | : float64_is_signaling_nan(a, status) |
| 733 | ? float_class_snan |
| 734 | : float_class_qnan); |
| 735 | b_cls = (!float64_is_any_nan(b) |
| 736 | ? float_class_normal |
| 737 | : float64_is_signaling_nan(b, status) |
| 738 | ? float_class_snan |
| 739 | : float_class_qnan); |
| 740 | |
pbrook | f090c9d | 2007-11-18 14:33:24 +0000 | [diff] [blame] | 741 | av = float64_val(a); |
| 742 | bv = float64_val(b); |
Aurelien Jarno | 1f398e0 | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 743 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 744 | if (is_snan(a_cls) || is_snan(b_cls)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 745 | float_raise(float_flag_invalid, status); |
| 746 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 747 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 748 | if (status->default_nan_mode) { |
| 749 | return float64_default_nan(status); |
| 750 | } |
Aurelien Jarno | 1020160 | 2011-01-14 20:39:17 +0100 | [diff] [blame] | 751 | |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 752 | if ((uint64_t)(av << 1) < (uint64_t)(bv << 1)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 753 | aIsLargerSignificand = 0; |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 754 | } else if ((uint64_t)(bv << 1) < (uint64_t)(av << 1)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 755 | aIsLargerSignificand = 1; |
| 756 | } else { |
| 757 | aIsLargerSignificand = (av < bv) ? 1 : 0; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 758 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 759 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 760 | if (pickNaN(a_cls, b_cls, aIsLargerSignificand)) { |
| 761 | if (is_snan(b_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 762 | return float64_silence_nan(b, status); |
| 763 | } |
| 764 | return b; |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 765 | } else { |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 766 | if (is_snan(a_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 767 | return float64_silence_nan(a, status); |
| 768 | } |
| 769 | return a; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 770 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Peter Maydell | 369be8f | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 773 | /*---------------------------------------------------------------------------- |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 774 | | Returns 1 if the extended double-precision floating-point value `a' is a |
Aurelien Jarno | de4af5f | 2011-01-17 19:29:33 +0100 | [diff] [blame] | 775 | | quiet NaN; otherwise returns 0. This slightly differs from the same |
| 776 | | function for other types as floatx80 has an explicit bit. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 777 | *----------------------------------------------------------------------------*/ |
| 778 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 779 | int floatx80_is_quiet_nan(floatx80 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 780 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 781 | #ifdef NO_SIGNALING_NANS |
| 782 | return floatx80_is_any_nan(a); |
| 783 | #else |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 784 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 785 | uint64_t aLow; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 786 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 787 | aLow = a.low & ~0x4000000000000000ULL; |
| 788 | return ((a.high & 0x7FFF) == 0x7FFF) |
| 789 | && (aLow << 1) |
| 790 | && (a.low == aLow); |
| 791 | } else { |
| 792 | return ((a.high & 0x7FFF) == 0x7FFF) |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 793 | && (UINT64_C(0x8000000000000000) <= ((uint64_t)(a.low << 1))); |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 794 | } |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 795 | #endif |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /*---------------------------------------------------------------------------- |
| 799 | | Returns 1 if the extended double-precision floating-point value `a' is a |
Aurelien Jarno | de4af5f | 2011-01-17 19:29:33 +0100 | [diff] [blame] | 800 | | signaling NaN; otherwise returns 0. This slightly differs from the same |
| 801 | | function for other types as floatx80 has an explicit bit. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 802 | *----------------------------------------------------------------------------*/ |
| 803 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 804 | int floatx80_is_signaling_nan(floatx80 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 805 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 806 | #ifdef NO_SIGNALING_NANS |
| 807 | return 0; |
| 808 | #else |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 809 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 810 | return ((a.high & 0x7FFF) == 0x7FFF) |
| 811 | && ((a.low << 1) >= 0x8000000000000000ULL); |
| 812 | } else { |
| 813 | uint64_t aLow; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 814 | |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 815 | aLow = a.low & ~UINT64_C(0x4000000000000000); |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 816 | return ((a.high & 0x7FFF) == 0x7FFF) |
| 817 | && (uint64_t)(aLow << 1) |
| 818 | && (a.low == aLow); |
| 819 | } |
Max Filippov | 213ff4e | 2012-09-19 04:23:51 +0400 | [diff] [blame] | 820 | #endif |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 821 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 822 | |
| 823 | /*---------------------------------------------------------------------------- |
Richard Henderson | d619bb9 | 2018-05-10 11:39:48 -0700 | [diff] [blame] | 824 | | Returns a quiet NaN from a signalling NaN for the extended double-precision |
| 825 | | floating point value `a'. |
| 826 | *----------------------------------------------------------------------------*/ |
| 827 | |
| 828 | floatx80 floatx80_silence_nan(floatx80 a, float_status *status) |
| 829 | { |
Richard Henderson | 377ed92 | 2018-05-14 14:26:38 -0700 | [diff] [blame] | 830 | /* None of the targets that have snan_bit_is_one use floatx80. */ |
| 831 | assert(!snan_bit_is_one(status)); |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 832 | a.low |= UINT64_C(0xC000000000000000); |
Richard Henderson | 377ed92 | 2018-05-14 14:26:38 -0700 | [diff] [blame] | 833 | return a; |
Richard Henderson | d619bb9 | 2018-05-10 11:39:48 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | /*---------------------------------------------------------------------------- |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 837 | | Returns the result of converting the extended double-precision floating- |
| 838 | | point NaN `a' to the canonical NaN format. If `a' is a signaling NaN, the |
| 839 | | invalid exception is raised. |
| 840 | *----------------------------------------------------------------------------*/ |
| 841 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 842 | static commonNaNT floatx80ToCommonNaN(floatx80 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 843 | { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 844 | floatx80 dflt; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 845 | commonNaNT z; |
| 846 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 847 | if (floatx80_is_signaling_nan(a, status)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 848 | float_raise(float_flag_invalid, status); |
| 849 | } |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 850 | if (a.low >> 63) { |
Aurelien Jarno | e2f4220 | 2011-04-20 13:04:22 +0200 | [diff] [blame] | 851 | z.sign = a.high >> 15; |
| 852 | z.low = 0; |
| 853 | z.high = a.low << 1; |
| 854 | } else { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 855 | dflt = floatx80_default_nan(status); |
| 856 | z.sign = dflt.high >> 15; |
Aurelien Jarno | e2f4220 | 2011-04-20 13:04:22 +0200 | [diff] [blame] | 857 | z.low = 0; |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 858 | z.high = dflt.low << 1; |
Aurelien Jarno | e2f4220 | 2011-04-20 13:04:22 +0200 | [diff] [blame] | 859 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 860 | return z; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | /*---------------------------------------------------------------------------- |
| 864 | | Returns the result of converting the canonical NaN `a' to the extended |
| 865 | | double-precision floating-point format. |
| 866 | *----------------------------------------------------------------------------*/ |
| 867 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 868 | static floatx80 commonNaNToFloatx80(commonNaNT a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 869 | { |
| 870 | floatx80 z; |
| 871 | |
Peter Maydell | a2f2d28 | 2015-02-02 18:57:35 +0000 | [diff] [blame] | 872 | if (status->default_nan_mode) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 873 | return floatx80_default_nan(status); |
Christophe Lyon | bcd4d9a | 2011-02-10 11:28:57 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Aurelien Jarno | e2f4220 | 2011-04-20 13:04:22 +0200 | [diff] [blame] | 876 | if (a.high >> 1) { |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 877 | z.low = UINT64_C(0x8000000000000000) | a.high >> 1; |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 878 | z.high = (((uint16_t)a.sign) << 15) | 0x7FFF; |
Aurelien Jarno | e2f4220 | 2011-04-20 13:04:22 +0200 | [diff] [blame] | 879 | } else { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 880 | z = floatx80_default_nan(status); |
Aurelien Jarno | e2f4220 | 2011-04-20 13:04:22 +0200 | [diff] [blame] | 881 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 882 | return z; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /*---------------------------------------------------------------------------- |
| 886 | | Takes two extended double-precision floating-point values `a' and `b', one |
| 887 | | of which is a NaN, and returns the appropriate NaN result. If either `a' or |
| 888 | | `b' is a signaling NaN, the invalid exception is raised. |
| 889 | *----------------------------------------------------------------------------*/ |
| 890 | |
Laurent Vivier | 88857ac | 2018-02-24 21:17:59 +0100 | [diff] [blame] | 891 | floatx80 propagateFloatx80NaN(floatx80 a, floatx80 b, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 892 | { |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 893 | bool aIsLargerSignificand; |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 894 | FloatClass a_cls, b_cls; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 895 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 896 | /* This is not complete, but is good enough for pickNaN. */ |
| 897 | a_cls = (!floatx80_is_any_nan(a) |
| 898 | ? float_class_normal |
| 899 | : floatx80_is_signaling_nan(a, status) |
| 900 | ? float_class_snan |
| 901 | : float_class_qnan); |
| 902 | b_cls = (!floatx80_is_any_nan(b) |
| 903 | ? float_class_normal |
| 904 | : floatx80_is_signaling_nan(b, status) |
| 905 | ? float_class_snan |
| 906 | : float_class_qnan); |
Aurelien Jarno | 1f398e0 | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 907 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 908 | if (is_snan(a_cls) || is_snan(b_cls)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 909 | float_raise(float_flag_invalid, status); |
| 910 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 911 | |
Peter Maydell | a2f2d28 | 2015-02-02 18:57:35 +0000 | [diff] [blame] | 912 | if (status->default_nan_mode) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 913 | return floatx80_default_nan(status); |
Aurelien Jarno | 1020160 | 2011-01-14 20:39:17 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 916 | if (a.low < b.low) { |
| 917 | aIsLargerSignificand = 0; |
| 918 | } else if (b.low < a.low) { |
| 919 | aIsLargerSignificand = 1; |
| 920 | } else { |
| 921 | aIsLargerSignificand = (a.high < b.high) ? 1 : 0; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 922 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 923 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 924 | if (pickNaN(a_cls, b_cls, aIsLargerSignificand)) { |
| 925 | if (is_snan(b_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 926 | return floatx80_silence_nan(b, status); |
| 927 | } |
| 928 | return b; |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 929 | } else { |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 930 | if (is_snan(a_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 931 | return floatx80_silence_nan(a, status); |
| 932 | } |
| 933 | return a; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 934 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 935 | } |
| 936 | |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 937 | /*---------------------------------------------------------------------------- |
ths | 5a6932d | 2007-11-16 14:57:36 +0000 | [diff] [blame] | 938 | | Returns 1 if the quadruple-precision floating-point value `a' is a quiet |
| 939 | | NaN; otherwise returns 0. |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 940 | *----------------------------------------------------------------------------*/ |
| 941 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 942 | bool float128_is_quiet_nan(float128 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 943 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 944 | #ifdef NO_SIGNALING_NANS |
| 945 | return float128_is_any_nan(a); |
| 946 | #else |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 947 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 948 | return (((a.high >> 47) & 0xFFFF) == 0xFFFE) |
| 949 | && (a.low || (a.high & 0x00007FFFFFFFFFFFULL)); |
| 950 | } else { |
| 951 | return ((a.high << 1) >= 0xFFFF000000000000ULL) |
| 952 | && (a.low || (a.high & 0x0000FFFFFFFFFFFFULL)); |
| 953 | } |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 954 | #endif |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | /*---------------------------------------------------------------------------- |
| 958 | | Returns 1 if the quadruple-precision floating-point value `a' is a |
| 959 | | signaling NaN; otherwise returns 0. |
| 960 | *----------------------------------------------------------------------------*/ |
| 961 | |
Richard Henderson | 150c7a9 | 2020-05-05 12:16:24 -0700 | [diff] [blame] | 962 | bool float128_is_signaling_nan(float128 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 963 | { |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 964 | #ifdef NO_SIGNALING_NANS |
| 965 | return 0; |
| 966 | #else |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 967 | if (snan_bit_is_one(status)) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 968 | return ((a.high << 1) >= 0xFFFF000000000000ULL) |
| 969 | && (a.low || (a.high & 0x0000FFFFFFFFFFFFULL)); |
| 970 | } else { |
| 971 | return (((a.high >> 47) & 0xFFFF) == 0xFFFE) |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 972 | && (a.low || (a.high & UINT64_C(0x00007FFFFFFFFFFF))); |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 973 | } |
Max Filippov | 213ff4e | 2012-09-19 04:23:51 +0400 | [diff] [blame] | 974 | #endif |
Richard Henderson | bca5223 | 2018-05-10 11:24:13 -0700 | [diff] [blame] | 975 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 976 | |
| 977 | /*---------------------------------------------------------------------------- |
Richard Henderson | d619bb9 | 2018-05-10 11:39:48 -0700 | [diff] [blame] | 978 | | Returns a quiet NaN from a signalling NaN for the quadruple-precision |
| 979 | | floating point value `a'. |
| 980 | *----------------------------------------------------------------------------*/ |
| 981 | |
| 982 | float128 float128_silence_nan(float128 a, float_status *status) |
| 983 | { |
| 984 | #ifdef NO_SIGNALING_NANS |
| 985 | g_assert_not_reached(); |
| 986 | #else |
Richard Henderson | 03385df | 2018-05-10 14:48:17 -0700 | [diff] [blame] | 987 | if (snan_bit_is_one(status)) { |
Richard Henderson | d619bb9 | 2018-05-10 11:39:48 -0700 | [diff] [blame] | 988 | return float128_default_nan(status); |
| 989 | } else { |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 990 | a.high |= UINT64_C(0x0000800000000000); |
Richard Henderson | d619bb9 | 2018-05-10 11:39:48 -0700 | [diff] [blame] | 991 | return a; |
| 992 | } |
| 993 | #endif |
| 994 | } |
| 995 | |
| 996 | /*---------------------------------------------------------------------------- |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 997 | | Returns the result of converting the quadruple-precision floating-point NaN |
| 998 | | `a' to the canonical NaN format. If `a' is a signaling NaN, the invalid |
| 999 | | exception is raised. |
| 1000 | *----------------------------------------------------------------------------*/ |
| 1001 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 1002 | static commonNaNT float128ToCommonNaN(float128 a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1003 | { |
| 1004 | commonNaNT z; |
| 1005 | |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 1006 | if (float128_is_signaling_nan(a, status)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 1007 | float_raise(float_flag_invalid, status); |
| 1008 | } |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 1009 | z.sign = a.high >> 63; |
| 1010 | shortShift128Left(a.high, a.low, 16, &z.high, &z.low); |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1011 | return z; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /*---------------------------------------------------------------------------- |
| 1015 | | Returns the result of converting the canonical NaN `a' to the quadruple- |
| 1016 | | precision floating-point format. |
| 1017 | *----------------------------------------------------------------------------*/ |
| 1018 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 1019 | static float128 commonNaNToFloat128(commonNaNT a, float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1020 | { |
| 1021 | float128 z; |
| 1022 | |
Peter Maydell | a2f2d28 | 2015-02-02 18:57:35 +0000 | [diff] [blame] | 1023 | if (status->default_nan_mode) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 1024 | return float128_default_nan(status); |
Christophe Lyon | bcd4d9a | 2011-02-10 11:28:57 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 1027 | shift128Right(a.high, a.low, 16, &z.high, &z.low); |
Alex Bennée | f7e81a9 | 2019-08-12 16:04:02 +0100 | [diff] [blame] | 1028 | z.high |= (((uint64_t)a.sign) << 63) | UINT64_C(0x7FFF000000000000); |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1029 | return z; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /*---------------------------------------------------------------------------- |
| 1033 | | Takes two quadruple-precision floating-point values `a' and `b', one of |
| 1034 | | which is a NaN, and returns the appropriate NaN result. If either `a' or |
| 1035 | | `b' is a signaling NaN, the invalid exception is raised. |
| 1036 | *----------------------------------------------------------------------------*/ |
| 1037 | |
Peter Maydell | e5a41ff | 2015-01-30 12:04:16 +0000 | [diff] [blame] | 1038 | static float128 propagateFloat128NaN(float128 a, float128 b, |
| 1039 | float_status *status) |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1040 | { |
Richard Henderson | c120391 | 2020-05-04 19:54:57 -0700 | [diff] [blame] | 1041 | bool aIsLargerSignificand; |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 1042 | FloatClass a_cls, b_cls; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1043 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 1044 | /* This is not complete, but is good enough for pickNaN. */ |
| 1045 | a_cls = (!float128_is_any_nan(a) |
| 1046 | ? float_class_normal |
| 1047 | : float128_is_signaling_nan(a, status) |
| 1048 | ? float_class_snan |
| 1049 | : float_class_qnan); |
| 1050 | b_cls = (!float128_is_any_nan(b) |
| 1051 | ? float_class_normal |
| 1052 | : float128_is_signaling_nan(b, status) |
| 1053 | ? float_class_snan |
| 1054 | : float_class_qnan); |
Aurelien Jarno | 1f398e0 | 2011-01-06 15:38:19 +0100 | [diff] [blame] | 1055 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 1056 | if (is_snan(a_cls) || is_snan(b_cls)) { |
Peter Maydell | ff32e16 | 2015-02-02 18:47:16 +0000 | [diff] [blame] | 1057 | float_raise(float_flag_invalid, status); |
| 1058 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 1059 | |
Peter Maydell | a2f2d28 | 2015-02-02 18:57:35 +0000 | [diff] [blame] | 1060 | if (status->default_nan_mode) { |
Aleksandar Markovic | af39bc8 | 2016-06-10 11:57:28 +0200 | [diff] [blame] | 1061 | return float128_default_nan(status); |
Aurelien Jarno | 1020160 | 2011-01-14 20:39:17 +0100 | [diff] [blame] | 1062 | } |
| 1063 | |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 1064 | if (lt128(a.high << 1, a.low, b.high << 1, b.low)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 1065 | aIsLargerSignificand = 0; |
Aleksandar Markovic | a59eaea | 2016-06-10 11:57:29 +0200 | [diff] [blame] | 1066 | } else if (lt128(b.high << 1, b.low, a.high << 1, a.low)) { |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 1067 | aIsLargerSignificand = 1; |
| 1068 | } else { |
| 1069 | aIsLargerSignificand = (a.high < b.high) ? 1 : 0; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1070 | } |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 1071 | |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 1072 | if (pickNaN(a_cls, b_cls, aIsLargerSignificand)) { |
| 1073 | if (is_snan(b_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 1074 | return float128_silence_nan(b, status); |
| 1075 | } |
| 1076 | return b; |
Peter Maydell | 354f211 | 2010-12-16 11:51:17 +0000 | [diff] [blame] | 1077 | } else { |
Richard Henderson | 4f251cf | 2018-05-10 15:21:31 -0700 | [diff] [blame] | 1078 | if (is_snan(a_cls)) { |
Richard Henderson | 4885312 | 2018-05-10 14:11:15 -0700 | [diff] [blame] | 1079 | return float128_silence_nan(a, status); |
| 1080 | } |
| 1081 | return a; |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1082 | } |
bellard | 158142c | 2005-03-13 16:54:06 +0000 | [diff] [blame] | 1083 | } |