1 /* Header file for fp-bit.c. */
2 /* Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING. If not, write to
18 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
31 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
32 from this file are compiled via additional -D options.
34 This avoids the need to pull in the entire fp emulation library
35 when only a small number of functions are needed.
37 If FINE_GRAINED_LIBRARIES is not defined, then compile every
39 #ifndef FINE_GRAINED_LIBRARIES
50 #define L_fpcmp_parts_sf
51 #define L_fpcmp_parts_df
87 #endif /* ! FINE_GRAINED_LIBRARIES */
89 #if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
90 # if defined(TFLOAT) || defined(L_sf_to_tf) || defined(L_df_to_tf)
95 typedef float SFtype
__attribute__ ((mode (SF
)));
96 typedef float DFtype
__attribute__ ((mode (DF
)));
98 typedef float TFtype
__attribute__ ((mode (TF
)));
101 typedef int HItype
__attribute__ ((mode (HI
)));
102 typedef int SItype
__attribute__ ((mode (SI
)));
103 typedef int DItype
__attribute__ ((mode (DI
)));
105 typedef int TItype
__attribute__ ((mode (TI
)));
108 /* The type of the result of a fp compare */
110 #define CMPtype SItype
113 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
114 typedef unsigned int USItype
__attribute__ ((mode (SI
)));
115 typedef unsigned int UDItype
__attribute__ ((mode (DI
)));
117 typedef unsigned int UTItype
__attribute__ ((mode (TI
)));
120 #define MAX_USI_INT (~(USItype)0)
121 #define MAX_SI_INT ((SItype) (MAX_USI_INT >> 1))
122 #define BITS_PER_SI (4 * BITS_PER_UNIT)
124 #define MAX_UDI_INT (~(UDItype)0)
125 #define MAX_DI_INT ((DItype) (MAX_UDI_INT >> 1))
126 #define BITS_PER_DI (8 * BITS_PER_UNIT)
135 # error "TFLOAT requires long double to have 113 bits of mantissa"
138 # define PREFIXFPDP tp
139 # define PREFIXSFDF tf
140 # define NGARDS 10L /* Is this right? */
141 # define GARDROUND 0x1ff
142 # define GARDMASK 0x3ff
143 # define GARDMSB 0x200
144 # define FRAC_NBITS 128
146 # if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
148 # define EXPBIAS 16383
149 # define EXPMAX (0x7fff)
150 # define QUIET_NAN ((TItype)0x8 << 108)
151 # define FRACHIGH ((TItype)0x8 << 124)
152 # define FRACHIGH2 ((TItype)0xc << 124)
153 # define FRACBITS 112
156 # if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
158 # define EXPBIAS 1023
159 # define EXPMAX (0x7ff)
160 # define QUIET_NAN ((TItype)0x8 << (48 + 64))
161 # define FRACHIGH ((TItype)0x8 << 124)
162 # define FRACHIGH2 ((TItype)0xc << 124)
163 # define FRACBITS 105
164 # define HALFFRACBITS 52
165 # define HALFSHIFT 64
168 # define pack_d __pack_t
169 # define unpack_d __unpack_t
170 # define __fpcmp_parts __fpcmp_parts_t
171 typedef UTItype fractype
;
172 typedef UDItype halffractype
;
173 typedef USItype qrtrfractype
;
174 #define qrtrfractype qrtrfractype
175 typedef TFtype FLO_type
;
176 typedef TItype intfrac
;
179 # define GARDROUND 0x3f
180 # define GARDMASK 0x7f
181 # define GARDMSB 0x40
185 # define EXPMAX (0xff)
186 # define QUIET_NAN 0x100000L
187 # define FRAC_NBITS 32
188 # define FRACHIGH 0x80000000L
189 # define FRACHIGH2 0xc0000000L
190 # define pack_d __pack_f
191 # define unpack_d __unpack_f
192 # define __fpcmp_parts __fpcmp_parts_f
193 typedef USItype fractype
;
194 typedef UHItype halffractype
;
195 typedef SFtype FLO_type
;
196 typedef SItype intfrac
;
199 # define PREFIXFPDP dp
200 # define PREFIXSFDF df
202 # define GARDROUND 0x7f
203 # define GARDMASK 0xff
204 # define GARDMSB 0x80
206 # define EXPBIAS 1023
208 # define EXPMAX (0x7ff)
209 # define QUIET_NAN 0x8000000000000LL
210 # define FRAC_NBITS 64
211 # define FRACHIGH 0x8000000000000000LL
212 # define FRACHIGH2 0xc000000000000000LL
213 # define pack_d __pack_d
214 # define unpack_d __unpack_d
215 # define __fpcmp_parts __fpcmp_parts_d
216 typedef UDItype fractype
;
217 typedef USItype halffractype
;
218 typedef DFtype FLO_type
;
219 typedef DItype intfrac
;
222 #ifdef US_SOFTWARE_GOFAST
224 # error "GOFAST TFmode not supported"
228 # define multiply fpmul
229 # define divide fpdiv
230 # define compare fpcmp
231 # define _unord_f2 __unordsf2
232 # define usi_to_float __floatunsisf
233 # define si_to_float sitofp
234 # define float_to_si fptosi
235 # define float_to_usi fptoui
236 # define negate __negsf2
237 # define sf_to_df fptodp
238 # define sf_to_tf __extendsftf2
242 # define multiply dpmul
243 # define divide dpdiv
244 # define compare dpcmp
245 # define _unord_f2 __unorddf2
246 # define usi_to_float __floatunsidf
247 # define si_to_float litodp
248 # define float_to_si dptoli
249 # define float_to_usi dptoul
250 # define negate __negdf2
251 # define df_to_sf dptofp
252 # define df_to_tf __extenddftf2
256 # define add __addtf3
257 # define sub __subtf3
258 # define multiply __multf3
259 # define divide __divtf3
260 # define compare __cmptf2
261 # define _eq_f2 __eqtf2
262 # define _ne_f2 __netf2
263 # define _gt_f2 __gttf2
264 # define _ge_f2 __getf2
265 # define _lt_f2 __lttf2
266 # define _le_f2 __letf2
267 # define _unord_f2 __unordtf2
268 # define usi_to_float __floatunsitf
269 # define si_to_float __floatsitf
270 # define float_to_si __fixtfsi
271 # define float_to_usi __fixunstfsi
272 # define negate __negtf2
273 # define tf_to_sf __trunctfsf2
274 # define tf_to_df __trunctfdf2
276 # define add __addsf3
277 # define sub __subsf3
278 # define multiply __mulsf3
279 # define divide __divsf3
280 # define compare __cmpsf2
281 # define _eq_f2 __eqsf2
282 # define _ne_f2 __nesf2
283 # define _gt_f2 __gtsf2
284 # define _ge_f2 __gesf2
285 # define _lt_f2 __ltsf2
286 # define _le_f2 __lesf2
287 # define _unord_f2 __unordsf2
288 # define usi_to_float __floatunsisf
289 # define si_to_float __floatsisf
290 # define float_to_si __fixsfsi
291 # define float_to_usi __fixunssfsi
292 # define negate __negsf2
293 # define sf_to_df __extendsfdf2
294 # define sf_to_tf __extendsftf2
296 # define add __adddf3
297 # define sub __subdf3
298 # define multiply __muldf3
299 # define divide __divdf3
300 # define compare __cmpdf2
301 # define _eq_f2 __eqdf2
302 # define _ne_f2 __nedf2
303 # define _gt_f2 __gtdf2
304 # define _ge_f2 __gedf2
305 # define _lt_f2 __ltdf2
306 # define _le_f2 __ledf2
307 # define _unord_f2 __unorddf2
308 # define usi_to_float __floatunsidf
309 # define si_to_float __floatsidf
310 # define float_to_si __fixdfsi
311 # define float_to_usi __fixunsdfsi
312 # define negate __negdf2
313 # define df_to_sf __truncdfsf2
314 # define df_to_tf __extenddftf2
316 #endif /* US_SOFTWARE_GOFAST */
319 #define INLINE __inline__
322 /* Preserve the sticky-bit when shifting fractions to the right. */
323 #define LSHIFT(a) { a = (a & 1) | (a >> 1); }
325 /* numeric parameters */
326 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
327 of a float and of a double. Assumes there are only two float types.
328 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
330 #define F_D_BITOFF (52+8-(23+7))
333 # define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
334 # define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
338 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
339 #define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
340 #define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
379 qrtrfractype qwords
[4];
381 halffractype words
[2];
385 #ifdef FLOAT_BIT_ORDER_MISMATCH
388 fractype fraction
:FRACBITS
__attribute__ ((packed
));
389 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
390 unsigned int sign
:1 __attribute__ ((packed
));
395 #ifdef _DEBUG_BITFLOAT
398 unsigned int sign
:1 __attribute__ ((packed
));
399 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
400 fractype fraction
:FRACBITS
__attribute__ ((packed
));
406 fractype fraction
:FRACBITS
__attribute__ ((packed
));
407 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
408 unsigned int sign
:1 __attribute__ ((packed
));
417 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
418 extern FLO_type
pack_d (fp_number_type
*);
421 extern void unpack_d (FLO_union_type
*, fp_number_type
*);
423 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
424 extern FLO_type
add (FLO_type
, FLO_type
);
425 extern FLO_type
sub (FLO_type
, FLO_type
);
428 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
429 extern FLO_type
multiply (FLO_type
, FLO_type
);
432 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
433 extern FLO_type
divide (FLO_type
, FLO_type
);
436 extern int __fpcmp_parts (fp_number_type
*, fp_number_type
*);
438 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
439 extern CMPtype
compare (FLO_type
, FLO_type
);
442 #ifndef US_SOFTWARE_GOFAST
444 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
445 extern CMPtype
_eq_f2 (FLO_type
, FLO_type
);
448 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
449 extern CMPtype
_ne_f2 (FLO_type
, FLO_type
);
452 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
453 extern CMPtype
_gt_f2 (FLO_type
, FLO_type
);
456 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
457 extern CMPtype
_ge_f2 (FLO_type
, FLO_type
);
460 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
461 extern CMPtype
_lt_f2 (FLO_type
, FLO_type
);
464 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
465 extern CMPtype
_le_f2 (FLO_type
, FLO_type
);
468 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
469 extern CMPtype
_unord_f2 (FLO_type
, FLO_type
);
472 #endif /* ! US_SOFTWARE_GOFAST */
474 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
475 extern FLO_type
si_to_float (SItype
);
478 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
479 extern SItype
float_to_si (FLO_type
);
482 #if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
483 #if defined(US_SOFTWARE_GOFAST) || defined(L_tf_to_usi)
484 extern USItype
float_to_usi (FLO_type
);
488 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
489 extern FLO_type
usi_to_float (USItype
);
492 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
493 extern FLO_type
negate (FLO_type
);
497 #if defined(L_make_sf)
498 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
501 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
502 #if defined(L_sf_to_df)
503 extern DFtype
sf_to_df (SFtype
);
505 #if defined(L_sf_to_tf) && defined(TMODES)
506 extern TFtype
sf_to_tf (SFtype
);
508 #endif /* ! FLOAT_ONLY */
512 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
513 #if defined(L_make_df)
514 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
516 #if defined(L_df_to_sf)
517 extern SFtype
df_to_sf (DFtype
);
519 #if defined(L_df_to_tf) && defined(TMODES)
520 extern TFtype
df_to_tf (DFtype
);
525 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
526 extern TFtype
__make_tp (fp_class_type
, unsigned int, int, UTItype
);
528 #if defined(L_tf_to_sf)
529 extern SFtype
tf_to_sf (TFtype
);
531 #if defined(L_tf_to_df)
532 extern DFtype
tf_to_df (TFtype
);
534 #if defined(L_di_to_tf)
535 extern TFtype
di_to_df (DItype
);
540 #endif /* ! GCC_FP_BIT_H */