1 /* Header file for fp-bit.c. */
2 /* Copyright (C) 2000, 2002, 2003, 2006, 2009 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
28 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
29 from this file are compiled via additional -D options.
31 This avoids the need to pull in the entire fp emulation library
32 when only a small number of functions are needed.
34 If FINE_GRAINED_LIBRARIES is not defined, then compile every
36 #ifndef FINE_GRAINED_LIBRARIES
47 #define L_fpcmp_parts_sf
48 #define L_fpcmp_parts_df
84 #endif /* ! FINE_GRAINED_LIBRARIES */
86 #if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
87 # if defined(TFLOAT) || defined(L_sf_to_tf) || defined(L_df_to_tf)
92 typedef float SFtype
__attribute__ ((mode (SF
)));
93 typedef float DFtype
__attribute__ ((mode (DF
)));
95 typedef float TFtype
__attribute__ ((mode (TF
)));
98 typedef int HItype
__attribute__ ((mode (HI
)));
99 typedef int SItype
__attribute__ ((mode (SI
)));
100 typedef int DItype
__attribute__ ((mode (DI
)));
102 typedef int TItype
__attribute__ ((mode (TI
)));
105 /* The type of the result of a floating point comparison. This must
106 match `__libgcc_cmp_return__' in GCC for the target. */
108 typedef int CMPtype
__attribute__ ((mode (__libgcc_cmp_return__
)));
111 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
112 typedef unsigned int USItype
__attribute__ ((mode (SI
)));
113 typedef unsigned int UDItype
__attribute__ ((mode (DI
)));
115 typedef unsigned int UTItype
__attribute__ ((mode (TI
)));
118 #define MAX_USI_INT (~(USItype)0)
119 #define MAX_SI_INT ((SItype) (MAX_USI_INT >> 1))
120 #define BITS_PER_SI (4 * BITS_PER_UNIT)
122 #define MAX_UDI_INT (~(UDItype)0)
123 #define MAX_DI_INT ((DItype) (MAX_UDI_INT >> 1))
124 #define BITS_PER_DI (8 * BITS_PER_UNIT)
133 # error "TFLOAT requires long double to have 113 bits of mantissa"
136 # define PREFIXFPDP tp
137 # define PREFIXSFDF tf
138 # define NGARDS 10L /* Is this right? */
139 # define GARDROUND 0x1ff
140 # define GARDMASK 0x3ff
141 # define GARDMSB 0x200
142 # define FRAC_NBITS 128
144 # if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
146 # define EXPBIAS 16383
147 # define EXPMAX (0x7fff)
148 # define QUIET_NAN ((TItype)0x8 << 108)
149 # define FRACHIGH ((TItype)0x8 << 124)
150 # define FRACHIGH2 ((TItype)0xc << 124)
151 # define FRACBITS 112
154 # if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
156 # define EXPBIAS 1023
157 # define EXPMAX (0x7ff)
158 # define QUIET_NAN ((TItype)0x8 << (48 + 64))
159 # define FRACHIGH ((TItype)0x8 << 124)
160 # define FRACHIGH2 ((TItype)0xc << 124)
161 # define FRACBITS 105
162 # define HALFFRACBITS 52
163 # define HALFSHIFT 64
166 # define pack_d __pack_t
167 # define unpack_d __unpack_t
168 # define __fpcmp_parts __fpcmp_parts_t
169 typedef UTItype fractype
;
170 typedef UDItype halffractype
;
171 typedef USItype qrtrfractype
;
172 #define qrtrfractype qrtrfractype
173 typedef TFtype FLO_type
;
174 typedef TItype intfrac
;
177 # define GARDROUND 0x3f
178 # define GARDMASK 0x7f
179 # define GARDMSB 0x40
183 # define EXPMAX (0xff)
184 # define QUIET_NAN 0x100000L
185 # define FRAC_NBITS 32
186 # define FRACHIGH 0x80000000L
187 # define FRACHIGH2 0xc0000000L
188 # define pack_d __pack_f
189 # define unpack_d __unpack_f
190 # define __fpcmp_parts __fpcmp_parts_f
191 typedef USItype fractype
;
192 typedef UHItype halffractype
;
193 typedef SFtype FLO_type
;
194 typedef SItype intfrac
;
197 # define PREFIXFPDP dp
198 # define PREFIXSFDF df
200 # define GARDROUND 0x7f
201 # define GARDMASK 0xff
202 # define GARDMSB 0x80
204 # define EXPBIAS 1023
206 # define EXPMAX (0x7ff)
207 # define QUIET_NAN 0x8000000000000LL
208 # define FRAC_NBITS 64
209 # define FRACHIGH 0x8000000000000000LL
210 # define FRACHIGH2 0xc000000000000000LL
211 # define pack_d __pack_d
212 # define unpack_d __unpack_d
213 # define __fpcmp_parts __fpcmp_parts_d
214 typedef UDItype fractype
;
215 typedef USItype halffractype
;
216 typedef DFtype FLO_type
;
217 typedef DItype intfrac
;
220 #ifdef US_SOFTWARE_GOFAST
222 # error "GOFAST TFmode not supported"
226 # define multiply fpmul
227 # define divide fpdiv
228 # define compare fpcmp
229 # define _unord_f2 __unordsf2
230 # define usi_to_float __floatunsisf
231 # define si_to_float sitofp
232 # define float_to_si fptosi
233 # define float_to_usi fptoui
234 # define negate __negsf2
235 # define sf_to_df fptodp
236 # define sf_to_tf __extendsftf2
240 # define multiply dpmul
241 # define divide dpdiv
242 # define compare dpcmp
243 # define _unord_f2 __unorddf2
244 # define usi_to_float __floatunsidf
245 # define si_to_float litodp
246 # define float_to_si dptoli
247 # define float_to_usi dptoul
248 # define negate __negdf2
249 # define df_to_sf dptofp
250 # define df_to_tf __extenddftf2
254 # define add __addtf3
255 # define sub __subtf3
256 # define multiply __multf3
257 # define divide __divtf3
258 # define compare __cmptf2
259 # define _eq_f2 __eqtf2
260 # define _ne_f2 __netf2
261 # define _gt_f2 __gttf2
262 # define _ge_f2 __getf2
263 # define _lt_f2 __lttf2
264 # define _le_f2 __letf2
265 # define _unord_f2 __unordtf2
266 # define usi_to_float __floatunsitf
267 # define si_to_float __floatsitf
268 # define float_to_si __fixtfsi
269 # define float_to_usi __fixunstfsi
270 # define negate __negtf2
271 # define tf_to_sf __trunctfsf2
272 # define tf_to_df __trunctfdf2
274 # define add __addsf3
275 # define sub __subsf3
276 # define multiply __mulsf3
277 # define divide __divsf3
278 # define compare __cmpsf2
279 # define _eq_f2 __eqsf2
280 # define _ne_f2 __nesf2
281 # define _gt_f2 __gtsf2
282 # define _ge_f2 __gesf2
283 # define _lt_f2 __ltsf2
284 # define _le_f2 __lesf2
285 # define _unord_f2 __unordsf2
286 # define usi_to_float __floatunsisf
287 # define si_to_float __floatsisf
288 # define float_to_si __fixsfsi
289 # define float_to_usi __fixunssfsi
290 # define negate __negsf2
291 # define sf_to_df __extendsfdf2
292 # define sf_to_tf __extendsftf2
294 # define add __adddf3
295 # define sub __subdf3
296 # define multiply __muldf3
297 # define divide __divdf3
298 # define compare __cmpdf2
299 # define _eq_f2 __eqdf2
300 # define _ne_f2 __nedf2
301 # define _gt_f2 __gtdf2
302 # define _ge_f2 __gedf2
303 # define _lt_f2 __ltdf2
304 # define _le_f2 __ledf2
305 # define _unord_f2 __unorddf2
306 # define usi_to_float __floatunsidf
307 # define si_to_float __floatsidf
308 # define float_to_si __fixdfsi
309 # define float_to_usi __fixunsdfsi
310 # define negate __negdf2
311 # define df_to_sf __truncdfsf2
312 # define df_to_tf __extenddftf2
314 #endif /* US_SOFTWARE_GOFAST */
317 #define INLINE __inline__
320 /* Preserve the sticky-bit when shifting fractions to the right. */
321 #define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
323 /* numeric parameters */
324 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
325 of a float and of a double. Assumes there are only two float types.
326 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
328 #define F_D_BITOFF (52+8-(23+7))
331 # define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
332 # define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
336 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
337 #define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
338 #define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
377 qrtrfractype qwords
[4];
379 halffractype words
[2];
383 #ifdef FLOAT_BIT_ORDER_MISMATCH
386 fractype fraction
:FRACBITS
__attribute__ ((packed
));
387 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
388 unsigned int sign
:1 __attribute__ ((packed
));
393 #ifdef _DEBUG_BITFLOAT
396 unsigned int sign
:1 __attribute__ ((packed
));
397 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
398 fractype fraction
:FRACBITS
__attribute__ ((packed
));
404 fractype fraction
:FRACBITS
__attribute__ ((packed
));
405 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
406 unsigned int sign
:1 __attribute__ ((packed
));
415 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
416 extern FLO_type
pack_d (const fp_number_type
*);
419 extern void unpack_d (FLO_union_type
*, fp_number_type
*);
421 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
422 extern FLO_type
add (FLO_type
, FLO_type
);
423 extern FLO_type
sub (FLO_type
, FLO_type
);
426 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
427 extern FLO_type
multiply (FLO_type
, FLO_type
);
430 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
431 extern FLO_type
divide (FLO_type
, FLO_type
);
434 extern int __fpcmp_parts (fp_number_type
*, fp_number_type
*);
436 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
437 extern CMPtype
compare (FLO_type
, FLO_type
);
440 #ifndef US_SOFTWARE_GOFAST
442 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
443 extern CMPtype
_eq_f2 (FLO_type
, FLO_type
);
446 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
447 extern CMPtype
_ne_f2 (FLO_type
, FLO_type
);
450 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
451 extern CMPtype
_gt_f2 (FLO_type
, FLO_type
);
454 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
455 extern CMPtype
_ge_f2 (FLO_type
, FLO_type
);
458 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
459 extern CMPtype
_lt_f2 (FLO_type
, FLO_type
);
462 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
463 extern CMPtype
_le_f2 (FLO_type
, FLO_type
);
466 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
467 extern CMPtype
_unord_f2 (FLO_type
, FLO_type
);
470 #endif /* ! US_SOFTWARE_GOFAST */
472 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
473 extern FLO_type
si_to_float (SItype
);
476 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
477 extern SItype
float_to_si (FLO_type
);
480 #if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
481 #if defined(US_SOFTWARE_GOFAST) || defined(L_tf_to_usi)
482 extern USItype
float_to_usi (FLO_type
);
486 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
487 extern FLO_type
usi_to_float (USItype
);
490 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
491 extern FLO_type
negate (FLO_type
);
495 #if defined(L_make_sf)
496 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
499 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
500 #if defined(L_sf_to_df)
501 extern DFtype
sf_to_df (SFtype
);
503 #if defined(L_sf_to_tf) && defined(TMODES)
504 extern TFtype
sf_to_tf (SFtype
);
506 #endif /* ! FLOAT_ONLY */
510 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
511 #if defined(L_make_df)
512 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
514 #if defined(L_df_to_sf)
515 extern SFtype
df_to_sf (DFtype
);
517 #if defined(L_df_to_tf) && defined(TMODES)
518 extern TFtype
df_to_tf (DFtype
);
523 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
524 extern TFtype
__make_tp (fp_class_type
, unsigned int, int, UTItype
);
526 #if defined(L_tf_to_sf)
527 extern SFtype
tf_to_sf (TFtype
);
529 #if defined(L_tf_to_df)
530 extern DFtype
tf_to_df (TFtype
);
532 #if defined(L_di_to_tf)
533 extern TFtype
di_to_df (DItype
);
538 #endif /* ! GCC_FP_BIT_H */