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