Oh GACK! src-clean doesn't quite work that easily since cleandist rebuilds the
[unix-history] / gnu / usr.bin / cc / common / real.h
CommitLineData
9bf86ebb
PR
1/* Front-end tree definitions for GNU compiler.
2 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the 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) || defined (REAL_ARITHMETIC)
51/* **** Start of software floating point emulator interface macros **** */
52
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
58typedef struct {
59 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
60} realvaluetype;
61#define REAL_VALUE_TYPE realvaluetype
62
63#else /* no XFmode support */
64
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
69typedef struct {
70 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
71} realvaluetype;
72#define REAL_VALUE_TYPE realvaluetype
73#else
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
77#endif
78#endif /* no XFmode support */
79
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))
89
90/* Declare functions in real.c that are referenced here. */
91void earith (), ereal_from_uint (), ereal_from_int (), ereal_to_int ();
92void etarldouble (), etardouble ();
93long etarsingle ();
94int ereal_cmp (), eroundi (), ereal_isneg ();
95unsigned int eroundui ();
96REAL_VALUE_TYPE etrunci (), etruncui (), ereal_ldexp (), ereal_atof ();
97REAL_VALUE_TYPE ereal_negate (), ereal_truncate ();
2a5f595d 98REAL_VALUE_TYPE ereal_from_float (), ereal_from_double ();
9bf86ebb
PR
99
100#define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
101/* true if x < y : */
102#define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
103#define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
104
105/* These return REAL_VALUE_TYPE: */
106#define REAL_VALUE_RNDZINT(x) (etrunci (x))
107#define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
108extern REAL_VALUE_TYPE real_value_truncate ();
109#define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
110
111/* These return int: */
112#define REAL_VALUE_FIX(x) (eroundi (x))
113#define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) eroundui (x))
114
115#define REAL_VALUE_ATOF ereal_atof
116#define REAL_VALUE_NEGATE ereal_negate
117
118#define REAL_VALUE_MINUS_ZERO(x) \
119 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
120
121#define REAL_VALUE_TO_INT ereal_to_int
122#define REAL_VALUE_FROM_INT(d, i, j) (ereal_from_int (&d, i, j))
123#define REAL_VALUE_FROM_UNSIGNED_INT(d, i, j) (ereal_from_uint (&d, i, j))
124
125/* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
126#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
127#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
2a5f595d
PR
128/* d is an array of longs. */
129#define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d))
9bf86ebb
PR
130/* IN is a REAL_VALUE_TYPE. OUT is a long. */
131#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
2a5f595d
PR
132/* f is a long. */
133#define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f))
9bf86ebb
PR
134
135/* Conversions to decimal ASCII string. */
136#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
137
138#endif /* REAL_ARITHMETIC defined */
139
140/* **** End of software floating point emulator interface macros **** */
141#else /* LONG_DOUBLE_TYPE_SIZE != 96 and REAL_ARITHMETIC not defined */
142
143/* old interface */
144#ifdef REAL_ARITHMETIC
145/* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
146 when REAL_ARITHMETIC etc. are not defined. */
147
148/* Now see if the host and target machines use the same format.
149 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
150 reals as doubles because we have no better way in this cross compiler.)
151 This turns off various optimizations that can happen when we know the
152 compiler's float format matches the target's float format.
153 */
154#if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
155#define REAL_IS_NOT_DOUBLE
156#ifndef REAL_VALUE_TYPE
157typedef struct {
158 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
159 } realvaluetype;
160#define REAL_VALUE_TYPE realvaluetype
161#endif /* no REAL_VALUE_TYPE */
162#endif /* formats differ */
163#endif /* 0 */
164
165#endif /* emulator not used */
166
167/* If we are not cross-compiling, use a `double' to represent the
168 floating-point value. Otherwise, use some other type
169 (probably a struct containing an array of longs). */
170#ifndef REAL_VALUE_TYPE
171#define REAL_VALUE_TYPE double
172#else
173#define REAL_IS_NOT_DOUBLE
174#endif
175
176#if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
177
178/* Convert a type `double' value in host format first to a type `float'
179 value in host format and then to a single type `long' value which
180 is the bitwise equivalent of the `float' value. */
181#ifndef REAL_VALUE_TO_TARGET_SINGLE
182#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
183do { float f = (float) (IN); \
184 (OUT) = *(long *) &f; \
185 } while (0)
186#endif
187
188/* Convert a type `double' value in host format to a pair of type `long'
189 values which is its bitwise equivalent, but put the two words into
190 proper word order for the target. */
191#ifndef REAL_VALUE_TO_TARGET_DOUBLE
192#if defined (HOST_WORDS_BIG_ENDIAN) == WORDS_BIG_ENDIAN
193#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
194do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
195 (OUT)[0] = ((long *) &in)[0]; \
196 (OUT)[1] = ((long *) &in)[1]; \
197 } while (0)
198#else
199#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
200do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
201 (OUT)[1] = ((long *) &in)[0]; \
202 (OUT)[0] = ((long *) &in)[1]; \
203 } while (0)
204#endif
205#endif
206#endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
207
208/* In this configuration, double and long double are the same. */
209#ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
210#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
211#endif
212
213/* Compare two floating-point values for equality. */
214#ifndef REAL_VALUES_EQUAL
215#define REAL_VALUES_EQUAL(x, y) ((x) == (y))
216#endif
217
218/* Compare two floating-point values for less than. */
219#ifndef REAL_VALUES_LESS
220#define REAL_VALUES_LESS(x, y) ((x) < (y))
221#endif
222
223/* Truncate toward zero to an integer floating-point value. */
224#ifndef REAL_VALUE_RNDZINT
225#define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
226#endif
227
228/* Truncate toward zero to an unsigned integer floating-point value. */
229#ifndef REAL_VALUE_UNSIGNED_RNDZINT
230#define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
231#endif
232
233/* Convert a floating-point value to integer, using any rounding mode. */
234#ifndef REAL_VALUE_FIX
235#define REAL_VALUE_FIX(x) ((int) (x))
236#endif
237
238/* Convert a floating-point value to unsigned integer, using any rounding
239 mode. */
240#ifndef REAL_VALUE_UNSIGNED_FIX
241#define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
242#endif
243
244/* Scale X by Y powers of 2. */
245#ifndef REAL_VALUE_LDEXP
246#define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
247extern double ldexp ();
248#endif
249
250/* Convert the string X to a floating-point value. */
251#ifndef REAL_VALUE_ATOF
252#if 1
253/* Use real.c to convert decimal numbers to binary, ... */
254REAL_VALUE_TYPE ereal_atof ();
255#define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
256#else
257/* ... or, if you like the host computer's atof, go ahead and use it: */
258#define REAL_VALUE_ATOF(x, s) atof (x)
259#if defined (MIPSEL) || defined (MIPSEB)
260/* MIPS compiler can't handle parens around the function name.
261 This problem *does not* appear to be connected with any
262 macro definition for atof. It does not seem there is one. */
263extern double atof ();
264#else
265extern double (atof) ();
266#endif
267#endif
268#endif
269
270/* Negate the floating-point value X. */
271#ifndef REAL_VALUE_NEGATE
272#define REAL_VALUE_NEGATE(x) (- (x))
273#endif
274
275/* Truncate the floating-point value X to mode MODE. This is correct only
276 for the most common case where the host and target have objects of the same
277 size and where `float' is SFmode. */
278
279/* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
280extern REAL_VALUE_TYPE real_value_truncate ();
281
282#ifndef REAL_VALUE_TRUNCATE
283#define REAL_VALUE_TRUNCATE(mode, x) \
284 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
285 ? (float) (x) : (x))
286#endif
287
288/* Determine whether a floating-point value X is infinite. */
289#ifndef REAL_VALUE_ISINF
290#define REAL_VALUE_ISINF(x) (target_isinf (x))
291#endif
292
293/* Determine whether a floating-point value X is a NaN. */
294#ifndef REAL_VALUE_ISNAN
295#define REAL_VALUE_ISNAN(x) (target_isnan (x))
296#endif
297
298/* Determine whether a floating-point value X is negative. */
299#ifndef REAL_VALUE_NEGATIVE
300#define REAL_VALUE_NEGATIVE(x) (target_negative (x))
301#endif
302
303/* Determine whether a floating-point value X is minus 0. */
304#ifndef REAL_VALUE_MINUS_ZERO
305#define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
306#endif
307\f
308/* Constant real values 0, 1, 2, and -1. */
309
310extern REAL_VALUE_TYPE dconst0;
311extern REAL_VALUE_TYPE dconst1;
312extern REAL_VALUE_TYPE dconst2;
313extern REAL_VALUE_TYPE dconstm1;
314
315/* Union type used for extracting real values from CONST_DOUBLEs
316 or putting them in. */
317
318union real_extract
319{
320 REAL_VALUE_TYPE d;
321 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
322};
323
324/* For a CONST_DOUBLE:
325 The usual two ints that hold the value.
326 For a DImode, that is all there are;
327 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
328 For a float, the number of ints varies,
329 and CONST_DOUBLE_LOW is the one that should come first *in memory*.
330 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */
331#define CONST_DOUBLE_LOW(r) XWINT (r, 2)
332#define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
333
334/* Link for chain of all CONST_DOUBLEs in use in current function. */
335#define CONST_DOUBLE_CHAIN(r) XEXP (r, 1)
336/* The MEM which represents this CONST_DOUBLE's value in memory,
337 or const0_rtx if no MEM has been made for it yet,
338 or cc0_rtx if it is not on the chain. */
339#define CONST_DOUBLE_MEM(r) XEXP (r, 0)
340
341/* Function to return a real value (not a tree node)
342 from a given integer constant. */
343REAL_VALUE_TYPE real_value_from_int_cst ();
344
345/* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
346
347#define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
348do { union real_extract u; \
349 bcopy (&CONST_DOUBLE_LOW ((from)), &u, sizeof u); \
350 to = u.d; } while (0)
351
352/* Return a CONST_DOUBLE with value R and mode M. */
353
354#define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
355
356/* Convert a floating point value `r', that can be interpreted
357 as a host machine float or double, to a decimal ASCII string `s'
358 using printf format string `fmt'. */
359#ifndef REAL_VALUE_TO_DECIMAL
360#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
361#endif
362
363#endif /* Not REAL_H_INCLUDED */