]>
Commit | Line | Data |
---|---|---|
1dbda2b4 AB |
1 | /* $NetBSD: softfloat.h,v 1.10 2013/04/24 18:04:46 matt Exp $ */\r |
2 | \r | |
3 | /* This is a derivative work. */\r | |
4 | \r | |
5 | /*\r | |
6 | ===============================================================================\r | |
7 | \r | |
8 | This C header file is part of the SoftFloat IEC/IEEE Floating-point\r | |
9 | Arithmetic Package, Release 2a.\r | |
10 | \r | |
11 | Written by John R. Hauser. This work was made possible in part by the\r | |
12 | International Computer Science Institute, located at Suite 600, 1947 Center\r | |
13 | Street, Berkeley, California 94704. Funding was partially provided by the\r | |
14 | National Science Foundation under grant MIP-9311980. The original version\r | |
15 | of this code was written as part of a project to build a fixed-point vector\r | |
16 | processor in collaboration with the University of California at Berkeley,\r | |
17 | overseen by Profs. Nelson Morgan and John Wawrzynek. More information\r | |
18 | is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/\r | |
19 | arithmetic/SoftFloat.html'.\r | |
20 | \r | |
21 | THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort\r | |
22 | has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT\r | |
23 | TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO\r | |
24 | PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY\r | |
25 | AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.\r | |
26 | \r | |
27 | Derivative works are acceptable, even for commercial purposes, so long as\r | |
28 | (1) they include prominent notice that the work is derivative, and (2) they\r | |
29 | include prominent notice akin to these four paragraphs for those parts of\r | |
30 | this code that are retained.\r | |
31 | \r | |
32 | ===============================================================================\r | |
33 | */\r | |
34 | \r | |
35 | /*\r | |
36 | -------------------------------------------------------------------------------\r | |
37 | The macro `FLOATX80' must be defined to enable the extended double-precision\r | |
38 | floating-point format `floatx80'. If this macro is not defined, the\r | |
39 | `floatx80' type will not be defined, and none of the functions that either\r | |
40 | input or output the `floatx80' type will be defined. The same applies to\r | |
41 | the `FLOAT128' macro and the quadruple-precision format `float128'.\r | |
42 | -------------------------------------------------------------------------------\r | |
43 | */\r | |
44 | /* #define FLOATX80 */\r | |
45 | /* #define FLOAT128 */\r | |
46 | \r | |
47 | #define FE_INVALID 0x01 /* invalid operation exception */\r | |
48 | #define FE_DIVBYZERO 0x02 /* divide-by-zero exception */\r | |
49 | #define FE_OVERFLOW 0x04 /* overflow exception */\r | |
50 | #define FE_UNDERFLOW 0x08 /* underflow exception */\r | |
51 | #define FE_INEXACT 0x10 /* imprecise (loss of precision; "inexact") */\r | |
52 | \r | |
53 | #define FE_ALL_EXCEPT 0x1f\r | |
54 | \r | |
55 | #define FE_TONEAREST 0 /* round to nearest representable number */\r | |
56 | #define FE_UPWARD 1 /* round toward positive infinity */\r | |
57 | #define FE_DOWNWARD 2 /* round toward negative infinity */\r | |
58 | #define FE_TOWARDZERO 3 /* round to zero (truncate) */\r | |
59 | \r | |
60 | typedef int fp_except;\r | |
61 | \r | |
62 | /* Bit defines for fp_except */\r | |
63 | \r | |
64 | #define FP_X_INV FE_INVALID /* invalid operation exception */\r | |
65 | #define FP_X_DZ FE_DIVBYZERO /* divide-by-zero exception */\r | |
66 | #define FP_X_OFL FE_OVERFLOW /* overflow exception */\r | |
67 | #define FP_X_UFL FE_UNDERFLOW /* underflow exception */\r | |
68 | #define FP_X_IMP FE_INEXACT /* imprecise (prec. loss; "inexact") */\r | |
69 | \r | |
70 | /* Rounding modes */\r | |
71 | \r | |
72 | typedef enum {\r | |
73 | FP_RN=FE_TONEAREST, /* round to nearest representable number */\r | |
74 | FP_RP=FE_UPWARD, /* round toward positive infinity */\r | |
75 | FP_RM=FE_DOWNWARD, /* round toward negative infinity */\r | |
76 | FP_RZ=FE_TOWARDZERO /* round to zero (truncate) */\r | |
77 | } fp_rnd;\r | |
78 | \r | |
79 | /*\r | |
80 | -------------------------------------------------------------------------------\r | |
81 | Software IEC/IEEE floating-point types.\r | |
82 | -------------------------------------------------------------------------------\r | |
83 | */\r | |
84 | typedef unsigned int float32;\r | |
85 | typedef unsigned long long float64;\r | |
86 | #ifdef FLOATX80\r | |
87 | typedef struct {\r | |
88 | unsigned short high;\r | |
89 | unsigned long long low;\r | |
90 | } floatx80;\r | |
91 | #endif\r | |
92 | #ifdef FLOAT128\r | |
93 | typedef struct {\r | |
94 | unsigned long long high, low;\r | |
95 | } float128;\r | |
96 | #endif\r | |
97 | \r | |
98 | /*\r | |
99 | -------------------------------------------------------------------------------\r | |
100 | Software IEC/IEEE floating-point underflow tininess-detection mode.\r | |
101 | -------------------------------------------------------------------------------\r | |
102 | */\r | |
103 | #ifndef SOFTFLOAT_FOR_GCC\r | |
104 | extern int float_detect_tininess;\r | |
105 | #endif\r | |
106 | enum {\r | |
107 | float_tininess_after_rounding = 0,\r | |
108 | float_tininess_before_rounding = 1\r | |
109 | };\r | |
110 | \r | |
111 | /*\r | |
112 | -------------------------------------------------------------------------------\r | |
113 | Software IEC/IEEE floating-point rounding mode.\r | |
114 | -------------------------------------------------------------------------------\r | |
115 | */\r | |
116 | extern fp_rnd float_rounding_mode;\r | |
117 | #define float_round_nearest_even FP_RN\r | |
118 | #define float_round_to_zero FP_RZ\r | |
119 | #define float_round_down FP_RM\r | |
120 | #define float_round_up FP_RP\r | |
121 | \r | |
122 | /*\r | |
123 | -------------------------------------------------------------------------------\r | |
124 | Software IEC/IEEE floating-point exception flags.\r | |
125 | -------------------------------------------------------------------------------\r | |
126 | */\r | |
127 | extern fp_except float_exception_flags;\r | |
128 | extern fp_except float_exception_mask;\r | |
129 | enum {\r | |
130 | float_flag_inexact = FP_X_IMP,\r | |
131 | float_flag_underflow = FP_X_UFL,\r | |
132 | float_flag_overflow = FP_X_OFL,\r | |
133 | float_flag_divbyzero = FP_X_DZ,\r | |
134 | float_flag_invalid = FP_X_INV\r | |
135 | };\r | |
136 | \r | |
137 | /*\r | |
138 | -------------------------------------------------------------------------------\r | |
139 | Routine to raise any or all of the software IEC/IEEE floating-point\r | |
140 | exception flags.\r | |
141 | -------------------------------------------------------------------------------\r | |
142 | */\r | |
143 | void float_raise( fp_except );\r | |
144 | \r | |
145 | /*\r | |
146 | -------------------------------------------------------------------------------\r | |
147 | Software IEC/IEEE integer-to-floating-point conversion routines.\r | |
148 | -------------------------------------------------------------------------------\r | |
149 | */\r | |
150 | float32 int32_to_float32( int32 );\r | |
151 | float32 uint32_to_float32( uint32 );\r | |
152 | float64 int32_to_float64( int32 );\r | |
153 | float64 uint32_to_float64( uint32 );\r | |
154 | #ifdef FLOATX80\r | |
155 | floatx80 int32_to_floatx80( int32 );\r | |
156 | floatx80 uint32_to_floatx80( uint32 );\r | |
157 | #endif\r | |
158 | #ifdef FLOAT128\r | |
159 | float128 int32_to_float128( int32 );\r | |
160 | float128 uint32_to_float128( uint32 );\r | |
161 | #endif\r | |
162 | #ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */\r | |
163 | float32 int64_to_float32( long long );\r | |
164 | float64 int64_to_float64( long long );\r | |
165 | #ifdef FLOATX80\r | |
166 | floatx80 int64_to_floatx80( long long );\r | |
167 | #endif\r | |
168 | #ifdef FLOAT128\r | |
169 | float128 int64_to_float128( long long );\r | |
170 | #endif\r | |
171 | #endif\r | |
172 | \r | |
173 | /*\r | |
174 | -------------------------------------------------------------------------------\r | |
175 | Software IEC/IEEE single-precision conversion routines.\r | |
176 | -------------------------------------------------------------------------------\r | |
177 | */\r | |
178 | int float32_to_int32( float32 );\r | |
179 | int float32_to_int32_round_to_zero( float32 );\r | |
180 | #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)\r | |
181 | unsigned int float32_to_uint32_round_to_zero( float32 );\r | |
182 | #endif\r | |
183 | #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */\r | |
184 | long long float32_to_int64( float32 );\r | |
185 | long long float32_to_int64_round_to_zero( float32 );\r | |
186 | #endif\r | |
187 | float64 float32_to_float64( float32 );\r | |
188 | #ifdef FLOATX80\r | |
189 | floatx80 float32_to_floatx80( float32 );\r | |
190 | #endif\r | |
191 | #ifdef FLOAT128\r | |
192 | float128 float32_to_float128( float32 );\r | |
193 | #endif\r | |
194 | \r | |
195 | /*\r | |
196 | -------------------------------------------------------------------------------\r | |
197 | Software IEC/IEEE single-precision operations.\r | |
198 | -------------------------------------------------------------------------------\r | |
199 | */\r | |
200 | float32 float32_round_to_int( float32 );\r | |
201 | float32 float32_add( float32, float32 );\r | |
202 | float32 float32_sub( float32, float32 );\r | |
203 | float32 float32_mul( float32, float32 );\r | |
204 | float32 float32_div( float32, float32 );\r | |
205 | float32 float32_rem( float32, float32 );\r | |
206 | float32 float32_sqrt( float32 );\r | |
207 | int float32_eq( float32, float32 );\r | |
208 | int float32_le( float32, float32 );\r | |
209 | int float32_lt( float32, float32 );\r | |
210 | int float32_eq_signaling( float32, float32 );\r | |
211 | int float32_le_quiet( float32, float32 );\r | |
212 | int float32_lt_quiet( float32, float32 );\r | |
213 | #ifndef SOFTFLOAT_FOR_GCC\r | |
214 | int float32_is_signaling_nan( float32 );\r | |
215 | #endif\r | |
216 | \r | |
217 | /*\r | |
218 | -------------------------------------------------------------------------------\r | |
219 | Software IEC/IEEE double-precision conversion routines.\r | |
220 | -------------------------------------------------------------------------------\r | |
221 | */\r | |
222 | int float64_to_int32( float64 );\r | |
223 | int float64_to_int32_round_to_zero( float64 );\r | |
224 | #if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)\r | |
225 | unsigned int float64_to_uint32_round_to_zero( float64 );\r | |
226 | #endif\r | |
227 | #ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */\r | |
228 | long long float64_to_int64( float64 );\r | |
229 | long long float64_to_int64_round_to_zero( float64 );\r | |
230 | #endif\r | |
231 | float32 float64_to_float32( float64 );\r | |
232 | #ifdef FLOATX80\r | |
233 | floatx80 float64_to_floatx80( float64 );\r | |
234 | #endif\r | |
235 | #ifdef FLOAT128\r | |
236 | float128 float64_to_float128( float64 );\r | |
237 | #endif\r | |
238 | \r | |
239 | /*\r | |
240 | -------------------------------------------------------------------------------\r | |
241 | Software IEC/IEEE double-precision operations.\r | |
242 | -------------------------------------------------------------------------------\r | |
243 | */\r | |
244 | float64 float64_round_to_int( float64 );\r | |
245 | float64 float64_add( float64, float64 );\r | |
246 | float64 float64_sub( float64, float64 );\r | |
247 | float64 float64_mul( float64, float64 );\r | |
248 | float64 float64_div( float64, float64 );\r | |
249 | float64 float64_rem( float64, float64 );\r | |
250 | float64 float64_sqrt( float64 );\r | |
251 | int float64_eq( float64, float64 );\r | |
252 | int float64_le( float64, float64 );\r | |
253 | int float64_lt( float64, float64 );\r | |
254 | int float64_eq_signaling( float64, float64 );\r | |
255 | int float64_le_quiet( float64, float64 );\r | |
256 | int float64_lt_quiet( float64, float64 );\r | |
257 | #ifndef SOFTFLOAT_FOR_GCC\r | |
258 | int float64_is_signaling_nan( float64 );\r | |
259 | #endif\r | |
260 | \r | |
261 | #ifdef FLOATX80\r | |
262 | \r | |
263 | /*\r | |
264 | -------------------------------------------------------------------------------\r | |
265 | Software IEC/IEEE extended double-precision conversion routines.\r | |
266 | -------------------------------------------------------------------------------\r | |
267 | */\r | |
268 | int floatx80_to_int32( floatx80 );\r | |
269 | int floatx80_to_int32_round_to_zero( floatx80 );\r | |
270 | long long floatx80_to_int64( floatx80 );\r | |
271 | long long floatx80_to_int64_round_to_zero( floatx80 );\r | |
272 | float32 floatx80_to_float32( floatx80 );\r | |
273 | float64 floatx80_to_float64( floatx80 );\r | |
274 | #ifdef FLOAT128\r | |
275 | float128 floatx80_to_float128( floatx80 );\r | |
276 | #endif\r | |
277 | \r | |
278 | /*\r | |
279 | -------------------------------------------------------------------------------\r | |
280 | Software IEC/IEEE extended double-precision rounding precision. Valid\r | |
281 | values are 32, 64, and 80.\r | |
282 | -------------------------------------------------------------------------------\r | |
283 | */\r | |
284 | extern int floatx80_rounding_precision;\r | |
285 | \r | |
286 | /*\r | |
287 | -------------------------------------------------------------------------------\r | |
288 | Software IEC/IEEE extended double-precision operations.\r | |
289 | -------------------------------------------------------------------------------\r | |
290 | */\r | |
291 | floatx80 floatx80_round_to_int( floatx80 );\r | |
292 | floatx80 floatx80_add( floatx80, floatx80 );\r | |
293 | floatx80 floatx80_sub( floatx80, floatx80 );\r | |
294 | floatx80 floatx80_mul( floatx80, floatx80 );\r | |
295 | floatx80 floatx80_div( floatx80, floatx80 );\r | |
296 | floatx80 floatx80_rem( floatx80, floatx80 );\r | |
297 | floatx80 floatx80_sqrt( floatx80 );\r | |
298 | int floatx80_eq( floatx80, floatx80 );\r | |
299 | int floatx80_le( floatx80, floatx80 );\r | |
300 | int floatx80_lt( floatx80, floatx80 );\r | |
301 | int floatx80_eq_signaling( floatx80, floatx80 );\r | |
302 | int floatx80_le_quiet( floatx80, floatx80 );\r | |
303 | int floatx80_lt_quiet( floatx80, floatx80 );\r | |
304 | int floatx80_is_signaling_nan( floatx80 );\r | |
305 | \r | |
306 | #endif\r | |
307 | \r | |
308 | #ifdef FLOAT128\r | |
309 | \r | |
310 | /*\r | |
311 | -------------------------------------------------------------------------------\r | |
312 | Software IEC/IEEE quadruple-precision conversion routines.\r | |
313 | -------------------------------------------------------------------------------\r | |
314 | */\r | |
315 | int float128_to_int32( float128 );\r | |
316 | int float128_to_int32_round_to_zero( float128 );\r | |
317 | long long float128_to_int64( float128 );\r | |
318 | long long float128_to_int64_round_to_zero( float128 );\r | |
319 | float32 float128_to_float32( float128 );\r | |
320 | float64 float128_to_float64( float128 );\r | |
321 | #ifdef FLOATX80\r | |
322 | floatx80 float128_to_floatx80( float128 );\r | |
323 | #endif\r | |
324 | \r | |
325 | /*\r | |
326 | -------------------------------------------------------------------------------\r | |
327 | Software IEC/IEEE quadruple-precision operations.\r | |
328 | -------------------------------------------------------------------------------\r | |
329 | */\r | |
330 | float128 float128_round_to_int( float128 );\r | |
331 | float128 float128_add( float128, float128 );\r | |
332 | float128 float128_sub( float128, float128 );\r | |
333 | float128 float128_mul( float128, float128 );\r | |
334 | float128 float128_div( float128, float128 );\r | |
335 | float128 float128_rem( float128, float128 );\r | |
336 | float128 float128_sqrt( float128 );\r | |
337 | int float128_eq( float128, float128 );\r | |
338 | int float128_le( float128, float128 );\r | |
339 | int float128_lt( float128, float128 );\r | |
340 | int float128_eq_signaling( float128, float128 );\r | |
341 | int float128_le_quiet( float128, float128 );\r | |
342 | int float128_lt_quiet( float128, float128 );\r | |
343 | int float128_is_signaling_nan( float128 );\r | |
344 | \r | |
345 | #endif\r |