1 2/*============================================================================ 3 4This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic 5Package, Release 3e, by John R. Hauser. 6 7Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2018 The Regents of the 8University of California. All rights reserved. 9 10Redistribution and use in source and binary forms, with or without 11modification, 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 24THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY 25EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE 27DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 28DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31ON 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 33SOFTWARE, 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 "primitiveTypes.h" 43#include "softfloat.h" 44 45/*---------------------------------------------------------------------------- 46| Default value for 'softfloat_detectTininess'. 47*----------------------------------------------------------------------------*/ 48#define init_detectTininess softfloat_tininess_afterRounding 49 50/*---------------------------------------------------------------------------- 51| The values to return on conversions to 32-bit integer formats that raise an 52| invalid exception. 53*----------------------------------------------------------------------------*/ 54#define ui32_fromPosOverflow 0xFFFFFFFF 55#define ui32_fromNegOverflow 0 56#define ui32_fromNaN 0xFFFFFFFF 57#define i32_fromPosOverflow 0x7FFFFFFF 58#define i32_fromNegOverflow (-0x7FFFFFFF - 1) 59#define i32_fromNaN 0x7FFFFFFF 60 61/*---------------------------------------------------------------------------- 62| The values to return on conversions to 64-bit integer formats that raise an 63| invalid exception. 64*----------------------------------------------------------------------------*/ 65#define ui64_fromPosOverflow UINT64_C( 0xFFFFFFFFFFFFFFFF ) 66#define ui64_fromNegOverflow 0 67#define ui64_fromNaN UINT64_C( 0xFFFFFFFFFFFFFFFF ) 68#define i64_fromPosOverflow INT64_C( 0x7FFFFFFFFFFFFFFF ) 69#define i64_fromNegOverflow (-INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1) 70#define i64_fromNaN INT64_C( 0x7FFFFFFFFFFFFFFF ) 71 72/*---------------------------------------------------------------------------- 73| "Common NaN" structure, used to transfer NaN representations from one format 74| to another. 75*----------------------------------------------------------------------------*/ 76struct commonNaN { char _unused; }; 77 78/*---------------------------------------------------------------------------- 79| The bit pattern for a default generated 16-bit floating-point NaN. 80*----------------------------------------------------------------------------*/ 81#define defaultNaNF16UI 0x7E00 82 83/*---------------------------------------------------------------------------- 84| Returns true when 16-bit unsigned integer 'uiA' has the bit pattern of a 85| 16-bit floating-point signaling NaN. 86| Note: This macro evaluates its argument more than once. 87*----------------------------------------------------------------------------*/ 88#define softfloat_isSigNaNF16UI( uiA ) ((((uiA) & 0x7E00) == 0x7C00) && ((uiA) & 0x01FF)) 89 90/*---------------------------------------------------------------------------- 91| Assuming 'uiA' has the bit pattern of a 16-bit floating-point NaN, converts 92| this NaN to the common NaN form, and stores the resulting common NaN at the 93| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid 94| exception is raised. 95*----------------------------------------------------------------------------*/ 96#define softfloat_f16UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & 0x0200) ) softfloat_raiseFlags( softfloat_flag_invalid ) 97 98/*---------------------------------------------------------------------------- 99| Converts the common NaN pointed to by 'aPtr' into a 16-bit floating-point 100| NaN, and returns the bit pattern of this value as an unsigned integer. 101*----------------------------------------------------------------------------*/ 102#define softfloat_commonNaNToF16UI( aPtr ) ((uint_fast16_t) defaultNaNF16UI) 103 104/*---------------------------------------------------------------------------- 105| Interpreting 'uiA' and 'uiB' as the bit patterns of two 16-bit floating- 106| point values, at least one of which is a NaN, returns the bit pattern of 107| the combined NaN result. If either 'uiA' or 'uiB' has the pattern of a 108| signaling NaN, the invalid exception is raised. 109*----------------------------------------------------------------------------*/ 110uint_fast16_t 111 softfloat_propagateNaNF16UI( uint_fast16_t uiA, uint_fast16_t uiB ); 112 113/*---------------------------------------------------------------------------- 114| The bit pattern for a default generated 32-bit floating-point NaN. 115*----------------------------------------------------------------------------*/ 116#define defaultNaNF32UI 0x7FC00000 117 118/*---------------------------------------------------------------------------- 119| Returns true when 32-bit unsigned integer 'uiA' has the bit pattern of a 120| 32-bit floating-point signaling NaN. 121| Note: This macro evaluates its argument more than once. 122*----------------------------------------------------------------------------*/ 123#define softfloat_isSigNaNF32UI( uiA ) ((((uiA) & 0x7FC00000) == 0x7F800000) && ((uiA) & 0x003FFFFF)) 124 125/*---------------------------------------------------------------------------- 126| Assuming 'uiA' has the bit pattern of a 32-bit floating-point NaN, converts 127| this NaN to the common NaN form, and stores the resulting common NaN at the 128| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid 129| exception is raised. 130*----------------------------------------------------------------------------*/ 131#define softfloat_f32UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & 0x00400000) ) softfloat_raiseFlags( softfloat_flag_invalid ) 132 133/*---------------------------------------------------------------------------- 134| Converts the common NaN pointed to by 'aPtr' into a 32-bit floating-point 135| NaN, and returns the bit pattern of this value as an unsigned integer. 136*----------------------------------------------------------------------------*/ 137#define softfloat_commonNaNToF32UI( aPtr ) ((uint_fast32_t) defaultNaNF32UI) 138 139/*---------------------------------------------------------------------------- 140| Interpreting 'uiA' and 'uiB' as the bit patterns of two 32-bit floating- 141| point values, at least one of which is a NaN, returns the bit pattern of 142| the combined NaN result. If either 'uiA' or 'uiB' has the pattern of a 143| signaling NaN, the invalid exception is raised. 144*----------------------------------------------------------------------------*/ 145uint_fast32_t 146 softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB ); 147 148/*---------------------------------------------------------------------------- 149| The bit pattern for a default generated 64-bit floating-point NaN. 150*----------------------------------------------------------------------------*/ 151#define defaultNaNF64UI UINT64_C( 0x7FF8000000000000 ) 152 153/*---------------------------------------------------------------------------- 154| Returns true when 64-bit unsigned integer 'uiA' has the bit pattern of a 155| 64-bit floating-point signaling NaN. 156| Note: This macro evaluates its argument more than once. 157*----------------------------------------------------------------------------*/ 158#define softfloat_isSigNaNF64UI( uiA ) ((((uiA) & UINT64_C( 0x7FF8000000000000 )) == UINT64_C( 0x7FF0000000000000 )) && ((uiA) & UINT64_C( 0x0007FFFFFFFFFFFF ))) 159 160/*---------------------------------------------------------------------------- 161| Assuming 'uiA' has the bit pattern of a 64-bit floating-point NaN, converts 162| this NaN to the common NaN form, and stores the resulting common NaN at the 163| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid 164| exception is raised. 165*----------------------------------------------------------------------------*/ 166#define softfloat_f64UIToCommonNaN( uiA, zPtr ) if ( ! ((uiA) & UINT64_C( 0x0008000000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid ) 167 168/*---------------------------------------------------------------------------- 169| Converts the common NaN pointed to by 'aPtr' into a 64-bit floating-point 170| NaN, and returns the bit pattern of this value as an unsigned integer. 171*----------------------------------------------------------------------------*/ 172#define softfloat_commonNaNToF64UI( aPtr ) ((uint_fast64_t) defaultNaNF64UI) 173 174/*---------------------------------------------------------------------------- 175| Interpreting 'uiA' and 'uiB' as the bit patterns of two 64-bit floating- 176| point values, at least one of which is a NaN, returns the bit pattern of 177| the combined NaN result. If either 'uiA' or 'uiB' has the pattern of a 178| signaling NaN, the invalid exception is raised. 179*----------------------------------------------------------------------------*/ 180uint_fast64_t 181 softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB ); 182 183/*---------------------------------------------------------------------------- 184| The bit pattern for a default generated 80-bit extended floating-point NaN. 185*----------------------------------------------------------------------------*/ 186#define defaultNaNExtF80UI64 0x7FFF 187#define defaultNaNExtF80UI0 UINT64_C( 0xC000000000000000 ) 188 189/*---------------------------------------------------------------------------- 190| Returns true when the 80-bit unsigned integer formed from concatenating 191| 16-bit 'uiA64' and 64-bit 'uiA0' has the bit pattern of an 80-bit extended 192| floating-point signaling NaN. 193| Note: This macro evaluates its arguments more than once. 194*----------------------------------------------------------------------------*/ 195#define softfloat_isSigNaNExtF80UI( uiA64, uiA0 ) ((((uiA64) & 0x7FFF) == 0x7FFF) && ! ((uiA0) & UINT64_C( 0x4000000000000000 )) && ((uiA0) & UINT64_C( 0x3FFFFFFFFFFFFFFF ))) 196 197#ifdef SOFTFLOAT_FAST_INT64 198 199/*---------------------------------------------------------------------------- 200| The following functions are needed only when 'SOFTFLOAT_FAST_INT64' is 201| defined. 202*----------------------------------------------------------------------------*/ 203 204/*---------------------------------------------------------------------------- 205| Assuming the unsigned integer formed from concatenating 'uiA64' and 'uiA0' 206| has the bit pattern of an 80-bit extended floating-point NaN, converts 207| this NaN to the common NaN form, and stores the resulting common NaN at the 208| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid 209| exception is raised. 210*----------------------------------------------------------------------------*/ 211#define softfloat_extF80UIToCommonNaN( uiA64, uiA0, zPtr ) if ( ! ((uiA0) & UINT64_C( 0x4000000000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid ) 212 213/*---------------------------------------------------------------------------- 214| Converts the common NaN pointed to by 'aPtr' into an 80-bit extended 215| floating-point NaN, and returns the bit pattern of this value as an unsigned 216| integer. 217*----------------------------------------------------------------------------*/ 218#if defined INLINE && ! defined softfloat_commonNaNToExtF80UI 219INLINE 220struct uint128 softfloat_commonNaNToExtF80UI( const struct commonNaN *aPtr ) 221{ 222 struct uint128 uiZ; 223 uiZ.v64 = defaultNaNExtF80UI64; 224 uiZ.v0 = defaultNaNExtF80UI0; 225 return uiZ; 226} 227#else 228struct uint128 softfloat_commonNaNToExtF80UI( const struct commonNaN *aPtr ); 229#endif 230 231/*---------------------------------------------------------------------------- 232| Interpreting the unsigned integer formed from concatenating 'uiA64' and 233| 'uiA0' as an 80-bit extended floating-point value, and likewise interpreting 234| the unsigned integer formed from concatenating 'uiB64' and 'uiB0' as another 235| 80-bit extended floating-point value, and assuming at least on of these 236| floating-point values is a NaN, returns the bit pattern of the combined NaN 237| result. If either original floating-point value is a signaling NaN, the 238| invalid exception is raised. 239*----------------------------------------------------------------------------*/ 240struct uint128 241 softfloat_propagateNaNExtF80UI( 242 uint_fast16_t uiA64, 243 uint_fast64_t uiA0, 244 uint_fast16_t uiB64, 245 uint_fast64_t uiB0 246 ); 247 248/*---------------------------------------------------------------------------- 249| The bit pattern for a default generated 128-bit floating-point NaN. 250*----------------------------------------------------------------------------*/ 251#define defaultNaNF128UI64 UINT64_C( 0x7FFF800000000000 ) 252#define defaultNaNF128UI0 UINT64_C( 0 ) 253 254/*---------------------------------------------------------------------------- 255| Returns true when the 128-bit unsigned integer formed from concatenating 256| 64-bit 'uiA64' and 64-bit 'uiA0' has the bit pattern of a 128-bit floating- 257| point signaling NaN. 258| Note: This macro evaluates its arguments more than once. 259*----------------------------------------------------------------------------*/ 260#define softfloat_isSigNaNF128UI( uiA64, uiA0 ) ((((uiA64) & UINT64_C( 0x7FFF800000000000 )) == UINT64_C( 0x7FFF000000000000 )) && ((uiA0) || ((uiA64) & UINT64_C( 0x00007FFFFFFFFFFF )))) 261 262/*---------------------------------------------------------------------------- 263| Assuming the unsigned integer formed from concatenating 'uiA64' and 'uiA0' 264| has the bit pattern of a 128-bit floating-point NaN, converts this NaN to 265| the common NaN form, and stores the resulting common NaN at the location 266| pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid exception 267| is raised. 268*----------------------------------------------------------------------------*/ 269#define softfloat_f128UIToCommonNaN( uiA64, uiA0, zPtr ) if ( ! ((uiA64) & UINT64_C( 0x0000800000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid ) 270 271/*---------------------------------------------------------------------------- 272| Converts the common NaN pointed to by 'aPtr' into a 128-bit floating-point 273| NaN, and returns the bit pattern of this value as an unsigned integer. 274*----------------------------------------------------------------------------*/ 275#if defined INLINE && ! defined softfloat_commonNaNToF128UI 276INLINE 277struct uint128 softfloat_commonNaNToF128UI( const struct commonNaN *aPtr ) 278{ 279 struct uint128 uiZ; 280 uiZ.v64 = defaultNaNF128UI64; 281 uiZ.v0 = defaultNaNF128UI0; 282 return uiZ; 283} 284#else 285struct uint128 softfloat_commonNaNToF128UI( const struct commonNaN * ); 286#endif 287 288/*---------------------------------------------------------------------------- 289| Interpreting the unsigned integer formed from concatenating 'uiA64' and 290| 'uiA0' as a 128-bit floating-point value, and likewise interpreting the 291| unsigned integer formed from concatenating 'uiB64' and 'uiB0' as another 292| 128-bit floating-point value, and assuming at least on of these floating- 293| point values is a NaN, returns the bit pattern of the combined NaN result. 294| If either original floating-point value is a signaling NaN, the invalid 295| exception is raised. 296*----------------------------------------------------------------------------*/ 297struct uint128 298 softfloat_propagateNaNF128UI( 299 uint_fast64_t uiA64, 300 uint_fast64_t uiA0, 301 uint_fast64_t uiB64, 302 uint_fast64_t uiB0 303 ); 304 305#else 306 307/*---------------------------------------------------------------------------- 308| The following functions are needed only when 'SOFTFLOAT_FAST_INT64' is not 309| defined. 310*----------------------------------------------------------------------------*/ 311 312/*---------------------------------------------------------------------------- 313| Assuming the 80-bit extended floating-point value pointed to by 'aSPtr' is 314| a NaN, converts this NaN to the common NaN form, and stores the resulting 315| common NaN at the location pointed to by 'zPtr'. If the NaN is a signaling 316| NaN, the invalid exception is raised. 317*----------------------------------------------------------------------------*/ 318#define softfloat_extF80MToCommonNaN( aSPtr, zPtr ) if ( ! ((aSPtr)->signif & UINT64_C( 0x4000000000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid ) 319 320/*---------------------------------------------------------------------------- 321| Converts the common NaN pointed to by 'aPtr' into an 80-bit extended 322| floating-point NaN, and stores this NaN at the location pointed to by 323| 'zSPtr'. 324*----------------------------------------------------------------------------*/ 325#if defined INLINE && ! defined softfloat_commonNaNToExtF80M 326INLINE 327void 328 softfloat_commonNaNToExtF80M( 329 const struct commonNaN *aPtr, struct extFloat80M *zSPtr ) 330{ 331 zSPtr->signExp = defaultNaNExtF80UI64; 332 zSPtr->signif = defaultNaNExtF80UI0; 333} 334#else 335void 336 softfloat_commonNaNToExtF80M( 337 const struct commonNaN *aPtr, struct extFloat80M *zSPtr ); 338#endif 339 340/*---------------------------------------------------------------------------- 341| Assuming at least one of the two 80-bit extended floating-point values 342| pointed to by 'aSPtr' and 'bSPtr' is a NaN, stores the combined NaN result 343| at the location pointed to by 'zSPtr'. If either original floating-point 344| value is a signaling NaN, the invalid exception is raised. 345*----------------------------------------------------------------------------*/ 346void 347 softfloat_propagateNaNExtF80M( 348 const struct extFloat80M *aSPtr, 349 const struct extFloat80M *bSPtr, 350 struct extFloat80M *zSPtr 351 ); 352 353/*---------------------------------------------------------------------------- 354| The bit pattern for a default generated 128-bit floating-point NaN. 355*----------------------------------------------------------------------------*/ 356#define defaultNaNF128UI96 0x7FFF8000 357#define defaultNaNF128UI64 0 358#define defaultNaNF128UI32 0 359#define defaultNaNF128UI0 0 360 361/*---------------------------------------------------------------------------- 362| Assuming the 128-bit floating-point value pointed to by 'aWPtr' is a NaN, 363| converts this NaN to the common NaN form, and stores the resulting common 364| NaN at the location pointed to by 'zPtr'. If the NaN is a signaling NaN, 365| the invalid exception is raised. Argument 'aWPtr' points to an array of 366| four 32-bit elements that concatenate in the platform's normal endian order 367| to form a 128-bit floating-point value. 368*----------------------------------------------------------------------------*/ 369#define softfloat_f128MToCommonNaN( aWPtr, zPtr ) if ( ! ((aWPtr)[indexWordHi( 4 )] & UINT64_C( 0x0000800000000000 )) ) softfloat_raiseFlags( softfloat_flag_invalid ) 370 371/*---------------------------------------------------------------------------- 372| Converts the common NaN pointed to by 'aPtr' into a 128-bit floating-point 373| NaN, and stores this NaN at the location pointed to by 'zWPtr'. Argument 374| 'zWPtr' points to an array of four 32-bit elements that concatenate in the 375| platform's normal endian order to form a 128-bit floating-point value. 376*----------------------------------------------------------------------------*/ 377#if defined INLINE && ! defined softfloat_commonNaNToF128M 378INLINE 379void 380 softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr ) 381{ 382 zWPtr[indexWord( 4, 3 )] = defaultNaNF128UI96; 383 zWPtr[indexWord( 4, 2 )] = defaultNaNF128UI64; 384 zWPtr[indexWord( 4, 1 )] = defaultNaNF128UI32; 385 zWPtr[indexWord( 4, 0 )] = defaultNaNF128UI0; 386} 387#else 388void 389 softfloat_commonNaNToF128M( const struct commonNaN *aPtr, uint32_t *zWPtr ); 390#endif 391 392/*---------------------------------------------------------------------------- 393| Assuming at least one of the two 128-bit floating-point values pointed to by 394| 'aWPtr' and 'bWPtr' is a NaN, stores the combined NaN result at the location 395| pointed to by 'zWPtr'. If either original floating-point value is a 396| signaling NaN, the invalid exception is raised. Each of 'aWPtr', 'bWPtr', 397| and 'zWPtr' points to an array of four 32-bit elements that concatenate in 398| the platform's normal endian order to form a 128-bit floating-point value. 399*----------------------------------------------------------------------------*/ 400void 401 softfloat_propagateNaNF128M( 402 const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr ); 403 404#endif 405 406#endif 407 408