1 2 /*============================================================================ 3 4 This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic 5 Package, Release 3a, by John R. Hauser. 6 7 Copyright 2011, 2012, 2013, 2014 The Regents of the University of California. 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions are met: 12 13 1. Redistributions of source code must retain the above copyright notice, 14 this list of conditions, and the following disclaimer. 15 16 2. Redistributions in binary form must reproduce the above copyright notice, 17 this list of conditions, and the following disclaimer in the documentation 18 and/or other materials provided with the distribution. 19 20 3. Neither the name of the University nor the names of its contributors may 21 be used to endorse or promote products derived from this software without 22 specific prior written permission. 23 24 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY 25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE 27 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 35 =============================================================================*/ 36 37 #ifndef specialize_h 38 #define specialize_h 1 39 40 #include <stdbool.h> 41 #include <stdint.h> 42 #include "softfloat_types.h" 43 44 /*---------------------------------------------------------------------------- 45 | Default value for `softfloat_detectTininess'. 46 *----------------------------------------------------------------------------*/ 47 #define init_detectTininess softfloat_tininess_afterRounding 48 49 /*---------------------------------------------------------------------------- 50 | "Common NaN" structure, used to transfer NaN representations from one format 51 | to another. 52 *----------------------------------------------------------------------------*/ 53 struct commonNaN { 54 bool sign; 55 #ifdef LITTLEENDIAN 56 uint64_t v0, v64; 57 #else 58 uint64_t v64, v0; 59 #endif 60 }; 61 62 /*---------------------------------------------------------------------------- 63 | The bit pattern for a default generated 32-bit floating-point NaN. 64 *----------------------------------------------------------------------------*/ 65 #define defaultNaNF32UI 0xFFC00000 66 67 /*---------------------------------------------------------------------------- 68 | Returns true when 32-bit unsigned integer `uiA' has the bit pattern of a 69 | 32-bit floating-point signaling NaN. 70 | Note: This macro evaluates its argument more than once. 71 *----------------------------------------------------------------------------*/ 72 #define softfloat_isSigNaNF32UI( uiA ) ((((uiA) & 0x7FC00000) == 0x7F800000) && ((uiA) & 0x003FFFFF)) 73 74 /*---------------------------------------------------------------------------- 75 | Assuming `uiA' has the bit pattern of a 32-bit floating-point NaN, converts 76 | this NaN to the common NaN form, and stores the resulting common NaN at the 77 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid 78 | exception is raised. 79 *----------------------------------------------------------------------------*/ 80 void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr ); 81 82 /*---------------------------------------------------------------------------- 83 | Converts the common NaN pointed to by `aPtr' into a 32-bit floating-point 84 | NaN, and returns the bit pattern of this value as an unsigned integer. 85 *----------------------------------------------------------------------------*/ 86 uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr ); 87 88 /*---------------------------------------------------------------------------- 89 | Interpreting `uiA' and `uiB' as the bit patterns of two 32-bit floating- 90 | point values, at least one of which is a NaN, returns the bit pattern of 91 | the combined NaN result. If either `uiA' or `uiB' has the pattern of a 92 | signaling NaN, the invalid exception is raised. 93 *----------------------------------------------------------------------------*/ 94 uint_fast32_t 95 softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB ); 96 97 /*---------------------------------------------------------------------------- 98 | The bit pattern for a default generated 64-bit floating-point NaN. 99 *----------------------------------------------------------------------------*/ 100 #define defaultNaNF64UI UINT64_C( 0xFFF8000000000000 ) 101 102 /*---------------------------------------------------------------------------- 103 | Returns true when 64-bit unsigned integer `uiA' has the bit pattern of a 104 | 64-bit floating-point signaling NaN. 105 | Note: This macro evaluates its argument more than once. 106 *----------------------------------------------------------------------------*/ 107 #define softfloat_isSigNaNF64UI( uiA ) ((((uiA) & UINT64_C( 0x7FF8000000000000 )) == UINT64_C( 0x7FF0000000000000 )) && ((uiA) & UINT64_C( 0x0007FFFFFFFFFFFF ))) 108 109 /*---------------------------------------------------------------------------- 110 | Assuming `uiA' has the bit pattern of a 64-bit floating-point NaN, converts 111 | this NaN to the common NaN form, and stores the resulting common NaN at the 112 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid 113 | exception is raised. 114 *----------------------------------------------------------------------------*/ 115 void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr ); 116 117 /*---------------------------------------------------------------------------- 118 | Converts the common NaN pointed to by `aPtr' into a 64-bit floating-point 119 | NaN, and returns the bit pattern of this value as an unsigned integer. 120 *----------------------------------------------------------------------------*/ 121 uint_fast64_t softfloat_commonNaNToF64UI( const struct commonNaN *aPtr ); 122 123 /*---------------------------------------------------------------------------- 124 | Interpreting `uiA' and `uiB' as the bit patterns of two 64-bit floating- 125 | point values, at least one of which is a NaN, returns the bit pattern of 126 | the combined NaN result. If either `uiA' or `uiB' has the pattern of a 127 | signaling NaN, the invalid exception is raised. 128 *----------------------------------------------------------------------------*/ 129 uint_fast64_t 130 softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB ); 131 132 /*---------------------------------------------------------------------------- 133 | The bit pattern for a default generated 80-bit extended floating-point NaN. 134 *----------------------------------------------------------------------------*/ 135 #define defaultNaNExtF80UI64 0xFFFF 136 #define defaultNaNExtF80UI0 UINT64_C( 0xC000000000000000 ) 137 138 /*---------------------------------------------------------------------------- 139 | Returns true when the 80-bit unsigned integer formed from concatenating 140 | 16-bit `uiA64' and 64-bit `uiA0' has the bit pattern of an 80-bit extended 141 | floating-point signaling NaN. 142 | Note: This macro evaluates its arguments more than once. 143 *----------------------------------------------------------------------------*/ 144 #define softfloat_isSigNaNExtF80UI( uiA64, uiA0 ) ((((uiA64) & 0x7FFF) == 0x7FFF) && ! ((uiA0) & UINT64_C( 0x4000000000000000 )) && ((uiA0) & UINT64_C( 0x3FFFFFFFFFFFFFFF ))) 145 146 #ifdef SOFTFLOAT_FAST_INT64 147 148 /*---------------------------------------------------------------------------- 149 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is 150 | defined. 151 *----------------------------------------------------------------------------*/ 152 153 /*---------------------------------------------------------------------------- 154 | Assuming the unsigned integer formed from concatenating `uiA64' and `uiA0' 155 | has the bit pattern of an 80-bit extended floating-point NaN, converts 156 | this NaN to the common NaN form, and stores the resulting common NaN at the 157 | location pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid 158 | exception is raised. 159 *----------------------------------------------------------------------------*/ 160 void 161 softfloat_extF80UIToCommonNaN( 162 uint_fast16_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr ); 163 164 /*---------------------------------------------------------------------------- 165 | Converts the common NaN pointed to by `aPtr' into an 80-bit extended 166 | floating-point NaN, and returns the bit pattern of this value as an unsigned 167 | integer. 168 *----------------------------------------------------------------------------*/ 169 struct uint128 softfloat_commonNaNToExtF80UI( const struct commonNaN *aPtr ); 170 171 /*---------------------------------------------------------------------------- 172 | Interpreting the unsigned integer formed from concatenating `uiA64' and 173 | `uiA0' as an 80-bit extended floating-point value, and likewise interpreting 174 | the unsigned integer formed from concatenating `uiB64' and `uiB0' as another 175 | 80-bit extended floating-point value, and assuming at least on of these 176 | floating-point values is a NaN, returns the bit pattern of the combined NaN 177 | result. If either original floating-point value is a signaling NaN, the 178 | invalid exception is raised. 179 *----------------------------------------------------------------------------*/ 180 struct uint128 181 softfloat_propagateNaNExtF80UI( 182 uint_fast16_t uiA64, 183 uint_fast64_t uiA0, 184 uint_fast16_t uiB64, 185 uint_fast64_t uiB0 186 ); 187 188 /*---------------------------------------------------------------------------- 189 | The bit pattern for a default generated 128-bit floating-point NaN. 190 *----------------------------------------------------------------------------*/ 191 #define defaultNaNF128UI64 UINT64_C( 0xFFFF800000000000 ) 192 #define defaultNaNF128UI0 UINT64_C( 0 ) 193 194 /*---------------------------------------------------------------------------- 195 | Returns true when the 128-bit unsigned integer formed from concatenating 196 | 64-bit `uiA64' and 64-bit `uiA0' has the bit pattern of a 128-bit floating- 197 | point signaling NaN. 198 | Note: This macro evaluates its arguments more than once. 199 *----------------------------------------------------------------------------*/ 200 #define softfloat_isSigNaNF128UI( uiA64, uiA0 ) ((((uiA64) & UINT64_C( 0x7FFF800000000000 )) == UINT64_C( 0x7FFF000000000000 )) && ((uiA0) || ((uiA64) & UINT64_C( 0x00007FFFFFFFFFFF )))) 201 202 /*---------------------------------------------------------------------------- 203 | Assuming the unsigned integer formed from concatenating `uiA64' and `uiA0' 204 | has the bit pattern of a 128-bit floating-point NaN, converts this NaN to 205 | the common NaN form, and stores the resulting common NaN at the location 206 | pointed to by `zPtr'. If the NaN is a signaling NaN, the invalid exception 207 | is raised. 208 *----------------------------------------------------------------------------*/ 209 void 210 softfloat_f128UIToCommonNaN( 211 uint_fast64_t uiA64, uint_fast64_t uiA0, struct commonNaN *zPtr ); 212 213 /*---------------------------------------------------------------------------- 214 | Converts the common NaN pointed to by `aPtr' into a 128-bit floating-point 215 | NaN, and returns the bit pattern of this value as an unsigned integer. 216 *----------------------------------------------------------------------------*/ 217 struct uint128 softfloat_commonNaNToF128UI( const struct commonNaN * ); 218 219 /*---------------------------------------------------------------------------- 220 | Interpreting the unsigned integer formed from concatenating `uiA64' and 221 | `uiA0' as a 128-bit floating-point value, and likewise interpreting the 222 | unsigned integer formed from concatenating `uiB64' and `uiB0' as another 223 | 128-bit floating-point value, and assuming at least on of these floating- 224 | point values is a NaN, returns the bit pattern of the combined NaN result. 225 | If either original floating-point value is a signaling NaN, the invalid 226 | exception is raised. 227 *----------------------------------------------------------------------------*/ 228 struct uint128 229 softfloat_propagateNaNF128UI( 230 uint_fast64_t uiA64, 231 uint_fast64_t uiA0, 232 uint_fast64_t uiB64, 233 uint_fast64_t uiB0 234 ); 235 236 #else 237 238 /*---------------------------------------------------------------------------- 239 | The following functions are needed only when `SOFTFLOAT_FAST_INT64' is not 240 | defined. 241 *----------------------------------------------------------------------------*/ 242 243 /*---------------------------------------------------------------------------- 244 | Assuming the 80-bit extended floating-point value pointed to by `aSPtr' is 245 | a NaN, converts this NaN to the common NaN form, and stores the resulting 246 | common NaN at the location pointed to by `zPtr'. If the NaN is a signaling 247 | NaN, the invalid exception is raised. 248 *----------------------------------------------------------------------------*/ 249 void 250 softfloat_extF80MToCommonNaN( 251 const struct extFloat80M *aSPtr, struct commonNaN *zPtr ); 252 253 /*---------------------------------------------------------------------------- 254 | Converts the common NaN pointed to by `aPtr' into an 80-bit extended 255 | floating-point NaN, and stores this NaN at the location pointed to by 256 | `zSPtr'. 257 *----------------------------------------------------------------------------*/ 258 void 259 softfloat_commonNaNToExtF80M( 260 const struct commonNaN *aPtr, struct extFloat80M *zSPtr ); 261 262 /*---------------------------------------------------------------------------- 263 | Assuming at least one of the two 80-bit extended floating-point values 264 | pointed to by `aSPtr' and `bSPtr' is a NaN, stores the combined NaN result 265 | at the location pointed to by `zSPtr'. If either original floating-point 266 | value is a signaling NaN, the invalid exception is raised. 267 *----------------------------------------------------------------------------*/ 268 void 269 softfloat_propagateNaNExtF80M( 270 const struct extFloat80M *aSPtr, 271 const struct extFloat80M *bSPtr, 272 struct extFloat80M *zSPtr 273 ); 274 275 /*---------------------------------------------------------------------------- 276 | The bit pattern for a default generated 128-bit floating-point NaN. 277 *----------------------------------------------------------------------------*/ 278 #define defaultNaNF128UI96 0xFFFF8000 279 #define defaultNaNF128UI64 0 280 #define defaultNaNF128UI32 0 281 #define defaultNaNF128UI0 0 282 283 /*---------------------------------------------------------------------------- 284 | Assuming the 128-bit floating-point value pointed to by `aWPtr' is a NaN, 285 | converts this NaN to the common NaN form, and stores the resulting common 286 | NaN at the location pointed to by `zPtr'. If the NaN is a signaling NaN, 287 | the invalid exception is raised. Argument `aWPtr' points to an array of 288 | four 32-bit elements that concatenate in the platform's normal endian order 289 | to form a 128-bit floating-point value. 290 *----------------------------------------------------------------------------*/ 291 void 292 softfloat_f128MToCommonNaN( const uint32_t *aWPtr, struct commonNaN *zPtr ); 293 294 /*---------------------------------------------------------------------------- 295 | Converts the common NaN pointed to by `aPtr' into a 128-bit floating-point 296 | NaN, and stores this NaN at the location pointed to by `zWPtr'. Argument 297 | `zWPtr' points to an array of four 32-bit elements that concatenate in the 298 | platform's normal endian order to form a 128-bit floating-point value. 299 *----------------------------------------------------------------------------*/ 300 void 301 softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr ); 302 303 /*---------------------------------------------------------------------------- 304 | Assuming at least one of the two 128-bit floating-point values pointed to by 305 | `aWPtr' and `bWPtr' is a NaN, stores the combined NaN result at the location 306 | pointed to by `zWPtr'. If either original floating-point value is a 307 | signaling NaN, the invalid exception is raised. Each of `aWPtr', `bWPtr', 308 | and `zWPtr' points to an array of four 32-bit elements that concatenate in 309 | the platform's normal endian order to form a 128-bit floating-point value. 310 *----------------------------------------------------------------------------*/ 311 void 312 softfloat_propagateNaNF128M( 313 const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr ); 314 315 #endif 316 317 #endif 318 319