3eddeed0343b13dc56d24a1dcc7456a2150ba28e
[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
132 /*----------------------------------------------------------------------------
133 | 64-bit (double-precision) floating-point operations.
134 *----------------------------------------------------------------------------*/
135 uint_fast32_t f64_to_ui32( float64_t, int_fast8_t, bool );
136 uint_fast64_t f64_to_ui64( float64_t, int_fast8_t, bool );
137 int_fast32_t f64_to_i32( float64_t, int_fast8_t, bool );
138 int_fast64_t f64_to_i64( float64_t, int_fast8_t, bool );
139 uint_fast32_t f64_to_ui32_r_minMag( float64_t, bool );
140 uint_fast64_t f64_to_ui64_r_minMag( float64_t, bool );
141 int_fast32_t f64_to_i32_r_minMag( float64_t, bool );
142 int_fast64_t f64_to_i64_r_minMag( float64_t, bool );
143 float32_t f64_to_f32( float64_t );
144 floatx80_t f64_to_fx80( float64_t );
145 float128_t f64_to_f128( float64_t );
146 float64_t f64_roundToInt( float64_t, int_fast8_t, bool );
147 float64_t f64_add( float64_t, float64_t );
148 float64_t f64_sub( float64_t, float64_t );
149 float64_t f64_mul( float64_t, float64_t );
150 float64_t f64_mulAdd( float64_t, float64_t, float64_t );
151 float64_t f64_div( float64_t, float64_t );
152 float64_t f64_rem( float64_t, float64_t );
153 float64_t f64_sqrt( float64_t );
154 bool f64_eq( float64_t, float64_t );
155 bool f64_le( float64_t, float64_t );
156 bool f64_lt( float64_t, float64_t );
157 bool f64_eq_signaling( float64_t, float64_t );
158 bool f64_le_quiet( float64_t, float64_t );
159 bool f64_lt_quiet( float64_t, float64_t );
160 bool f64_isSignalingNaN( float64_t );
161
162 /*----------------------------------------------------------------------------
163 | Extended double-precision rounding precision. Valid values are 32, 64, and
164 | 80.
165 *----------------------------------------------------------------------------*/
166 extern int_fast8_t floatx80_roundingPrecision;
167
168 /*----------------------------------------------------------------------------
169 | Extended double-precision floating-point operations.
170 *----------------------------------------------------------------------------*/
171 uint_fast32_t fx80_to_ui32( floatx80_t, int_fast8_t, bool );
172 uint_fast64_t fx80_to_ui64( floatx80_t, int_fast8_t, bool );
173 int_fast32_t fx80_to_i32( floatx80_t, int_fast8_t, bool );
174 int_fast64_t fx80_to_i64( floatx80_t, int_fast8_t, bool );
175 uint_fast32_t fx80_to_ui32_r_minMag( floatx80_t, bool );
176 uint_fast64_t fx80_to_ui64_r_minMag( floatx80_t, bool );
177 int_fast32_t fx80_to_i32_r_minMag( floatx80_t, bool );
178 int_fast64_t fx80_to_i64_r_minMag( floatx80_t, bool );
179 float32_t fx80_to_f32( floatx80_t );
180 float64_t fx80_to_f64( floatx80_t );
181 float128_t fx80_to_f128( floatx80_t );
182 floatx80_t fx80_roundToInt( floatx80_t, int_fast8_t, bool );
183 floatx80_t fx80_add( floatx80_t, floatx80_t );
184 floatx80_t fx80_sub( floatx80_t, floatx80_t );
185 floatx80_t fx80_mul( floatx80_t, floatx80_t );
186 floatx80_t fx80_mulAdd( floatx80_t, floatx80_t, floatx80_t );
187 floatx80_t fx80_div( floatx80_t, floatx80_t );
188 floatx80_t fx80_rem( floatx80_t, floatx80_t );
189 floatx80_t fx80_sqrt( floatx80_t );
190 bool fx80_eq( floatx80_t, floatx80_t );
191 bool fx80_le( floatx80_t, floatx80_t );
192 bool fx80_lt( floatx80_t, floatx80_t );
193 bool fx80_eq_signaling( floatx80_t, floatx80_t );
194 bool fx80_le_quiet( floatx80_t, floatx80_t );
195 bool fx80_lt_quiet( floatx80_t, floatx80_t );
196 bool fx80_isSignalingNaN( floatx80_t );
197
198 /*----------------------------------------------------------------------------
199 | 128-bit (quadruple-precision) floating-point operations.
200 *----------------------------------------------------------------------------*/
201 uint_fast32_t f128_to_ui32( float128_t, int_fast8_t, bool );
202 uint_fast64_t f128_to_ui64( float128_t, int_fast8_t, bool );
203 int_fast32_t f128_to_i32( float128_t, int_fast8_t, bool );
204 int_fast64_t f128_to_i64( float128_t, int_fast8_t, bool );
205 uint_fast32_t f128_to_ui32_r_minMag( float128_t, bool );
206 uint_fast64_t f128_to_ui64_r_minMag( float128_t, bool );
207 int_fast32_t f128_to_i32_r_minMag( float128_t, bool );
208 int_fast64_t f128_to_i64_r_minMag( float128_t, bool );
209 float32_t f128_to_f32( float128_t );
210 float64_t f128_to_f64( float128_t );
211 floatx80_t f128_to_fx80( float128_t );
212 float128_t f128_roundToInt( float128_t, int_fast8_t, bool );
213 float128_t f128_add( float128_t, float128_t );
214 float128_t f128_sub( float128_t, float128_t );
215 float128_t f128_mul( float128_t, float128_t );
216 float128_t f128_mulAdd( float128_t, float128_t, float128_t );
217 float128_t f128_div( float128_t, float128_t );
218 float128_t f128_rem( float128_t, float128_t );
219 float128_t f128_sqrt( float128_t );
220 bool f128_eq( float128_t, float128_t );
221 bool f128_le( float128_t, float128_t );
222 bool f128_lt( float128_t, float128_t );
223 bool f128_eq_signaling( float128_t, float128_t );
224 bool f128_le_quiet( float128_t, float128_t );
225 bool f128_lt_quiet( float128_t, float128_t );
226 bool f128_isSignalingNaN( float128_t );
227
228 #ifdef __cplusplus
229 }
230 #endif
231
232 #endif
233