bf57bc988d30f92ec507635e27c76bce1ecb1127
[riscv-isa-sim.git] / softfloat_riscv / specialize.h
1
2 /*============================================================================
3
4 *** FIX.
5
6 This C source fragment is part of the SoftFloat IEC/IEEE Floating-point
7 Arithmetic Package, Release 2b.
8
9 Written by John R. Hauser. This work was made possible in part by the
10 International Computer Science Institute, located at Suite 600, 1947 Center
11 Street, Berkeley, California 94704. Funding was partially provided by the
12 National Science Foundation under grant MIP-9311980. The original version
13 of this code was written as part of a project to build a fixed-point vector
14 processor in collaboration with the University of California at Berkeley,
15 overseen by Profs. Nelson Morgan and John Wawrzynek. More information
16 is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
17 arithmetic/SoftFloat.html'.
18
19 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
20 been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
21 RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
22 AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
23 COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
24 EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
25 INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
26 OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
27
28 Derivative works are acceptable, even for commercial purposes, so long as
29 (1) the source code for the derivative work includes prominent notice that
30 the work is derivative, and (2) the source code includes prominent notice with
31 these four paragraphs for those parts of this code that are retained.
32
33 =============================================================================*/
34
35 #include <stdbool.h>
36 #include <stdint.h>
37
38 /*----------------------------------------------------------------------------
39 *----------------------------------------------------------------------------*/
40 #define init_detectTininess softfloat_tininess_beforeRounding;
41
42 /*----------------------------------------------------------------------------
43 | Structure used to transfer NaN representations from one format to another.
44 *----------------------------------------------------------------------------*/
45 struct commonNaN {
46 bool sign;
47 uint64_t v64, v0;
48 };
49
50 /*----------------------------------------------------------------------------
51 | The pattern for a default generated single-precision NaN.
52 *----------------------------------------------------------------------------*/
53 #define defaultNaNF32UI 0xFFFFFFFF
54
55 /*----------------------------------------------------------------------------
56 | Returns 1 if the single-precision floating-point value `a' is a signaling
57 | NaN; otherwise, returns 0.
58 *----------------------------------------------------------------------------*/
59 #if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL )
60 INLINE bool softfloat_isSigNaNF32UI( uint_fast32_t ui )
61 { return ( ( ui>>22 & 0x1FF ) == 0x1FE ) && ( ui & 0x003FFFFF ); }
62 #else
63 bool softfloat_isSigNaNF32UI( uint_fast32_t );
64 #endif
65
66 /*----------------------------------------------------------------------------
67 *----------------------------------------------------------------------------*/
68 struct commonNaN softfloat_f32UIToCommonNaN( uint_fast32_t );
69 #if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL )
70 INLINE uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN a )
71 { return (uint_fast32_t) a.sign<<31 | 0x7FFFFFFF; }
72 #else
73 uint_fast32_t softfloat_commonNaNToF32UI( struct commonNaN );
74 #endif
75
76 /*----------------------------------------------------------------------------
77 | Takes two single-precision floating-point values `a' and `b', one of which
78 | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
79 | signaling NaN, the invalid exception is raised.
80 *----------------------------------------------------------------------------*/
81 uint_fast32_t softfloat_propagateNaNF32UI( uint_fast32_t, uint_fast32_t );
82
83 /*----------------------------------------------------------------------------
84 | The pattern for a default generated double-precision NaN.
85 *----------------------------------------------------------------------------*/
86 #define defaultNaNF64UI UINT64_C(0xFFF8000000000000)
87
88 /*----------------------------------------------------------------------------
89 *----------------------------------------------------------------------------*/
90 #if defined INLINE_LEVEL && ( 1 <= INLINE_LEVEL )
91 INLINE bool softfloat_isSigNaNF64UI( uint_fast64_t ui )
92 {
93 return
94 ( ( ui>>51 & 0xFFF ) == 0xFFE )
95 && ( ui & UINT64_C( 0x0007FFFFFFFFFFFF ) );
96 }
97 #else
98 bool softfloat_isSigNaNF64UI( uint_fast64_t );
99 #endif
100
101 /*----------------------------------------------------------------------------
102 *----------------------------------------------------------------------------*/
103 /*** MIGHT BE INLINE'D. ***/
104 struct commonNaN softfloat_f64UIToCommonNaN( uint_fast64_t );
105 uint_fast64_t softfloat_commonNaNToF64UI( struct commonNaN );
106
107 /*----------------------------------------------------------------------------
108 | Takes two double-precision floating-point values `a' and `b', one of which
109 | is a NaN, and returns the appropriate NaN result. If either `a' or `b' is a
110 | signaling NaN, the invalid exception is raised.
111 *----------------------------------------------------------------------------*/
112 uint_fast64_t softfloat_propagateNaNF64UI( uint_fast64_t, uint_fast64_t );
113