1 /* Header file for fp-bit.c. */
2 /* Copyright (C) 2000, 2002, 2003, 2006, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
29 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
30 from this file are compiled via additional -D options.
32 This avoids the need to pull in the entire fp emulation library
33 when only a small number of functions are needed.
35 If FINE_GRAINED_LIBRARIES is not defined, then compile every
37 #ifndef FINE_GRAINED_LIBRARIES
48 #define L_fpcmp_parts_sf
49 #define L_fpcmp_parts_df
85 #endif /* ! FINE_GRAINED_LIBRARIES */
87 #if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
88 # if defined(TFLOAT) || defined(L_sf_to_tf) || defined(L_df_to_tf)
93 typedef float SFtype
__attribute__ ((mode (SF
)));
94 typedef float DFtype
__attribute__ ((mode (DF
)));
96 typedef float TFtype
__attribute__ ((mode (TF
)));
99 typedef int HItype
__attribute__ ((mode (HI
)));
100 typedef int SItype
__attribute__ ((mode (SI
)));
101 typedef int DItype
__attribute__ ((mode (DI
)));
103 typedef int TItype
__attribute__ ((mode (TI
)));
106 /* The type of the result of a floating point comparison. This must
107 match `__libgcc_cmp_return__' in GCC for the target. */
109 typedef int CMPtype
__attribute__ ((mode (__libgcc_cmp_return__
)));
112 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
113 typedef unsigned int USItype
__attribute__ ((mode (SI
)));
114 typedef unsigned int UDItype
__attribute__ ((mode (DI
)));
116 typedef unsigned int UTItype
__attribute__ ((mode (TI
)));
119 #define MAX_USI_INT (~(USItype)0)
120 #define MAX_SI_INT ((SItype) (MAX_USI_INT >> 1))
121 #define BITS_PER_SI (4 * BITS_PER_UNIT)
123 #define MAX_UDI_INT (~(UDItype)0)
124 #define MAX_DI_INT ((DItype) (MAX_UDI_INT >> 1))
125 #define BITS_PER_DI (8 * BITS_PER_UNIT)
134 # error "TFLOAT requires long double to have 113 bits of mantissa"
137 # define PREFIXFPDP tp
138 # define PREFIXSFDF tf
139 # define NGARDS 10L /* Is this right? */
140 # define GARDROUND 0x1ff
141 # define GARDMASK 0x3ff
142 # define GARDMSB 0x200
143 # define FRAC_NBITS 128
145 # if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
147 # define EXPBIAS 16383
148 # define EXPMAX (0x7fff)
149 # define QUIET_NAN ((TItype)0x8 << 108)
150 # define FRACHIGH ((TItype)0x8 << 124)
151 # define FRACHIGH2 ((TItype)0xc << 124)
152 # define FRACBITS 112
155 # if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
157 # define EXPBIAS 1023
158 # define EXPMAX (0x7ff)
159 # define QUIET_NAN ((TItype)0x8 << (48 + 64))
160 # define FRACHIGH ((TItype)0x8 << 124)
161 # define FRACHIGH2 ((TItype)0xc << 124)
162 # define FRACBITS 105
163 # define HALFFRACBITS 52
164 # define HALFSHIFT 64
167 # define pack_d __pack_t
168 # define unpack_d __unpack_t
169 # define __fpcmp_parts __fpcmp_parts_t
170 typedef UTItype fractype
;
171 typedef UDItype halffractype
;
172 typedef USItype qrtrfractype
;
173 #define qrtrfractype qrtrfractype
174 typedef TFtype FLO_type
;
175 typedef TItype intfrac
;
178 # define GARDROUND 0x3f
179 # define GARDMASK 0x7f
180 # define GARDMSB 0x40
184 # define EXPMAX (0xff)
185 # define QUIET_NAN 0x100000L
186 # define FRAC_NBITS 32
187 # define FRACHIGH 0x80000000L
188 # define FRACHIGH2 0xc0000000L
189 # define pack_d __pack_f
190 # define unpack_d __unpack_f
191 # define __fpcmp_parts __fpcmp_parts_f
192 typedef USItype fractype
;
193 typedef UHItype halffractype
;
194 typedef SFtype FLO_type
;
195 typedef SItype intfrac
;
198 # define PREFIXFPDP dp
199 # define PREFIXSFDF df
201 # define GARDROUND 0x7f
202 # define GARDMASK 0xff
203 # define GARDMSB 0x80
205 # define EXPBIAS 1023
207 # define EXPMAX (0x7ff)
208 # define QUIET_NAN 0x8000000000000LL
209 # define FRAC_NBITS 64
210 # define FRACHIGH 0x8000000000000000LL
211 # define FRACHIGH2 0xc000000000000000LL
212 # define pack_d __pack_d
213 # define unpack_d __unpack_d
214 # define __fpcmp_parts __fpcmp_parts_d
215 typedef UDItype fractype
;
216 typedef USItype halffractype
;
217 typedef DFtype FLO_type
;
218 typedef DItype intfrac
;
222 # define add __addtf3
223 # define sub __subtf3
224 # define multiply __multf3
225 # define divide __divtf3
226 # define compare __cmptf2
227 # define _eq_f2 __eqtf2
228 # define _ne_f2 __netf2
229 # define _gt_f2 __gttf2
230 # define _ge_f2 __getf2
231 # define _lt_f2 __lttf2
232 # define _le_f2 __letf2
233 # define _unord_f2 __unordtf2
234 # define usi_to_float __floatunsitf
235 # define si_to_float __floatsitf
236 # define float_to_si __fixtfsi
237 # define float_to_usi __fixunstfsi
238 # define negate __negtf2
239 # define tf_to_sf __trunctfsf2
240 # define tf_to_df __trunctfdf2
242 # define add __addsf3
243 # define sub __subsf3
244 # define multiply __mulsf3
245 # define divide __divsf3
246 # define compare __cmpsf2
247 # define _eq_f2 __eqsf2
248 # define _ne_f2 __nesf2
249 # define _gt_f2 __gtsf2
250 # define _ge_f2 __gesf2
251 # define _lt_f2 __ltsf2
252 # define _le_f2 __lesf2
253 # define _unord_f2 __unordsf2
254 # define usi_to_float __floatunsisf
255 # define si_to_float __floatsisf
256 # define float_to_si __fixsfsi
257 # define float_to_usi __fixunssfsi
258 # define negate __negsf2
259 # define sf_to_df __extendsfdf2
260 # define sf_to_tf __extendsftf2
262 # define add __adddf3
263 # define sub __subdf3
264 # define multiply __muldf3
265 # define divide __divdf3
266 # define compare __cmpdf2
267 # define _eq_f2 __eqdf2
268 # define _ne_f2 __nedf2
269 # define _gt_f2 __gtdf2
270 # define _ge_f2 __gedf2
271 # define _lt_f2 __ltdf2
272 # define _le_f2 __ledf2
273 # define _unord_f2 __unorddf2
274 # define usi_to_float __floatunsidf
275 # define si_to_float __floatsidf
276 # define float_to_si __fixdfsi
277 # define float_to_usi __fixunsdfsi
278 # define negate __negdf2
279 # define df_to_sf __truncdfsf2
280 # define df_to_tf __extenddftf2
284 #define INLINE __inline__
287 /* Preserve the sticky-bit when shifting fractions to the right. */
288 #define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
290 /* numeric parameters */
291 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
292 of a float and of a double. Assumes there are only two float types.
293 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
295 #define F_D_BITOFF (52+8-(23+7))
298 # define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
299 # define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
303 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
304 #define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
305 #define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
344 qrtrfractype qwords
[4];
346 halffractype words
[2];
350 #ifdef FLOAT_BIT_ORDER_MISMATCH
353 fractype fraction
:FRACBITS
__attribute__ ((packed
));
354 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
355 unsigned int sign
:1 __attribute__ ((packed
));
360 #ifdef _DEBUG_BITFLOAT
363 unsigned int sign
:1 __attribute__ ((packed
));
364 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
365 fractype fraction
:FRACBITS
__attribute__ ((packed
));
371 fractype fraction
:FRACBITS
__attribute__ ((packed
));
372 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
373 unsigned int sign
:1 __attribute__ ((packed
));
382 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
383 extern FLO_type
pack_d (const fp_number_type
*);
386 extern void unpack_d (FLO_union_type
*, fp_number_type
*);
388 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
389 extern FLO_type
add (FLO_type
, FLO_type
);
390 extern FLO_type
sub (FLO_type
, FLO_type
);
393 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
394 extern FLO_type
multiply (FLO_type
, FLO_type
);
397 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
398 extern FLO_type
divide (FLO_type
, FLO_type
);
401 extern int __fpcmp_parts (fp_number_type
*, fp_number_type
*);
403 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
404 extern CMPtype
compare (FLO_type
, FLO_type
);
407 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
408 extern CMPtype
_eq_f2 (FLO_type
, FLO_type
);
411 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
412 extern CMPtype
_ne_f2 (FLO_type
, FLO_type
);
415 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
416 extern CMPtype
_gt_f2 (FLO_type
, FLO_type
);
419 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
420 extern CMPtype
_ge_f2 (FLO_type
, FLO_type
);
423 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
424 extern CMPtype
_lt_f2 (FLO_type
, FLO_type
);
427 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
428 extern CMPtype
_le_f2 (FLO_type
, FLO_type
);
431 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
432 extern CMPtype
_unord_f2 (FLO_type
, FLO_type
);
435 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
436 extern FLO_type
si_to_float (SItype
);
439 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
440 extern SItype
float_to_si (FLO_type
);
443 #if defined(L_tf_to_usi)
444 extern USItype
float_to_usi (FLO_type
);
447 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
448 extern FLO_type
usi_to_float (USItype
);
451 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
452 extern FLO_type
negate (FLO_type
);
456 #if defined(L_make_sf)
457 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
460 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
461 #if defined(L_sf_to_df)
462 extern DFtype
sf_to_df (SFtype
);
464 #if defined(L_sf_to_tf) && defined(TMODES)
465 extern TFtype
sf_to_tf (SFtype
);
467 #endif /* ! FLOAT_ONLY */
471 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
472 #if defined(L_make_df)
473 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
475 #if defined(L_df_to_sf)
476 extern SFtype
df_to_sf (DFtype
);
478 #if defined(L_df_to_tf) && defined(TMODES)
479 extern TFtype
df_to_tf (DFtype
);
484 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
485 extern TFtype
__make_tp (fp_class_type
, unsigned int, int, UTItype
);
487 #if defined(L_tf_to_sf)
488 extern SFtype
tf_to_sf (TFtype
);
490 #if defined(L_tf_to_df)
491 extern DFtype
tf_to_df (TFtype
);
493 #if defined(L_di_to_tf)
494 extern TFtype
di_to_df (DItype
);
499 #endif /* ! GCC_FP_BIT_H */