[sim] integrated SoftFloat-3 with ISA sim; removed SoftFloat-2b
[riscv-isa-sim.git] / softfloat / softfloat.h
1
2 #ifndef softfloat_h
3 #define softfloat_h
4
5 /*** UPDATE COMMENTS. ***/
6
7 /*============================================================================
8
9 This C header file is part of the SoftFloat IEEE Floating-point Arithmetic
10 Package, Release 2b.
11
12 Written by John R. Hauser. This work was made possible in part by the
13 International Computer Science Institute, located at Suite 600, 1947 Center
14 Street, Berkeley, California 94704. Funding was partially provided by the
15 National Science Foundation under grant MIP-9311980. The original version
16 of this code was written as part of a project to build a fixed-point vector
17 processor in collaboration with the University of California at Berkeley,
18 overseen by Profs. Nelson Morgan and John Wawrzynek. More information
19 is available through the Web page `http://www.cs.berkeley.edu/~jhauser/
20 arithmetic/SoftFloat.html'.
21
22 THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort has
23 been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT TIMES
24 RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO PERSONS
25 AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ALL LOSSES,
26 COSTS, OR OTHER PROBLEMS THEY INCUR DUE TO THE SOFTWARE, AND WHO FURTHERMORE
27 EFFECTIVELY INDEMNIFY JOHN HAUSER AND THE INTERNATIONAL COMPUTER SCIENCE
28 INSTITUTE (possibly via similar legal warning) AGAINST ALL LOSSES, COSTS, OR
29 OTHER PROBLEMS INCURRED BY THEIR CUSTOMERS AND CLIENTS DUE TO THE SOFTWARE.
30
31 Derivative works are acceptable, even for commercial purposes, so long as
32 (1) the source code for the derivative work includes prominent notice that
33 the work is derivative, and (2) the source code includes prominent notice with
34 these four paragraphs for those parts of this code that are retained.
35
36 =============================================================================*/
37
38 #include "softfloat_types.h"
39
40 /*----------------------------------------------------------------------------
41 | Software floating-point underflow tininess-detection mode.
42 *----------------------------------------------------------------------------*/
43 extern int_fast8_t softfloat_detectTininess;
44 enum {
45 softfloat_tininess_beforeRounding = 0,
46 softfloat_tininess_afterRounding = 1
47 };
48
49 /*----------------------------------------------------------------------------
50 | Software floating-point rounding mode.
51 *----------------------------------------------------------------------------*/
52 extern int_fast8_t softfloat_roundingMode;
53 enum {
54 softfloat_round_nearest_even = 0,
55 softfloat_round_minMag = 1,
56 softfloat_round_min = 2,
57 softfloat_round_max = 3,
58 softfloat_round_nearest_maxMag = 4
59 };
60
61 /*----------------------------------------------------------------------------
62 | Software floating-point exception flags.
63 *----------------------------------------------------------------------------*/
64 extern int_fast8_t softfloat_exceptionFlags;
65 enum {
66 softfloat_flag_inexact = 1,
67 softfloat_flag_underflow = 2,
68 softfloat_flag_overflow = 4,
69 softfloat_flag_infinity = 8,
70 softfloat_flag_invalid = 16
71 };
72
73 /*----------------------------------------------------------------------------
74 | Routine to raise any or all of the software floating-point exception flags.
75 *----------------------------------------------------------------------------*/
76 void softfloat_raiseFlags( int_fast8_t );
77
78 /*----------------------------------------------------------------------------
79 | Integer-to-floating-point conversion routines.
80 *----------------------------------------------------------------------------*/
81 float32_t ui32_to_f32( uint_fast32_t );
82 float64_t ui32_to_f64( uint_fast32_t );
83 floatx80_t ui32_to_fx80( uint_fast32_t );
84 float128_t ui32_to_f128( uint_fast32_t );
85 float32_t ui64_to_f32( uint_fast64_t );
86 float64_t ui64_to_f64( uint_fast64_t );
87 floatx80_t ui64_to_fx80( uint_fast64_t );
88 float128_t ui64_to_f128( uint_fast64_t );
89 float32_t i32_to_f32( int_fast32_t );
90 float64_t i32_to_f64( int_fast32_t );
91 floatx80_t i32_to_fx80( int_fast32_t );
92 float128_t i32_to_f128( int_fast32_t );
93 float32_t i64_to_f32( int_fast64_t );
94 float64_t i64_to_f64( int_fast64_t );
95 floatx80_t i64_to_fx80( int_fast64_t );
96 float128_t i64_to_f128( int_fast64_t );
97
98 /*----------------------------------------------------------------------------
99 | 32-bit (single-precision) floating-point operations.
100 *----------------------------------------------------------------------------*/
101 uint_fast32_t f32_to_ui32( float32_t, int_fast8_t, bool );
102 uint_fast64_t f32_to_ui64( float32_t, int_fast8_t, bool );
103 int_fast32_t f32_to_i32( float32_t, int_fast8_t, bool );
104 int_fast64_t f32_to_i64( float32_t, int_fast8_t, bool );
105 uint_fast32_t f32_to_ui32_r_minMag( float32_t, bool );
106 uint_fast64_t f32_to_ui64_r_minMag( float32_t, bool );
107 int_fast32_t f32_to_i32_r_minMag( float32_t, bool );
108 int_fast64_t f32_to_i64_r_minMag( float32_t, bool );
109 float64_t f32_to_f64( float32_t );
110 floatx80_t f32_to_fx80( float32_t );
111 float128_t f32_to_f128( float32_t );
112 float32_t f32_roundToInt( float32_t, int_fast8_t, bool );
113 float32_t f32_add( float32_t, float32_t );
114 float32_t f32_sub( float32_t, float32_t );
115 float32_t f32_mul( float32_t, float32_t );
116 float32_t f32_mulAdd( float32_t, float32_t, float32_t );
117 float32_t f32_div( float32_t, float32_t );
118 float32_t f32_rem( float32_t, float32_t );
119 float32_t f32_sqrt( float32_t );
120 bool f32_eq( float32_t, float32_t );
121 bool f32_le( float32_t, float32_t );
122 bool f32_lt( float32_t, float32_t );
123 bool f32_eq_signaling( float32_t, float32_t );
124 bool f32_le_quiet( float32_t, float32_t );
125 bool f32_lt_quiet( float32_t, float32_t );
126 bool f32_isSignalingNaN( float32_t );
127
128 /*----------------------------------------------------------------------------
129 | 64-bit (double-precision) floating-point operations.
130 *----------------------------------------------------------------------------*/
131 uint_fast32_t f64_to_ui32( float64_t, int_fast8_t, bool );
132 uint_fast64_t f64_to_ui64( float64_t, int_fast8_t, bool );
133 int_fast32_t f64_to_i32( float64_t, int_fast8_t, bool );
134 int_fast64_t f64_to_i64( float64_t, int_fast8_t, bool );
135 uint_fast32_t f64_to_ui32_r_minMag( float64_t, bool );
136 uint_fast64_t f64_to_ui64_r_minMag( float64_t, bool );
137 int_fast32_t f64_to_i32_r_minMag( float64_t, bool );
138 int_fast64_t f64_to_i64_r_minMag( float64_t, bool );
139 float32_t f64_to_f32( float64_t );
140 floatx80_t f64_to_fx80( float64_t );
141 float128_t f64_to_f128( float64_t );
142 float64_t f64_roundToInt( float64_t, int_fast8_t, bool );
143 float64_t f64_add( float64_t, float64_t );
144 float64_t f64_sub( float64_t, float64_t );
145 float64_t f64_mul( float64_t, float64_t );
146 float64_t f64_mulAdd( float64_t, float64_t, float64_t );
147 float64_t f64_div( float64_t, float64_t );
148 float64_t f64_rem( float64_t, float64_t );
149 float64_t f64_sqrt( float64_t );
150 bool f64_eq( float64_t, float64_t );
151 bool f64_le( float64_t, float64_t );
152 bool f64_lt( float64_t, float64_t );
153 bool f64_eq_signaling( float64_t, float64_t );
154 bool f64_le_quiet( float64_t, float64_t );
155 bool f64_lt_quiet( float64_t, float64_t );
156 bool f64_isSignalingNaN( float64_t );
157
158 /*----------------------------------------------------------------------------
159 | Extended double-precision rounding precision. Valid values are 32, 64, and
160 | 80.
161 *----------------------------------------------------------------------------*/
162 extern int_fast8_t floatx80_roundingPrecision;
163
164 /*----------------------------------------------------------------------------
165 | Extended double-precision floating-point operations.
166 *----------------------------------------------------------------------------*/
167 uint_fast32_t fx80_to_ui32( floatx80_t, int_fast8_t, bool );
168 uint_fast64_t fx80_to_ui64( floatx80_t, int_fast8_t, bool );
169 int_fast32_t fx80_to_i32( floatx80_t, int_fast8_t, bool );
170 int_fast64_t fx80_to_i64( floatx80_t, int_fast8_t, bool );
171 uint_fast32_t fx80_to_ui32_r_minMag( floatx80_t, bool );
172 uint_fast64_t fx80_to_ui64_r_minMag( floatx80_t, bool );
173 int_fast32_t fx80_to_i32_r_minMag( floatx80_t, bool );
174 int_fast64_t fx80_to_i64_r_minMag( floatx80_t, bool );
175 float32_t fx80_to_f32( floatx80_t );
176 float64_t fx80_to_f64( floatx80_t );
177 float128_t fx80_to_f128( floatx80_t );
178 floatx80_t fx80_roundToInt( floatx80_t, int_fast8_t, bool );
179 floatx80_t fx80_add( floatx80_t, floatx80_t );
180 floatx80_t fx80_sub( floatx80_t, floatx80_t );
181 floatx80_t fx80_mul( floatx80_t, floatx80_t );
182 floatx80_t fx80_mulAdd( floatx80_t, floatx80_t, floatx80_t );
183 floatx80_t fx80_div( floatx80_t, floatx80_t );
184 floatx80_t fx80_rem( floatx80_t, floatx80_t );
185 floatx80_t fx80_sqrt( floatx80_t );
186 bool fx80_eq( floatx80_t, floatx80_t );
187 bool fx80_le( floatx80_t, floatx80_t );
188 bool fx80_lt( floatx80_t, floatx80_t );
189 bool fx80_eq_signaling( floatx80_t, floatx80_t );
190 bool fx80_le_quiet( floatx80_t, floatx80_t );
191 bool fx80_lt_quiet( floatx80_t, floatx80_t );
192 bool fx80_isSignalingNaN( floatx80_t );
193
194 /*----------------------------------------------------------------------------
195 | 128-bit (quadruple-precision) floating-point operations.
196 *----------------------------------------------------------------------------*/
197 uint_fast32_t f128_to_ui32( float128_t, int_fast8_t, bool );
198 uint_fast64_t f128_to_ui64( float128_t, int_fast8_t, bool );
199 int_fast32_t f128_to_i32( float128_t, int_fast8_t, bool );
200 int_fast64_t f128_to_i64( float128_t, int_fast8_t, bool );
201 uint_fast32_t f128_to_ui32_r_minMag( float128_t, bool );
202 uint_fast64_t f128_to_ui64_r_minMag( float128_t, bool );
203 int_fast32_t f128_to_i32_r_minMag( float128_t, bool );
204 int_fast64_t f128_to_i64_r_minMag( float128_t, bool );
205 float32_t f128_to_f32( float128_t );
206 float64_t f128_to_f64( float128_t );
207 floatx80_t f128_to_fx80( float128_t );
208 float128_t f128_roundToInt( float128_t, int_fast8_t, bool );
209 float128_t f128_add( float128_t, float128_t );
210 float128_t f128_sub( float128_t, float128_t );
211 float128_t f128_mul( float128_t, float128_t );
212 float128_t f128_mulAdd( float128_t, float128_t, float128_t );
213 float128_t f128_div( float128_t, float128_t );
214 float128_t f128_rem( float128_t, float128_t );
215 float128_t f128_sqrt( float128_t );
216 bool f128_eq( float128_t, float128_t );
217 bool f128_le( float128_t, float128_t );
218 bool f128_lt( float128_t, float128_t );
219 bool f128_eq_signaling( float128_t, float128_t );
220 bool f128_le_quiet( float128_t, float128_t );
221 bool f128_lt_quiet( float128_t, float128_t );
222 bool f128_isSignalingNaN( float128_t );
223
224 #endif
225