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