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