2012-11-08 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / libgcc / fp-bit.h
blob1ae0741d6af9969d2779941d04fbac6bd8bdc692
1 /* Header file for fp-bit.c. */
2 /* Copyright (C) 2000, 2002, 2003, 2006, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef GCC_FP_BIT_H
27 #define GCC_FP_BIT_H
29 /* Defining FINE_GRAINED_LIBRARIES allows one to select which routines
30 from this file are compiled via additional -D options.
32 This avoids the need to pull in the entire fp emulation library
33 when only a small number of functions are needed.
35 If FINE_GRAINED_LIBRARIES is not defined, then compile every
36 suitable routine. */
37 #ifndef FINE_GRAINED_LIBRARIES
38 #define L_pack_df
39 #define L_unpack_df
40 #define L_pack_sf
41 #define L_unpack_sf
42 #define L_addsub_sf
43 #define L_addsub_df
44 #define L_mul_sf
45 #define L_mul_df
46 #define L_div_sf
47 #define L_div_df
48 #define L_fpcmp_parts_sf
49 #define L_fpcmp_parts_df
50 #define L_compare_sf
51 #define L_compare_df
52 #define L_eq_sf
53 #define L_eq_df
54 #define L_ne_sf
55 #define L_ne_df
56 #define L_gt_sf
57 #define L_gt_df
58 #define L_ge_sf
59 #define L_ge_df
60 #define L_lt_sf
61 #define L_lt_df
62 #define L_le_sf
63 #define L_le_df
64 #define L_unord_sf
65 #define L_unord_df
66 #define L_usi_to_sf
67 #define L_usi_to_df
68 #define L_si_to_sf
69 #define L_si_to_df
70 #define L_sf_to_si
71 #define L_df_to_si
72 #define L_f_to_usi
73 #define L_df_to_usi
74 #define L_negate_sf
75 #define L_negate_df
76 #define L_make_sf
77 #define L_make_df
78 #define L_sf_to_df
79 #define L_df_to_sf
80 #ifdef FLOAT
81 #define L_thenan_sf
82 #else
83 #define L_thenan_df
84 #endif
85 #endif /* ! FINE_GRAINED_LIBRARIES */
87 #if __LDBL_MANT_DIG__ == 113 || __LDBL_MANT_DIG__ == 106
88 # if defined(TFLOAT) || defined(L_sf_to_tf) || defined(L_df_to_tf)
89 # define TMODES
90 # endif
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 floating point comparison. This must
107 match `__libgcc_cmp_return__' in GCC for the target. */
108 #ifndef CMPtype
109 typedef int CMPtype __attribute__ ((mode (__libgcc_cmp_return__)));
110 #endif
112 typedef unsigned int UHItype __attribute__ ((mode (HI)));
113 typedef unsigned int USItype __attribute__ ((mode (SI)));
114 typedef unsigned int UDItype __attribute__ ((mode (DI)));
115 #ifdef TMODES
116 typedef unsigned int UTItype __attribute__ ((mode (TI)));
117 #endif
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)
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
128 #ifdef FLOAT_ONLY
129 #define NO_DI_MODE
130 #endif
132 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
133 #define FLOAT_BIT_ORDER_MISMATCH
134 #endif
136 #if __BYTE_ORDER__ != __FLOAT_WORD_ORDER__
137 #define FLOAT_WORD_ORDER_MISMATCH
138 #endif
140 #ifdef TFLOAT
141 # ifndef TMODES
142 # error "TFLOAT requires long double to have 113 bits of mantissa"
143 # endif
145 # define PREFIXFPDP tp
146 # define PREFIXSFDF tf
147 # define NGARDS 10L /* Is this right? */
148 # define GARDROUND 0x1ff
149 # define GARDMASK 0x3ff
150 # define GARDMSB 0x200
151 # define FRAC_NBITS 128
153 # if __LDBL_MANT_DIG__ == 113 /* IEEE quad */
154 # define EXPBITS 15
155 # define EXPBIAS 16383
156 # define EXPMAX (0x7fff)
157 # define QUIET_NAN ((TItype)0x8 << 108)
158 # define FRACHIGH ((TItype)0x8 << 124)
159 # define FRACHIGH2 ((TItype)0xc << 124)
160 # define FRACBITS 112
161 # endif
163 # if __LDBL_MANT_DIG__ == 106 /* IBM extended (double+double) */
164 # define EXPBITS 11
165 # define EXPBIAS 1023
166 # define EXPMAX (0x7ff)
167 # define QUIET_NAN ((TItype)0x8 << (48 + 64))
168 # define FRACHIGH ((TItype)0x8 << 124)
169 # define FRACHIGH2 ((TItype)0xc << 124)
170 # define FRACBITS 105
171 # define HALFFRACBITS 52
172 # define HALFSHIFT 64
173 # endif
175 # define pack_d __pack_t
176 # define unpack_d __unpack_t
177 # define __fpcmp_parts __fpcmp_parts_t
178 typedef UTItype fractype;
179 typedef UDItype halffractype;
180 typedef USItype qrtrfractype;
181 #define qrtrfractype qrtrfractype
182 typedef TFtype FLO_type;
183 typedef TItype intfrac;
184 #elif defined FLOAT
185 # define NGARDS 7L
186 # define GARDROUND 0x3f
187 # define GARDMASK 0x7f
188 # define GARDMSB 0x40
189 # define EXPBITS 8
190 # define EXPBIAS 127
191 # define FRACBITS 23
192 # define EXPMAX (0xff)
193 # define QUIET_NAN 0x100000L
194 # define FRAC_NBITS 32
195 # define FRACHIGH 0x80000000L
196 # define FRACHIGH2 0xc0000000L
197 # define pack_d __pack_f
198 # define unpack_d __unpack_f
199 # define __fpcmp_parts __fpcmp_parts_f
200 typedef USItype fractype;
201 typedef UHItype halffractype;
202 typedef SFtype FLO_type;
203 typedef SItype intfrac;
205 #else
206 # define PREFIXFPDP dp
207 # define PREFIXSFDF df
208 # define NGARDS 8L
209 # define GARDROUND 0x7f
210 # define GARDMASK 0xff
211 # define GARDMSB 0x80
212 # define EXPBITS 11
213 # define EXPBIAS 1023
214 # define FRACBITS 52
215 # define EXPMAX (0x7ff)
216 # define QUIET_NAN 0x8000000000000LL
217 # define FRAC_NBITS 64
218 # define FRACHIGH 0x8000000000000000LL
219 # define FRACHIGH2 0xc000000000000000LL
220 # define pack_d __pack_d
221 # define unpack_d __unpack_d
222 # define __fpcmp_parts __fpcmp_parts_d
223 typedef UDItype fractype;
224 typedef USItype halffractype;
225 typedef DFtype FLO_type;
226 typedef DItype intfrac;
227 #endif /* FLOAT */
229 #ifdef TFLOAT
230 # define add __addtf3
231 # define sub __subtf3
232 # define multiply __multf3
233 # define divide __divtf3
234 # define compare __cmptf2
235 # define _eq_f2 __eqtf2
236 # define _ne_f2 __netf2
237 # define _gt_f2 __gttf2
238 # define _ge_f2 __getf2
239 # define _lt_f2 __lttf2
240 # define _le_f2 __letf2
241 # define _unord_f2 __unordtf2
242 # define usi_to_float __floatunsitf
243 # define si_to_float __floatsitf
244 # define float_to_si __fixtfsi
245 # define float_to_usi __fixunstfsi
246 # define negate __negtf2
247 # define tf_to_sf __trunctfsf2
248 # define tf_to_df __trunctfdf2
249 #elif defined FLOAT
250 # define add __addsf3
251 # define sub __subsf3
252 # define multiply __mulsf3
253 # define divide __divsf3
254 # define compare __cmpsf2
255 # define _eq_f2 __eqsf2
256 # define _ne_f2 __nesf2
257 # define _gt_f2 __gtsf2
258 # define _ge_f2 __gesf2
259 # define _lt_f2 __ltsf2
260 # define _le_f2 __lesf2
261 # define _unord_f2 __unordsf2
262 # define usi_to_float __floatunsisf
263 # define si_to_float __floatsisf
264 # define float_to_si __fixsfsi
265 # define float_to_usi __fixunssfsi
266 # define negate __negsf2
267 # define sf_to_df __extendsfdf2
268 # define sf_to_tf __extendsftf2
269 #else
270 # define add __adddf3
271 # define sub __subdf3
272 # define multiply __muldf3
273 # define divide __divdf3
274 # define compare __cmpdf2
275 # define _eq_f2 __eqdf2
276 # define _ne_f2 __nedf2
277 # define _gt_f2 __gtdf2
278 # define _ge_f2 __gedf2
279 # define _lt_f2 __ltdf2
280 # define _le_f2 __ledf2
281 # define _unord_f2 __unorddf2
282 # define usi_to_float __floatunsidf
283 # define si_to_float __floatsidf
284 # define float_to_si __fixdfsi
285 # define float_to_usi __fixunsdfsi
286 # define negate __negdf2
287 # define df_to_sf __truncdfsf2
288 # define df_to_tf __extenddftf2
289 #endif /* FLOAT */
291 #ifndef INLINE
292 #define INLINE __inline__
293 #endif
295 /* Preserve the sticky-bit when shifting fractions to the right. */
296 #define LSHIFT(a, s) { a = (a >> s) | !!(a & (((fractype) 1 << s) - 1)); }
298 /* numeric parameters */
299 /* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
300 of a float and of a double. Assumes there are only two float types.
301 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
303 #define F_D_BITOFF (52+8-(23+7))
305 #ifdef TMODES
306 # define F_T_BITOFF (__LDBL_MANT_DIG__-1+10-(23+7))
307 # define D_T_BITOFF (__LDBL_MANT_DIG__-1+10-(52+8))
308 #endif
311 #define NORMAL_EXPMIN (-(EXPBIAS)+1)
312 #define IMPLICIT_1 ((fractype)1<<(FRACBITS+NGARDS))
313 #define IMPLICIT_2 ((fractype)1<<(FRACBITS+1+NGARDS))
315 /* common types */
317 typedef enum
319 CLASS_SNAN,
320 CLASS_QNAN,
321 CLASS_ZERO,
322 CLASS_NUMBER,
323 CLASS_INFINITY
324 } fp_class_type;
326 typedef struct
328 #ifdef SMALL_MACHINE
329 char class;
330 unsigned char sign;
331 short normal_exp;
332 #else
333 fp_class_type class;
334 unsigned int sign;
335 int normal_exp;
336 #endif
338 union
340 fractype ll;
341 halffractype l[2];
342 } fraction;
343 } fp_number_type;
345 typedef union
347 FLO_type value;
348 fractype value_raw;
350 #ifndef FLOAT
351 # ifdef qrtrfractype
352 qrtrfractype qwords[4];
353 # else
354 halffractype words[2];
355 # endif
356 #endif
358 #ifdef FLOAT_BIT_ORDER_MISMATCH
359 struct
361 fractype fraction:FRACBITS __attribute__ ((packed));
362 unsigned int exp:EXPBITS __attribute__ ((packed));
363 unsigned int sign:1 __attribute__ ((packed));
365 bits;
366 #endif
368 #ifdef _DEBUG_BITFLOAT
369 struct
371 unsigned int sign:1 __attribute__ ((packed));
372 unsigned int exp:EXPBITS __attribute__ ((packed));
373 fractype fraction:FRACBITS __attribute__ ((packed));
375 bits_big_endian;
377 struct
379 fractype fraction:FRACBITS __attribute__ ((packed));
380 unsigned int exp:EXPBITS __attribute__ ((packed));
381 unsigned int sign:1 __attribute__ ((packed));
383 bits_little_endian;
384 #endif
386 FLO_union_type;
388 /* Prototypes. */
390 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
391 extern FLO_type pack_d (const fp_number_type *);
392 #endif
394 extern void unpack_d (FLO_union_type *, fp_number_type *);
396 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
397 extern FLO_type add (FLO_type, FLO_type);
398 extern FLO_type sub (FLO_type, FLO_type);
399 #endif
401 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
402 extern FLO_type multiply (FLO_type, FLO_type);
403 #endif
405 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
406 extern FLO_type divide (FLO_type, FLO_type);
407 #endif
409 extern int __fpcmp_parts (fp_number_type *, fp_number_type *);
411 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compare_tf)
412 extern CMPtype compare (FLO_type, FLO_type);
413 #endif
415 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
416 extern CMPtype _eq_f2 (FLO_type, FLO_type);
417 #endif
419 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
420 extern CMPtype _ne_f2 (FLO_type, FLO_type);
421 #endif
423 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
424 extern CMPtype _gt_f2 (FLO_type, FLO_type);
425 #endif
427 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
428 extern CMPtype _ge_f2 (FLO_type, FLO_type);
429 #endif
431 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
432 extern CMPtype _lt_f2 (FLO_type, FLO_type);
433 #endif
435 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
436 extern CMPtype _le_f2 (FLO_type, FLO_type);
437 #endif
439 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
440 extern CMPtype _unord_f2 (FLO_type, FLO_type);
441 #endif
443 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
444 extern FLO_type si_to_float (SItype);
445 #endif
447 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
448 extern SItype float_to_si (FLO_type);
449 #endif
451 #if defined(L_tf_to_usi)
452 extern USItype float_to_usi (FLO_type);
453 #endif
455 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
456 extern FLO_type usi_to_float (USItype);
457 #endif
459 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
460 extern FLO_type negate (FLO_type);
461 #endif
463 #ifdef FLOAT
464 #if defined(L_make_sf)
465 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
466 #endif
467 #ifndef FLOAT_ONLY
468 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
469 #if defined(L_sf_to_df)
470 extern DFtype sf_to_df (SFtype);
471 #endif
472 #if defined(L_sf_to_tf) && defined(TMODES)
473 extern TFtype sf_to_tf (SFtype);
474 #endif
475 #endif /* ! FLOAT_ONLY */
476 #endif /* FLOAT */
478 #ifndef FLOAT
479 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
480 #if defined(L_make_df)
481 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
482 #endif
483 #if defined(L_df_to_sf)
484 extern SFtype df_to_sf (DFtype);
485 #endif
486 #if defined(L_df_to_tf) && defined(TMODES)
487 extern TFtype df_to_tf (DFtype);
488 #endif
489 #endif /* ! FLOAT */
491 #ifdef TMODES
492 extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
493 extern TFtype __make_tp (fp_class_type, unsigned int, int, UTItype);
494 #ifdef TFLOAT
495 #if defined(L_tf_to_sf)
496 extern SFtype tf_to_sf (TFtype);
497 #endif
498 #if defined(L_tf_to_df)
499 extern DFtype tf_to_df (TFtype);
500 #endif
501 #if defined(L_di_to_tf)
502 extern TFtype di_to_df (DItype);
503 #endif
504 #endif /* TFLOAT */
505 #endif /* TMODES */
507 #endif /* ! GCC_FP_BIT_H */