1 /* Header file for fp-bit.c. */
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
32 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
33 from this file are compiled via additional -D options.
35 This avoids the need to pull in the entire fp emulation library
36 when only a small number of functions are needed.
38 If FINE_GRAINED_LIBRARIES is not defined, then compile every
40 #ifndef FINE_GRAINED_LIBRARIES
51 #define L_fpcmp_parts_sf
52 #define L_fpcmp_parts_df
86 #endif /* ! FINE_GRAINED_LIBRARIES */
88 typedef float SFtype __attribute__ ((mode (SF)));
89 typedef float DFtype __attribute__ ((mode (DF)));
91 typedef int HItype __attribute__ ((mode (HI)));
92 typedef int SItype __attribute__ ((mode (SI)));
93 typedef int DItype __attribute__ ((mode (DI)));
95 /* The type of the result of a fp compare */
97 #define CMPtype SItype
100 typedef unsigned int UHItype __attribute__ ((mode (HI)));
101 typedef unsigned int USItype __attribute__ ((mode (SI)));
102 typedef unsigned int UDItype __attribute__ ((mode (DI)));
104 #define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
105 #define MAX_USI_INT ((USItype) ~0)
114 # define GARDROUND 0x3f
115 # define GARDMASK 0x7f
116 # define GARDMSB 0x40
120 # define EXPMAX (0xff)
121 # define QUIET_NAN 0x100000L
122 # define FRAC_NBITS 32
123 # define FRACHIGH 0x80000000L
124 # define FRACHIGH2 0xc0000000L
125 # define pack_d __pack_f
126 # define unpack_d __unpack_f
127 # define __fpcmp_parts __fpcmp_parts_f
128 typedef USItype fractype;
129 typedef UHItype halffractype;
130 typedef SFtype FLO_type;
131 typedef SItype intfrac;
134 # define PREFIXFPDP dp
135 # define PREFIXSFDF df
137 # define GARDROUND 0x7f
138 # define GARDMASK 0xff
139 # define GARDMSB 0x80
141 # define EXPBIAS 1023
143 # define EXPMAX (0x7ff)
144 # define QUIET_NAN 0x8000000000000LL
145 # define FRAC_NBITS 64
146 # define FRACHIGH 0x8000000000000000LL
147 # define FRACHIGH2 0xc000000000000000LL
148 # define pack_d __pack_d
149 # define unpack_d __unpack_d
150 # define __fpcmp_parts __fpcmp_parts_d
151 typedef UDItype fractype;
152 typedef USItype halffractype;
153 typedef DFtype FLO_type;
154 typedef DItype intfrac;
157 #ifdef US_SOFTWARE_GOFAST
161 # define multiply fpmul
162 # define divide fpdiv
163 # define compare fpcmp
164 # define si_to_float sitofp
165 # define float_to_si fptosi
166 # define float_to_usi fptoui
167 # define negate __negsf2
168 # define sf_to_df fptodp
169 # define dptofp dptofp
173 # define multiply dpmul
174 # define divide dpdiv
175 # define compare dpcmp
176 # define si_to_float litodp
177 # define float_to_si dptoli
178 # define float_to_usi dptoul
179 # define negate __negdf2
180 # define df_to_sf dptofp
184 # define add __addsf3
185 # define sub __subsf3
186 # define multiply __mulsf3
187 # define divide __divsf3
188 # define compare __cmpsf2
189 # define _eq_f2 __eqsf2
190 # define _ne_f2 __nesf2
191 # define _gt_f2 __gtsf2
192 # define _ge_f2 __gesf2
193 # define _lt_f2 __ltsf2
194 # define _le_f2 __lesf2
195 # define _unord_f2 __unordsf2
196 # define si_to_float __floatsisf
197 # define float_to_si __fixsfsi
198 # define float_to_usi __fixunssfsi
199 # define negate __negsf2
200 # define sf_to_df __extendsfdf2
202 # define add __adddf3
203 # define sub __subdf3
204 # define multiply __muldf3
205 # define divide __divdf3
206 # define compare __cmpdf2
207 # define _eq_f2 __eqdf2
208 # define _ne_f2 __nedf2
209 # define _gt_f2 __gtdf2
210 # define _ge_f2 __gedf2
211 # define _lt_f2 __ltdf2
212 # define _le_f2 __ledf2
213 # define _unord_f2 __unorddf2
214 # define si_to_float __floatsidf
215 # define float_to_si __fixdfsi
216 # define float_to_usi __fixunsdfsi
217 # define negate __negdf2
218 # define df_to_sf __truncdfsf2
220 #endif /* US_SOFTWARE_GOFAST */
223 #define INLINE __inline__
226 /* Preserve the sticky-bit when shifting fractions to the right. */
227 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
229 /* numeric parameters */
230 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
231 of a float and of a double. Assumes there are only two float types.
232 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
234 #define F_D_BITOFF (52+8-(23+7))
237 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
238 #define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
239 #define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
277 halffractype words[2];
280 #ifdef FLOAT_BIT_ORDER_MISMATCH
283 fractype fraction:FRACBITS __attribute__ ((packed));
284 unsigned int exp:EXPBITS __attribute__ ((packed));
285 unsigned int sign:1 __attribute__ ((packed));
290 #ifdef _DEBUG_BITFLOAT
293 unsigned int sign:1 __attribute__ ((packed));
294 unsigned int exp:EXPBITS __attribute__ ((packed));
295 fractype fraction:FRACBITS __attribute__ ((packed));
301 fractype fraction:FRACBITS __attribute__ ((packed));
302 unsigned int exp:EXPBITS __attribute__ ((packed));
303 unsigned int sign:1 __attribute__ ((packed));
312 #if defined(L_pack_df) || defined(L_pack_sf)
313 extern FLO_type pack_d (fp_number_type *);
316 extern void unpack_d (FLO_union_type *, fp_number_type *);
318 #if defined(L_addsub_sf) || defined(L_addsub_df)
319 extern FLO_type add (FLO_type, FLO_type);
320 extern FLO_type sub (FLO_type, FLO_type);
323 #if defined(L_mul_sf) || defined(L_mul_df)
324 extern FLO_type multiply (FLO_type, FLO_type);
327 #if defined(L_div_sf) || defined(L_div_df)
328 extern FLO_type divide (FLO_type, FLO_type);
331 extern int __fpcmp_parts (fp_number_type *, fp_number_type *);
333 #if defined(L_compare_sf) || defined(L_compare_df)
334 extern CMPtype compare (FLO_type, FLO_type);
337 #ifndef US_SOFTWARE_GOFAST
339 #if defined(L_eq_sf) || defined(L_eq_df)
340 extern CMPtype _eq_f2 (FLO_type, FLO_type);
343 #if defined(L_ne_sf) || defined(L_ne_df)
344 extern CMPtype _ne_f2 (FLO_type, FLO_type);
347 #if defined(L_gt_sf) || defined(L_gt_df)
348 extern CMPtype _gt_f2 (FLO_type, FLO_type);
351 #if defined(L_ge_sf) || defined(L_ge_df)
352 extern CMPtype _ge_f2 (FLO_type, FLO_type);
355 #if defined(L_lt_sf) || defined(L_lt_df)
356 extern CMPtype _lt_f2 (FLO_type, FLO_type);
359 #if defined(L_le_sf) || defined(L_le_df)
360 extern CMPtype _le_f2 (FLO_type, FLO_type);
363 #if defined(L_unord_sf) || defined(L_unord_df)
364 extern CMPtype _unord_f2 (FLO_type, FLO_type);
367 #endif /* ! US_SOFTWARE_GOFAST */
369 #if defined(L_si_to_sf) || defined(L_si_to_df)
370 extern FLO_type si_to_float (SItype);
373 #if defined(L_sf_to_si) || defined(L_df_to_si)
374 extern SItype float_to_si (FLO_type);
377 #if defined(L_sf_to_usi) || defined(L_df_to_usi)
378 #ifdef US_SOFTWARE_GOFAST
379 extern USItype float_to_usi (FLO_type);
383 #if defined(L_negate_sf) || defined(L_negate_df)
384 extern FLO_type negate (FLO_type);
388 #if defined(L_make_sf)
389 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
392 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
393 #if defined(L_sf_to_df)
394 extern DFtype sf_to_df (SFtype);
396 #endif /* ! FLOAT_ONLY */
400 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
401 #if defined(L_make_df)
402 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
404 #if defined(L_df_to_sf)
405 extern SFtype df_to_sf (DFtype);
409 #endif /* __FP_BIT_H__ */