OSDN Git Service

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