* Makefile.in (rtlanal.o): Depend on $(TM_P_H).
[official-gcc.git] / gcc / real.h
blob1e4dab188e25a9dc99e13dd4c8b0fa6ca6cdba10
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 GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #ifndef GCC_REAL_H
23 #define GCC_REAL_H
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
36 #endif
38 #ifndef HOST_FLOAT_FORMAT
39 #define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
40 #endif
42 #ifndef INTEL_EXTENDED_IEEE_FORMAT
43 #define INTEL_EXTENDED_IEEE_FORMAT 0
44 #endif
46 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
47 #define REAL_INFINITY
48 #endif
50 /* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined
51 in the header files, then this implies the word-endianness is the same as
52 for integers. */
54 /* This is defined 0 or 1, like WORDS_BIG_ENDIAN. */
55 #ifndef FLOAT_WORDS_BIG_ENDIAN
56 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
57 #endif
59 /* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN. */
60 #ifndef HOST_FLOAT_WORDS_BIG_ENDIAN
61 #ifdef HOST_WORDS_BIG_ENDIAN
62 #define HOST_FLOAT_WORDS_BIG_ENDIAN 1
63 #else
64 #define HOST_FLOAT_WORDS_BIG_ENDIAN 0
65 #endif
66 #endif
68 /* Defining REAL_ARITHMETIC invokes a floating point emulator
69 that can produce a target machine format differing by more
70 than just endian-ness from the host's format. The emulator
71 is also used to support extended real XFmode. */
72 #ifndef LONG_DOUBLE_TYPE_SIZE
73 #define LONG_DOUBLE_TYPE_SIZE 64
74 #endif
75 /* MAX_LONG_DOUBLE_TYPE_SIZE is a constant tested by #if.
76 LONG_DOUBLE_TYPE_SIZE can vary at compiler run time.
77 So long as macros like REAL_VALUE_TO_TARGET_LONG_DOUBLE cannot
78 vary too, however, then XFmode and TFmode long double
79 cannot both be supported at the same time. */
80 #ifndef MAX_LONG_DOUBLE_TYPE_SIZE
81 #define MAX_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
82 #endif
83 #if (MAX_LONG_DOUBLE_TYPE_SIZE == 96) || (MAX_LONG_DOUBLE_TYPE_SIZE == 128)
84 #ifndef REAL_ARITHMETIC
85 #define REAL_ARITHMETIC
86 #endif
87 #endif
88 #ifdef REAL_ARITHMETIC
89 /* **** Start of software floating point emulator interface macros **** */
91 /* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
92 has been defined to be 96 in the tm.h machine file. */
93 #if (MAX_LONG_DOUBLE_TYPE_SIZE == 96)
94 #define REAL_IS_NOT_DOUBLE
95 #define REAL_ARITHMETIC
96 typedef struct {
97 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
98 } realvaluetype;
99 #define REAL_VALUE_TYPE realvaluetype
101 #else /* no XFmode support */
103 #if (MAX_LONG_DOUBLE_TYPE_SIZE == 128)
105 #define REAL_IS_NOT_DOUBLE
106 #define REAL_ARITHMETIC
107 typedef struct {
108 HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
109 } realvaluetype;
110 #define REAL_VALUE_TYPE realvaluetype
112 #else /* not TFmode */
114 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
115 /* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
116 but it is not necessarily a host machine double. */
117 #define REAL_IS_NOT_DOUBLE
118 typedef struct {
119 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
120 } realvaluetype;
121 #define REAL_VALUE_TYPE realvaluetype
122 #else
123 /* If host and target formats are compatible, then a REAL_VALUE_TYPE
124 is actually a host machine double. */
125 #define REAL_VALUE_TYPE double
126 #endif
128 #endif /* no TFmode support */
129 #endif /* no XFmode support */
131 extern unsigned int significand_size PARAMS ((enum machine_mode));
133 /* If emulation has been enabled by defining REAL_ARITHMETIC or by
134 setting LONG_DOUBLE_TYPE_SIZE to 96 or 128, then define macros so that
135 they invoke emulator functions. This will succeed only if the machine
136 files have been updated to use these macros in place of any
137 references to host machine `double' or `float' types. */
138 #ifdef REAL_ARITHMETIC
139 #undef REAL_ARITHMETIC
140 #define REAL_ARITHMETIC(value, code, d1, d2) \
141 earith (&(value), (code), &(d1), &(d2))
143 /* Declare functions in real.c. */
144 extern void earith PARAMS ((REAL_VALUE_TYPE *, int,
145 REAL_VALUE_TYPE *, REAL_VALUE_TYPE *));
146 extern REAL_VALUE_TYPE etrunci PARAMS ((REAL_VALUE_TYPE));
147 extern REAL_VALUE_TYPE etruncui PARAMS ((REAL_VALUE_TYPE));
148 extern REAL_VALUE_TYPE ereal_negate PARAMS ((REAL_VALUE_TYPE));
149 extern HOST_WIDE_INT efixi PARAMS ((REAL_VALUE_TYPE));
150 extern unsigned HOST_WIDE_INT efixui PARAMS ((REAL_VALUE_TYPE));
151 extern void ereal_from_int PARAMS ((REAL_VALUE_TYPE *,
152 HOST_WIDE_INT, HOST_WIDE_INT,
153 enum machine_mode));
154 extern void ereal_from_uint PARAMS ((REAL_VALUE_TYPE *,
155 unsigned HOST_WIDE_INT,
156 unsigned HOST_WIDE_INT,
157 enum machine_mode));
158 extern void ereal_to_int PARAMS ((HOST_WIDE_INT *, HOST_WIDE_INT *,
159 REAL_VALUE_TYPE));
160 extern REAL_VALUE_TYPE ereal_ldexp PARAMS ((REAL_VALUE_TYPE, int));
162 extern void etartdouble PARAMS ((REAL_VALUE_TYPE, long *));
163 extern void etarldouble PARAMS ((REAL_VALUE_TYPE, long *));
164 extern void etardouble PARAMS ((REAL_VALUE_TYPE, long *));
165 extern long etarsingle PARAMS ((REAL_VALUE_TYPE));
166 extern void ereal_to_decimal PARAMS ((REAL_VALUE_TYPE, char *));
167 extern int ereal_cmp PARAMS ((REAL_VALUE_TYPE, REAL_VALUE_TYPE));
168 extern int ereal_isneg PARAMS ((REAL_VALUE_TYPE));
169 extern REAL_VALUE_TYPE ereal_unto_float PARAMS ((long));
170 extern REAL_VALUE_TYPE ereal_unto_double PARAMS ((long *));
171 extern REAL_VALUE_TYPE ereal_from_float PARAMS ((HOST_WIDE_INT));
172 extern REAL_VALUE_TYPE ereal_from_double PARAMS ((HOST_WIDE_INT *));
174 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
175 /* true if x < y : */
176 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
177 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
179 /* These return REAL_VALUE_TYPE: */
180 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
181 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
182 #define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
184 /* These return HOST_WIDE_INT: */
185 /* Convert a floating-point value to integer, rounding toward zero. */
186 #define REAL_VALUE_FIX(x) (efixi (x))
187 /* Convert a floating-point value to unsigned integer, rounding
188 toward zero. */
189 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
191 /* Convert ASCII string S to floating point in mode M.
192 Decimal input uses ATOF. Hexadecimal uses HTOF. */
193 #define REAL_VALUE_ATOF(s,m) ereal_atof(s,m)
194 #define REAL_VALUE_HTOF(s,m) ereal_atof(s,m)
196 #define REAL_VALUE_NEGATE ereal_negate
198 #define REAL_VALUE_MINUS_ZERO(x) \
199 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
201 #define REAL_VALUE_TO_INT ereal_to_int
203 /* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */
204 #define REAL_VALUE_FROM_INT(d, lo, hi, mode) \
205 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode)
207 #define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \
208 ereal_from_uint (&d, lo, hi, mode)
210 /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
211 #if (INTEL_EXTENDED_IEEE_FORMAT != 0) && (MAX_LONG_DOUBLE_TYPE_SIZE == 128)
212 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
213 #else
214 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) \
215 (LONG_DOUBLE_TYPE_SIZE == 64 ? etardouble ((IN), (OUT)) \
216 : LONG_DOUBLE_TYPE_SIZE == 96 ? etarldouble ((IN), (OUT)) \
217 : LONG_DOUBLE_TYPE_SIZE == 128 ? etartdouble ((IN), (OUT)) \
218 : abort())
219 #endif
220 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
222 /* IN is a REAL_VALUE_TYPE. OUT is a long. */
223 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
225 /* Inverse of REAL_VALUE_TO_TARGET_DOUBLE. */
226 #define REAL_VALUE_UNTO_TARGET_DOUBLE(d) (ereal_unto_double (d))
228 /* Inverse of REAL_VALUE_TO_TARGET_SINGLE. */
229 #define REAL_VALUE_UNTO_TARGET_SINGLE(f) (ereal_unto_float (f))
231 /* d is an array of HOST_WIDE_INT that holds a double precision
232 value in the target computer's floating point format. */
233 #define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d))
235 /* f is a HOST_WIDE_INT containing a single precision target float value. */
236 #define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f))
238 /* Conversions to decimal ASCII string. */
239 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
241 #endif /* REAL_ARITHMETIC defined */
243 /* **** End of software floating point emulator interface macros **** */
244 #else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */
246 /* old interface */
247 #ifdef REAL_ARITHMETIC
248 /* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
249 when REAL_ARITHMETIC etc. are not defined. */
251 /* Now see if the host and target machines use the same format.
252 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
253 reals as doubles because we have no better way in this cross compiler.)
254 This turns off various optimizations that can happen when we know the
255 compiler's float format matches the target's float format.
257 #if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
258 #define REAL_IS_NOT_DOUBLE
259 #ifndef REAL_VALUE_TYPE
260 typedef struct {
261 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
262 } realvaluetype;
263 #define REAL_VALUE_TYPE realvaluetype
264 #endif /* no REAL_VALUE_TYPE */
265 #endif /* formats differ */
266 #endif /* 0 */
268 #endif /* emulator not used */
270 /* If we are not cross-compiling, use a `double' to represent the
271 floating-point value. Otherwise, use some other type
272 (probably a struct containing an array of longs). */
273 #ifndef REAL_VALUE_TYPE
274 #define REAL_VALUE_TYPE double
275 #else
276 #define REAL_IS_NOT_DOUBLE
277 #endif
279 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
281 /* Convert a type `double' value in host format first to a type `float'
282 value in host format and then to a single type `long' value which
283 is the bitwise equivalent of the `float' value. */
284 #ifndef REAL_VALUE_TO_TARGET_SINGLE
285 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
286 do { \
287 union { \
288 float f; \
289 HOST_WIDE_INT l; \
290 } u; \
291 if (sizeof(HOST_WIDE_INT) < sizeof(float)) \
292 abort(); \
293 u.l = 0; \
294 u.f = (IN); \
295 (OUT) = u.l; \
296 } while (0)
297 #endif
299 /* Convert a type `double' value in host format to a pair of type `long'
300 values which is its bitwise equivalent, but put the two words into
301 proper word order for the target. */
302 #ifndef REAL_VALUE_TO_TARGET_DOUBLE
303 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
304 do { \
305 union { \
306 REAL_VALUE_TYPE f; \
307 HOST_WIDE_INT l[2]; \
308 } u; \
309 if (sizeof(HOST_WIDE_INT) * 2 < sizeof(REAL_VALUE_TYPE)) \
310 abort(); \
311 u.l[0] = u.l[1] = 0; \
312 u.f = (IN); \
313 if (HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN) \
314 (OUT)[0] = u.l[0], (OUT)[1] = u.l[1]; \
315 else \
316 (OUT)[1] = u.l[0], (OUT)[0] = u.l[1]; \
317 } while (0)
318 #endif
319 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
321 /* In this configuration, double and long double are the same. */
322 #ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
323 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
324 #endif
326 /* Compare two floating-point objects for bitwise identity.
327 This is not the same as comparing for equality on IEEE hosts:
328 -0.0 equals 0.0 but they are not identical, and conversely
329 two NaNs might be identical but they cannot be equal. */
330 #define REAL_VALUES_IDENTICAL(x, y) \
331 (!memcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE)))
333 /* Compare two floating-point values for equality. */
334 #ifndef REAL_VALUES_EQUAL
335 #define REAL_VALUES_EQUAL(x, y) ((x) == (y))
336 #endif
338 /* Compare two floating-point values for less than. */
339 #ifndef REAL_VALUES_LESS
340 #define REAL_VALUES_LESS(x, y) ((x) < (y))
341 #endif
343 /* Truncate toward zero to an integer floating-point value. */
344 #ifndef REAL_VALUE_RNDZINT
345 #define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
346 #endif
348 /* Truncate toward zero to an unsigned integer floating-point value. */
349 #ifndef REAL_VALUE_UNSIGNED_RNDZINT
350 #define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
351 #endif
353 /* Convert a floating-point value to integer, rounding toward zero. */
354 #ifndef REAL_VALUE_FIX
355 #define REAL_VALUE_FIX(x) ((int) (x))
356 #endif
358 /* Convert a floating-point value to unsigned integer, rounding
359 toward zero. */
360 #ifndef REAL_VALUE_UNSIGNED_FIX
361 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
362 #endif
364 /* Scale X by Y powers of 2. */
365 #ifndef REAL_VALUE_LDEXP
366 #define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
367 extern double ldexp PARAMS ((double, int));
368 #endif
370 /* Convert the string X to a floating-point value. */
371 #ifndef REAL_VALUE_ATOF
372 #if 1
373 /* Use real.c to convert decimal numbers to binary, ... */
374 #define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
375 /* Could use ereal_atof here for hexadecimal floats too, but real_hex_to_f
376 is OK and it uses faster native fp arithmetic. */
377 /* #define REAL_VALUE_HTOF(x, s) ereal_atof (x, s) */
378 #else
379 /* ... or, if you like the host computer's atof, go ahead and use it: */
380 #define REAL_VALUE_ATOF(x, s) atof (x)
381 #if defined (MIPSEL) || defined (MIPSEB)
382 /* MIPS compiler can't handle parens around the function name.
383 This problem *does not* appear to be connected with any
384 macro definition for atof. It does not seem there is one. */
385 extern double atof ();
386 #else
387 extern double (atof) ();
388 #endif
389 #endif
390 #endif
392 /* Hexadecimal floating constant input for use with host computer's
393 fp arithmetic. */
394 #ifndef REAL_VALUE_HTOF
395 extern REAL_VALUE_TYPE real_hex_to_f PARAMS ((const char *,
396 enum machine_mode));
397 #define REAL_VALUE_HTOF(s,m) real_hex_to_f(s,m)
398 #endif
400 /* Negate the floating-point value X. */
401 #ifndef REAL_VALUE_NEGATE
402 #define REAL_VALUE_NEGATE(x) (- (x))
403 #endif
405 /* Truncate the floating-point value X to mode MODE. This is correct only
406 for the most common case where the host and target have objects of the same
407 size and where `float' is SFmode. */
409 /* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
410 extern REAL_VALUE_TYPE real_value_truncate PARAMS ((enum machine_mode,
411 REAL_VALUE_TYPE));
413 #ifndef REAL_VALUE_TRUNCATE
414 #define REAL_VALUE_TRUNCATE(mode, x) \
415 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
416 ? (float) (x) : (x))
417 #endif
419 /* Determine whether a floating-point value X is infinite. */
420 #ifndef REAL_VALUE_ISINF
421 #define REAL_VALUE_ISINF(x) (target_isinf (x))
422 #endif
424 /* Determine whether a floating-point value X is a NaN. */
425 #ifndef REAL_VALUE_ISNAN
426 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
427 #endif
429 /* Determine whether a floating-point value X is negative. */
430 #ifndef REAL_VALUE_NEGATIVE
431 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
432 #endif
434 /* Determine whether a floating-point value X is minus 0. */
435 #ifndef REAL_VALUE_MINUS_ZERO
436 #define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
437 #endif
439 /* Constant real values 0, 1, 2, and -1. */
441 extern REAL_VALUE_TYPE dconst0;
442 extern REAL_VALUE_TYPE dconst1;
443 extern REAL_VALUE_TYPE dconst2;
444 extern REAL_VALUE_TYPE dconstm1;
446 /* Union type used for extracting real values from CONST_DOUBLEs
447 or putting them in. */
449 union real_extract
451 REAL_VALUE_TYPE d;
452 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
455 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
456 /* Function to return a real value (not a tree node)
457 from a given integer constant. */
458 union tree_node;
459 REAL_VALUE_TYPE real_value_from_int_cst PARAMS ((union tree_node *,
460 union tree_node *));
462 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
463 do { union real_extract u; \
464 memcpy (&u, &CONST_DOUBLE_LOW ((from)), sizeof u); \
465 to = u.d; } while (0)
467 /* Return a CONST_DOUBLE with value R and mode M. */
469 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
470 extern struct rtx_def *immed_real_const_1 PARAMS ((REAL_VALUE_TYPE,
471 enum machine_mode));
474 /* Convert a floating point value `r', that can be interpreted
475 as a host machine float or double, to a decimal ASCII string `s'
476 using printf format string `fmt'. */
477 #ifndef REAL_VALUE_TO_DECIMAL
478 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
479 #endif
481 /* Replace R by 1/R in the given machine mode, if the result is exact. */
482 extern int exact_real_inverse PARAMS ((enum machine_mode, REAL_VALUE_TYPE *));
483 extern int target_isnan PARAMS ((REAL_VALUE_TYPE));
484 extern int target_isinf PARAMS ((REAL_VALUE_TYPE));
485 extern int target_negative PARAMS ((REAL_VALUE_TYPE));
486 extern void debug_real PARAMS ((REAL_VALUE_TYPE));
487 extern REAL_VALUE_TYPE ereal_atof PARAMS ((const char *, enum machine_mode));
489 #endif /* ! GCC_REAL_H */