OSDN Git Service

e734b26548e8e207a44657fa0b93d22ca5dfeedc
[pf3gnuchains/gcc-fork.git] / gcc / real.h
1 /* Definitions of floating-point access for GNU compiler.
2    Copyright (C) 1989, 1991, 1994, 1996, 1997, 1998,
3    1999, 2000, 2002 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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 2, or (at your option) any later
10 version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING.  If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.  */
21
22 #ifndef GCC_REAL_H
23 #define GCC_REAL_H
24
25 /* Define codes for all the float formats that we know of.  */
26 #define UNKNOWN_FLOAT_FORMAT 0
27 #define IEEE_FLOAT_FORMAT 1
28 #define VAX_FLOAT_FORMAT 2
29 #define IBM_FLOAT_FORMAT 3
30 #define C4X_FLOAT_FORMAT 4
31
32 /* Default to IEEE float if not specified.  Nearly all machines use it.  */
33
34 #ifndef TARGET_FLOAT_FORMAT
35 #define TARGET_FLOAT_FORMAT     IEEE_FLOAT_FORMAT
36 #endif
37
38 #ifndef HOST_FLOAT_FORMAT
39 #define HOST_FLOAT_FORMAT       IEEE_FLOAT_FORMAT
40 #endif
41
42 #ifndef INTEL_EXTENDED_IEEE_FORMAT
43 #define INTEL_EXTENDED_IEEE_FORMAT 0
44 #endif
45
46 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
47 #define REAL_INFINITY
48 #endif
49
50 /* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined
51    in the header files, then this implies the word-endianness is the same as
52    for integers.  */
53
54 /* This is defined 0 or 1, like WORDS_BIG_ENDIAN.  */
55 #ifndef FLOAT_WORDS_BIG_ENDIAN
56 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
57 #endif
58
59 /* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN.  */
60 #ifndef HOST_FLOAT_WORDS_BIG_ENDIAN
61 #ifdef HOST_WORDS_BIG_ENDIAN
62 #define HOST_FLOAT_WORDS_BIG_ENDIAN 1
63 #else
64 #define HOST_FLOAT_WORDS_BIG_ENDIAN 0
65 #endif
66 #endif
67
68 #ifndef LONG_DOUBLE_TYPE_SIZE
69 #define LONG_DOUBLE_TYPE_SIZE 64
70 #endif
71 /* MAX_LONG_DOUBLE_TYPE_SIZE is a constant tested by #if.
72    LONG_DOUBLE_TYPE_SIZE can vary at compiler run time.
73    So long as macros like REAL_VALUE_TO_TARGET_LONG_DOUBLE cannot
74    vary too, however, then XFmode and TFmode long double
75    cannot both be supported at the same time.  */
76 #ifndef MAX_LONG_DOUBLE_TYPE_SIZE
77 #define MAX_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
78 #endif
79
80 /* **** Start of software floating point emulator interface macros **** */
81
82 /* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
83    has been defined to be 96 in the tm.h machine file.  */
84 #if (MAX_LONG_DOUBLE_TYPE_SIZE == 96)
85 #define REAL_IS_NOT_DOUBLE
86 typedef struct {
87   HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
88 } realvaluetype;
89 #define REAL_VALUE_TYPE realvaluetype
90
91 #else /* no XFmode support */
92
93 #if (MAX_LONG_DOUBLE_TYPE_SIZE == 128)
94
95 #define REAL_IS_NOT_DOUBLE
96 typedef struct {
97   HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
98 } realvaluetype;
99 #define REAL_VALUE_TYPE realvaluetype
100
101 #else /* not TFmode */
102
103 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
104 /* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
105    but it is not necessarily a host machine double.  */
106 #define REAL_IS_NOT_DOUBLE
107 typedef struct {
108   HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
109 } realvaluetype;
110 #define REAL_VALUE_TYPE realvaluetype
111 #else
112 /* If host and target formats are compatible, then a REAL_VALUE_TYPE
113    is actually a host machine double.  */
114 #define REAL_VALUE_TYPE double
115 #endif
116
117 #endif /* no TFmode support */
118 #endif /* no XFmode support */
119
120 extern unsigned int significand_size    PARAMS ((enum machine_mode));
121
122 #define REAL_ARITHMETIC(value, code, d1, d2) \
123   earith (&(value), (code), &(d1), &(d2))
124
125 /* Declare functions in real.c.  */
126 extern void earith              PARAMS ((REAL_VALUE_TYPE *, int,
127                                        REAL_VALUE_TYPE *, REAL_VALUE_TYPE *));
128 extern REAL_VALUE_TYPE etrunci  PARAMS ((REAL_VALUE_TYPE));
129 extern REAL_VALUE_TYPE etruncui PARAMS ((REAL_VALUE_TYPE));
130 extern REAL_VALUE_TYPE ereal_negate PARAMS ((REAL_VALUE_TYPE));
131 extern HOST_WIDE_INT efixi      PARAMS ((REAL_VALUE_TYPE));
132 extern unsigned HOST_WIDE_INT efixui PARAMS ((REAL_VALUE_TYPE));
133 extern void ereal_from_int      PARAMS ((REAL_VALUE_TYPE *,
134                                        HOST_WIDE_INT, HOST_WIDE_INT,
135                                        enum machine_mode));
136 extern void ereal_from_uint     PARAMS ((REAL_VALUE_TYPE *,
137                                        unsigned HOST_WIDE_INT,
138                                        unsigned HOST_WIDE_INT,
139                                        enum machine_mode));
140 extern void ereal_to_int        PARAMS ((HOST_WIDE_INT *, HOST_WIDE_INT *,
141                                        REAL_VALUE_TYPE));
142 extern REAL_VALUE_TYPE ereal_ldexp PARAMS ((REAL_VALUE_TYPE, int));
143
144 extern void etartdouble         PARAMS ((REAL_VALUE_TYPE, long *));
145 extern void etarldouble         PARAMS ((REAL_VALUE_TYPE, long *));
146 extern void etardouble          PARAMS ((REAL_VALUE_TYPE, long *));
147 extern long etarsingle          PARAMS ((REAL_VALUE_TYPE));
148 extern void ereal_to_decimal    PARAMS ((REAL_VALUE_TYPE, char *));
149 extern int ereal_cmp            PARAMS ((REAL_VALUE_TYPE, REAL_VALUE_TYPE));
150 extern int ereal_isneg          PARAMS ((REAL_VALUE_TYPE));
151 extern REAL_VALUE_TYPE ereal_unto_float PARAMS ((long));
152 extern REAL_VALUE_TYPE ereal_unto_double PARAMS ((long *));
153 extern REAL_VALUE_TYPE ereal_from_float PARAMS ((HOST_WIDE_INT));
154 extern REAL_VALUE_TYPE ereal_from_double PARAMS ((HOST_WIDE_INT *));
155
156 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
157 /* true if x < y : */
158 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
159 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
160
161 /* Compare two floating-point objects for bitwise identity.
162    This is not the same as comparing for equality on IEEE hosts:
163    -0.0 equals 0.0 but they are not identical, and conversely
164    two NaNs might be identical but they cannot be equal.  */
165 #define REAL_VALUES_IDENTICAL(x, y) \
166   (!memcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE)))
167
168 /* These return REAL_VALUE_TYPE: */
169 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
170 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
171
172 /* Truncate the floating-point value X to mode MODE.  */
173 #define REAL_VALUE_TRUNCATE(mode, x)  real_value_truncate (mode, x)
174 extern REAL_VALUE_TYPE real_value_truncate PARAMS ((enum machine_mode,
175                                                  REAL_VALUE_TYPE));
176
177 /* These return HOST_WIDE_INT: */
178 /* Convert a floating-point value to integer, rounding toward zero.  */
179 #define REAL_VALUE_FIX(x) (efixi (x))
180 /* Convert a floating-point value to unsigned integer, rounding
181    toward zero.  */
182 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
183
184 /* Convert ASCII string S to floating point in mode M.
185    Decimal input uses ATOF.  Hexadecimal uses HTOF.  */
186 #define REAL_VALUE_ATOF(s,m) ereal_atof(s,m)
187 #define REAL_VALUE_HTOF(s,m) ereal_atof(s,m)
188
189 #define REAL_VALUE_NEGATE ereal_negate
190
191 /* Determine whether a floating-point value X is infinite.  */
192 #define REAL_VALUE_ISINF(x) (target_isinf (x))
193
194 /* Determine whether a floating-point value X is a NaN.  */
195 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
196
197 /* Determine whether a floating-point value X is negative.  */
198 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
199
200 /* Determine whether a floating-point value X is minus zero.  */
201 #define REAL_VALUE_MINUS_ZERO(x) \
202  ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
203
204 #define REAL_VALUE_TO_INT ereal_to_int
205
206 /* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0.  */
207 #define REAL_VALUE_FROM_INT(d, lo, hi, mode) \
208   ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode)
209
210 #define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \
211   ereal_from_uint (&d, lo, hi, mode)
212
213 /* IN is a REAL_VALUE_TYPE.  OUT is an array of longs.  */
214 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT)               \
215    (LONG_DOUBLE_TYPE_SIZE == 64 ? etardouble ((IN), (OUT))      \
216     : LONG_DOUBLE_TYPE_SIZE == 96 ? etarldouble ((IN), (OUT))   \
217     : LONG_DOUBLE_TYPE_SIZE == 128 ? etartdouble ((IN), (OUT))  \
218     : abort ())
219 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
220
221 /* IN is a REAL_VALUE_TYPE.  OUT is a long.  */
222 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
223
224 /* Inverse of REAL_VALUE_TO_TARGET_DOUBLE.  */
225 #define REAL_VALUE_UNTO_TARGET_DOUBLE(d)  (ereal_unto_double (d))
226
227 /* Inverse of REAL_VALUE_TO_TARGET_SINGLE.  */
228 #define REAL_VALUE_UNTO_TARGET_SINGLE(f)  (ereal_unto_float (f))
229
230 /* d is an array of HOST_WIDE_INT that holds a double precision
231    value in the target computer's floating point format.  */
232 #define REAL_VALUE_FROM_TARGET_DOUBLE(d)  (ereal_from_double (d))
233
234 /* f is a HOST_WIDE_INT containing a single precision target float value.  */
235 #define REAL_VALUE_FROM_TARGET_SINGLE(f)  (ereal_from_float (f))
236
237 /* Conversions to decimal ASCII string.  */
238 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
239
240 /* **** End of software floating point emulator interface macros **** */
241 \f
242 /* Constant real values 0, 1, 2, and -1.  */
243
244 extern REAL_VALUE_TYPE dconst0;
245 extern REAL_VALUE_TYPE dconst1;
246 extern REAL_VALUE_TYPE dconst2;
247 extern REAL_VALUE_TYPE dconstm1;
248
249 /* Union type used for extracting real values from CONST_DOUBLEs
250    or putting them in.  */
251
252 union real_extract 
253 {
254   REAL_VALUE_TYPE d;
255   HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
256 };
257
258 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents.  */
259 /* Function to return a real value (not a tree node)
260    from a given integer constant.  */
261 union tree_node;
262 REAL_VALUE_TYPE real_value_from_int_cst PARAMS ((union tree_node *,
263                                                 union tree_node *));
264
265 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from)          \
266 do { union real_extract u;                              \
267      memcpy (&u, &CONST_DOUBLE_LOW ((from)), sizeof u); \
268      to = u.d; } while (0)
269
270 /* Return a CONST_DOUBLE with value R and mode M.  */
271
272 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r,  m)
273 extern struct rtx_def *immed_real_const_1       PARAMS ((REAL_VALUE_TYPE,
274                                                        enum machine_mode));
275
276 /* Replace R by 1/R in the given machine mode, if the result is exact.  */
277 extern int exact_real_inverse   PARAMS ((enum machine_mode, REAL_VALUE_TYPE *));
278 extern int target_isnan         PARAMS ((REAL_VALUE_TYPE));
279 extern int target_isinf         PARAMS ((REAL_VALUE_TYPE));
280 extern int target_negative      PARAMS ((REAL_VALUE_TYPE));
281 extern void debug_real          PARAMS ((REAL_VALUE_TYPE));
282 extern REAL_VALUE_TYPE ereal_atof PARAMS ((const char *, enum machine_mode));
283
284 #endif /* ! GCC_REAL_H */