1209878Snwhitehorn/*	$NetBSD: softfloat.h,v 1.6 2002/05/12 13:12:46 bjh21 Exp $	*/
2209878Snwhitehorn/* $FreeBSD$ */
3209878Snwhitehorn
4209878Snwhitehorn/* This is a derivative work. */
5209878Snwhitehorn
6209878Snwhitehorn/*
7209878Snwhitehorn===============================================================================
8209878Snwhitehorn
9209878SnwhitehornThis C header file is part of the SoftFloat IEC/IEEE Floating-point
10209878SnwhitehornArithmetic Package, Release 2a.
11209878Snwhitehorn
12209878SnwhitehornWritten by John R. Hauser.  This work was made possible in part by the
13209878SnwhitehornInternational Computer Science Institute, located at Suite 600, 1947 Center
14209878SnwhitehornStreet, Berkeley, California 94704.  Funding was partially provided by the
15209878SnwhitehornNational Science Foundation under grant MIP-9311980.  The original version
16209878Snwhitehornof this code was written as part of a project to build a fixed-point vector
17209878Snwhitehornprocessor in collaboration with the University of California at Berkeley,
18209878Snwhitehornoverseen by Profs. Nelson Morgan and John Wawrzynek.  More information
19209878Snwhitehornis available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/
20209878Snwhitehornarithmetic/SoftFloat.html'.
21209878Snwhitehorn
22209878SnwhitehornTHIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE.  Although reasonable effort
23209878Snwhitehornhas been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT
24209878SnwhitehornTIMES RESULT IN INCORRECT BEHAVIOR.  USE OF THIS SOFTWARE IS RESTRICTED TO
25209878SnwhitehornPERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY
26209878SnwhitehornAND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE.
27209878Snwhitehorn
28209878SnwhitehornDerivative works are acceptable, even for commercial purposes, so long as
29209878Snwhitehorn(1) they include prominent notice that the work is derivative, and (2) they
30209878Snwhitehorninclude prominent notice akin to these four paragraphs for those parts of
31209878Snwhitehornthis code that are retained.
32209878Snwhitehorn
33209878Snwhitehorn===============================================================================
34209878Snwhitehorn*/
35209878Snwhitehorn
36209878Snwhitehorn/*
37209878Snwhitehorn-------------------------------------------------------------------------------
38209878SnwhitehornThe macro `FLOATX80' must be defined to enable the extended double-precision
39209878Snwhitehornfloating-point format `floatx80'.  If this macro is not defined, the
40209878Snwhitehorn`floatx80' type will not be defined, and none of the functions that either
41209878Snwhitehorninput or output the `floatx80' type will be defined.  The same applies to
42209878Snwhitehornthe `FLOAT128' macro and the quadruple-precision format `float128'.
43209878Snwhitehorn-------------------------------------------------------------------------------
44209878Snwhitehorn*/
45209878Snwhitehorn/* #define FLOATX80 */
46209878Snwhitehorn/* #define FLOAT128 */
47209878Snwhitehorn
48209878Snwhitehorn#include <machine/ieeefp.h>
49209878Snwhitehorn
50209878Snwhitehorn/*
51209878Snwhitehorn-------------------------------------------------------------------------------
52209878SnwhitehornSoftware IEC/IEEE floating-point types.
53209878Snwhitehorn-------------------------------------------------------------------------------
54209878Snwhitehorn*/
55209878Snwhitehorntypedef unsigned int float32;
56209878Snwhitehorntypedef unsigned long long float64;
57209878Snwhitehorn#ifdef FLOATX80
58209878Snwhitehorntypedef struct {
59209878Snwhitehorn    unsigned short high;
60209878Snwhitehorn    unsigned long long low;
61209878Snwhitehorn} floatx80;
62209878Snwhitehorn#endif
63209878Snwhitehorn#ifdef FLOAT128
64209878Snwhitehorntypedef struct {
65209878Snwhitehorn    unsigned long long high, low;
66209878Snwhitehorn} float128;
67209878Snwhitehorn#endif
68209878Snwhitehorn
69209878Snwhitehorn/*
70209878Snwhitehorn-------------------------------------------------------------------------------
71209878SnwhitehornSoftware IEC/IEEE floating-point underflow tininess-detection mode.
72209878Snwhitehorn-------------------------------------------------------------------------------
73209878Snwhitehorn*/
74209878Snwhitehorn#ifndef SOFTFLOAT_FOR_GCC
75209878Snwhitehornextern int8 float_detect_tininess;
76209878Snwhitehorn#endif
77209878Snwhitehornenum {
78209878Snwhitehorn    float_tininess_after_rounding  = 0,
79209878Snwhitehorn    float_tininess_before_rounding = 1
80209878Snwhitehorn};
81209878Snwhitehorn
82209878Snwhitehorn/*
83209878Snwhitehorn-------------------------------------------------------------------------------
84209878SnwhitehornSoftware IEC/IEEE floating-point rounding mode.
85209878Snwhitehorn-------------------------------------------------------------------------------
86209878Snwhitehorn*/
87209878Snwhitehornextern fp_rnd_t float_rounding_mode;
88209878Snwhitehornenum {
89209878Snwhitehorn    float_round_nearest_even = FP_RN,
90209878Snwhitehorn    float_round_to_zero      = FP_RZ,
91209878Snwhitehorn    float_round_down         = FP_RM,
92209878Snwhitehorn    float_round_up           = FP_RP
93209878Snwhitehorn};
94209878Snwhitehorn
95209878Snwhitehorn/*
96209878Snwhitehorn-------------------------------------------------------------------------------
97209878SnwhitehornSoftware IEC/IEEE floating-point exception flags.
98209878Snwhitehorn-------------------------------------------------------------------------------
99209878Snwhitehorn*/
100209878Snwhitehorntypedef fp_except_t fp_except;
101209878Snwhitehorn
102209878Snwhitehornextern fp_except float_exception_flags;
103209878Snwhitehornextern fp_except float_exception_mask;
104209878Snwhitehornenum {
105209878Snwhitehorn    float_flag_inexact   = FP_X_IMP,
106209878Snwhitehorn    float_flag_underflow = FP_X_UFL,
107209878Snwhitehorn    float_flag_overflow  = FP_X_OFL,
108209878Snwhitehorn    float_flag_divbyzero = FP_X_DZ,
109209878Snwhitehorn    float_flag_invalid   = FP_X_INV
110209878Snwhitehorn};
111209878Snwhitehorn
112209878Snwhitehorn/*
113209878Snwhitehorn-------------------------------------------------------------------------------
114209878SnwhitehornRoutine to raise any or all of the software IEC/IEEE floating-point
115209878Snwhitehornexception flags.
116209878Snwhitehorn-------------------------------------------------------------------------------
117209878Snwhitehorn*/
118209878Snwhitehornvoid float_raise( fp_except );
119209878Snwhitehorn
120209878Snwhitehorn/*
121209878Snwhitehorn-------------------------------------------------------------------------------
122209878SnwhitehornSoftware IEC/IEEE integer-to-floating-point conversion routines.
123209878Snwhitehorn-------------------------------------------------------------------------------
124209878Snwhitehorn*/
125209878Snwhitehornfloat32 int32_to_float32( int );
126209878Snwhitehornfloat64 int32_to_float64( int );
127209878Snwhitehorn#ifdef FLOATX80
128209878Snwhitehornfloatx80 int32_to_floatx80( int );
129209878Snwhitehorn#endif
130209878Snwhitehorn#ifdef FLOAT128
131209878Snwhitehornfloat128 int32_to_float128( int );
132209878Snwhitehorn#endif
133209878Snwhitehornfloat32 int64_to_float32( long long );
134209878Snwhitehornfloat64 int64_to_float64( long long );
135209878Snwhitehorn#ifdef FLOATX80
136209878Snwhitehornfloatx80 int64_to_floatx80( long long );
137209878Snwhitehorn#endif
138209878Snwhitehorn#ifdef FLOAT128
139209878Snwhitehornfloat128 int64_to_float128( long long );
140209878Snwhitehorn#endif
141209878Snwhitehorn
142209878Snwhitehorn/*
143209878Snwhitehorn-------------------------------------------------------------------------------
144209878SnwhitehornSoftware IEC/IEEE single-precision conversion routines.
145209878Snwhitehorn-------------------------------------------------------------------------------
146209878Snwhitehorn*/
147209878Snwhitehornint float32_to_int32( float32 );
148209878Snwhitehornint float32_to_int32_round_to_zero( float32 );
149209878Snwhitehornunsigned int float32_to_uint32_round_to_zero( float32 );
150209878Snwhitehornlong long float32_to_int64( float32 );
151209878Snwhitehornlong long float32_to_int64_round_to_zero( float32 );
152209878Snwhitehornfloat64 float32_to_float64( float32 );
153209878Snwhitehorn#ifdef FLOATX80
154209878Snwhitehornfloatx80 float32_to_floatx80( float32 );
155209878Snwhitehorn#endif
156209878Snwhitehorn#ifdef FLOAT128
157209878Snwhitehornfloat128 float32_to_float128( float32 );
158209878Snwhitehorn#endif
159209878Snwhitehorn
160209878Snwhitehorn/*
161209878Snwhitehorn-------------------------------------------------------------------------------
162209878SnwhitehornSoftware IEC/IEEE single-precision operations.
163209878Snwhitehorn-------------------------------------------------------------------------------
164209878Snwhitehorn*/
165209878Snwhitehornfloat32 float32_round_to_int( float32 );
166209878Snwhitehornfloat32 float32_add( float32, float32 );
167209878Snwhitehornfloat32 float32_sub( float32, float32 );
168209878Snwhitehornfloat32 float32_mul( float32, float32 );
169209878Snwhitehornfloat32 float32_div( float32, float32 );
170209878Snwhitehornfloat32 float32_rem( float32, float32 );
171209878Snwhitehornfloat32 float32_sqrt( float32 );
172209878Snwhitehornint float32_eq( float32, float32 );
173209878Snwhitehornint float32_le( float32, float32 );
174209878Snwhitehornint float32_lt( float32, float32 );
175209878Snwhitehornint float32_eq_signaling( float32, float32 );
176209878Snwhitehornint float32_le_quiet( float32, float32 );
177209878Snwhitehornint float32_lt_quiet( float32, float32 );
178209878Snwhitehorn#ifndef SOFTFLOAT_FOR_GCC
179209878Snwhitehornint float32_is_signaling_nan( float32 );
180209878Snwhitehorn#endif
181209878Snwhitehorn
182209878Snwhitehorn/*
183209878Snwhitehorn-------------------------------------------------------------------------------
184209878SnwhitehornSoftware IEC/IEEE double-precision conversion routines.
185209878Snwhitehorn-------------------------------------------------------------------------------
186209878Snwhitehorn*/
187209878Snwhitehornint float64_to_int32( float64 );
188209878Snwhitehornint float64_to_int32_round_to_zero( float64 );
189209878Snwhitehornunsigned int float64_to_uint32_round_to_zero( float64 );
190209878Snwhitehornlong long float64_to_int64( float64 );
191209878Snwhitehornlong long float64_to_int64_round_to_zero( float64 );
192209878Snwhitehornfloat32 float64_to_float32( float64 );
193209878Snwhitehorn#ifdef FLOATX80
194209878Snwhitehornfloatx80 float64_to_floatx80( float64 );
195209878Snwhitehorn#endif
196209878Snwhitehorn#ifdef FLOAT128
197209878Snwhitehornfloat128 float64_to_float128( float64 );
198209878Snwhitehorn#endif
199209878Snwhitehorn
200209878Snwhitehorn/*
201209878Snwhitehorn-------------------------------------------------------------------------------
202209878SnwhitehornSoftware IEC/IEEE double-precision operations.
203209878Snwhitehorn-------------------------------------------------------------------------------
204209878Snwhitehorn*/
205209878Snwhitehornfloat64 float64_round_to_int( float64 );
206209878Snwhitehornfloat64 float64_add( float64, float64 );
207209878Snwhitehornfloat64 float64_sub( float64, float64 );
208209878Snwhitehornfloat64 float64_mul( float64, float64 );
209209878Snwhitehornfloat64 float64_div( float64, float64 );
210209878Snwhitehornfloat64 float64_rem( float64, float64 );
211209878Snwhitehornfloat64 float64_sqrt( float64 );
212209878Snwhitehornint float64_eq( float64, float64 );
213209878Snwhitehornint float64_le( float64, float64 );
214209878Snwhitehornint float64_lt( float64, float64 );
215209878Snwhitehornint float64_eq_signaling( float64, float64 );
216209878Snwhitehornint float64_le_quiet( float64, float64 );
217209878Snwhitehornint float64_lt_quiet( float64, float64 );
218209878Snwhitehorn#ifndef SOFTFLOAT_FOR_GCC
219209878Snwhitehornint float64_is_signaling_nan( float64 );
220209878Snwhitehorn#endif
221209878Snwhitehorn
222209878Snwhitehorn#ifdef FLOATX80
223209878Snwhitehorn
224209878Snwhitehorn/*
225209878Snwhitehorn-------------------------------------------------------------------------------
226209878SnwhitehornSoftware IEC/IEEE extended double-precision conversion routines.
227209878Snwhitehorn-------------------------------------------------------------------------------
228209878Snwhitehorn*/
229209878Snwhitehornint floatx80_to_int32( floatx80 );
230209878Snwhitehornint floatx80_to_int32_round_to_zero( floatx80 );
231209878Snwhitehornlong long floatx80_to_int64( floatx80 );
232209878Snwhitehornlong long floatx80_to_int64_round_to_zero( floatx80 );
233209878Snwhitehornfloat32 floatx80_to_float32( floatx80 );
234209878Snwhitehornfloat64 floatx80_to_float64( floatx80 );
235209878Snwhitehorn#ifdef FLOAT128
236209878Snwhitehornfloat128 floatx80_to_float128( floatx80 );
237209878Snwhitehorn#endif
238209878Snwhitehorn
239209878Snwhitehorn/*
240209878Snwhitehorn-------------------------------------------------------------------------------
241209878SnwhitehornSoftware IEC/IEEE extended double-precision rounding precision.  Valid
242209878Snwhitehornvalues are 32, 64, and 80.
243209878Snwhitehorn-------------------------------------------------------------------------------
244209878Snwhitehorn*/
245209878Snwhitehornextern int floatx80_rounding_precision;
246209878Snwhitehorn
247209878Snwhitehorn/*
248209878Snwhitehorn-------------------------------------------------------------------------------
249209878SnwhitehornSoftware IEC/IEEE extended double-precision operations.
250209878Snwhitehorn-------------------------------------------------------------------------------
251209878Snwhitehorn*/
252209878Snwhitehornfloatx80 floatx80_round_to_int( floatx80 );
253209878Snwhitehornfloatx80 floatx80_add( floatx80, floatx80 );
254209878Snwhitehornfloatx80 floatx80_sub( floatx80, floatx80 );
255209878Snwhitehornfloatx80 floatx80_mul( floatx80, floatx80 );
256209878Snwhitehornfloatx80 floatx80_div( floatx80, floatx80 );
257209878Snwhitehornfloatx80 floatx80_rem( floatx80, floatx80 );
258209878Snwhitehornfloatx80 floatx80_sqrt( floatx80 );
259209878Snwhitehornint floatx80_eq( floatx80, floatx80 );
260209878Snwhitehornint floatx80_le( floatx80, floatx80 );
261209878Snwhitehornint floatx80_lt( floatx80, floatx80 );
262209878Snwhitehornint floatx80_eq_signaling( floatx80, floatx80 );
263209878Snwhitehornint floatx80_le_quiet( floatx80, floatx80 );
264209878Snwhitehornint floatx80_lt_quiet( floatx80, floatx80 );
265209878Snwhitehornint floatx80_is_signaling_nan( floatx80 );
266209878Snwhitehorn
267209878Snwhitehorn#endif
268209878Snwhitehorn
269209878Snwhitehorn#ifdef FLOAT128
270209878Snwhitehorn
271209878Snwhitehorn/*
272209878Snwhitehorn-------------------------------------------------------------------------------
273209878SnwhitehornSoftware IEC/IEEE quadruple-precision conversion routines.
274209878Snwhitehorn-------------------------------------------------------------------------------
275209878Snwhitehorn*/
276209878Snwhitehornint float128_to_int32( float128 );
277209878Snwhitehornint float128_to_int32_round_to_zero( float128 );
278209878Snwhitehornlong long float128_to_int64( float128 );
279209878Snwhitehornlong long float128_to_int64_round_to_zero( float128 );
280209878Snwhitehornfloat32 float128_to_float32( float128 );
281209878Snwhitehornfloat64 float128_to_float64( float128 );
282209878Snwhitehorn#ifdef FLOATX80
283209878Snwhitehornfloatx80 float128_to_floatx80( float128 );
284209878Snwhitehorn#endif
285209878Snwhitehorn
286209878Snwhitehorn/*
287209878Snwhitehorn-------------------------------------------------------------------------------
288209878SnwhitehornSoftware IEC/IEEE quadruple-precision operations.
289209878Snwhitehorn-------------------------------------------------------------------------------
290209878Snwhitehorn*/
291209878Snwhitehornfloat128 float128_round_to_int( float128 );
292209878Snwhitehornfloat128 float128_add( float128, float128 );
293209878Snwhitehornfloat128 float128_sub( float128, float128 );
294209878Snwhitehornfloat128 float128_mul( float128, float128 );
295209878Snwhitehornfloat128 float128_div( float128, float128 );
296209878Snwhitehornfloat128 float128_rem( float128, float128 );
297209878Snwhitehornfloat128 float128_sqrt( float128 );
298209878Snwhitehornint float128_eq( float128, float128 );
299209878Snwhitehornint float128_le( float128, float128 );
300209878Snwhitehornint float128_lt( float128, float128 );
301209878Snwhitehornint float128_eq_signaling( float128, float128 );
302209878Snwhitehornint float128_le_quiet( float128, float128 );
303209878Snwhitehornint float128_lt_quiet( float128, float128 );
304209878Snwhitehornint float128_is_signaling_nan( float128 );
305209878Snwhitehorn
306209878Snwhitehorn#endif
307209878Snwhitehorn
308