1 /* Definitions of floating-point access for GNU compiler.
2 Copyright (C) 1989, 1991, 1994, 1996, 1997 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
29 #define C4X_FLOAT_FORMAT 4
31 /* Default to IEEE float if not specified. Nearly all machines use it. */
33 #ifndef TARGET_FLOAT_FORMAT
34 #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
37 #ifndef HOST_FLOAT_FORMAT
38 #define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
41 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
45 /* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined
46 in the header files, then this implies the word-endianness is the same as
49 /* This is defined 0 or 1, like WORDS_BIG_ENDIAN. */
50 #ifndef FLOAT_WORDS_BIG_ENDIAN
51 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
54 /* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN. */
55 #ifndef HOST_FLOAT_WORDS_BIG_ENDIAN
56 #ifdef HOST_WORDS_BIG_ENDIAN
57 #define HOST_FLOAT_WORDS_BIG_ENDIAN 1
59 #define HOST_FLOAT_WORDS_BIG_ENDIAN 0
63 /* Defining REAL_ARITHMETIC invokes a floating point emulator
64 that can produce a target machine format differing by more
65 than just endian-ness from the host's format. The emulator
66 is also used to support extended real XFmode. */
67 #ifndef LONG_DOUBLE_TYPE_SIZE
68 #define LONG_DOUBLE_TYPE_SIZE 64
70 #if (LONG_DOUBLE_TYPE_SIZE == 96) || (LONG_DOUBLE_TYPE_SIZE == 128)
71 #ifndef REAL_ARITHMETIC
72 #define REAL_ARITHMETIC
75 #ifdef REAL_ARITHMETIC
76 /* **** Start of software floating point emulator interface macros **** */
78 /* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
79 has been defined to be 96 in the tm.h machine file. */
80 #if (LONG_DOUBLE_TYPE_SIZE == 96)
81 #define REAL_IS_NOT_DOUBLE
82 #define REAL_ARITHMETIC
84 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
86 #define REAL_VALUE_TYPE realvaluetype
88 #else /* no XFmode support */
90 #if (LONG_DOUBLE_TYPE_SIZE == 128)
92 #define REAL_IS_NOT_DOUBLE
93 #define REAL_ARITHMETIC
95 HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
97 #define REAL_VALUE_TYPE realvaluetype
99 #else /* not TFmode */
101 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
102 /* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
103 but it is not necessarily a host machine double. */
104 #define REAL_IS_NOT_DOUBLE
106 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
108 #define REAL_VALUE_TYPE realvaluetype
110 /* If host and target formats are compatible, then a REAL_VALUE_TYPE
111 is actually a host machine double. */
112 #define REAL_VALUE_TYPE double
115 #endif /* no TFmode support */
116 #endif /* no XFmode support */
118 extern int significand_size PROTO((enum machine_mode));
120 /* If emulation has been enabled by defining REAL_ARITHMETIC or by
121 setting LONG_DOUBLE_TYPE_SIZE to 96 or 128, then define macros so that
122 they invoke emulator functions. This will succeed only if the machine
123 files have been updated to use these macros in place of any
124 references to host machine `double' or `float' types. */
125 #ifdef REAL_ARITHMETIC
126 #undef REAL_ARITHMETIC
127 #define REAL_ARITHMETIC(value, code, d1, d2) \
128 earith (&(value), (code), &(d1), &(d2))
130 /* Declare functions in real.c. */
131 extern void earith PROTO((REAL_VALUE_TYPE *, int,
132 REAL_VALUE_TYPE *, REAL_VALUE_TYPE *));
133 extern REAL_VALUE_TYPE etrunci PROTO((REAL_VALUE_TYPE));
134 extern REAL_VALUE_TYPE etruncui PROTO((REAL_VALUE_TYPE));
135 extern REAL_VALUE_TYPE ereal_atof PROTO((char *, enum machine_mode));
136 extern REAL_VALUE_TYPE ereal_negate PROTO((REAL_VALUE_TYPE));
137 extern HOST_WIDE_INT efixi PROTO((REAL_VALUE_TYPE));
138 extern unsigned HOST_WIDE_INT efixui PROTO((REAL_VALUE_TYPE));
139 extern void ereal_from_int PROTO((REAL_VALUE_TYPE *,
140 HOST_WIDE_INT, HOST_WIDE_INT,
142 extern void ereal_from_uint PROTO((REAL_VALUE_TYPE *,
143 unsigned HOST_WIDE_INT,
144 unsigned HOST_WIDE_INT,
146 extern void ereal_to_int PROTO((HOST_WIDE_INT *, HOST_WIDE_INT *,
148 extern REAL_VALUE_TYPE ereal_ldexp PROTO((REAL_VALUE_TYPE, int));
150 extern void etartdouble PROTO((REAL_VALUE_TYPE, long *));
151 extern void etarldouble PROTO((REAL_VALUE_TYPE, long *));
152 extern void etardouble PROTO((REAL_VALUE_TYPE, long *));
153 extern long etarsingle PROTO((REAL_VALUE_TYPE));
154 extern void ereal_to_decimal PROTO((REAL_VALUE_TYPE, char *));
155 extern int ereal_cmp PROTO((REAL_VALUE_TYPE, REAL_VALUE_TYPE));
156 extern int ereal_isneg PROTO((REAL_VALUE_TYPE));
157 extern REAL_VALUE_TYPE ereal_unto_float PROTO((long));
158 extern REAL_VALUE_TYPE ereal_unto_double PROTO((long *));
159 extern REAL_VALUE_TYPE ereal_from_float PROTO((HOST_WIDE_INT));
160 extern REAL_VALUE_TYPE ereal_from_double PROTO((HOST_WIDE_INT *));
162 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
163 /* true if x < y : */
164 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
165 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
167 /* These return REAL_VALUE_TYPE: */
168 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
169 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
170 extern REAL_VALUE_TYPE real_value_truncate PROTO ((enum machine_mode,
172 #define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
174 /* These return HOST_WIDE_INT: */
175 /* Convert a floating-point value to integer, rounding toward zero. */
176 #define REAL_VALUE_FIX(x) (efixi (x))
177 /* Convert a floating-point value to unsigned integer, rounding
179 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
181 #define REAL_VALUE_ATOF ereal_atof
182 #define REAL_VALUE_NEGATE ereal_negate
184 #define REAL_VALUE_MINUS_ZERO(x) \
185 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
187 #define REAL_VALUE_TO_INT ereal_to_int
189 /* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */
190 #define REAL_VALUE_FROM_INT(d, lo, hi, mode) \
191 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode)
193 #define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \
194 ereal_from_uint (&d, lo, hi, mode)
196 /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
197 #if LONG_DOUBLE_TYPE_SIZE == 96
198 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
200 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT)))
202 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
204 /* IN is a REAL_VALUE_TYPE. OUT is a long. */
205 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
207 /* Inverse of REAL_VALUE_TO_TARGET_DOUBLE. */
208 #define REAL_VALUE_UNTO_TARGET_DOUBLE(d) (ereal_unto_double (d))
210 /* Inverse of REAL_VALUE_TO_TARGET_SINGLE. */
211 #define REAL_VALUE_UNTO_TARGET_SINGLE(f) (ereal_unto_float (f))
213 /* d is an array of HOST_WIDE_INT that holds a double precision
214 value in the target computer's floating point format. */
215 #define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d))
217 /* f is a HOST_WIDE_INT containing a single precision target float value. */
218 #define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f))
220 /* Conversions to decimal ASCII string. */
221 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
223 #endif /* REAL_ARITHMETIC defined */
225 /* **** End of software floating point emulator interface macros **** */
226 #else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */
229 #ifdef REAL_ARITHMETIC
230 /* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
231 when REAL_ARITHMETIC etc. are not defined. */
233 /* Now see if the host and target machines use the same format.
234 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
235 reals as doubles because we have no better way in this cross compiler.)
236 This turns off various optimizations that can happen when we know the
237 compiler's float format matches the target's float format.
239 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
240 #define REAL_IS_NOT_DOUBLE
241 #ifndef REAL_VALUE_TYPE
243 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
245 #define REAL_VALUE_TYPE realvaluetype
246 #endif /* no REAL_VALUE_TYPE */
247 #endif /* formats differ */
250 #endif /* emulator not used */
252 /* If we are not cross-compiling, use a `double' to represent the
253 floating-point value. Otherwise, use some other type
254 (probably a struct containing an array of longs). */
255 #ifndef REAL_VALUE_TYPE
256 #define REAL_VALUE_TYPE double
258 #define REAL_IS_NOT_DOUBLE
261 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
263 /* Convert a type `double' value in host format first to a type `float'
264 value in host format and then to a single type `long' value which
265 is the bitwise equivalent of the `float' value. */
266 #ifndef REAL_VALUE_TO_TARGET_SINGLE
267 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
273 if (sizeof(HOST_WIDE_INT) < sizeof(float)) \
281 /* Convert a type `double' value in host format to a pair of type `long'
282 values which is its bitwise equivalent, but put the two words into
283 proper word order for the target. */
284 #ifndef REAL_VALUE_TO_TARGET_DOUBLE
285 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
289 HOST_WIDE_INT l[2]; \
291 if (sizeof(HOST_WIDE_INT) * 2 < sizeof(REAL_VALUE_TYPE)) \
293 u.l[0] = u.l[1] = 0; \
295 if (HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN) \
296 (OUT)[0] = u.l[0], (OUT)[1] = u.l[1]; \
298 (OUT)[1] = u.l[0], (OUT)[0] = u.l[1]; \
301 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
303 /* In this configuration, double and long double are the same. */
304 #ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
305 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
308 /* Compare two floating-point objects for bitwise identity.
309 This is not the same as comparing for equality on IEEE hosts:
310 -0.0 equals 0.0 but they are not identical, and conversely
311 two NaNs might be identical but they cannot be equal. */
312 #define REAL_VALUES_IDENTICAL(x, y) \
313 (!bcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE)))
315 /* Compare two floating-point values for equality. */
316 #ifndef REAL_VALUES_EQUAL
317 #define REAL_VALUES_EQUAL(x, y) ((x) == (y))
320 /* Compare two floating-point values for less than. */
321 #ifndef REAL_VALUES_LESS
322 #define REAL_VALUES_LESS(x, y) ((x) < (y))
325 /* Truncate toward zero to an integer floating-point value. */
326 #ifndef REAL_VALUE_RNDZINT
327 #define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
330 /* Truncate toward zero to an unsigned integer floating-point value. */
331 #ifndef REAL_VALUE_UNSIGNED_RNDZINT
332 #define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
335 /* Convert a floating-point value to integer, rounding toward zero. */
336 #ifndef REAL_VALUE_FIX
337 #define REAL_VALUE_FIX(x) ((int) (x))
340 /* Convert a floating-point value to unsigned integer, rounding
342 #ifndef REAL_VALUE_UNSIGNED_FIX
343 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
346 /* Scale X by Y powers of 2. */
347 #ifndef REAL_VALUE_LDEXP
348 #define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
349 extern double ldexp ();
352 /* Convert the string X to a floating-point value. */
353 #ifndef REAL_VALUE_ATOF
355 /* Use real.c to convert decimal numbers to binary, ... */
356 REAL_VALUE_TYPE ereal_atof ();
357 #define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
359 /* ... or, if you like the host computer's atof, go ahead and use it: */
360 #define REAL_VALUE_ATOF(x, s) atof (x)
361 #if defined (MIPSEL) || defined (MIPSEB)
362 /* MIPS compiler can't handle parens around the function name.
363 This problem *does not* appear to be connected with any
364 macro definition for atof. It does not seem there is one. */
365 extern double atof ();
367 extern double (atof) ();
372 /* Negate the floating-point value X. */
373 #ifndef REAL_VALUE_NEGATE
374 #define REAL_VALUE_NEGATE(x) (- (x))
377 /* Truncate the floating-point value X to mode MODE. This is correct only
378 for the most common case where the host and target have objects of the same
379 size and where `float' is SFmode. */
381 /* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
382 extern REAL_VALUE_TYPE real_value_truncate PROTO((enum machine_mode, REAL_VALUE_TYPE));
384 #ifndef REAL_VALUE_TRUNCATE
385 #define REAL_VALUE_TRUNCATE(mode, x) \
386 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
390 /* Determine whether a floating-point value X is infinite. */
391 #ifndef REAL_VALUE_ISINF
392 #define REAL_VALUE_ISINF(x) (target_isinf (x))
395 /* Determine whether a floating-point value X is a NaN. */
396 #ifndef REAL_VALUE_ISNAN
397 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
400 /* Determine whether a floating-point value X is negative. */
401 #ifndef REAL_VALUE_NEGATIVE
402 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
405 extern int target_isnan PROTO ((REAL_VALUE_TYPE));
406 extern int target_isinf PROTO ((REAL_VALUE_TYPE));
407 extern int target_negative PROTO ((REAL_VALUE_TYPE));
409 /* Determine whether a floating-point value X is minus 0. */
410 #ifndef REAL_VALUE_MINUS_ZERO
411 #define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
414 /* Constant real values 0, 1, 2, and -1. */
416 extern REAL_VALUE_TYPE dconst0;
417 extern REAL_VALUE_TYPE dconst1;
418 extern REAL_VALUE_TYPE dconst2;
419 extern REAL_VALUE_TYPE dconstm1;
421 /* Union type used for extracting real values from CONST_DOUBLEs
422 or putting them in. */
427 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
430 /* For a CONST_DOUBLE:
431 The usual two ints that hold the value.
432 For a DImode, that is all there are;
433 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
434 For a float, the number of ints varies,
435 and CONST_DOUBLE_LOW is the one that should come first *in memory*.
436 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */
437 #define CONST_DOUBLE_LOW(r) XWINT (r, 2)
438 #define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
440 /* Link for chain of all CONST_DOUBLEs in use in current function. */
441 #define CONST_DOUBLE_CHAIN(r) XEXP (r, 1)
442 /* The MEM which represents this CONST_DOUBLE's value in memory,
443 or const0_rtx if no MEM has been made for it yet,
444 or cc0_rtx if it is not on the chain. */
445 #define CONST_DOUBLE_MEM(r) XEXP (r, 0)
447 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
448 /* Function to return a real value (not a tree node)
449 from a given integer constant. */
451 REAL_VALUE_TYPE real_value_from_int_cst PROTO ((union tree_node *,
454 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
455 do { union real_extract u; \
456 bcopy ((char *) &CONST_DOUBLE_LOW ((from)), (char *) &u, sizeof u); \
457 to = u.d; } while (0)
459 /* Return a CONST_DOUBLE with value R and mode M. */
461 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
462 extern struct rtx_def *immed_real_const_1 PROTO((REAL_VALUE_TYPE,
466 /* Convert a floating point value `r', that can be interpreted
467 as a host machine float or double, to a decimal ASCII string `s'
468 using printf format string `fmt'. */
469 #ifndef REAL_VALUE_TO_DECIMAL
470 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
473 /* Replace R by 1/R in the given machine mode, if the result is exact. */
474 extern int exact_real_inverse PROTO((enum machine_mode, REAL_VALUE_TYPE *));
476 extern void debug_real PROTO ((REAL_VALUE_TYPE));
479 extern void assemble_real PROTO ((REAL_VALUE_TYPE,
481 #endif /* Not REAL_H_INCLUDED */