OSDN Git Service

(REAL_VALUE_TYPE): Define array at least 20 bytes wide
[pf3gnuchains/gcc-fork.git] / gcc / real.h
1 /* Front-end tree definitions for GNU compiler.
2    Copyright (C) 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC 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.
10
11 GNU CC 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.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #ifndef REAL_H_INCLUDED
21 #define REAL_H_INCLUDED
22
23 /* Define codes for all the float formats that we know of.  */
24 #define UNKNOWN_FLOAT_FORMAT 0
25 #define IEEE_FLOAT_FORMAT 1
26 #define VAX_FLOAT_FORMAT 2
27 #define IBM_FLOAT_FORMAT 3
28
29 /* Default to IEEE float if not specified.  Nearly all machines use it.  */
30
31 #ifndef TARGET_FLOAT_FORMAT
32 #define TARGET_FLOAT_FORMAT     IEEE_FLOAT_FORMAT
33 #endif
34
35 #ifndef HOST_FLOAT_FORMAT
36 #define HOST_FLOAT_FORMAT       IEEE_FLOAT_FORMAT
37 #endif
38
39 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
40 #define REAL_INFINITY
41 #endif
42
43 /* Defining REAL_ARITHMETIC invokes a floating point emulator
44    that can produce a target machine format differing by more
45    than just endian-ness from the host's format.  The emulator
46    is also used to support extended real XFmode.  */
47 #ifndef LONG_DOUBLE_TYPE_SIZE
48 #define LONG_DOUBLE_TYPE_SIZE 64
49 #endif
50 #if (LONG_DOUBLE_TYPE_SIZE == 96) || (LONG_DOUBLE_TYPE_SIZE == 128)
51 #ifndef REAL_ARITHMETIC
52 #define REAL_ARITHMETIC
53 #endif
54 #endif
55 #ifdef REAL_ARITHMETIC
56 /* **** Start of software floating point emulator interface macros **** */
57
58 /* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
59    has been defined to be 96 in the tm.h machine file. */
60 #if (LONG_DOUBLE_TYPE_SIZE == 96)
61 #define REAL_IS_NOT_DOUBLE
62 #define REAL_ARITHMETIC
63 typedef struct {
64   HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
65 } realvaluetype;
66 #define REAL_VALUE_TYPE realvaluetype
67
68 #else /* no XFmode support */
69
70 #if (LONG_DOUBLE_TYPE_SIZE == 128)
71
72 #define REAL_IS_NOT_DOUBLE
73 #define REAL_ARITHMETIC
74 typedef struct {
75   HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
76 } realvaluetype;
77 #define REAL_VALUE_TYPE realvaluetype
78
79 #else /* not TFmode */
80
81 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
82 /* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
83    but it is not necessarily a host machine double. */
84 #define REAL_IS_NOT_DOUBLE
85 typedef struct {
86   HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
87 } realvaluetype;
88 #define REAL_VALUE_TYPE realvaluetype
89 #else
90 /* If host and target formats are compatible, then a REAL_VALUE_TYPE
91    is actually a host machine double. */
92 #define REAL_VALUE_TYPE double
93 #endif
94
95 #endif /* no TFmode support */
96 #endif /* no XFmode support */
97
98 /* If emulation has been enabled by defining REAL_ARITHMETIC or by
99    setting LONG_DOUBLE_TYPE_SIZE to 96 or 128, then define macros so that
100    they invoke emulator functions. This will succeed only if the machine
101    files have been updated to use these macros in place of any
102    references to host machine `double' or `float' types.  */
103 #ifdef REAL_ARITHMETIC
104 #undef REAL_ARITHMETIC
105 #define REAL_ARITHMETIC(value, code, d1, d2) \
106   earith (&(value), (code), &(d1), &(d2))
107
108 /* Declare functions in real.c that are referenced here. */
109 void earith (), ereal_from_uint (), ereal_from_int (), ereal_to_int ();
110 void etarldouble (), etartdouble (), etardouble ();
111 long etarsingle (), efixi ();
112 unsigned long efixui ();
113 int ereal_cmp (), ereal_isneg ();
114 unsigned int eroundui ();
115 REAL_VALUE_TYPE etrunci (), etruncui (), ereal_ldexp (), ereal_atof ();
116 REAL_VALUE_TYPE ereal_negate (), ereal_truncate ();
117 REAL_VALUE_TYPE ereal_from_float (), ereal_from_double ();
118
119 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
120 /* true if x < y : */
121 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
122 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
123
124 /* These return REAL_VALUE_TYPE: */
125 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
126 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
127 extern REAL_VALUE_TYPE real_value_truncate ();
128 #define REAL_VALUE_TRUNCATE(mode, x)  real_value_truncate (mode, x)
129
130 /* These return int: */
131 /* Convert a floating-point value to integer, rounding toward zero.  */
132 #define REAL_VALUE_FIX(x) (efixi (x))
133 /* Convert a floating-point value to unsigned integer, rounding
134    toward zero. */
135 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
136
137 #define REAL_VALUE_ATOF ereal_atof
138 #define REAL_VALUE_NEGATE ereal_negate
139
140 #define REAL_VALUE_MINUS_ZERO(x) \
141  ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
142
143 #define REAL_VALUE_TO_INT ereal_to_int
144 #define REAL_VALUE_FROM_INT(d, i, j) (ereal_from_int (&d, i, j))
145 #define REAL_VALUE_FROM_UNSIGNED_INT(d, i, j) (ereal_from_uint (&d, i, j))
146
147 /* IN is a REAL_VALUE_TYPE.  OUT is an array of longs. */
148 #if LONG_DOUBLE_TYPE_SIZE == 96
149 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
150 #else
151 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT)))
152 #endif
153 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
154
155 /* IN is a REAL_VALUE_TYPE.  OUT is a long. */
156 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
157
158 /* d is an array of longs. */
159 #define REAL_VALUE_FROM_TARGET_DOUBLE(d)  (ereal_from_double (d))
160
161 /* f is a long. */
162 #define REAL_VALUE_FROM_TARGET_SINGLE(f)  (ereal_from_float (f))
163
164 /* Conversions to decimal ASCII string.  */
165 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
166
167 #endif /* REAL_ARITHMETIC defined */
168
169 /* **** End of software floating point emulator interface macros **** */
170 #else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */
171
172 /* old interface */
173 #ifdef REAL_ARITHMETIC
174 /* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
175    when REAL_ARITHMETIC etc. are not defined.  */
176
177 /* Now see if the host and target machines use the same format. 
178    If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
179    reals as doubles because we have no better way in this cross compiler.)
180    This turns off various optimizations that can happen when we know the
181    compiler's float format matches the target's float format.
182    */
183 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
184 #define REAL_IS_NOT_DOUBLE
185 #ifndef REAL_VALUE_TYPE
186 typedef struct {
187     HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
188   } realvaluetype;
189 #define REAL_VALUE_TYPE realvaluetype
190 #endif /* no REAL_VALUE_TYPE */
191 #endif /* formats differ */
192 #endif /* 0 */
193
194 #endif /* emulator not used */
195
196 /* If we are not cross-compiling, use a `double' to represent the
197    floating-point value.  Otherwise, use some other type
198    (probably a struct containing an array of longs).  */
199 #ifndef REAL_VALUE_TYPE
200 #define REAL_VALUE_TYPE double
201 #else
202 #define REAL_IS_NOT_DOUBLE
203 #endif
204
205 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
206
207 /* Convert a type `double' value in host format first to a type `float'
208    value in host format and then to a single type `long' value which
209    is the bitwise equivalent of the `float' value.  */
210 #ifndef REAL_VALUE_TO_TARGET_SINGLE
211 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT)                            \
212 do { float f = (float) (IN);                                            \
213      (OUT) = *(long *) &f;                                              \
214    } while (0)
215 #endif
216
217 /* Convert a type `double' value in host format to a pair of type `long'
218    values which is its bitwise equivalent, but put the two words into
219    proper word order for the target.  */
220 #ifndef REAL_VALUE_TO_TARGET_DOUBLE
221 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
222 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT)                            \
223 do { REAL_VALUE_TYPE in = (IN);  /* Make sure it's not in a register.  */\
224      (OUT)[0] = ((long *) &in)[0];                                      \
225      (OUT)[1] = ((long *) &in)[1];                                      \
226    } while (0)
227 #else
228 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT)                            \
229 do { REAL_VALUE_TYPE in = (IN);  /* Make sure it's not in a register.  */\
230      (OUT)[1] = ((long *) &in)[0];                                      \
231      (OUT)[0] = ((long *) &in)[1];                                      \
232    } while (0)
233 #endif
234 #endif
235 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
236
237 /* In this configuration, double and long double are the same. */
238 #ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
239 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
240 #endif
241
242 /* Compare two floating-point values for equality.  */
243 #ifndef REAL_VALUES_EQUAL
244 #define REAL_VALUES_EQUAL(x, y) ((x) == (y))
245 #endif
246
247 /* Compare two floating-point values for less than.  */
248 #ifndef REAL_VALUES_LESS
249 #define REAL_VALUES_LESS(x, y) ((x) < (y))
250 #endif
251
252 /* Truncate toward zero to an integer floating-point value.  */
253 #ifndef REAL_VALUE_RNDZINT
254 #define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
255 #endif
256
257 /* Truncate toward zero to an unsigned integer floating-point value.  */
258 #ifndef REAL_VALUE_UNSIGNED_RNDZINT
259 #define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
260 #endif
261
262 /* Convert a floating-point value to integer, rounding toward zero.  */
263 #ifndef REAL_VALUE_FIX
264 #define REAL_VALUE_FIX(x) ((int) (x))
265 #endif
266
267 /* Convert a floating-point value to unsigned integer, rounding
268    toward zero. */
269 #ifndef REAL_VALUE_UNSIGNED_FIX
270 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
271 #endif
272
273 /* Scale X by Y powers of 2.  */
274 #ifndef REAL_VALUE_LDEXP
275 #define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
276 extern double ldexp ();
277 #endif
278
279 /* Convert the string X to a floating-point value.  */
280 #ifndef REAL_VALUE_ATOF
281 #if 1
282 /* Use real.c to convert decimal numbers to binary, ... */
283 REAL_VALUE_TYPE ereal_atof ();
284 #define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
285 #else
286 /* ... or, if you like the host computer's atof, go ahead and use it: */
287 #define REAL_VALUE_ATOF(x, s) atof (x)
288 #if defined (MIPSEL) || defined (MIPSEB)
289 /* MIPS compiler can't handle parens around the function name.
290    This problem *does not* appear to be connected with any
291    macro definition for atof.  It does not seem there is one.  */
292 extern double atof ();
293 #else
294 extern double (atof) ();
295 #endif
296 #endif
297 #endif
298
299 /* Negate the floating-point value X.  */
300 #ifndef REAL_VALUE_NEGATE
301 #define REAL_VALUE_NEGATE(x) (- (x))
302 #endif
303
304 /* Truncate the floating-point value X to mode MODE.  This is correct only
305    for the most common case where the host and target have objects of the same
306    size and where `float' is SFmode.  */
307
308 /* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate.  */
309 extern REAL_VALUE_TYPE real_value_truncate ();
310
311 #ifndef REAL_VALUE_TRUNCATE
312 #define REAL_VALUE_TRUNCATE(mode, x) \
313  (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR        \
314   ? (float) (x) : (x))
315 #endif
316
317 /* Determine whether a floating-point value X is infinite. */
318 #ifndef REAL_VALUE_ISINF
319 #define REAL_VALUE_ISINF(x) (target_isinf (x))
320 #endif
321
322 /* Determine whether a floating-point value X is a NaN. */
323 #ifndef REAL_VALUE_ISNAN
324 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
325 #endif
326
327 /* Determine whether a floating-point value X is negative. */
328 #ifndef REAL_VALUE_NEGATIVE
329 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
330 #endif
331
332 /* Determine whether a floating-point value X is minus 0. */
333 #ifndef REAL_VALUE_MINUS_ZERO
334 #define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
335 #endif
336 \f
337 /* Constant real values 0, 1, 2, and -1.  */
338
339 extern REAL_VALUE_TYPE dconst0;
340 extern REAL_VALUE_TYPE dconst1;
341 extern REAL_VALUE_TYPE dconst2;
342 extern REAL_VALUE_TYPE dconstm1;
343
344 /* Union type used for extracting real values from CONST_DOUBLEs
345    or putting them in.  */
346
347 union real_extract 
348 {
349   REAL_VALUE_TYPE d;
350   HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
351 };
352
353 /* For a CONST_DOUBLE:
354    The usual two ints that hold the value.
355    For a DImode, that is all there are;
356     and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
357    For a float, the number of ints varies,
358     and CONST_DOUBLE_LOW is the one that should come first *in memory*.
359     So use &CONST_DOUBLE_LOW(r) as the address of an array of ints.  */
360 #define CONST_DOUBLE_LOW(r) XWINT (r, 2)
361 #define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
362
363 /* Link for chain of all CONST_DOUBLEs in use in current function.  */
364 #define CONST_DOUBLE_CHAIN(r) XEXP (r, 1)
365 /* The MEM which represents this CONST_DOUBLE's value in memory,
366    or const0_rtx if no MEM has been made for it yet,
367    or cc0_rtx if it is not on the chain.  */
368 #define CONST_DOUBLE_MEM(r) XEXP (r, 0)
369
370 /* Function to return a real value (not a tree node)
371    from a given integer constant.  */
372 REAL_VALUE_TYPE real_value_from_int_cst ();
373
374 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents.  */
375
376 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from)          \
377 do { union real_extract u;                              \
378      bcopy (&CONST_DOUBLE_LOW ((from)), &u, sizeof u);  \
379      to = u.d; } while (0)
380
381 /* Return a CONST_DOUBLE with value R and mode M.  */
382
383 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r,  m)
384
385 /* Convert a floating point value `r', that can be interpreted
386    as a host machine float or double, to a decimal ASCII string `s'
387    using printf format string `fmt'.  */
388 #ifndef REAL_VALUE_TO_DECIMAL
389 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
390 #endif
391
392 #endif /* Not REAL_H_INCLUDED */