| 1 |
|
| 2 |
/*============================================================================ |
| 3 |
|
| 4 |
This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic |
| 5 |
Package, Release 3e, by John R. Hauser. |
| 6 |
|
| 7 |
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 The Regents of the |
| 8 |
University of California. 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/primitiveTypes.h" |
| 43 |
#include "softfloat.h" |
| 44 |
|
| 45 |
/*---------------------------------------------------------------------------- |
| 46 |
| Default value for 'softfloat_detectTininess'. |
| 47 |
*----------------------------------------------------------------------------*/ |
| 48 |
#define init_detectTininess softfloat_tininess_beforeRounding |
| 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 0 |
| 57 |
#define i32_fromPosOverflow 0x7FFFFFFF |
| 58 |
#define i32_fromNegOverflow (-0x7FFFFFFF - 1) |
| 59 |
#define i32_fromNaN 0 |
| 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 0 |
| 68 |
#define i64_fromPosOverflow INT64_C( 0x7FFFFFFFFFFFFFFF ) |
| 69 |
#define i64_fromNegOverflow (-INT64_C( 0x7FFFFFFFFFFFFFFF ) - 1) |
| 70 |
#define i64_fromNaN 0 |
| 71 |
|
| 72 |
/*---------------------------------------------------------------------------- |
| 73 |
| "Common NaN" structure, used to transfer NaN representations from one format |
| 74 |
| to another. |
| 75 |
*----------------------------------------------------------------------------*/ |
| 76 |
struct commonNaN { |
| 77 |
bool sign; |
| 78 |
#ifdef LITTLEENDIAN |
| 79 |
uint64_t v0, v64; |
| 80 |
#else |
| 81 |
uint64_t v64, v0; |
| 82 |
#endif |
| 83 |
}; |
| 84 |
|
| 85 |
/*---------------------------------------------------------------------------- |
| 86 |
| The bit pattern for a default generated 32-bit floating-point NaN. |
| 87 |
*----------------------------------------------------------------------------*/ |
| 88 |
#define defaultNaNF32UI 0x7FC00000 |
| 89 |
|
| 90 |
/*---------------------------------------------------------------------------- |
| 91 |
| Returns true when 32-bit unsigned integer 'uiA' has the bit pattern of a |
| 92 |
| 32-bit floating-point signaling NaN. |
| 93 |
| Note: This macro evaluates its argument more than once. |
| 94 |
*----------------------------------------------------------------------------*/ |
| 95 |
#define softfloat_isSigNaNF32UI( uiA ) ((((uiA) & 0x7FC00000) == 0x7F800000) && ((uiA) & 0x003FFFFF)) |
| 96 |
|
| 97 |
/*---------------------------------------------------------------------------- |
| 98 |
| Assuming 'uiA' has the bit pattern of a 32-bit floating-point NaN, converts |
| 99 |
| this NaN to the common NaN form, and stores the resulting common NaN at the |
| 100 |
| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid |
| 101 |
| exception is raised. |
| 102 |
*----------------------------------------------------------------------------*/ |
| 103 |
void softfloat_f32UIToCommonNaN( uint_fast32_t uiA, struct commonNaN *zPtr ); |
| 104 |
|
| 105 |
/*---------------------------------------------------------------------------- |
| 106 |
| Converts the common NaN pointed to by 'aPtr' into a 32-bit floating-point |
| 107 |
| NaN, and returns the bit pattern of this value as an unsigned integer. |
| 108 |
*----------------------------------------------------------------------------*/ |
| 109 |
uint_fast32_t softfloat_commonNaNToF32UI( const struct commonNaN *aPtr ); |
| 110 |
|
| 111 |
/*---------------------------------------------------------------------------- |
| 112 |
| Interpreting 'uiA' and 'uiB' as the bit patterns of two 32-bit floating- |
| 113 |
| point values, at least one of which is a NaN, returns the bit pattern of |
| 114 |
| the combined NaN result. If either 'uiA' or 'uiB' has the pattern of a |
| 115 |
| signaling NaN, the invalid exception is raised. |
| 116 |
*----------------------------------------------------------------------------*/ |
| 117 |
uint_fast32_t |
| 118 |
softfloat_propagateNaNF32UI( uint_fast32_t uiA, uint_fast32_t uiB ); |
| 119 |
|
| 120 |
/*---------------------------------------------------------------------------- |
| 121 |
| The bit pattern for a default generated 64-bit floating-point NaN. |
| 122 |
*----------------------------------------------------------------------------*/ |
| 123 |
#define defaultNaNF64UI UINT64_C( 0x7FF8000000000000 ) |
| 124 |
|
| 125 |
/*---------------------------------------------------------------------------- |
| 126 |
| The bit pattern for a default generated 64-bit floating-point NaN. |
| 127 |
*----------------------------------------------------------------------------*/ |
| 128 |
#define defaultNaNF64UI UINT64_C( 0x7FF8000000000000 ) |
| 129 |
|
| 130 |
/*---------------------------------------------------------------------------- |
| 131 |
| Returns true when 64-bit unsigned integer 'uiA' has the bit pattern of a |
| 132 |
| 64-bit floating-point signaling NaN. |
| 133 |
| Note: This macro evaluates its argument more than once. |
| 134 |
*----------------------------------------------------------------------------*/ |
| 135 |
#define softfloat_isSigNaNF64UI( uiA ) ((((uiA) & UINT64_C( 0x7FF8000000000000 )) == UINT64_C( 0x7FF0000000000000 )) && ((uiA) & UINT64_C( 0x0007FFFFFFFFFFFF ))) |
| 136 |
|
| 137 |
/*---------------------------------------------------------------------------- |
| 138 |
| Assuming 'uiA' has the bit pattern of a 64-bit floating-point NaN, converts |
| 139 |
| this NaN to the common NaN form, and stores the resulting common NaN at the |
| 140 |
| location pointed to by 'zPtr'. If the NaN is a signaling NaN, the invalid |
| 141 |
| exception is raised. |
| 142 |
*----------------------------------------------------------------------------*/ |
| 143 |
void softfloat_f64UIToCommonNaN( uint_fast64_t uiA, struct commonNaN *zPtr ); |
| 144 |
|
| 145 |
/*---------------------------------------------------------------------------- |
| 146 |
| Converts the common NaN pointed to by 'aPtr' into a 64-bit floating-point |
| 147 |
| NaN, and returns the bit pattern of this value as an unsigned integer. |
| 148 |
*----------------------------------------------------------------------------*/ |
| 149 |
uint_fast64_t softfloat_commonNaNToF64UI( const struct commonNaN *aPtr ); |
| 150 |
|
| 151 |
/*---------------------------------------------------------------------------- |
| 152 |
| Interpreting 'uiA' and 'uiB' as the bit patterns of two 64-bit floating- |
| 153 |
| point values, at least one of which is a NaN, returns the bit pattern of |
| 154 |
| the combined NaN result. If either 'uiA' or 'uiB' has the pattern of a |
| 155 |
| signaling NaN, the invalid exception is raised. |
| 156 |
*----------------------------------------------------------------------------*/ |
| 157 |
uint_fast64_t |
| 158 |
softfloat_propagateNaNF64UI( uint_fast64_t uiA, uint_fast64_t uiB ); |
| 159 |
|
| 160 |
#endif |