]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/fp-bit.h
2003-01-29 Laurent Guerby <guerby@acm.org>
[thirdparty/gcc.git] / gcc / config / fp-bit.h
CommitLineData
f52117db 1/* Header file for fp-bit.c. */
5b7344c7 2/* Copyright (C) 2000, 2002, 2003
f52117db 3 Free Software Foundation, Inc.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22/* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
28
2a281353 29#ifndef GCC_FP_BIT_H
30#define GCC_FP_BIT_H
f52117db 31
32/* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
33 from this file are compiled via additional -D options.
34
35 This avoids the need to pull in the entire fp emulation library
36 when only a small number of functions are needed.
37
8e0db77e 38 If FINE_GRAINED_LIBRARIES is not defined, then compile every
f52117db 39 suitable routine. */
40#ifndef FINE_GRAINED_LIBRARIES
41#define L_pack_df
42#define L_unpack_df
43#define L_pack_sf
44#define L_unpack_sf
45#define L_addsub_sf
46#define L_addsub_df
47#define L_mul_sf
48#define L_mul_df
49#define L_div_sf
50#define L_div_df
51#define L_fpcmp_parts_sf
52#define L_fpcmp_parts_df
53#define L_compare_sf
54#define L_compare_df
55#define L_eq_sf
56#define L_eq_df
57#define L_ne_sf
58#define L_ne_df
59#define L_gt_sf
60#define L_gt_df
61#define L_ge_sf
62#define L_ge_df
63#define L_lt_sf
64#define L_lt_df
65#define L_le_sf
66#define L_le_df
67#define L_unord_sf
68#define L_unord_df
320f29dc 69#define L_usi_to_sf
70#define L_usi_to_df
f52117db 71#define L_si_to_sf
72#define L_si_to_df
73#define L_sf_to_si
74#define L_df_to_si
75#define L_f_to_usi
76#define L_df_to_usi
77#define L_negate_sf
78#define L_negate_df
79#define L_make_sf
80#define L_make_df
81#define L_sf_to_df
82#define L_df_to_sf
83#ifdef FLOAT
84#define L_thenan_sf
85#else
86#define L_thenan_df
87#endif
88#endif /* ! FINE_GRAINED_LIBRARIES */
89
199bff55 90#if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
5b7344c7 91# define TMODES
92#endif
93
f52117db 94typedef float SFtype __attribute__ ((mode (SF)));
95typedef float DFtype __attribute__ ((mode (DF)));
5b7344c7 96#ifdef TMODES
97typedef float TFtype __attribute__ ((mode (TF)));
98#endif
f52117db 99
100typedef int HItype __attribute__ ((mode (HI)));
101typedef int SItype __attribute__ ((mode (SI)));
102typedef int DItype __attribute__ ((mode (DI)));
5b7344c7 103#ifdef TMODES
104typedef int TItype __attribute__ ((mode (TI)));
105#endif
f52117db 106
107/* The type of the result of a fp compare */
108#ifndef CMPtype
109#define CMPtype SItype
110#endif
111
112typedef unsigned int UHItype __attribute__ ((mode (HI)));
113typedef unsigned int USItype __attribute__ ((mode (SI)));
114typedef unsigned int UDItype __attribute__ ((mode (DI)));
5b7344c7 115#ifdef TMODES
116typedef unsigned int UTItype __attribute__ ((mode (TI)));
117#endif
f52117db 118
ec7a9913 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)
5b7344c7 122#ifdef TMODES
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)
126#endif
f52117db 127
128#ifdef FLOAT_ONLY
129#define NO_DI_MODE
130#endif
131
5b7344c7 132#ifdef TFLOAT
133# ifndef TMODES
134# error "TFLOAT requires long double to have 113 bits of mantissa"
135# endif
136
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
144
145# if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
146# define EXPBITS 15
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
153# endif
154
199bff55 155# if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
156# define EXPBITS 11
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
165# endif
166
5b7344c7 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;
176#elif defined FLOAT
f52117db 177# define NGARDS 7L
178# define GARDROUND 0x3f
179# define GARDMASK 0x7f
180# define GARDMSB 0x40
181# define EXPBITS 8
182# define EXPBIAS 127
183# define FRACBITS 23
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;
196
197#else
198# define PREFIXFPDP dp
199# define PREFIXSFDF df
200# define NGARDS 8L
201# define GARDROUND 0x7f
202# define GARDMASK 0xff
203# define GARDMSB 0x80
204# define EXPBITS 11
205# define EXPBIAS 1023
206# define FRACBITS 52
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;
219#endif /* FLOAT */
220
221#ifdef US_SOFTWARE_GOFAST
5b7344c7 222# ifdef TFLOAT
223# error "GOFAST TFmode not supported"
224# elif defined FLOAT
f52117db 225# define add fpadd
226# define sub fpsub
227# define multiply fpmul
228# define divide fpdiv
229# define compare fpcmp
8e0db77e 230# define _unord_f2 __unordsf2
8cffdc05 231# define usi_to_float __floatunsisf
f52117db 232# define si_to_float sitofp
233# define float_to_si fptosi
234# define float_to_usi fptoui
235# define negate __negsf2
236# define sf_to_df fptodp
5b7344c7 237# define sf_to_tf __extendsftf2
238# else
f52117db 239# define add dpadd
240# define sub dpsub
241# define multiply dpmul
242# define divide dpdiv
243# define compare dpcmp
8e0db77e 244# define _unord_f2 __unorddf2
8cffdc05 245# define usi_to_float __floatunsidf
f52117db 246# define si_to_float litodp
247# define float_to_si dptoli
248# define float_to_usi dptoul
249# define negate __negdf2
250# define df_to_sf dptofp
5b7344c7 251# define df_to_tf __extenddftf2
f52117db 252# endif /* FLOAT */
253#else
5b7344c7 254# ifdef TFLOAT
255# define add __addtf3
256# define sub __subtf3
257# define multiply __multf3
258# define divide __divtf3
259# define compare __cmptf2
260# define _eq_f2 __eqtf2
261# define _ne_f2 __netf2
262# define _gt_f2 __gttf2
263# define _ge_f2 __getf2
264# define _lt_f2 __lttf2
265# define _le_f2 __letf2
266# define _unord_f2 __unordtf2
267# define usi_to_float __floatunsitf
268# define si_to_float __floatsitf
269# define float_to_si __fixtfsi
270# define float_to_usi __fixunstfsi
271# define negate __negtf2
272# define tf_to_sf __trunctfsf2
273# define tf_to_df __trunctfdf2
274# elif defined FLOAT
f52117db 275# define add __addsf3
276# define sub __subsf3
277# define multiply __mulsf3
278# define divide __divsf3
279# define compare __cmpsf2
280# define _eq_f2 __eqsf2
281# define _ne_f2 __nesf2
282# define _gt_f2 __gtsf2
283# define _ge_f2 __gesf2
284# define _lt_f2 __ltsf2
285# define _le_f2 __lesf2
286# define _unord_f2 __unordsf2
320f29dc 287# define usi_to_float __floatunsisf
f52117db 288# define si_to_float __floatsisf
289# define float_to_si __fixsfsi
290# define float_to_usi __fixunssfsi
291# define negate __negsf2
292# define sf_to_df __extendsfdf2
5b7344c7 293# define sf_to_tf __extendsftf2
294# else
f52117db 295# define add __adddf3
296# define sub __subdf3
297# define multiply __muldf3
298# define divide __divdf3
299# define compare __cmpdf2
300# define _eq_f2 __eqdf2
301# define _ne_f2 __nedf2
302# define _gt_f2 __gtdf2
303# define _ge_f2 __gedf2
304# define _lt_f2 __ltdf2
305# define _le_f2 __ledf2
306# define _unord_f2 __unorddf2
320f29dc 307# define usi_to_float __floatunsidf
f52117db 308# define si_to_float __floatsidf
309# define float_to_si __fixdfsi
310# define float_to_usi __fixunsdfsi
311# define negate __negdf2
312# define df_to_sf __truncdfsf2
5b7344c7 313# define df_to_tf __extenddftf2
f52117db 314# endif /* FLOAT */
315#endif /* US_SOFTWARE_GOFAST */
316
317#ifndef INLINE
318#define INLINE __inline__
319#endif
320
321/* Preserve the sticky-bit when shifting fractions to the right. */
322#define LSHIFT(a) { a = (a & 1) | (a >> 1); }
323
324/* numeric parameters */
325/* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
326 of a float and of a double. Assumes there are only two float types.
327 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
328 */
329#define F_D_BITOFF (52+8-(23+7))
330
5b7344c7 331#ifdef TMODES
332# define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
333# define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
334#endif
335
f52117db 336
337#define NORMAL_EXPMIN (-(EXPBIAS)+1)
5b7344c7 338#define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
339#define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
f52117db 340
341/* common types */
342
343typedef enum
344{
345 CLASS_SNAN,
346 CLASS_QNAN,
347 CLASS_ZERO,
348 CLASS_NUMBER,
349 CLASS_INFINITY
350} fp_class_type;
351
352typedef struct
353{
354#ifdef SMALL_MACHINE
355 char class;
356 unsigned char sign;
357 short normal_exp;
358#else
359 fp_class_type class;
360 unsigned int sign;
361 int normal_exp;
362#endif
363
364 union
365 {
366 fractype ll;
367 halffractype l[2];
368 } fraction;
369} fp_number_type;
370
371typedef union
372{
373 FLO_type value;
374 fractype value_raw;
375
376#ifndef FLOAT
5b7344c7 377# ifdef qrtrfractype
378 qrtrfractype qwords[4];
379# else
f52117db 380 halffractype words[2];
5b7344c7 381# endif
f52117db 382#endif
383
384#ifdef FLOAT_BIT_ORDER_MISMATCH
385 struct
386 {
387 fractype fraction:FRACBITS __attribute__ ((packed));
388 unsigned int exp:EXPBITS __attribute__ ((packed));
389 unsigned int sign:1 __attribute__ ((packed));
390 }
391 bits;
392#endif
393
394#ifdef _DEBUG_BITFLOAT
395 struct
396 {
397 unsigned int sign:1 __attribute__ ((packed));
398 unsigned int exp:EXPBITS __attribute__ ((packed));
399 fractype fraction:FRACBITS __attribute__ ((packed));
400 }
401 bits_big_endian;
402
403 struct
404 {
405 fractype fraction:FRACBITS __attribute__ ((packed));
406 unsigned int exp:EXPBITS __attribute__ ((packed));
407 unsigned int sign:1 __attribute__ ((packed));
408 }
409 bits_little_endian;
410#endif
411}
412FLO_union_type;
413
414/* Prototypes */
415
5b7344c7 416#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
f52117db 417extern FLO_type pack_d (fp_number_type *);
418#endif
419
420extern void unpack_d (FLO_union_type *, fp_number_type *);
421
5b7344c7 422#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
f52117db 423extern FLO_type add (FLO_type, FLO_type);
424extern FLO_type sub (FLO_type, FLO_type);
425#endif
426
5b7344c7 427#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
f52117db 428extern FLO_type multiply (FLO_type, FLO_type);
429#endif
430
5b7344c7 431#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
f52117db 432extern FLO_type divide (FLO_type, FLO_type);
433#endif
434
435extern int __fpcmp_parts (fp_number_type *, fp_number_type *);
436
5b7344c7 437#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
f52117db 438extern CMPtype compare (FLO_type, FLO_type);
439#endif
440
441#ifndef US_SOFTWARE_GOFAST
442
5b7344c7 443#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
f52117db 444extern CMPtype _eq_f2 (FLO_type, FLO_type);
445#endif
446
5b7344c7 447#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
f52117db 448extern CMPtype _ne_f2 (FLO_type, FLO_type);
449#endif
450
5b7344c7 451#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
f52117db 452extern CMPtype _gt_f2 (FLO_type, FLO_type);
453#endif
454
5b7344c7 455#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
f52117db 456extern CMPtype _ge_f2 (FLO_type, FLO_type);
457#endif
458
5b7344c7 459#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
f52117db 460extern CMPtype _lt_f2 (FLO_type, FLO_type);
461#endif
462
5b7344c7 463#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
f52117db 464extern CMPtype _le_f2 (FLO_type, FLO_type);
465#endif
466
5b7344c7 467#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
f52117db 468extern CMPtype _unord_f2 (FLO_type, FLO_type);
469#endif
470
471#endif /* ! US_SOFTWARE_GOFAST */
472
5b7344c7 473#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
f52117db 474extern FLO_type si_to_float (SItype);
475#endif
476
5b7344c7 477#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
f52117db 478extern SItype float_to_si (FLO_type);
479#endif
480
5b7344c7 481#if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
f52117db 482#ifdef US_SOFTWARE_GOFAST
483extern USItype float_to_usi (FLO_type);
484#endif
485#endif
486
5b7344c7 487#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
a23072e2 488extern FLO_type usi_to_float (USItype);
489#endif
490
5b7344c7 491#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
f52117db 492extern FLO_type negate (FLO_type);
493#endif
494
495#ifdef FLOAT
496#if defined(L_make_sf)
497extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
498#endif
499#ifndef FLOAT_ONLY
500extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
501#if defined(L_sf_to_df)
502extern DFtype sf_to_df (SFtype);
503#endif
5b7344c7 504#if defined(L_sf_to_tf) && defined(TMODES)
505extern TFtype sf_to_tf (SFtype);
506#endif
f52117db 507#endif /* ! FLOAT_ONLY */
508#endif /* FLOAT */
509
510#ifndef FLOAT
511extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
512#if defined(L_make_df)
513extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
514#endif
515#if defined(L_df_to_sf)
516extern SFtype df_to_sf (DFtype);
517#endif
5b7344c7 518#if defined(L_df_to_tf) && defined(TMODES)
519extern TFtype df_to_tf (DFtype);
520#endif
f52117db 521#endif /* ! FLOAT */
522
5b7344c7 523#ifdef TMODES
524extern TFtype __make_tp (fp_class_type, unsigned int, int, UTItype);
525#ifdef TFLOAT
526#if defined(L_tf_to_sf)
527extern SFtype tf_to_sf (TFtype);
528#endif
529#if defined(L_tf_to_df)
530extern DFtype tf_to_df (TFtype);
531#endif
532#if defined(L_di_to_tf)
533extern TFtype di_to_df (DItype);
534#endif
535#endif /* TFLOAT */
536#endif /* TMODES */
537
2a281353 538#endif /* ! GCC_FP_BIT_H */