1 /* Definitions of floating-point access for GNU compiler.
2 Copyright (C) 1989, 1991, 1994, 1996, 1997, 1998,
3 1999, 2000 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #ifndef REAL_H_INCLUDED
23 #define REAL_H_INCLUDED
25 /* Define codes for all the float formats that we know of. */
26 #define UNKNOWN_FLOAT_FORMAT 0
27 #define IEEE_FLOAT_FORMAT 1
28 #define VAX_FLOAT_FORMAT 2
29 #define IBM_FLOAT_FORMAT 3
30 #define C4X_FLOAT_FORMAT 4
32 /* Default to IEEE float if not specified. Nearly all machines use it. */
34 #ifndef TARGET_FLOAT_FORMAT
35 #define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
38 #ifndef HOST_FLOAT_FORMAT
39 #define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
42 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
46 /* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined
47 in the header files, then this implies the word-endianness is the same as
50 /* This is defined 0 or 1, like WORDS_BIG_ENDIAN. */
51 #ifndef FLOAT_WORDS_BIG_ENDIAN
52 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
55 /* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN. */
56 #ifndef HOST_FLOAT_WORDS_BIG_ENDIAN
57 #ifdef HOST_WORDS_BIG_ENDIAN
58 #define HOST_FLOAT_WORDS_BIG_ENDIAN 1
60 #define HOST_FLOAT_WORDS_BIG_ENDIAN 0
64 /* Defining REAL_ARITHMETIC invokes a floating point emulator
65 that can produce a target machine format differing by more
66 than just endian-ness from the host's format. The emulator
67 is also used to support extended real XFmode. */
68 #ifndef LONG_DOUBLE_TYPE_SIZE
69 #define LONG_DOUBLE_TYPE_SIZE 64
71 #if (LONG_DOUBLE_TYPE_SIZE == 96) || (LONG_DOUBLE_TYPE_SIZE == 128)
72 #ifndef REAL_ARITHMETIC
73 #define REAL_ARITHMETIC
76 #ifdef REAL_ARITHMETIC
77 /* **** Start of software floating point emulator interface macros **** */
79 /* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
80 has been defined to be 96 in the tm.h machine file. */
81 #if (LONG_DOUBLE_TYPE_SIZE == 96)
82 #define REAL_IS_NOT_DOUBLE
83 #define REAL_ARITHMETIC
85 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
87 #define REAL_VALUE_TYPE realvaluetype
89 #else /* no XFmode support */
91 #if (LONG_DOUBLE_TYPE_SIZE == 128)
93 #define REAL_IS_NOT_DOUBLE
94 #define REAL_ARITHMETIC
96 HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
98 #define REAL_VALUE_TYPE realvaluetype
100 #else /* not TFmode */
102 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
103 /* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
104 but it is not necessarily a host machine double. */
105 #define REAL_IS_NOT_DOUBLE
107 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
109 #define REAL_VALUE_TYPE realvaluetype
111 /* If host and target formats are compatible, then a REAL_VALUE_TYPE
112 is actually a host machine double. */
113 #define REAL_VALUE_TYPE double
116 #endif /* no TFmode support */
117 #endif /* no XFmode support */
119 extern int significand_size PARAMS ((enum machine_mode));
121 /* If emulation has been enabled by defining REAL_ARITHMETIC or by
122 setting LONG_DOUBLE_TYPE_SIZE to 96 or 128, then define macros so that
123 they invoke emulator functions. This will succeed only if the machine
124 files have been updated to use these macros in place of any
125 references to host machine `double' or `float' types. */
126 #ifdef REAL_ARITHMETIC
127 #undef REAL_ARITHMETIC
128 #define REAL_ARITHMETIC(value, code, d1, d2) \
129 earith (&(value), (code), &(d1), &(d2))
131 /* Declare functions in real.c. */
132 extern void earith PARAMS ((REAL_VALUE_TYPE *, int,
133 REAL_VALUE_TYPE *, REAL_VALUE_TYPE *));
134 extern REAL_VALUE_TYPE etrunci PARAMS ((REAL_VALUE_TYPE));
135 extern REAL_VALUE_TYPE etruncui PARAMS ((REAL_VALUE_TYPE));
136 extern REAL_VALUE_TYPE ereal_atof PARAMS ((const char *, enum machine_mode));
137 extern REAL_VALUE_TYPE ereal_negate PARAMS ((REAL_VALUE_TYPE));
138 extern HOST_WIDE_INT efixi PARAMS ((REAL_VALUE_TYPE));
139 extern unsigned HOST_WIDE_INT efixui PARAMS ((REAL_VALUE_TYPE));
140 extern void ereal_from_int PARAMS ((REAL_VALUE_TYPE *,
141 HOST_WIDE_INT, HOST_WIDE_INT,
143 extern void ereal_from_uint PARAMS ((REAL_VALUE_TYPE *,
144 unsigned HOST_WIDE_INT,
145 unsigned HOST_WIDE_INT,
147 extern void ereal_to_int PARAMS ((HOST_WIDE_INT *, HOST_WIDE_INT *,
149 extern REAL_VALUE_TYPE ereal_ldexp PARAMS ((REAL_VALUE_TYPE, int));
151 extern void etartdouble PARAMS ((REAL_VALUE_TYPE, long *));
152 extern void etarldouble PARAMS ((REAL_VALUE_TYPE, long *));
153 extern void etardouble PARAMS ((REAL_VALUE_TYPE, long *));
154 extern long etarsingle PARAMS ((REAL_VALUE_TYPE));
155 extern void ereal_to_decimal PARAMS ((REAL_VALUE_TYPE, char *));
156 extern int ereal_cmp PARAMS ((REAL_VALUE_TYPE, REAL_VALUE_TYPE));
157 extern int ereal_isneg PARAMS ((REAL_VALUE_TYPE));
158 extern REAL_VALUE_TYPE ereal_unto_float PARAMS ((long));
159 extern REAL_VALUE_TYPE ereal_unto_double PARAMS ((long *));
160 extern REAL_VALUE_TYPE ereal_from_float PARAMS ((HOST_WIDE_INT));
161 extern REAL_VALUE_TYPE ereal_from_double PARAMS ((HOST_WIDE_INT *));
163 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
164 /* true if x < y : */
165 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
166 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
168 /* These return REAL_VALUE_TYPE: */
169 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
170 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
171 extern REAL_VALUE_TYPE real_value_truncate PARAMS ((enum machine_mode,
173 #define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
175 /* These return HOST_WIDE_INT: */
176 /* Convert a floating-point value to integer, rounding toward zero. */
177 #define REAL_VALUE_FIX(x) (efixi (x))
178 /* Convert a floating-point value to unsigned integer, rounding
180 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
182 /* Convert ASCII string S to floating point in mode M.
183 Decimal input uses ATOF. Hexadecimal uses HTOF. */
184 #define REAL_VALUE_ATOF(s,m) ereal_atof(s,m)
185 #define REAL_VALUE_HTOF(s,m) ereal_atof(s,m)
187 #define REAL_VALUE_NEGATE ereal_negate
189 #define REAL_VALUE_MINUS_ZERO(x) \
190 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
192 #define REAL_VALUE_TO_INT ereal_to_int
194 /* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */
195 #define REAL_VALUE_FROM_INT(d, lo, hi, mode) \
196 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode)
198 #define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \
199 ereal_from_uint (&d, lo, hi, mode)
201 /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
202 #if LONG_DOUBLE_TYPE_SIZE == 96
203 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
205 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT)))
207 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
209 /* IN is a REAL_VALUE_TYPE. OUT is a long. */
210 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
212 /* Inverse of REAL_VALUE_TO_TARGET_DOUBLE. */
213 #define REAL_VALUE_UNTO_TARGET_DOUBLE(d) (ereal_unto_double (d))
215 /* Inverse of REAL_VALUE_TO_TARGET_SINGLE. */
216 #define REAL_VALUE_UNTO_TARGET_SINGLE(f) (ereal_unto_float (f))
218 /* d is an array of HOST_WIDE_INT that holds a double precision
219 value in the target computer's floating point format. */
220 #define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d))
222 /* f is a HOST_WIDE_INT containing a single precision target float value. */
223 #define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f))
225 /* Conversions to decimal ASCII string. */
226 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
228 #endif /* REAL_ARITHMETIC defined */
230 /* **** End of software floating point emulator interface macros **** */
231 #else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */
234 #ifdef REAL_ARITHMETIC
235 /* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
236 when REAL_ARITHMETIC etc. are not defined. */
238 /* Now see if the host and target machines use the same format.
239 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
240 reals as doubles because we have no better way in this cross compiler.)
241 This turns off various optimizations that can happen when we know the
242 compiler's float format matches the target's float format.
244 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
245 #define REAL_IS_NOT_DOUBLE
246 #ifndef REAL_VALUE_TYPE
248 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
250 #define REAL_VALUE_TYPE realvaluetype
251 #endif /* no REAL_VALUE_TYPE */
252 #endif /* formats differ */
255 #endif /* emulator not used */
257 /* If we are not cross-compiling, use a `double' to represent the
258 floating-point value. Otherwise, use some other type
259 (probably a struct containing an array of longs). */
260 #ifndef REAL_VALUE_TYPE
261 #define REAL_VALUE_TYPE double
263 #define REAL_IS_NOT_DOUBLE
266 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
268 /* Convert a type `double' value in host format first to a type `float'
269 value in host format and then to a single type `long' value which
270 is the bitwise equivalent of the `float' value. */
271 #ifndef REAL_VALUE_TO_TARGET_SINGLE
272 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
278 if (sizeof(HOST_WIDE_INT) < sizeof(float)) \
286 /* Convert a type `double' value in host format to a pair of type `long'
287 values which is its bitwise equivalent, but put the two words into
288 proper word order for the target. */
289 #ifndef REAL_VALUE_TO_TARGET_DOUBLE
290 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
294 HOST_WIDE_INT l[2]; \
296 if (sizeof(HOST_WIDE_INT) * 2 < sizeof(REAL_VALUE_TYPE)) \
298 u.l[0] = u.l[1] = 0; \
300 if (HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN) \
301 (OUT)[0] = u.l[0], (OUT)[1] = u.l[1]; \
303 (OUT)[1] = u.l[0], (OUT)[0] = u.l[1]; \
306 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
308 /* In this configuration, double and long double are the same. */
309 #ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
310 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
313 /* Compare two floating-point objects for bitwise identity.
314 This is not the same as comparing for equality on IEEE hosts:
315 -0.0 equals 0.0 but they are not identical, and conversely
316 two NaNs might be identical but they cannot be equal. */
317 #define REAL_VALUES_IDENTICAL(x, y) \
318 (!bcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE)))
320 /* Compare two floating-point values for equality. */
321 #ifndef REAL_VALUES_EQUAL
322 #define REAL_VALUES_EQUAL(x, y) ((x) == (y))
325 /* Compare two floating-point values for less than. */
326 #ifndef REAL_VALUES_LESS
327 #define REAL_VALUES_LESS(x, y) ((x) < (y))
330 /* Truncate toward zero to an integer floating-point value. */
331 #ifndef REAL_VALUE_RNDZINT
332 #define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
335 /* Truncate toward zero to an unsigned integer floating-point value. */
336 #ifndef REAL_VALUE_UNSIGNED_RNDZINT
337 #define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
340 /* Convert a floating-point value to integer, rounding toward zero. */
341 #ifndef REAL_VALUE_FIX
342 #define REAL_VALUE_FIX(x) ((int) (x))
345 /* Convert a floating-point value to unsigned integer, rounding
347 #ifndef REAL_VALUE_UNSIGNED_FIX
348 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
351 /* Scale X by Y powers of 2. */
352 #ifndef REAL_VALUE_LDEXP
353 #define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
354 extern double ldexp ();
357 /* Convert the string X to a floating-point value. */
358 #ifndef REAL_VALUE_ATOF
360 /* Use real.c to convert decimal numbers to binary, ... */
361 extern REAL_VALUE_TYPE ereal_atof PARAMS ((const char *, enum machine_mode));
362 #define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
363 /* Could use ereal_atof here for hexadecimal floats too, but real_hex_to_f
364 is OK and it uses faster native fp arithmetic. */
365 /* #define REAL_VALUE_HTOF(x, s) ereal_atof (x, s) */
367 /* ... or, if you like the host computer's atof, go ahead and use it: */
368 #define REAL_VALUE_ATOF(x, s) atof (x)
369 #if defined (MIPSEL) || defined (MIPSEB)
370 /* MIPS compiler can't handle parens around the function name.
371 This problem *does not* appear to be connected with any
372 macro definition for atof. It does not seem there is one. */
373 extern double atof ();
375 extern double (atof) ();
380 /* Hexadecimal floating constant input for use with host computer's
382 #ifndef REAL_VALUE_HTOF
383 extern REAL_VALUE_TYPE real_hex_to_f PARAMS ((char *, enum machine_mode));
384 #define REAL_VALUE_HTOF(s,m) real_hex_to_f(s,m)
387 /* Negate the floating-point value X. */
388 #ifndef REAL_VALUE_NEGATE
389 #define REAL_VALUE_NEGATE(x) (- (x))
392 /* Truncate the floating-point value X to mode MODE. This is correct only
393 for the most common case where the host and target have objects of the same
394 size and where `float' is SFmode. */
396 /* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
397 extern REAL_VALUE_TYPE real_value_truncate PARAMS ((enum machine_mode,
400 #ifndef REAL_VALUE_TRUNCATE
401 #define REAL_VALUE_TRUNCATE(mode, x) \
402 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
406 /* Determine whether a floating-point value X is infinite. */
407 #ifndef REAL_VALUE_ISINF
408 #define REAL_VALUE_ISINF(x) (target_isinf (x))
411 /* Determine whether a floating-point value X is a NaN. */
412 #ifndef REAL_VALUE_ISNAN
413 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
416 /* Determine whether a floating-point value X is negative. */
417 #ifndef REAL_VALUE_NEGATIVE
418 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
421 extern int target_isnan PARAMS ((REAL_VALUE_TYPE));
422 extern int target_isinf PARAMS ((REAL_VALUE_TYPE));
423 extern int target_negative PARAMS ((REAL_VALUE_TYPE));
425 /* Determine whether a floating-point value X is minus 0. */
426 #ifndef REAL_VALUE_MINUS_ZERO
427 #define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
430 /* Constant real values 0, 1, 2, and -1. */
432 extern REAL_VALUE_TYPE dconst0;
433 extern REAL_VALUE_TYPE dconst1;
434 extern REAL_VALUE_TYPE dconst2;
435 extern REAL_VALUE_TYPE dconstm1;
437 /* Union type used for extracting real values from CONST_DOUBLEs
438 or putting them in. */
443 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
446 /* For a CONST_DOUBLE:
447 The usual two ints that hold the value.
448 For a DImode, that is all there are;
449 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
450 For a float, the number of ints varies,
451 and CONST_DOUBLE_LOW is the one that should come first *in memory*.
452 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */
453 #define CONST_DOUBLE_LOW(r) XWINT (r, 2)
454 #define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
456 /* Link for chain of all CONST_DOUBLEs in use in current function. */
457 #define CONST_DOUBLE_CHAIN(r) X0EXP (r, 1)
458 /* The MEM which represents this CONST_DOUBLE's value in memory,
459 or const0_rtx if no MEM has been made for it yet,
460 or cc0_rtx if it is not on the chain. */
461 #define CONST_DOUBLE_MEM(r) XEXP (r, 0)
463 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
464 /* Function to return a real value (not a tree node)
465 from a given integer constant. */
467 REAL_VALUE_TYPE real_value_from_int_cst PARAMS ((union tree_node *,
470 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
471 do { union real_extract u; \
472 bcopy ((char *) &CONST_DOUBLE_LOW ((from)), (char *) &u, sizeof u); \
473 to = u.d; } while (0)
475 /* Return a CONST_DOUBLE with value R and mode M. */
477 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
478 extern struct rtx_def *immed_real_const_1 PARAMS ((REAL_VALUE_TYPE,
482 /* Convert a floating point value `r', that can be interpreted
483 as a host machine float or double, to a decimal ASCII string `s'
484 using printf format string `fmt'. */
485 #ifndef REAL_VALUE_TO_DECIMAL
486 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
489 /* Replace R by 1/R in the given machine mode, if the result is exact. */
490 extern int exact_real_inverse PARAMS ((enum machine_mode, REAL_VALUE_TYPE *));
491 extern int target_isnan PARAMS ((REAL_VALUE_TYPE));
492 extern int target_isinf PARAMS ((REAL_VALUE_TYPE));
493 extern int target_negative PARAMS ((REAL_VALUE_TYPE));
494 extern void debug_real PARAMS ((REAL_VALUE_TYPE));
497 extern void assemble_real PARAMS ((REAL_VALUE_TYPE,
499 extern void debug_real PARAMS ((REAL_VALUE_TYPE));
502 extern void assemble_real PARAMS ((REAL_VALUE_TYPE,
504 #endif /* Not REAL_H_INCLUDED */