1 /* Front-end tree definitions for GNU compiler.
2 Copyright (C) 1989, 1991 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #ifndef REAL_H_INCLUDED
21 #define REAL_H_INCLUDED
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
29 /* Default to IEEE float if not specified. Nearly all machines use it. */
31 #ifndef TARGET_FLOAT_FORMAT
32 #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
35 #ifndef HOST_FLOAT_FORMAT
36 #define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
39 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
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
50 #if (LONG_DOUBLE_TYPE_SIZE == 96) || defined (REAL_ARITHMETIC)
51 /* **** Start of software floating point emulator interface macros **** */
53 /* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
54 has been defined to be 96 in the tm.h machine file. */
55 #if (LONG_DOUBLE_TYPE_SIZE == 96)
56 #define REAL_IS_NOT_DOUBLE
57 #define REAL_ARITHMETIC
59 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
61 #define REAL_VALUE_TYPE realvaluetype
63 #else /* no XFmode support */
65 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
66 /* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
67 but it is not necessarily a host machine double. */
68 #define REAL_IS_NOT_DOUBLE
70 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
72 #define REAL_VALUE_TYPE realvaluetype
74 /* If host and target formats are compatible, then a REAL_VALUE_TYPE
75 is actually a host machine double. */
76 #define REAL_VALUE_TYPE double
78 #endif /* no XFmode support */
80 /* If emulation has been enabled by defining REAL_ARITHMETIC or by
81 setting LONG_DOUBLE_TYPE_SIZE to 96, then define macros so that
82 they invoke emulator functions. This will succeed only if the machine
83 files have been updated to use these macros in place of any
84 references to host machine `double' or `float' types. */
85 #ifdef REAL_ARITHMETIC
86 #undef REAL_ARITHMETIC
87 #define REAL_ARITHMETIC(value, code, d1, d2) \
88 earith (&(value), (code), &(d1), &(d2))
90 /* Declare functions in real.c that are referenced here. */
91 void earith (), ereal_from_uint (), ereal_from_int (), ereal_to_int ();
92 void etarldouble (), etardouble ();
94 int ereal_cmp (), eroundi (), ereal_isneg ();
95 unsigned int eroundui ();
96 REAL_VALUE_TYPE etrunci (), etruncui (), ereal_ldexp (), ereal_atof ();
97 REAL_VALUE_TYPE ereal_negate (), ereal_truncate ();
99 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
100 /* true if x < y : */
101 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
102 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
104 /* These return REAL_VALUE_TYPE: */
105 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
106 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
107 extern REAL_VALUE_TYPE real_value_truncate ();
108 #define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
110 /* These return int: */
111 #define REAL_VALUE_FIX(x) (eroundi (x))
112 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) eroundui (x))
114 #define REAL_VALUE_ATOF ereal_atof
115 #define REAL_VALUE_NEGATE ereal_negate
117 #define REAL_VALUE_MINUS_ZERO(x) \
118 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
120 #define REAL_VALUE_TO_INT ereal_to_int
121 #define REAL_VALUE_FROM_INT(d, i, j) (ereal_from_int (&d, i, j))
122 #define REAL_VALUE_FROM_UNSIGNED_INT(d, i, j) (ereal_from_uint (&d, i, j))
124 /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
125 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
126 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
128 /* IN is a REAL_VALUE_TYPE. OUT is a long. */
129 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
131 /* Conversions to decimal ASCII string. */
132 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
134 #endif /* REAL_ARITHMETIC defined */
136 /* **** End of software floating point emulator interface macros **** */
137 #else /* LONG_DOUBLE_TYPE_SIZE != 96 and REAL_ARITHMETIC not defined */
140 #ifdef REAL_ARITHMETIC
141 /* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
142 when REAL_ARITHMETIC etc. are not defined. */
144 /* Now see if the host and target machines use the same format.
145 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
146 reals as doubles because we have no better way in this cross compiler.)
147 This turns off various optimizations that can happen when we know the
148 compiler's float format matches the target's float format.
150 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
151 #define REAL_IS_NOT_DOUBLE
152 #ifndef REAL_VALUE_TYPE
154 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
156 #define REAL_VALUE_TYPE realvaluetype
157 #endif /* no REAL_VALUE_TYPE */
158 #endif /* formats differ */
161 #endif /* emulator not used */
163 /* If we are not cross-compiling, use a `double' to represent the
164 floating-point value. Otherwise, use some other type
165 (probably a struct containing an array of longs). */
166 #ifndef REAL_VALUE_TYPE
167 #define REAL_VALUE_TYPE double
169 #define REAL_IS_NOT_DOUBLE
172 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
174 /* Convert a type `double' value in host format first to a type `float'
175 value in host format and then to a single type `long' value which
176 is the bitwise equivalent of the `float' value. */
177 #ifndef REAL_VALUE_TO_TARGET_SINGLE
178 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
179 do { float f = (float) (IN); \
180 (OUT) = *(long *) &f; \
184 /* Convert a type `double' value in host format to a pair of type `long'
185 values which is its bitwise equivalent, but put the two words into
186 proper word order for the target. */
187 #ifndef REAL_VALUE_TO_TARGET_DOUBLE
188 #if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
189 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
190 do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
191 (OUT)[0] = ((long *) &in)[0]; \
192 (OUT)[1] = ((long *) &in)[1]; \
195 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
196 do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
197 (OUT)[1] = ((long *) &in)[0]; \
198 (OUT)[0] = ((long *) &in)[1]; \
202 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
204 /* In this configuration, double and long double are the same. */
205 #ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
206 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
209 /* Compare two floating-point values for equality. */
210 #ifndef REAL_VALUES_EQUAL
211 #define REAL_VALUES_EQUAL(x, y) ((x) == (y))
214 /* Compare two floating-point values for less than. */
215 #ifndef REAL_VALUES_LESS
216 #define REAL_VALUES_LESS(x, y) ((x) < (y))
219 /* Truncate toward zero to an integer floating-point value. */
220 #ifndef REAL_VALUE_RNDZINT
221 #define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
224 /* Truncate toward zero to an unsigned integer floating-point value. */
225 #ifndef REAL_VALUE_UNSIGNED_RNDZINT
226 #define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
229 /* Convert a floating-point value to integer, using any rounding mode. */
230 #ifndef REAL_VALUE_FIX
231 #define REAL_VALUE_FIX(x) ((int) (x))
234 /* Convert a floating-point value to unsigned integer, using any rounding
236 #ifndef REAL_VALUE_UNSIGNED_FIX
237 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
240 /* Scale X by Y powers of 2. */
241 #ifndef REAL_VALUE_LDEXP
242 #define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
243 extern double ldexp ();
246 /* Convert the string X to a floating-point value. */
247 #ifndef REAL_VALUE_ATOF
249 /* Use real.c to convert decimal numbers to binary, ... */
250 REAL_VALUE_TYPE ereal_atof ();
251 #define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
253 /* ... or, if you like the host computer's atof, go ahead and use it: */
254 #define REAL_VALUE_ATOF(x, s) atof (x)
255 #if defined (MIPSEL) || defined (MIPSEB)
256 /* MIPS compiler can't handle parens around the function name.
257 This problem *does not* appear to be connected with any
258 macro definition for atof. It does not seem there is one. */
259 extern double atof ();
261 extern double (atof) ();
266 /* Negate the floating-point value X. */
267 #ifndef REAL_VALUE_NEGATE
268 #define REAL_VALUE_NEGATE(x) (- (x))
271 /* Truncate the floating-point value X to mode MODE. This is correct only
272 for the most common case where the host and target have objects of the same
273 size and where `float' is SFmode. */
275 /* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
276 extern REAL_VALUE_TYPE real_value_truncate ();
278 #ifndef REAL_VALUE_TRUNCATE
279 #define REAL_VALUE_TRUNCATE(mode, x) \
280 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
284 /* Determine whether a floating-point value X is infinite. */
285 #ifndef REAL_VALUE_ISINF
286 #define REAL_VALUE_ISINF(x) (target_isinf (x))
289 /* Determine whether a floating-point value X is a NaN. */
290 #ifndef REAL_VALUE_ISNAN
291 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
294 /* Determine whether a floating-point value X is negative. */
295 #ifndef REAL_VALUE_NEGATIVE
296 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
299 /* Determine whether a floating-point value X is minus 0. */
300 #ifndef REAL_VALUE_MINUS_ZERO
301 #define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
304 /* Constant real values 0, 1, 2, and -1. */
306 extern REAL_VALUE_TYPE dconst0;
307 extern REAL_VALUE_TYPE dconst1;
308 extern REAL_VALUE_TYPE dconst2;
309 extern REAL_VALUE_TYPE dconstm1;
311 /* Union type used for extracting real values from CONST_DOUBLEs
312 or putting them in. */
317 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
320 /* For a CONST_DOUBLE:
321 The usual two ints that hold the value.
322 For a DImode, that is all there are;
323 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
324 For a float, the number of ints varies,
325 and CONST_DOUBLE_LOW is the one that should come first *in memory*.
326 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */
327 #define CONST_DOUBLE_LOW(r) XWINT (r, 2)
328 #define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
330 /* Link for chain of all CONST_DOUBLEs in use in current function. */
331 #define CONST_DOUBLE_CHAIN(r) XEXP (r, 1)
332 /* The MEM which represents this CONST_DOUBLE's value in memory,
333 or const0_rtx if no MEM has been made for it yet,
334 or cc0_rtx if it is not on the chain. */
335 #define CONST_DOUBLE_MEM(r) XEXP (r, 0)
337 /* Function to return a real value (not a tree node)
338 from a given integer constant. */
339 REAL_VALUE_TYPE real_value_from_int_cst ();
341 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
343 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
344 do { union real_extract u; \
345 bcopy (&CONST_DOUBLE_LOW ((from)), &u, sizeof u); \
346 to = u.d; } while (0)
348 /* Return a CONST_DOUBLE with value R and mode M. */
350 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
352 /* Convert a floating point value `r', that can be interpreted
353 as a host machine float or double, to a decimal ASCII string `s'
354 using printf format string `fmt'. */
355 #ifndef REAL_VALUE_TO_DECIMAL
356 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
359 #endif /* Not REAL_H_INCLUDED */