1 /* Header file for fp-bit.c. */
2 /* Copyright (C) 2000-2024 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 * __CHAR_BIT__)
122 #define MAX_UDI_INT (~(UDItype)0)
123 #define MAX_DI_INT ((DItype) (MAX_UDI_INT >> 1))
124 #define BITS_PER_DI (8 * __CHAR_BIT__)
131 #if __BYTE_ORDER__ != __FLOAT_WORD_ORDER__
132 #define FLOAT_WORD_ORDER_MISMATCH
137 # error "TFLOAT requires long double to have 113 bits of mantissa"
140 # define PREFIXFPDP tp
141 # define PREFIXSFDF tf
142 # define NGARDS 10L /* Is this right? */
143 # define GARDROUND 0x1ff
144 # define GARDMASK 0x3ff
145 # define GARDMSB 0x200
146 # define FRAC_NBITS 128
148 # if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
150 # define EXPBIAS 16383
151 # define EXPMAX (0x7fff)
152 # define QUIET_NAN ((TItype)0x8 << 108)
153 # define FRACHIGH ((TItype)0x8 << 124)
154 # define FRACHIGH2 ((TItype)0xc << 124)
155 # define FRACBITS 112
158 # if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
160 # define EXPBIAS 1023
161 # define EXPMAX (0x7ff)
162 # define QUIET_NAN ((TItype)0x8 << (48 + 64))
163 # define FRACHIGH ((TItype)0x8 << 124)
164 # define FRACHIGH2 ((TItype)0xc << 124)
165 # define FRACBITS 105
166 # define HALFFRACBITS 52
167 # define HALFSHIFT 64
170 # define pack_d __pack_t
171 # define unpack_d __unpack_t
172 # define __fpcmp_parts __fpcmp_parts_t
173 typedef UTItype fractype
;
174 typedef UDItype halffractype
;
175 typedef USItype qrtrfractype
;
176 #define qrtrfractype qrtrfractype
177 typedef TFtype FLO_type
;
178 typedef TItype intfrac
;
181 # define GARDROUND 0x3f
182 # define GARDMASK 0x7f
183 # define GARDMSB 0x40
187 # define EXPMAX (0xff)
188 # define QUIET_NAN 0x400000L
189 # define FRAC_NBITS 32
190 # define FRACHIGH 0x80000000L
191 # define FRACHIGH2 0xc0000000L
192 # define pack_d __pack_f
193 # define unpack_d __unpack_f
194 # define __fpcmp_parts __fpcmp_parts_f
195 typedef USItype fractype
;
196 typedef UHItype halffractype
;
197 typedef SFtype FLO_type
;
198 typedef SItype intfrac
;
201 # define PREFIXFPDP dp
202 # define PREFIXSFDF df
204 # define GARDROUND 0x7f
205 # define GARDMASK 0xff
206 # define GARDMSB 0x80
208 # define EXPBIAS 1023
210 # define EXPMAX (0x7ff)
211 # define QUIET_NAN 0x8000000000000LL
212 # define FRAC_NBITS 64
213 # define FRACHIGH 0x8000000000000000LL
214 # define FRACHIGH2 0xc000000000000000LL
215 # define pack_d __pack_d
216 # define unpack_d __unpack_d
217 # define __fpcmp_parts __fpcmp_parts_d
218 typedef UDItype fractype
;
219 typedef USItype halffractype
;
220 typedef DFtype FLO_type
;
221 typedef DItype intfrac
;
225 # define add __addtf3
226 # define sub __subtf3
227 # define multiply __multf3
228 # define divide __divtf3
229 # define compare __cmptf2
230 # define _eq_f2 __eqtf2
231 # define _ne_f2 __netf2
232 # define _gt_f2 __gttf2
233 # define _ge_f2 __getf2
234 # define _lt_f2 __lttf2
235 # define _le_f2 __letf2
236 # define _unord_f2 __unordtf2
237 # define usi_to_float __floatunsitf
238 # define si_to_float __floatsitf
239 # define float_to_si __fixtfsi
240 # define float_to_usi __fixunstfsi
241 # define negate __negtf2
242 # define tf_to_sf __trunctfsf2
243 # define tf_to_df __trunctfdf2
245 # define add __addsf3
246 # define sub __subsf3
247 # define multiply __mulsf3
248 # define divide __divsf3
249 # define compare __cmpsf2
250 # define _eq_f2 __eqsf2
251 # define _ne_f2 __nesf2
252 # define _gt_f2 __gtsf2
253 # define _ge_f2 __gesf2
254 # define _lt_f2 __ltsf2
255 # define _le_f2 __lesf2
256 # define _unord_f2 __unordsf2
257 # define usi_to_float __floatunsisf
258 # define si_to_float __floatsisf
259 # define float_to_si __fixsfsi
260 # define float_to_usi __fixunssfsi
261 # define negate __negsf2
262 # define sf_to_df __extendsfdf2
263 # define sf_to_tf __extendsftf2
265 # define add __adddf3
266 # define sub __subdf3
267 # define multiply __muldf3
268 # define divide __divdf3
269 # define compare __cmpdf2
270 # define _eq_f2 __eqdf2
271 # define _ne_f2 __nedf2
272 # define _gt_f2 __gtdf2
273 # define _ge_f2 __gedf2
274 # define _lt_f2 __ltdf2
275 # define _le_f2 __ledf2
276 # define _unord_f2 __unorddf2
277 # define usi_to_float __floatunsidf
278 # define si_to_float __floatsidf
279 # define float_to_si __fixdfsi
280 # define float_to_usi __fixunsdfsi
281 # define negate __negdf2
282 # define df_to_sf __truncdfsf2
283 # define df_to_tf __extenddftf2
287 #define INLINE __inline__
290 /* Preserve the sticky-bit when shifting fractions to the right. */
291 #define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
293 /* numeric parameters */
294 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
295 of a float and of a double. Assumes there are only two float types.
296 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS+float::NGARDS))
298 #define F_D_BITOFF (52+8-(23+7))
301 # define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
302 # define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
306 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
307 #define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
308 #define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
347 qrtrfractype qwords
[4];
349 halffractype words
[2];
353 #ifdef _DEBUG_BITFLOAT
356 unsigned int sign
:1 __attribute__ ((packed
));
357 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
358 fractype fraction
:FRACBITS
__attribute__ ((packed
));
364 fractype fraction
:FRACBITS
__attribute__ ((packed
));
365 unsigned int exp
:EXPBITS
__attribute__ ((packed
));
366 unsigned int sign
:1 __attribute__ ((packed
));
375 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
376 extern FLO_type
pack_d (const fp_number_type
*);
379 extern void unpack_d (FLO_union_type
*, fp_number_type
*);
381 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
382 extern FLO_type
add (FLO_type
, FLO_type
);
383 extern FLO_type
sub (FLO_type
, FLO_type
);
386 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
387 extern FLO_type
multiply (FLO_type
, FLO_type
);
390 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
391 extern FLO_type
divide (FLO_type
, FLO_type
);
394 extern int __fpcmp_parts (fp_number_type
*, fp_number_type
*);
396 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
397 extern CMPtype
compare (FLO_type
, FLO_type
);
400 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
401 extern CMPtype
_eq_f2 (FLO_type
, FLO_type
);
404 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
405 extern CMPtype
_ne_f2 (FLO_type
, FLO_type
);
408 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
409 extern CMPtype
_gt_f2 (FLO_type
, FLO_type
);
412 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
413 extern CMPtype
_ge_f2 (FLO_type
, FLO_type
);
416 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
417 extern CMPtype
_lt_f2 (FLO_type
, FLO_type
);
420 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
421 extern CMPtype
_le_f2 (FLO_type
, FLO_type
);
424 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
425 extern CMPtype
_unord_f2 (FLO_type
, FLO_type
);
428 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
429 extern FLO_type
si_to_float (SItype
);
432 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
433 extern SItype
float_to_si (FLO_type
);
436 #if defined(L_tf_to_usi)
437 extern USItype
float_to_usi (FLO_type
);
440 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
441 extern FLO_type
usi_to_float (USItype
);
444 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
445 extern FLO_type
negate (FLO_type
);
449 #if defined(L_make_sf)
450 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
453 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
454 #if defined(L_sf_to_df)
455 extern DFtype
sf_to_df (SFtype
);
457 #if defined(L_sf_to_tf) && defined(TMODES)
458 extern TFtype
sf_to_tf (SFtype
);
460 #endif /* ! FLOAT_ONLY */
464 extern SFtype
__make_fp (fp_class_type
, unsigned int, int, USItype
);
465 #if defined(L_make_df)
466 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
468 #if defined(L_df_to_sf)
469 extern SFtype
df_to_sf (DFtype
);
471 #if defined(L_df_to_tf) && defined(TMODES)
472 extern TFtype
df_to_tf (DFtype
);
477 extern DFtype
__make_dp (fp_class_type
, unsigned int, int, UDItype
);
478 extern TFtype
__make_tp (fp_class_type
, unsigned int, int, UTItype
);
480 #if defined(L_tf_to_sf)
481 extern SFtype
tf_to_sf (TFtype
);
483 #if defined(L_tf_to_df)
484 extern DFtype
tf_to_df (TFtype
);
486 #if defined(L_di_to_tf)
487 extern TFtype
di_to_df (DItype
);
492 #endif /* ! GCC_FP_BIT_H */