1 /* Header file for fp-bit.c. */
2 /* Copyright (C) 2000-2015 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)
131 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
132 #define FLOAT_BIT_ORDER_MISMATCH
135 #if __BYTE_ORDER__ != __FLOAT_WORD_ORDER__
136 #define FLOAT_WORD_ORDER_MISMATCH
141 # error "TFLOAT requires long double to have 113 bits of mantissa"
144 # define PREFIXFPDP tp
145 # define PREFIXSFDF tf
146 # define NGARDS 10L /* Is this right? */
147 # define GARDROUND 0x1ff
148 # define GARDMASK 0x3ff
149 # define GARDMSB 0x200
150 # define FRAC_NBITS 128
152 # if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
154 # define EXPBIAS 16383
155 # define EXPMAX (0x7fff)
156 # define QUIET_NAN ((TItype)0x8 << 108)
157 # define FRACHIGH ((TItype)0x8 << 124)
158 # define FRACHIGH2 ((TItype)0xc << 124)
159 # define FRACBITS 112
162 # if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
164 # define EXPBIAS 1023
165 # define EXPMAX (0x7ff)
166 # define QUIET_NAN ((TItype)0x8 << (48 + 64))
167 # define FRACHIGH ((TItype)0x8 << 124)
168 # define FRACHIGH2 ((TItype)0xc << 124)
169 # define FRACBITS 105
170 # define HALFFRACBITS 52
171 # define HALFSHIFT 64
174 # define pack_d __pack_t
175 # define unpack_d __unpack_t
176 # define __fpcmp_parts __fpcmp_parts_t
177 typedef UTItype fractype
;
178 typedef UDItype halffractype
;
179 typedef USItype qrtrfractype
;
180 #define qrtrfractype qrtrfractype
181 typedef TFtype FLO_type
;
182 typedef TItype intfrac
;
185 # define GARDROUND 0x3f
186 # define GARDMASK 0x7f
187 # define GARDMSB 0x40
191 # define EXPMAX (0xff)
192 # define QUIET_NAN 0x400000L
193 # define FRAC_NBITS 32
194 # define FRACHIGH 0x80000000L
195 # define FRACHIGH2 0xc0000000L
196 # define pack_d __pack_f
197 # define unpack_d __unpack_f
198 # define __fpcmp_parts __fpcmp_parts_f
199 typedef USItype fractype
;
200 typedef UHItype halffractype
;
201 typedef SFtype FLO_type
;
202 typedef SItype intfrac
;
205 # define PREFIXFPDP dp
206 # define PREFIXSFDF df
208 # define GARDROUND 0x7f
209 # define GARDMASK 0xff
210 # define GARDMSB 0x80
212 # define EXPBIAS 1023
214 # define EXPMAX (0x7ff)
215 # define QUIET_NAN 0x8000000000000LL
216 # define FRAC_NBITS 64
217 # define FRACHIGH 0x8000000000000000LL
218 # define FRACHIGH2 0xc000000000000000LL
219 # define pack_d __pack_d
220 # define unpack_d __unpack_d
221 # define __fpcmp_parts __fpcmp_parts_d
222 typedef UDItype fractype
;
223 typedef USItype halffractype
;
224 typedef DFtype FLO_type
;
225 typedef DItype intfrac
;
229 # define add __addtf3
230 # define sub __subtf3
231 # define multiply __multf3
232 # define divide __divtf3
233 # define compare __cmptf2
234 # define _eq_f2 __eqtf2
235 # define _ne_f2 __netf2
236 # define _gt_f2 __gttf2
237 # define _ge_f2 __getf2
238 # define _lt_f2 __lttf2
239 # define _le_f2 __letf2
240 # define _unord_f2 __unordtf2
241 # define usi_to_float __floatunsitf
242 # define si_to_float __floatsitf
243 # define float_to_si __fixtfsi
244 # define float_to_usi __fixunstfsi
245 # define negate __negtf2
246 # define tf_to_sf __trunctfsf2
247 # define tf_to_df __trunctfdf2
249 # define add __addsf3
250 # define sub __subsf3
251 # define multiply __mulsf3
252 # define divide __divsf3
253 # define compare __cmpsf2
254 # define _eq_f2 __eqsf2
255 # define _ne_f2 __nesf2
256 # define _gt_f2 __gtsf2
257 # define _ge_f2 __gesf2
258 # define _lt_f2 __ltsf2
259 # define _le_f2 __lesf2
260 # define _unord_f2 __unordsf2
261 # define usi_to_float __floatunsisf
262 # define si_to_float __floatsisf
263 # define float_to_si __fixsfsi
264 # define float_to_usi __fixunssfsi
265 # define negate __negsf2
266 # define sf_to_df __extendsfdf2
267 # define sf_to_tf __extendsftf2
269 # define add __adddf3
270 # define sub __subdf3
271 # define multiply __muldf3
272 # define divide __divdf3
273 # define compare __cmpdf2
274 # define _eq_f2 __eqdf2
275 # define _ne_f2 __nedf2
276 # define _gt_f2 __gtdf2
277 # define _ge_f2 __gedf2
278 # define _lt_f2 __ltdf2
279 # define _le_f2 __ledf2
280 # define _unord_f2 __unorddf2
281 # define usi_to_float __floatunsidf
282 # define si_to_float __floatsidf
283 # define float_to_si __fixdfsi
284 # define float_to_usi __fixunsdfsi
285 # define negate __negdf2
286 # define df_to_sf __truncdfsf2
287 # define df_to_tf __extenddftf2
291 #define INLINE __inline__
294 /* Preserve the sticky-bit when shifting fractions to the right. */
295 #define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
297 /* numeric parameters */
298 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
299 of a float and of a double. Assumes there are only two float types.
300 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS+float::NGARDS))
302 #define F_D_BITOFF (52+8-(23+7))
305 # define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
306 # define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
310 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
311 #define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
312 #define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
351 qrtrfractype qwords
[4];
353 halffractype words
[2];
357 #ifdef FLOAT_BIT_ORDER_MISMATCH
360 fractype fraction
:FRACBITS
__attribute__ ((packed
));
361 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
362 unsigned int sign
:1 __attribute__ ((packed
));
367 #ifdef _DEBUG_BITFLOAT
370 unsigned int sign
:1 __attribute__ ((packed
));
371 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
372 fractype fraction
:FRACBITS
__attribute__ ((packed
));
378 fractype fraction
:FRACBITS
__attribute__ ((packed
));
379 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
380 unsigned int sign
:1 __attribute__ ((packed
));
389 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
390 extern FLO_type
pack_d (const fp_number_type
*);
393 extern void unpack_d (FLO_union_type
*, fp_number_type
*);
395 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
396 extern FLO_type
add (FLO_type
, FLO_type
);
397 extern FLO_type
sub (FLO_type
, FLO_type
);
400 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
401 extern FLO_type
multiply (FLO_type
, FLO_type
);
404 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
405 extern FLO_type
divide (FLO_type
, FLO_type
);
408 extern int __fpcmp_parts (fp_number_type
*, fp_number_type
*);
410 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
411 extern CMPtype
compare (FLO_type
, FLO_type
);
414 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
415 extern CMPtype
_eq_f2 (FLO_type
, FLO_type
);
418 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
419 extern CMPtype
_ne_f2 (FLO_type
, FLO_type
);
422 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
423 extern CMPtype
_gt_f2 (FLO_type
, FLO_type
);
426 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
427 extern CMPtype
_ge_f2 (FLO_type
, FLO_type
);
430 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
431 extern CMPtype
_lt_f2 (FLO_type
, FLO_type
);
434 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
435 extern CMPtype
_le_f2 (FLO_type
, FLO_type
);
438 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
439 extern CMPtype
_unord_f2 (FLO_type
, FLO_type
);
442 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
443 extern FLO_type
si_to_float (SItype
);
446 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
447 extern SItype
float_to_si (FLO_type
);
450 #if defined(L_tf_to_usi)
451 extern USItype
float_to_usi (FLO_type
);
454 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
455 extern FLO_type
usi_to_float (USItype
);
458 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
459 extern FLO_type
negate (FLO_type
);
463 #if defined(L_make_sf)
464 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
467 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
468 #if defined(L_sf_to_df)
469 extern DFtype
sf_to_df (SFtype
);
471 #if defined(L_sf_to_tf) && defined(TMODES)
472 extern TFtype
sf_to_tf (SFtype
);
474 #endif /* ! FLOAT_ONLY */
478 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
479 #if defined(L_make_df)
480 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
482 #if defined(L_df_to_sf)
483 extern SFtype
df_to_sf (DFtype
);
485 #if defined(L_df_to_tf) && defined(TMODES)
486 extern TFtype
df_to_tf (DFtype
);
491 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
492 extern TFtype
__make_tp (fp_class_type
, unsigned int, int, UTItype
);
494 #if defined(L_tf_to_sf)
495 extern SFtype
tf_to_sf (TFtype
);
497 #if defined(L_tf_to_df)
498 extern DFtype
tf_to_df (TFtype
);
500 #if defined(L_di_to_tf)
501 extern TFtype
di_to_df (DItype
);
506 #endif /* ! GCC_FP_BIT_H */