1 /* Front-end tree definitions for GNU compiler.
2 Copyright (C) 1989, 1991, 1994, 1996 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef REAL_H_INCLUDED
22 #define REAL_H_INCLUDED
24 /* Define codes for all the float formats that we know of. */
25 #define UNKNOWN_FLOAT_FORMAT 0
26 #define IEEE_FLOAT_FORMAT 1
27 #define VAX_FLOAT_FORMAT 2
28 #define IBM_FLOAT_FORMAT 3
30 /* Default to IEEE float if not specified. Nearly all machines use it. */
32 #ifndef TARGET_FLOAT_FORMAT
33 #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
36 #ifndef HOST_FLOAT_FORMAT
37 #define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
40 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
44 /* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined
45 in the header files, then this implies the word-endianness is the same as
48 /* This is defined 0 or 1, like WORDS_BIG_ENDIAN. */
49 #ifndef FLOAT_WORDS_BIG_ENDIAN
50 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
53 /* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN. */
54 #ifndef HOST_FLOAT_WORDS_BIG_ENDIAN
55 #ifdef HOST_WORDS_BIG_ENDIAN
56 #define HOST_FLOAT_WORDS_BIG_ENDIAN 1
58 #define HOST_FLOAT_WORDS_BIG_ENDIAN 0
62 /* Defining REAL_ARITHMETIC invokes a floating point emulator
63 that can produce a target machine format differing by more
64 than just endian-ness from the host's format. The emulator
65 is also used to support extended real XFmode. */
66 #ifndef LONG_DOUBLE_TYPE_SIZE
67 #define LONG_DOUBLE_TYPE_SIZE 64
69 #if (LONG_DOUBLE_TYPE_SIZE == 96) || (LONG_DOUBLE_TYPE_SIZE == 128)
70 #ifndef REAL_ARITHMETIC
71 #define REAL_ARITHMETIC
74 #ifdef REAL_ARITHMETIC
75 /* **** Start of software floating point emulator interface macros **** */
77 /* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
78 has been defined to be 96 in the tm.h machine file. */
79 #if (LONG_DOUBLE_TYPE_SIZE == 96)
80 #define REAL_IS_NOT_DOUBLE
81 #define REAL_ARITHMETIC
83 HOST_WIDE_INT r
[(11 + sizeof (HOST_WIDE_INT
))/(sizeof (HOST_WIDE_INT
))];
85 #define REAL_VALUE_TYPE realvaluetype
87 #else /* no XFmode support */
89 #if (LONG_DOUBLE_TYPE_SIZE == 128)
91 #define REAL_IS_NOT_DOUBLE
92 #define REAL_ARITHMETIC
94 HOST_WIDE_INT r
[(19 + sizeof (HOST_WIDE_INT
))/(sizeof (HOST_WIDE_INT
))];
96 #define REAL_VALUE_TYPE realvaluetype
98 #else /* not TFmode */
100 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
101 /* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
102 but it is not necessarily a host machine double. */
103 #define REAL_IS_NOT_DOUBLE
105 HOST_WIDE_INT r
[(7 + sizeof (HOST_WIDE_INT
))/(sizeof (HOST_WIDE_INT
))];
107 #define REAL_VALUE_TYPE realvaluetype
109 /* If host and target formats are compatible, then a REAL_VALUE_TYPE
110 is actually a host machine double. */
111 #define REAL_VALUE_TYPE double
114 #endif /* no TFmode support */
115 #endif /* no XFmode support */
117 extern int significand_size
PROTO((enum machine_mode
));
119 /* If emulation has been enabled by defining REAL_ARITHMETIC or by
120 setting LONG_DOUBLE_TYPE_SIZE to 96 or 128, then define macros so that
121 they invoke emulator functions. This will succeed only if the machine
122 files have been updated to use these macros in place of any
123 references to host machine `double' or `float' types. */
124 #ifdef REAL_ARITHMETIC
125 #undef REAL_ARITHMETIC
126 #define REAL_ARITHMETIC(value, code, d1, d2) \
127 earith (&(value), (code), &(d1), &(d2))
129 /* Declare functions in real.c. */
130 extern void earith
PROTO((REAL_VALUE_TYPE
*, int,
131 REAL_VALUE_TYPE
*, REAL_VALUE_TYPE
*));
132 extern REAL_VALUE_TYPE etrunci
PROTO((REAL_VALUE_TYPE
));
133 extern REAL_VALUE_TYPE etruncui
PROTO((REAL_VALUE_TYPE
));
134 extern REAL_VALUE_TYPE ereal_atof
PROTO((char *, enum machine_mode
));
135 extern REAL_VALUE_TYPE ereal_negate
PROTO((REAL_VALUE_TYPE
));
136 extern HOST_WIDE_INT efixi
PROTO((REAL_VALUE_TYPE
));
137 extern unsigned HOST_WIDE_INT efixui
PROTO((REAL_VALUE_TYPE
));
138 extern void ereal_from_int
PROTO((REAL_VALUE_TYPE
*,
139 HOST_WIDE_INT
, HOST_WIDE_INT
,
141 extern void ereal_from_uint
PROTO((REAL_VALUE_TYPE
*,
142 unsigned HOST_WIDE_INT
,
143 unsigned HOST_WIDE_INT
,
145 extern void ereal_to_int
PROTO((HOST_WIDE_INT
*, HOST_WIDE_INT
*,
147 extern REAL_VALUE_TYPE ereal_ldexp
PROTO((REAL_VALUE_TYPE
, int));
149 extern void etartdouble
PROTO((REAL_VALUE_TYPE
, long *));
150 extern void etarldouble
PROTO((REAL_VALUE_TYPE
, long *));
151 extern void etardouble
PROTO((REAL_VALUE_TYPE
, long *));
152 extern long etarsingle
PROTO((REAL_VALUE_TYPE
));
153 extern void ereal_to_decimal
PROTO((REAL_VALUE_TYPE
, char *));
154 extern int ereal_cmp
PROTO((REAL_VALUE_TYPE
, REAL_VALUE_TYPE
));
155 extern int ereal_isneg
PROTO((REAL_VALUE_TYPE
));
156 extern REAL_VALUE_TYPE ereal_from_float
PROTO((HOST_WIDE_INT
));
157 extern REAL_VALUE_TYPE ereal_from_double
PROTO((HOST_WIDE_INT
*));
159 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
160 /* true if x < y : */
161 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
162 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
164 /* These return REAL_VALUE_TYPE: */
165 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
166 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
167 extern REAL_VALUE_TYPE
real_value_truncate ();
168 #define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
170 /* These return HOST_WIDE_INT: */
171 /* Convert a floating-point value to integer, rounding toward zero. */
172 #define REAL_VALUE_FIX(x) (efixi (x))
173 /* Convert a floating-point value to unsigned integer, rounding
175 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
177 #define REAL_VALUE_ATOF ereal_atof
178 #define REAL_VALUE_NEGATE ereal_negate
180 #define REAL_VALUE_MINUS_ZERO(x) \
181 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
183 #define REAL_VALUE_TO_INT ereal_to_int
185 /* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */
186 #define REAL_VALUE_FROM_INT(d, lo, hi, mode) \
187 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode)
189 #define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \
190 ereal_from_uint (&d, lo, hi, mode)
192 /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
193 #if LONG_DOUBLE_TYPE_SIZE == 96
194 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
196 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT)))
198 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
200 /* IN is a REAL_VALUE_TYPE. OUT is a long. */
201 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
203 /* d is an array of HOST_WIDE_INT that holds a double precision
204 value in the target computer's floating point format. */
205 #define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d))
207 /* f is a HOST_WIDE_INT containing a single precision target float value. */
208 #define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f))
210 /* Conversions to decimal ASCII string. */
211 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
213 #endif /* REAL_ARITHMETIC defined */
215 /* **** End of software floating point emulator interface macros **** */
216 #else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */
219 #ifdef REAL_ARITHMETIC
220 /* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
221 when REAL_ARITHMETIC etc. are not defined. */
223 /* Now see if the host and target machines use the same format.
224 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
225 reals as doubles because we have no better way in this cross compiler.)
226 This turns off various optimizations that can happen when we know the
227 compiler's float format matches the target's float format.
229 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
230 #define REAL_IS_NOT_DOUBLE
231 #ifndef REAL_VALUE_TYPE
233 HOST_WIDE_INT r
[sizeof (double)/sizeof (HOST_WIDE_INT
)];
235 #define REAL_VALUE_TYPE realvaluetype
236 #endif /* no REAL_VALUE_TYPE */
237 #endif /* formats differ */
240 #endif /* emulator not used */
242 /* If we are not cross-compiling, use a `double' to represent the
243 floating-point value. Otherwise, use some other type
244 (probably a struct containing an array of longs). */
245 #ifndef REAL_VALUE_TYPE
246 #define REAL_VALUE_TYPE double
248 #define REAL_IS_NOT_DOUBLE
251 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
253 /* Convert a type `double' value in host format first to a type `float'
254 value in host format and then to a single type `long' value which
255 is the bitwise equivalent of the `float' value. */
256 #ifndef REAL_VALUE_TO_TARGET_SINGLE
257 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
258 do { float f = (float) (IN); \
259 (OUT) = *(long *) &f; \
263 /* Convert a type `double' value in host format to a pair of type `long'
264 values which is its bitwise equivalent, but put the two words into
265 proper word order for the target. */
266 #ifndef REAL_VALUE_TO_TARGET_DOUBLE
267 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
268 do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
269 if (HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN) \
271 (OUT)[0] = ((long *) &in)[0]; \
272 (OUT)[1] = ((long *) &in)[1]; \
276 (OUT)[1] = ((long *) &in)[0]; \
277 (OUT)[0] = ((long *) &in)[1]; \
281 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
283 /* In this configuration, double and long double are the same. */
284 #ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
285 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
288 /* Compare two floating-point values for equality. */
289 #ifndef REAL_VALUES_EQUAL
290 #define REAL_VALUES_EQUAL(x, y) ((x) == (y))
293 /* Compare two floating-point values for less than. */
294 #ifndef REAL_VALUES_LESS
295 #define REAL_VALUES_LESS(x, y) ((x) < (y))
298 /* Truncate toward zero to an integer floating-point value. */
299 #ifndef REAL_VALUE_RNDZINT
300 #define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
303 /* Truncate toward zero to an unsigned integer floating-point value. */
304 #ifndef REAL_VALUE_UNSIGNED_RNDZINT
305 #define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
308 /* Convert a floating-point value to integer, rounding toward zero. */
309 #ifndef REAL_VALUE_FIX
310 #define REAL_VALUE_FIX(x) ((int) (x))
313 /* Convert a floating-point value to unsigned integer, rounding
315 #ifndef REAL_VALUE_UNSIGNED_FIX
316 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
319 /* Scale X by Y powers of 2. */
320 #ifndef REAL_VALUE_LDEXP
321 #define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
322 extern double ldexp ();
325 /* Convert the string X to a floating-point value. */
326 #ifndef REAL_VALUE_ATOF
328 /* Use real.c to convert decimal numbers to binary, ... */
329 REAL_VALUE_TYPE
ereal_atof ();
330 #define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
332 /* ... or, if you like the host computer's atof, go ahead and use it: */
333 #define REAL_VALUE_ATOF(x, s) atof (x)
334 #if defined (MIPSEL) || defined (MIPSEB)
335 /* MIPS compiler can't handle parens around the function name.
336 This problem *does not* appear to be connected with any
337 macro definition for atof. It does not seem there is one. */
338 extern double atof ();
340 extern double (atof
) ();
345 /* Negate the floating-point value X. */
346 #ifndef REAL_VALUE_NEGATE
347 #define REAL_VALUE_NEGATE(x) (- (x))
350 /* Truncate the floating-point value X to mode MODE. This is correct only
351 for the most common case where the host and target have objects of the same
352 size and where `float' is SFmode. */
354 /* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
355 extern REAL_VALUE_TYPE
real_value_truncate ();
357 #ifndef REAL_VALUE_TRUNCATE
358 #define REAL_VALUE_TRUNCATE(mode, x) \
359 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
363 /* Determine whether a floating-point value X is infinite. */
364 #ifndef REAL_VALUE_ISINF
365 #define REAL_VALUE_ISINF(x) (target_isinf (x))
368 /* Determine whether a floating-point value X is a NaN. */
369 #ifndef REAL_VALUE_ISNAN
370 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
373 /* Determine whether a floating-point value X is negative. */
374 #ifndef REAL_VALUE_NEGATIVE
375 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
378 /* Determine whether a floating-point value X is minus 0. */
379 #ifndef REAL_VALUE_MINUS_ZERO
380 #define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
383 /* Constant real values 0, 1, 2, and -1. */
385 extern REAL_VALUE_TYPE dconst0
;
386 extern REAL_VALUE_TYPE dconst1
;
387 extern REAL_VALUE_TYPE dconst2
;
388 extern REAL_VALUE_TYPE dconstm1
;
390 /* Union type used for extracting real values from CONST_DOUBLEs
391 or putting them in. */
396 HOST_WIDE_INT i
[sizeof (REAL_VALUE_TYPE
) / sizeof (HOST_WIDE_INT
)];
399 /* For a CONST_DOUBLE:
400 The usual two ints that hold the value.
401 For a DImode, that is all there are;
402 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
403 For a float, the number of ints varies,
404 and CONST_DOUBLE_LOW is the one that should come first *in memory*.
405 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */
406 #define CONST_DOUBLE_LOW(r) XWINT (r, 2)
407 #define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
409 /* Link for chain of all CONST_DOUBLEs in use in current function. */
410 #define CONST_DOUBLE_CHAIN(r) XEXP (r, 1)
411 /* The MEM which represents this CONST_DOUBLE's value in memory,
412 or const0_rtx if no MEM has been made for it yet,
413 or cc0_rtx if it is not on the chain. */
414 #define CONST_DOUBLE_MEM(r) XEXP (r, 0)
416 /* Function to return a real value (not a tree node)
417 from a given integer constant. */
418 REAL_VALUE_TYPE
real_value_from_int_cst ();
420 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
422 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
423 do { union real_extract u; \
424 bcopy ((char *) &CONST_DOUBLE_LOW ((from)), (char *) &u, sizeof u); \
425 to = u.d; } while (0)
427 /* Return a CONST_DOUBLE with value R and mode M. */
429 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
430 extern struct rtx_def
*immed_real_const_1
PROTO((REAL_VALUE_TYPE
,
434 /* Convert a floating point value `r', that can be interpreted
435 as a host machine float or double, to a decimal ASCII string `s'
436 using printf format string `fmt'. */
437 #ifndef REAL_VALUE_TO_DECIMAL
438 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
441 /* Replace R by 1/R in the given machine mode, if the result is exact. */
442 extern int exact_real_inverse
PROTO((enum machine_mode
, REAL_VALUE_TYPE
*));
444 #endif /* Not REAL_H_INCLUDED */