]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Library/ArmSoftFloatLib/Arm/softfloat.h
ArmPkg/ArmSoftFloatLib: switch to new version of softfloat library
[mirror_edk2.git] / ArmPkg / Library / ArmSoftFloatLib / Arm / softfloat.h
CommitLineData
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
8This C header file is part of the SoftFloat IEC/IEEE Floating-point\r
9Arithmetic Package, Release 2a.\r
10\r
11Written by John R. Hauser. This work was made possible in part by the\r
12International Computer Science Institute, located at Suite 600, 1947 Center\r
13Street, Berkeley, California 94704. Funding was partially provided by the\r
14National Science Foundation under grant MIP-9311980. The original version\r
15of this code was written as part of a project to build a fixed-point vector\r
16processor in collaboration with the University of California at Berkeley,\r
17overseen by Profs. Nelson Morgan and John Wawrzynek. More information\r
18is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/\r
19arithmetic/SoftFloat.html'.\r
20\r
21THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort\r
22has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT\r
23TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO\r
24PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY\r
25AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.\r
26\r
27Derivative 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
29include prominent notice akin to these four paragraphs for those parts of\r
30this code that are retained.\r
31\r
32===============================================================================\r
33*/\r
34\r
35/*\r
36-------------------------------------------------------------------------------\r
37The macro `FLOATX80' must be defined to enable the extended double-precision\r
38floating-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
40input or output the `floatx80' type will be defined. The same applies to\r
41the `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
60typedef 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
72typedef 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
81Software IEC/IEEE floating-point types.\r
82-------------------------------------------------------------------------------\r
83*/\r
84typedef unsigned int float32;\r
85typedef unsigned long long float64;\r
86#ifdef FLOATX80\r
87typedef struct {\r
88 unsigned short high;\r
89 unsigned long long low;\r
90} floatx80;\r
91#endif\r
92#ifdef FLOAT128\r
93typedef struct {\r
94 unsigned long long high, low;\r
95} float128;\r
96#endif\r
97\r
98/*\r
99-------------------------------------------------------------------------------\r
100Software IEC/IEEE floating-point underflow tininess-detection mode.\r
101-------------------------------------------------------------------------------\r
102*/\r
103#ifndef SOFTFLOAT_FOR_GCC\r
104extern int float_detect_tininess;\r
105#endif\r
106enum {\r
107 float_tininess_after_rounding = 0,\r
108 float_tininess_before_rounding = 1\r
109};\r
110\r
111/*\r
112-------------------------------------------------------------------------------\r
113Software IEC/IEEE floating-point rounding mode.\r
114-------------------------------------------------------------------------------\r
115*/\r
116extern 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
124Software IEC/IEEE floating-point exception flags.\r
125-------------------------------------------------------------------------------\r
126*/\r
127extern fp_except float_exception_flags;\r
128extern fp_except float_exception_mask;\r
129enum {\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
139Routine to raise any or all of the software IEC/IEEE floating-point\r
140exception flags.\r
141-------------------------------------------------------------------------------\r
142*/\r
143void float_raise( fp_except );\r
144\r
145/*\r
146-------------------------------------------------------------------------------\r
147Software IEC/IEEE integer-to-floating-point conversion routines.\r
148-------------------------------------------------------------------------------\r
149*/\r
150float32 int32_to_float32( int32 );\r
151float32 uint32_to_float32( uint32 );\r
152float64 int32_to_float64( int32 );\r
153float64 uint32_to_float64( uint32 );\r
154#ifdef FLOATX80\r
155floatx80 int32_to_floatx80( int32 );\r
156floatx80 uint32_to_floatx80( uint32 );\r
157#endif\r
158#ifdef FLOAT128\r
159float128 int32_to_float128( int32 );\r
160float128 uint32_to_float128( uint32 );\r
161#endif\r
162#ifndef SOFTFLOAT_FOR_GCC /* __floatdi?f is in libgcc2.c */\r
163float32 int64_to_float32( long long );\r
164float64 int64_to_float64( long long );\r
165#ifdef FLOATX80\r
166floatx80 int64_to_floatx80( long long );\r
167#endif\r
168#ifdef FLOAT128\r
169float128 int64_to_float128( long long );\r
170#endif\r
171#endif\r
172\r
173/*\r
174-------------------------------------------------------------------------------\r
175Software IEC/IEEE single-precision conversion routines.\r
176-------------------------------------------------------------------------------\r
177*/\r
178int float32_to_int32( float32 );\r
179int float32_to_int32_round_to_zero( float32 );\r
180#if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)\r
181unsigned int float32_to_uint32_round_to_zero( float32 );\r
182#endif\r
183#ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */\r
184long long float32_to_int64( float32 );\r
185long long float32_to_int64_round_to_zero( float32 );\r
186#endif\r
187float64 float32_to_float64( float32 );\r
188#ifdef FLOATX80\r
189floatx80 float32_to_floatx80( float32 );\r
190#endif\r
191#ifdef FLOAT128\r
192float128 float32_to_float128( float32 );\r
193#endif\r
194\r
195/*\r
196-------------------------------------------------------------------------------\r
197Software IEC/IEEE single-precision operations.\r
198-------------------------------------------------------------------------------\r
199*/\r
200float32 float32_round_to_int( float32 );\r
201float32 float32_add( float32, float32 );\r
202float32 float32_sub( float32, float32 );\r
203float32 float32_mul( float32, float32 );\r
204float32 float32_div( float32, float32 );\r
205float32 float32_rem( float32, float32 );\r
206float32 float32_sqrt( float32 );\r
207int float32_eq( float32, float32 );\r
208int float32_le( float32, float32 );\r
209int float32_lt( float32, float32 );\r
210int float32_eq_signaling( float32, float32 );\r
211int float32_le_quiet( float32, float32 );\r
212int float32_lt_quiet( float32, float32 );\r
213#ifndef SOFTFLOAT_FOR_GCC\r
214int float32_is_signaling_nan( float32 );\r
215#endif\r
216\r
217/*\r
218-------------------------------------------------------------------------------\r
219Software IEC/IEEE double-precision conversion routines.\r
220-------------------------------------------------------------------------------\r
221*/\r
222int float64_to_int32( float64 );\r
223int float64_to_int32_round_to_zero( float64 );\r
224#if defined(SOFTFLOAT_FOR_GCC) && defined(SOFTFLOAT_NEED_FIXUNS)\r
225unsigned int float64_to_uint32_round_to_zero( float64 );\r
226#endif\r
227#ifndef SOFTFLOAT_FOR_GCC /* __fix?fdi provided by libgcc2.c */\r
228long long float64_to_int64( float64 );\r
229long long float64_to_int64_round_to_zero( float64 );\r
230#endif\r
231float32 float64_to_float32( float64 );\r
232#ifdef FLOATX80\r
233floatx80 float64_to_floatx80( float64 );\r
234#endif\r
235#ifdef FLOAT128\r
236float128 float64_to_float128( float64 );\r
237#endif\r
238\r
239/*\r
240-------------------------------------------------------------------------------\r
241Software IEC/IEEE double-precision operations.\r
242-------------------------------------------------------------------------------\r
243*/\r
244float64 float64_round_to_int( float64 );\r
245float64 float64_add( float64, float64 );\r
246float64 float64_sub( float64, float64 );\r
247float64 float64_mul( float64, float64 );\r
248float64 float64_div( float64, float64 );\r
249float64 float64_rem( float64, float64 );\r
250float64 float64_sqrt( float64 );\r
251int float64_eq( float64, float64 );\r
252int float64_le( float64, float64 );\r
253int float64_lt( float64, float64 );\r
254int float64_eq_signaling( float64, float64 );\r
255int float64_le_quiet( float64, float64 );\r
256int float64_lt_quiet( float64, float64 );\r
257#ifndef SOFTFLOAT_FOR_GCC\r
258int float64_is_signaling_nan( float64 );\r
259#endif\r
260\r
261#ifdef FLOATX80\r
262\r
263/*\r
264-------------------------------------------------------------------------------\r
265Software IEC/IEEE extended double-precision conversion routines.\r
266-------------------------------------------------------------------------------\r
267*/\r
268int floatx80_to_int32( floatx80 );\r
269int floatx80_to_int32_round_to_zero( floatx80 );\r
270long long floatx80_to_int64( floatx80 );\r
271long long floatx80_to_int64_round_to_zero( floatx80 );\r
272float32 floatx80_to_float32( floatx80 );\r
273float64 floatx80_to_float64( floatx80 );\r
274#ifdef FLOAT128\r
275float128 floatx80_to_float128( floatx80 );\r
276#endif\r
277\r
278/*\r
279-------------------------------------------------------------------------------\r
280Software IEC/IEEE extended double-precision rounding precision. Valid\r
281values are 32, 64, and 80.\r
282-------------------------------------------------------------------------------\r
283*/\r
284extern int floatx80_rounding_precision;\r
285\r
286/*\r
287-------------------------------------------------------------------------------\r
288Software IEC/IEEE extended double-precision operations.\r
289-------------------------------------------------------------------------------\r
290*/\r
291floatx80 floatx80_round_to_int( floatx80 );\r
292floatx80 floatx80_add( floatx80, floatx80 );\r
293floatx80 floatx80_sub( floatx80, floatx80 );\r
294floatx80 floatx80_mul( floatx80, floatx80 );\r
295floatx80 floatx80_div( floatx80, floatx80 );\r
296floatx80 floatx80_rem( floatx80, floatx80 );\r
297floatx80 floatx80_sqrt( floatx80 );\r
298int floatx80_eq( floatx80, floatx80 );\r
299int floatx80_le( floatx80, floatx80 );\r
300int floatx80_lt( floatx80, floatx80 );\r
301int floatx80_eq_signaling( floatx80, floatx80 );\r
302int floatx80_le_quiet( floatx80, floatx80 );\r
303int floatx80_lt_quiet( floatx80, floatx80 );\r
304int floatx80_is_signaling_nan( floatx80 );\r
305\r
306#endif\r
307\r
308#ifdef FLOAT128\r
309\r
310/*\r
311-------------------------------------------------------------------------------\r
312Software IEC/IEEE quadruple-precision conversion routines.\r
313-------------------------------------------------------------------------------\r
314*/\r
315int float128_to_int32( float128 );\r
316int float128_to_int32_round_to_zero( float128 );\r
317long long float128_to_int64( float128 );\r
318long long float128_to_int64_round_to_zero( float128 );\r
319float32 float128_to_float32( float128 );\r
320float64 float128_to_float64( float128 );\r
321#ifdef FLOATX80\r
322floatx80 float128_to_floatx80( float128 );\r
323#endif\r
324\r
325/*\r
326-------------------------------------------------------------------------------\r
327Software IEC/IEEE quadruple-precision operations.\r
328-------------------------------------------------------------------------------\r
329*/\r
330float128 float128_round_to_int( float128 );\r
331float128 float128_add( float128, float128 );\r
332float128 float128_sub( float128, float128 );\r
333float128 float128_mul( float128, float128 );\r
334float128 float128_div( float128, float128 );\r
335float128 float128_rem( float128, float128 );\r
336float128 float128_sqrt( float128 );\r
337int float128_eq( float128, float128 );\r
338int float128_le( float128, float128 );\r
339int float128_lt( float128, float128 );\r
340int float128_eq_signaling( float128, float128 );\r
341int float128_le_quiet( float128, float128 );\r
342int float128_lt_quiet( float128, float128 );\r
343int float128_is_signaling_nan( float128 );\r
344\r
345#endif\r