hartids knob description added
[riscv-isa-sim.git] / softfloat / softfloat.h
1
2 /*============================================================================
3
4 This C header file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3a, by John R. Hauser.
6
7 Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
8 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
38 /*============================================================================
39 | Note: If SoftFloat is made available as a general library for programs to
40 | use, it is strongly recommended that a platform-specific version of this
41 | header, "softfloat.h", be created that folds in "softfloat_types.h" and that
42 | eliminates all dependencies on compile-time macros.
43 *============================================================================*/
44
45
46 #ifndef softfloat_h
47 #define softfloat_h 1
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 #include <stdbool.h>
54 #include <stdint.h>
55
56 #include "softfloat_types.h"
57
58 /*----------------------------------------------------------------------------
59 | Software floating-point underflow tininess-detection mode.
60 *----------------------------------------------------------------------------*/
61 extern uint_fast8_t softfloat_detectTininess;
62 enum {
63 softfloat_tininess_beforeRounding = 0,
64 softfloat_tininess_afterRounding = 1
65 };
66
67 /*----------------------------------------------------------------------------
68 | Software floating-point rounding mode.
69 *----------------------------------------------------------------------------*/
70 extern uint_fast8_t softfloat_roundingMode;
71 enum {
72 softfloat_round_near_even = 0,
73 softfloat_round_minMag = 1,
74 softfloat_round_min = 2,
75 softfloat_round_max = 3,
76 softfloat_round_near_maxMag = 4
77 };
78
79 /*----------------------------------------------------------------------------
80 | Software floating-point exception flags.
81 *----------------------------------------------------------------------------*/
82 extern uint_fast8_t softfloat_exceptionFlags;
83 enum {
84 softfloat_flag_inexact = 1,
85 softfloat_flag_underflow = 2,
86 softfloat_flag_overflow = 4,
87 softfloat_flag_infinite = 8,
88 softfloat_flag_invalid = 16
89 };
90
91 /*----------------------------------------------------------------------------
92 | Routine to raise any or all of the software floating-point exception flags.
93 *----------------------------------------------------------------------------*/
94 void softfloat_raiseFlags( uint_fast8_t );
95
96 /*----------------------------------------------------------------------------
97 | Integer-to-floating-point conversion routines.
98 *----------------------------------------------------------------------------*/
99 float32_t ui32_to_f32( uint32_t );
100 float64_t ui32_to_f64( uint32_t );
101 #ifdef SOFTFLOAT_FAST_INT64
102 extFloat80_t ui32_to_extF80( uint32_t );
103 float128_t ui32_to_f128( uint32_t );
104 #endif
105 void ui32_to_extF80M( uint32_t, extFloat80_t * );
106 void ui32_to_f128M( uint32_t, float128_t * );
107 float32_t ui64_to_f32( uint64_t );
108 float64_t ui64_to_f64( uint64_t );
109 #ifdef SOFTFLOAT_FAST_INT64
110 extFloat80_t ui64_to_extF80( uint64_t );
111 float128_t ui64_to_f128( uint64_t );
112 #endif
113 void ui64_to_extF80M( uint64_t, extFloat80_t * );
114 void ui64_to_f128M( uint64_t, float128_t * );
115 float32_t i32_to_f32( int32_t );
116 float64_t i32_to_f64( int32_t );
117 #ifdef SOFTFLOAT_FAST_INT64
118 extFloat80_t i32_to_extF80( int32_t );
119 float128_t i32_to_f128( int32_t );
120 #endif
121 void i32_to_extF80M( int32_t, extFloat80_t * );
122 void i32_to_f128M( int32_t, float128_t * );
123 float32_t i64_to_f32( int64_t );
124 float64_t i64_to_f64( int64_t );
125 #ifdef SOFTFLOAT_FAST_INT64
126 extFloat80_t i64_to_extF80( int64_t );
127 float128_t i64_to_f128( int64_t );
128 #endif
129 void i64_to_extF80M( int64_t, extFloat80_t * );
130 void i64_to_f128M( int64_t, float128_t * );
131
132 /*----------------------------------------------------------------------------
133 | 32-bit (single-precision) floating-point operations.
134 *----------------------------------------------------------------------------*/
135 uint_fast32_t f32_to_ui32( float32_t, uint_fast8_t, bool );
136 uint_fast64_t f32_to_ui64( float32_t, uint_fast8_t, bool );
137 int_fast32_t f32_to_i32( float32_t, uint_fast8_t, bool );
138 int_fast64_t f32_to_i64( float32_t, uint_fast8_t, bool );
139 uint_fast32_t f32_to_ui32_r_minMag( float32_t, bool );
140 uint_fast64_t f32_to_ui64_r_minMag( float32_t, bool );
141 int_fast32_t f32_to_i32_r_minMag( float32_t, bool );
142 int_fast64_t f32_to_i64_r_minMag( float32_t, bool );
143 float64_t f32_to_f64( float32_t );
144 #ifdef SOFTFLOAT_FAST_INT64
145 extFloat80_t f32_to_extF80( float32_t );
146 float128_t f32_to_f128( float32_t );
147 #endif
148 void f32_to_extF80M( float32_t, extFloat80_t * );
149 void f32_to_f128M( float32_t, float128_t * );
150 float32_t f32_roundToInt( float32_t, uint_fast8_t, bool );
151 float32_t f32_add( float32_t, float32_t );
152 float32_t f32_sub( float32_t, float32_t );
153 float32_t f32_mul( float32_t, float32_t );
154 float32_t f32_mulAdd( float32_t, float32_t, float32_t );
155 float32_t f32_div( float32_t, float32_t );
156 float32_t f32_rem( float32_t, float32_t );
157 float32_t f32_sqrt( float32_t );
158 bool f32_eq( float32_t, float32_t );
159 bool f32_le( float32_t, float32_t );
160 bool f32_lt( float32_t, float32_t );
161 bool f32_eq_signaling( float32_t, float32_t );
162 bool f32_le_quiet( float32_t, float32_t );
163 bool f32_lt_quiet( float32_t, float32_t );
164 bool f32_isSignalingNaN( float32_t );
165 uint_fast16_t f32_classify( float32_t );
166
167 /*----------------------------------------------------------------------------
168 | 64-bit (double-precision) floating-point operations.
169 *----------------------------------------------------------------------------*/
170 uint_fast32_t f64_to_ui32( float64_t, uint_fast8_t, bool );
171 uint_fast64_t f64_to_ui64( float64_t, uint_fast8_t, bool );
172 int_fast32_t f64_to_i32( float64_t, uint_fast8_t, bool );
173 int_fast64_t f64_to_i64( float64_t, uint_fast8_t, bool );
174 uint_fast32_t f64_to_ui32_r_minMag( float64_t, bool );
175 uint_fast64_t f64_to_ui64_r_minMag( float64_t, bool );
176 int_fast32_t f64_to_i32_r_minMag( float64_t, bool );
177 int_fast64_t f64_to_i64_r_minMag( float64_t, bool );
178 float32_t f64_to_f32( float64_t );
179 #ifdef SOFTFLOAT_FAST_INT64
180 extFloat80_t f64_to_extF80( float64_t );
181 float128_t f64_to_f128( float64_t );
182 #endif
183 void f64_to_extF80M( float64_t, extFloat80_t * );
184 void f64_to_f128M( float64_t, float128_t * );
185 float64_t f64_roundToInt( float64_t, uint_fast8_t, bool );
186 float64_t f64_add( float64_t, float64_t );
187 float64_t f64_sub( float64_t, float64_t );
188 float64_t f64_mul( float64_t, float64_t );
189 float64_t f64_mulAdd( float64_t, float64_t, float64_t );
190 float64_t f64_div( float64_t, float64_t );
191 float64_t f64_rem( float64_t, float64_t );
192 float64_t f64_sqrt( float64_t );
193 bool f64_eq( float64_t, float64_t );
194 bool f64_le( float64_t, float64_t );
195 bool f64_lt( float64_t, float64_t );
196 bool f64_eq_signaling( float64_t, float64_t );
197 bool f64_le_quiet( float64_t, float64_t );
198 bool f64_lt_quiet( float64_t, float64_t );
199 bool f64_isSignalingNaN( float64_t );
200 uint_fast16_t f64_classify( float64_t );
201
202 /*----------------------------------------------------------------------------
203 | Rounding precision for 80-bit extended double-precision floating-point.
204 | Valid values are 32, 64, and 80.
205 *----------------------------------------------------------------------------*/
206 extern uint_fast8_t extF80_roundingPrecision;
207
208 /*----------------------------------------------------------------------------
209 | 80-bit extended double-precision floating-point operations.
210 *----------------------------------------------------------------------------*/
211 #ifdef SOFTFLOAT_FAST_INT64
212 uint_fast32_t extF80_to_ui32( extFloat80_t, uint_fast8_t, bool );
213 uint_fast64_t extF80_to_ui64( extFloat80_t, uint_fast8_t, bool );
214 int_fast32_t extF80_to_i32( extFloat80_t, uint_fast8_t, bool );
215 int_fast64_t extF80_to_i64( extFloat80_t, uint_fast8_t, bool );
216 uint_fast32_t extF80_to_ui32_r_minMag( extFloat80_t, bool );
217 uint_fast64_t extF80_to_ui64_r_minMag( extFloat80_t, bool );
218 int_fast32_t extF80_to_i32_r_minMag( extFloat80_t, bool );
219 int_fast64_t extF80_to_i64_r_minMag( extFloat80_t, bool );
220 float32_t extF80_to_f32( extFloat80_t );
221 float64_t extF80_to_f64( extFloat80_t );
222 float128_t extF80_to_f128( extFloat80_t );
223 extFloat80_t extF80_roundToInt( extFloat80_t, uint_fast8_t, bool );
224 extFloat80_t extF80_add( extFloat80_t, extFloat80_t );
225 extFloat80_t extF80_sub( extFloat80_t, extFloat80_t );
226 extFloat80_t extF80_mul( extFloat80_t, extFloat80_t );
227 extFloat80_t extF80_div( extFloat80_t, extFloat80_t );
228 extFloat80_t extF80_rem( extFloat80_t, extFloat80_t );
229 extFloat80_t extF80_sqrt( extFloat80_t );
230 bool extF80_eq( extFloat80_t, extFloat80_t );
231 bool extF80_le( extFloat80_t, extFloat80_t );
232 bool extF80_lt( extFloat80_t, extFloat80_t );
233 bool extF80_eq_signaling( extFloat80_t, extFloat80_t );
234 bool extF80_le_quiet( extFloat80_t, extFloat80_t );
235 bool extF80_lt_quiet( extFloat80_t, extFloat80_t );
236 bool extF80_isSignalingNaN( extFloat80_t );
237 #endif
238 uint_fast32_t extF80M_to_ui32( const extFloat80_t *, uint_fast8_t, bool );
239 uint_fast64_t extF80M_to_ui64( const extFloat80_t *, uint_fast8_t, bool );
240 int_fast32_t extF80M_to_i32( const extFloat80_t *, uint_fast8_t, bool );
241 int_fast64_t extF80M_to_i64( const extFloat80_t *, uint_fast8_t, bool );
242 uint_fast32_t extF80M_to_ui32_r_minMag( const extFloat80_t *, bool );
243 uint_fast64_t extF80M_to_ui64_r_minMag( const extFloat80_t *, bool );
244 int_fast32_t extF80M_to_i32_r_minMag( const extFloat80_t *, bool );
245 int_fast64_t extF80M_to_i64_r_minMag( const extFloat80_t *, bool );
246 float32_t extF80M_to_f32( const extFloat80_t * );
247 float64_t extF80M_to_f64( const extFloat80_t * );
248 void extF80M_to_f128M( const extFloat80_t *, float128_t * );
249 void
250 extF80M_roundToInt(
251 const extFloat80_t *, uint_fast8_t, bool, extFloat80_t * );
252 void extF80M_add( const extFloat80_t *, const extFloat80_t *, extFloat80_t * );
253 void extF80M_sub( const extFloat80_t *, const extFloat80_t *, extFloat80_t * );
254 void extF80M_mul( const extFloat80_t *, const extFloat80_t *, extFloat80_t * );
255 void extF80M_div( const extFloat80_t *, const extFloat80_t *, extFloat80_t * );
256 void extF80M_rem( const extFloat80_t *, const extFloat80_t *, extFloat80_t * );
257 void extF80M_sqrt( const extFloat80_t *, extFloat80_t * );
258 bool extF80M_eq( const extFloat80_t *, const extFloat80_t * );
259 bool extF80M_le( const extFloat80_t *, const extFloat80_t * );
260 bool extF80M_lt( const extFloat80_t *, const extFloat80_t * );
261 bool extF80M_eq_signaling( const extFloat80_t *, const extFloat80_t * );
262 bool extF80M_le_quiet( const extFloat80_t *, const extFloat80_t * );
263 bool extF80M_lt_quiet( const extFloat80_t *, const extFloat80_t * );
264 bool extF80M_isSignalingNaN( const extFloat80_t * );
265
266 /*----------------------------------------------------------------------------
267 | 128-bit (quadruple-precision) floating-point operations.
268 *----------------------------------------------------------------------------*/
269 #ifdef SOFTFLOAT_FAST_INT64
270 uint_fast32_t f128_to_ui32( float128_t, uint_fast8_t, bool );
271 uint_fast64_t f128_to_ui64( float128_t, uint_fast8_t, bool );
272 int_fast32_t f128_to_i32( float128_t, uint_fast8_t, bool );
273 int_fast64_t f128_to_i64( float128_t, uint_fast8_t, bool );
274 uint_fast32_t f128_to_ui32_r_minMag( float128_t, bool );
275 uint_fast64_t f128_to_ui64_r_minMag( float128_t, bool );
276 int_fast32_t f128_to_i32_r_minMag( float128_t, bool );
277 int_fast64_t f128_to_i64_r_minMag( float128_t, bool );
278 float32_t f128_to_f32( float128_t );
279 float64_t f128_to_f64( float128_t );
280 extFloat80_t f128_to_extF80( float128_t );
281 float128_t f128_roundToInt( float128_t, uint_fast8_t, bool );
282 float128_t f128_add( float128_t, float128_t );
283 float128_t f128_sub( float128_t, float128_t );
284 float128_t f128_mul( float128_t, float128_t );
285 float128_t f128_mulAdd( float128_t, float128_t, float128_t );
286 float128_t f128_div( float128_t, float128_t );
287 float128_t f128_rem( float128_t, float128_t );
288 float128_t f128_sqrt( float128_t );
289 bool f128_eq( float128_t, float128_t );
290 bool f128_le( float128_t, float128_t );
291 bool f128_lt( float128_t, float128_t );
292 bool f128_eq_signaling( float128_t, float128_t );
293 bool f128_le_quiet( float128_t, float128_t );
294 bool f128_lt_quiet( float128_t, float128_t );
295 bool f128_isSignalingNaN( float128_t );
296 #endif
297 uint_fast32_t f128M_to_ui32( const float128_t *, uint_fast8_t, bool );
298 uint_fast64_t f128M_to_ui64( const float128_t *, uint_fast8_t, bool );
299 int_fast32_t f128M_to_i32( const float128_t *, uint_fast8_t, bool );
300 int_fast64_t f128M_to_i64( const float128_t *, uint_fast8_t, bool );
301 uint_fast32_t f128M_to_ui32_r_minMag( const float128_t *, bool );
302 uint_fast64_t f128M_to_ui64_r_minMag( const float128_t *, bool );
303 int_fast32_t f128M_to_i32_r_minMag( const float128_t *, bool );
304 int_fast64_t f128M_to_i64_r_minMag( const float128_t *, bool );
305 float32_t f128M_to_f32( const float128_t * );
306 float64_t f128M_to_f64( const float128_t * );
307 void f128M_to_extF80M( const float128_t *, extFloat80_t * );
308 void f128M_roundToInt( const float128_t *, uint_fast8_t, bool, float128_t * );
309 void f128M_add( const float128_t *, const float128_t *, float128_t * );
310 void f128M_sub( const float128_t *, const float128_t *, float128_t * );
311 void f128M_mul( const float128_t *, const float128_t *, float128_t * );
312 void
313 f128M_mulAdd(
314 const float128_t *, const float128_t *, const float128_t *, float128_t *
315 );
316 void f128M_div( const float128_t *, const float128_t *, float128_t * );
317 void f128M_rem( const float128_t *, const float128_t *, float128_t * );
318 void f128M_sqrt( const float128_t *, float128_t * );
319 bool f128M_eq( const float128_t *, const float128_t * );
320 bool f128M_le( const float128_t *, const float128_t * );
321 bool f128M_lt( const float128_t *, const float128_t * );
322 bool f128M_eq_signaling( const float128_t *, const float128_t * );
323 bool f128M_le_quiet( const float128_t *, const float128_t * );
324 bool f128M_lt_quiet( const float128_t *, const float128_t * );
325 bool f128M_isSignalingNaN( const float128_t * );
326
327 #ifdef __cplusplus
328 }
329 #endif
330
331 #endif
332