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