]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/fp-bit.h
2019-08-20 Bernd Edlinger <bernd.edlinger@hotmail.de>
[thirdparty/gcc.git] / libgcc / fp-bit.h
CommitLineData
f52117db 1/* Header file for fp-bit.c. */
fbd26352 2/* Copyright (C) 2000-2019 Free Software Foundation, Inc.
f52117db 3
187b36cf 4This file is part of GCC.
f52117db 5
b1825ae2 6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
6bc9506f 8Software Foundation; either version 3, or (at your option) any later
b1825ae2 9version.
10
b1825ae2 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
f52117db 15
6bc9506f 16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23<http://www.gnu.org/licenses/>. */
f52117db 24
2a281353 25#ifndef GCC_FP_BIT_H
26#define GCC_FP_BIT_H
f52117db 27
28/* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
29 from this file are compiled via additional -D options.
30
31 This avoids the need to pull in the entire fp emulation library
32 when only a small number of functions are needed.
33
8e0db77e 34 If FINE_GRAINED_LIBRARIES is not defined, then compile every
f52117db 35 suitable routine. */
36#ifndef FINE_GRAINED_LIBRARIES
37#define L_pack_df
38#define L_unpack_df
39#define L_pack_sf
40#define L_unpack_sf
41#define L_addsub_sf
42#define L_addsub_df
43#define L_mul_sf
44#define L_mul_df
45#define L_div_sf
46#define L_div_df
47#define L_fpcmp_parts_sf
48#define L_fpcmp_parts_df
49#define L_compare_sf
50#define L_compare_df
51#define L_eq_sf
52#define L_eq_df
53#define L_ne_sf
54#define L_ne_df
55#define L_gt_sf
56#define L_gt_df
57#define L_ge_sf
58#define L_ge_df
59#define L_lt_sf
60#define L_lt_df
61#define L_le_sf
62#define L_le_df
63#define L_unord_sf
64#define L_unord_df
320f29dc 65#define L_usi_to_sf
66#define L_usi_to_df
f52117db 67#define L_si_to_sf
68#define L_si_to_df
69#define L_sf_to_si
70#define L_df_to_si
71#define L_f_to_usi
72#define L_df_to_usi
73#define L_negate_sf
74#define L_negate_df
75#define L_make_sf
76#define L_make_df
77#define L_sf_to_df
78#define L_df_to_sf
79#ifdef FLOAT
80#define L_thenan_sf
81#else
82#define L_thenan_df
83#endif
84#endif /* ! FINE_GRAINED_LIBRARIES */
85
199bff55 86#if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
baad77c2 87# if defined(TFLOAT) || defined(L_sf_to_tf) || defined(L_df_to_tf)
88# define TMODES
89# endif
5b7344c7 90#endif
91
f52117db 92typedef float SFtype __attribute__ ((mode (SF)));
93typedef float DFtype __attribute__ ((mode (DF)));
5b7344c7 94#ifdef TMODES
95typedef float TFtype __attribute__ ((mode (TF)));
96#endif
f52117db 97
98typedef int HItype __attribute__ ((mode (HI)));
99typedef int SItype __attribute__ ((mode (SI)));
100typedef int DItype __attribute__ ((mode (DI)));
5b7344c7 101#ifdef TMODES
102typedef int TItype __attribute__ ((mode (TI)));
103#endif
f52117db 104
edc6a305 105/* The type of the result of a floating point comparison. This must
ea32e033 106 match `__libgcc_cmp_return__' in GCC for the target. */
f52117db 107#ifndef CMPtype
ea32e033 108typedef int CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
f52117db 109#endif
110
111typedef unsigned int UHItype __attribute__ ((mode (HI)));
112typedef unsigned int USItype __attribute__ ((mode (SI)));
113typedef unsigned int UDItype __attribute__ ((mode (DI)));
5b7344c7 114#ifdef TMODES
115typedef unsigned int UTItype __attribute__ ((mode (TI)));
116#endif
f52117db 117
ec7a9913 118#define MAX_USI_INT (~(USItype)0)
119#define MAX_SI_INT ((SItype) (MAX_USI_INT >> 1))
d2dc729f 120#define BITS_PER_SI (4 * __CHAR_BIT__)
5b7344c7 121#ifdef TMODES
122#define MAX_UDI_INT (~(UDItype)0)
123#define MAX_DI_INT ((DItype) (MAX_UDI_INT >> 1))
d2dc729f 124#define BITS_PER_DI (8 * __CHAR_BIT__)
5b7344c7 125#endif
f52117db 126
127#ifdef FLOAT_ONLY
128#define NO_DI_MODE
129#endif
130
a23b9c51 131#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
132#define FLOAT_BIT_ORDER_MISMATCH
133#endif
134
135#if __BYTE_ORDER__ != __FLOAT_WORD_ORDER__
136#define FLOAT_WORD_ORDER_MISMATCH
137#endif
138
5b7344c7 139#ifdef TFLOAT
140# ifndef TMODES
141# error "TFLOAT requires long double to have 113 bits of mantissa"
142# endif
143
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
151
152# if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
153# define EXPBITS 15
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
160# endif
161
199bff55 162# if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
163# define EXPBITS 11
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
172# endif
173
5b7344c7 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;
183#elif defined FLOAT
f52117db 184# define NGARDS 7L
185# define GARDROUND 0x3f
186# define GARDMASK 0x7f
187# define GARDMSB 0x40
188# define EXPBITS 8
189# define EXPBIAS 127
190# define FRACBITS 23
191# define EXPMAX (0xff)
9e849aff 192# define QUIET_NAN 0x400000L
f52117db 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;
203
204#else
205# define PREFIXFPDP dp
206# define PREFIXSFDF df
207# define NGARDS 8L
208# define GARDROUND 0x7f
209# define GARDMASK 0xff
210# define GARDMSB 0x80
211# define EXPBITS 11
212# define EXPBIAS 1023
213# define FRACBITS 52
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;
226#endif /* FLOAT */
227
1d88eb71 228#ifdef TFLOAT
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
248#elif defined FLOAT
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
f52117db 268#else
1d88eb71 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
288#endif /* FLOAT */
f52117db 289
290#ifndef INLINE
291#define INLINE __inline__
292#endif
293
294/* Preserve the sticky-bit when shifting fractions to the right. */
2a33161d 295#define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
f52117db 296
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.
dfa9a36a 300 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS+float::NGARDS))
f52117db 301 */
302#define F_D_BITOFF (52+8-(23+7))
303
5b7344c7 304#ifdef TMODES
305# define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
306# define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
307#endif
308
f52117db 309
310#define NORMAL_EXPMIN (-(EXPBIAS)+1)
5b7344c7 311#define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
312#define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
f52117db 313
314/* common types */
315
316typedef enum
317{
318 CLASS_SNAN,
319 CLASS_QNAN,
320 CLASS_ZERO,
321 CLASS_NUMBER,
322 CLASS_INFINITY
323} fp_class_type;
324
325typedef struct
326{
327#ifdef SMALL_MACHINE
328 char class;
329 unsigned char sign;
330 short normal_exp;
331#else
332 fp_class_type class;
333 unsigned int sign;
334 int normal_exp;
335#endif
336
337 union
338 {
339 fractype ll;
340 halffractype l[2];
341 } fraction;
342} fp_number_type;
343
344typedef union
345{
346 FLO_type value;
347 fractype value_raw;
348
349#ifndef FLOAT
5b7344c7 350# ifdef qrtrfractype
351 qrtrfractype qwords[4];
352# else
f52117db 353 halffractype words[2];
5b7344c7 354# endif
f52117db 355#endif
356
357#ifdef FLOAT_BIT_ORDER_MISMATCH
358 struct
359 {
360 fractype fraction:FRACBITS __attribute__ ((packed));
361 unsigned int exp:EXPBITS __attribute__ ((packed));
362 unsigned int sign:1 __attribute__ ((packed));
363 }
364 bits;
365#endif
366
367#ifdef _DEBUG_BITFLOAT
368 struct
369 {
370 unsigned int sign:1 __attribute__ ((packed));
371 unsigned int exp:EXPBITS __attribute__ ((packed));
372 fractype fraction:FRACBITS __attribute__ ((packed));
373 }
374 bits_big_endian;
375
376 struct
377 {
378 fractype fraction:FRACBITS __attribute__ ((packed));
379 unsigned int exp:EXPBITS __attribute__ ((packed));
380 unsigned int sign:1 __attribute__ ((packed));
381 }
382 bits_little_endian;
383#endif
384}
385FLO_union_type;
386
5c8520a4 387/* Prototypes. */
f52117db 388
5b7344c7 389#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
5c8520a4 390extern FLO_type pack_d (const fp_number_type *);
f52117db 391#endif
392
393extern void unpack_d (FLO_union_type *, fp_number_type *);
394
5b7344c7 395#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
f52117db 396extern FLO_type add (FLO_type, FLO_type);
397extern FLO_type sub (FLO_type, FLO_type);
398#endif
399
5b7344c7 400#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
f52117db 401extern FLO_type multiply (FLO_type, FLO_type);
402#endif
403
5b7344c7 404#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
f52117db 405extern FLO_type divide (FLO_type, FLO_type);
406#endif
407
408extern int __fpcmp_parts (fp_number_type *, fp_number_type *);
409
5b7344c7 410#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
f52117db 411extern CMPtype compare (FLO_type, FLO_type);
412#endif
413
5b7344c7 414#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
f52117db 415extern CMPtype _eq_f2 (FLO_type, FLO_type);
416#endif
417
5b7344c7 418#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
f52117db 419extern CMPtype _ne_f2 (FLO_type, FLO_type);
420#endif
421
5b7344c7 422#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
f52117db 423extern CMPtype _gt_f2 (FLO_type, FLO_type);
424#endif
425
5b7344c7 426#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
f52117db 427extern CMPtype _ge_f2 (FLO_type, FLO_type);
428#endif
429
5b7344c7 430#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
f52117db 431extern CMPtype _lt_f2 (FLO_type, FLO_type);
432#endif
433
5b7344c7 434#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
f52117db 435extern CMPtype _le_f2 (FLO_type, FLO_type);
436#endif
437
5b7344c7 438#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
f52117db 439extern CMPtype _unord_f2 (FLO_type, FLO_type);
440#endif
441
5b7344c7 442#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
f52117db 443extern FLO_type si_to_float (SItype);
444#endif
445
5b7344c7 446#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
f52117db 447extern SItype float_to_si (FLO_type);
448#endif
449
1d88eb71 450#if defined(L_tf_to_usi)
f52117db 451extern USItype float_to_usi (FLO_type);
452#endif
f52117db 453
5b7344c7 454#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
a23072e2 455extern FLO_type usi_to_float (USItype);
456#endif
457
5b7344c7 458#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
f52117db 459extern FLO_type negate (FLO_type);
460#endif
461
462#ifdef FLOAT
463#if defined(L_make_sf)
464extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
465#endif
466#ifndef FLOAT_ONLY
467extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
468#if defined(L_sf_to_df)
469extern DFtype sf_to_df (SFtype);
470#endif
5b7344c7 471#if defined(L_sf_to_tf) && defined(TMODES)
472extern TFtype sf_to_tf (SFtype);
473#endif
f52117db 474#endif /* ! FLOAT_ONLY */
475#endif /* FLOAT */
476
477#ifndef FLOAT
478extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
479#if defined(L_make_df)
480extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
481#endif
482#if defined(L_df_to_sf)
483extern SFtype df_to_sf (DFtype);
484#endif
5b7344c7 485#if defined(L_df_to_tf) && defined(TMODES)
486extern TFtype df_to_tf (DFtype);
487#endif
f52117db 488#endif /* ! FLOAT */
489
5b7344c7 490#ifdef TMODES
e8899d83 491extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
5b7344c7 492extern TFtype __make_tp (fp_class_type, unsigned int, int, UTItype);
493#ifdef TFLOAT
494#if defined(L_tf_to_sf)
495extern SFtype tf_to_sf (TFtype);
496#endif
497#if defined(L_tf_to_df)
498extern DFtype tf_to_df (TFtype);
499#endif
500#if defined(L_di_to_tf)
501extern TFtype di_to_df (DItype);
502#endif
503#endif /* TFLOAT */
504#endif /* TMODES */
505
2a281353 506#endif /* ! GCC_FP_BIT_H */