]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/fp-bit.h
fp-bit.h: New file.
[thirdparty/gcc.git] / gcc / config / fp-bit.h
CommitLineData
cb4b535d
KG
1/* Header file for fp-bit.c. */
2/* Copyright (C) 2000
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
29#ifndef __FP_BIT_H__
30#define __FP_BIT_H__
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
38 If FINE_GRAINED_LIBRARIES is not defined, then compile every
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
69#define L_si_to_sf
70#define L_si_to_df
71#define L_sf_to_si
72#define L_df_to_si
73#define L_f_to_usi
74#define L_df_to_usi
75#define L_negate_sf
76#define L_negate_df
77#define L_make_sf
78#define L_make_df
79#define L_sf_to_df
80#define L_df_to_sf
81#ifdef FLOAT
82#define L_thenan_sf
83#else
84#define L_thenan_df
85#endif
86#endif /* ! FINE_GRAINED_LIBRARIES */
87
88typedef float SFtype __attribute__ ((mode (SF)));
89typedef float DFtype __attribute__ ((mode (DF)));
90
91typedef int HItype __attribute__ ((mode (HI)));
92typedef int SItype __attribute__ ((mode (SI)));
93typedef int DItype __attribute__ ((mode (DI)));
94
95/* The type of the result of a fp compare */
96#ifndef CMPtype
97#define CMPtype SItype
98#endif
99
100typedef unsigned int UHItype __attribute__ ((mode (HI)));
101typedef unsigned int USItype __attribute__ ((mode (SI)));
102typedef unsigned int UDItype __attribute__ ((mode (DI)));
103
104#define MAX_SI_INT ((SItype) ((unsigned) (~0)>>1))
105#define MAX_USI_INT ((USItype) ~0)
106
107
108#ifdef FLOAT_ONLY
109#define NO_DI_MODE
110#endif
111
112#ifdef FLOAT
113# define NGARDS 7L
114# define GARDROUND 0x3f
115# define GARDMASK 0x7f
116# define GARDMSB 0x40
117# define EXPBITS 8
118# define EXPBIAS 127
119# define FRACBITS 23
120# define EXPMAX (0xff)
121# define QUIET_NAN 0x100000L
122# define FRAC_NBITS 32
123# define FRACHIGH 0x80000000L
124# define FRACHIGH2 0xc0000000L
125# define pack_d __pack_f
126# define unpack_d __unpack_f
127# define __fpcmp_parts __fpcmp_parts_f
128 typedef USItype fractype;
129 typedef UHItype halffractype;
130 typedef SFtype FLO_type;
131 typedef SItype intfrac;
132
133#else
134# define PREFIXFPDP dp
135# define PREFIXSFDF df
136# define NGARDS 8L
137# define GARDROUND 0x7f
138# define GARDMASK 0xff
139# define GARDMSB 0x80
140# define EXPBITS 11
141# define EXPBIAS 1023
142# define FRACBITS 52
143# define EXPMAX (0x7ff)
144# define QUIET_NAN 0x8000000000000LL
145# define FRAC_NBITS 64
146# define FRACHIGH 0x8000000000000000LL
147# define FRACHIGH2 0xc000000000000000LL
148# define pack_d __pack_d
149# define unpack_d __unpack_d
150# define __fpcmp_parts __fpcmp_parts_d
151 typedef UDItype fractype;
152 typedef USItype halffractype;
153 typedef DFtype FLO_type;
154 typedef DItype intfrac;
155#endif /* FLOAT */
156
157#ifdef US_SOFTWARE_GOFAST
158# ifdef FLOAT
159# define add fpadd
160# define sub fpsub
161# define multiply fpmul
162# define divide fpdiv
163# define compare fpcmp
164# define si_to_float sitofp
165# define float_to_si fptosi
166# define float_to_usi fptoui
167# define negate __negsf2
168# define sf_to_df fptodp
169# define dptofp dptofp
170#else
171# define add dpadd
172# define sub dpsub
173# define multiply dpmul
174# define divide dpdiv
175# define compare dpcmp
176# define si_to_float litodp
177# define float_to_si dptoli
178# define float_to_usi dptoul
179# define negate __negdf2
180# define df_to_sf dptofp
181# endif /* FLOAT */
182#else
183# ifdef FLOAT
184# define add __addsf3
185# define sub __subsf3
186# define multiply __mulsf3
187# define divide __divsf3
188# define compare __cmpsf2
189# define _eq_f2 __eqsf2
190# define _ne_f2 __nesf2
191# define _gt_f2 __gtsf2
192# define _ge_f2 __gesf2
193# define _lt_f2 __ltsf2
194# define _le_f2 __lesf2
195# define _unord_f2 __unordsf2
196# define si_to_float __floatsisf
197# define float_to_si __fixsfsi
198# define float_to_usi __fixunssfsi
199# define negate __negsf2
200# define sf_to_df __extendsfdf2
201#else
202# define add __adddf3
203# define sub __subdf3
204# define multiply __muldf3
205# define divide __divdf3
206# define compare __cmpdf2
207# define _eq_f2 __eqdf2
208# define _ne_f2 __nedf2
209# define _gt_f2 __gtdf2
210# define _ge_f2 __gedf2
211# define _lt_f2 __ltdf2
212# define _le_f2 __ledf2
213# define _unord_f2 __unorddf2
214# define si_to_float __floatsidf
215# define float_to_si __fixdfsi
216# define float_to_usi __fixunsdfsi
217# define negate __negdf2
218# define df_to_sf __truncdfsf2
219# endif /* FLOAT */
220#endif /* US_SOFTWARE_GOFAST */
221
222#ifndef INLINE
223#define INLINE __inline__
224#endif
225
226/* Preserve the sticky-bit when shifting fractions to the right. */
227#define LSHIFT(a) { a = (a & 1) | (a >> 1); }
228
229/* numeric parameters */
230/* F_D_BITOFF is the number of bits offset between the MSB of the mantissa
231 of a float and of a double. Assumes there are only two float types.
232 (double::FRAC_BITS+double::NGARDS-(float::FRAC_BITS-float::NGARDS))
233 */
234#define F_D_BITOFF (52+8-(23+7))
235
236
237#define NORMAL_EXPMIN (-(EXPBIAS)+1)
238#define IMPLICIT_1 (1LL<<(FRACBITS+NGARDS))
239#define IMPLICIT_2 (1LL<<(FRACBITS+1+NGARDS))
240
241/* common types */
242
243typedef enum
244{
245 CLASS_SNAN,
246 CLASS_QNAN,
247 CLASS_ZERO,
248 CLASS_NUMBER,
249 CLASS_INFINITY
250} fp_class_type;
251
252typedef struct
253{
254#ifdef SMALL_MACHINE
255 char class;
256 unsigned char sign;
257 short normal_exp;
258#else
259 fp_class_type class;
260 unsigned int sign;
261 int normal_exp;
262#endif
263
264 union
265 {
266 fractype ll;
267 halffractype l[2];
268 } fraction;
269} fp_number_type;
270
271typedef union
272{
273 FLO_type value;
274 fractype value_raw;
275
276#ifndef FLOAT
277 halffractype words[2];
278#endif
279
280#ifdef FLOAT_BIT_ORDER_MISMATCH
281 struct
282 {
283 fractype fraction:FRACBITS __attribute__ ((packed));
284 unsigned int exp:EXPBITS __attribute__ ((packed));
285 unsigned int sign:1 __attribute__ ((packed));
286 }
287 bits;
288#endif
289
290#ifdef _DEBUG_BITFLOAT
291 struct
292 {
293 unsigned int sign:1 __attribute__ ((packed));
294 unsigned int exp:EXPBITS __attribute__ ((packed));
295 fractype fraction:FRACBITS __attribute__ ((packed));
296 }
297 bits_big_endian;
298
299 struct
300 {
301 fractype fraction:FRACBITS __attribute__ ((packed));
302 unsigned int exp:EXPBITS __attribute__ ((packed));
303 unsigned int sign:1 __attribute__ ((packed));
304 }
305 bits_little_endian;
306#endif
307}
308FLO_union_type;
309
310/* Prototypes */
311
312#if defined(L_pack_df) || defined(L_pack_sf)
313extern FLO_type pack_d (fp_number_type *);
314#endif
315
316extern void unpack_d (FLO_union_type *, fp_number_type *);
317
318#if defined(L_addsub_sf) || defined(L_addsub_df)
319extern FLO_type add (FLO_type, FLO_type);
320extern FLO_type sub (FLO_type, FLO_type);
321#endif
322
323#if defined(L_mul_sf) || defined(L_mul_df)
324extern FLO_type multiply (FLO_type, FLO_type);
325#endif
326
327#if defined(L_div_sf) || defined(L_div_df)
328extern FLO_type divide (FLO_type, FLO_type);
329#endif
330
331extern int __fpcmp_parts (fp_number_type *, fp_number_type *);
332
333#if defined(L_compare_sf) || defined(L_compare_df)
334extern CMPtype compare (FLO_type, FLO_type);
335#endif
336
337#ifndef US_SOFTWARE_GOFAST
338
339#if defined(L_eq_sf) || defined(L_eq_df)
340extern CMPtype _eq_f2 (FLO_type, FLO_type);
341#endif
342
343#if defined(L_ne_sf) || defined(L_ne_df)
344extern CMPtype _ne_f2 (FLO_type, FLO_type);
345#endif
346
347#if defined(L_gt_sf) || defined(L_gt_df)
348extern CMPtype _gt_f2 (FLO_type, FLO_type);
349#endif
350
351#if defined(L_ge_sf) || defined(L_ge_df)
352extern CMPtype _ge_f2 (FLO_type, FLO_type);
353#endif
354
355#if defined(L_lt_sf) || defined(L_lt_df)
356extern CMPtype _lt_f2 (FLO_type, FLO_type);
357#endif
358
359#if defined(L_le_sf) || defined(L_le_df)
360extern CMPtype _le_f2 (FLO_type, FLO_type);
361#endif
362
363#if defined(L_unord_sf) || defined(L_unord_df)
364extern CMPtype _unord_f2 (FLO_type, FLO_type);
365#endif
366
367#endif /* ! US_SOFTWARE_GOFAST */
368
369#if defined(L_si_to_sf) || defined(L_si_to_df)
370extern FLO_type si_to_float (SItype);
371#endif
372
373#if defined(L_sf_to_si) || defined(L_df_to_si)
374extern SItype float_to_si (FLO_type);
375#endif
376
377#if defined(L_sf_to_usi) || defined(L_df_to_usi)
378#ifdef US_SOFTWARE_GOFAST
379extern USItype float_to_usi (FLO_type);
380#endif
381#endif
382
383#if defined(L_negate_sf) || defined(L_negate_df)
384extern FLO_type negate (FLO_type);
385#endif
386
387#ifdef FLOAT
388#if defined(L_make_sf)
389extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
390#endif
391#ifndef FLOAT_ONLY
392extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
393#if defined(L_sf_to_df)
394extern DFtype sf_to_df (SFtype);
395#endif
396#endif /* ! FLOAT_ONLY */
397#endif /* FLOAT */
398
399#ifndef FLOAT
400extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
401#if defined(L_make_df)
402extern DFtype __make_dp (fp_class_type, unsigned int, int, UDItype);
403#endif
404#if defined(L_df_to_sf)
405extern SFtype df_to_sf (DFtype);
406#endif
407#endif /* ! FLOAT */
408
409#endif /* __FP_BIT_H__ */