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