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