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