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