Undo June 11th change
[official-gcc.git] / gcc / real.h
blob848ef184f2f72fc53dc1b66a1d307761da7f8241
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)
9 any later version.
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
35 #endif
37 #ifndef HOST_FLOAT_FORMAT
38 #define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
39 #endif
41 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
42 #define REAL_INFINITY
43 #endif
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
47 for integers. */
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
52 #endif
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
58 #else
59 #define HOST_FLOAT_WORDS_BIG_ENDIAN 0
60 #endif
61 #endif
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
69 #endif
70 #if (LONG_DOUBLE_TYPE_SIZE == 96) || (LONG_DOUBLE_TYPE_SIZE == 128)
71 #ifndef REAL_ARITHMETIC
72 #define REAL_ARITHMETIC
73 #endif
74 #endif
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
83 typedef struct {
84 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
85 } realvaluetype;
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
94 typedef struct {
95 HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
96 } realvaluetype;
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
105 typedef struct {
106 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
107 } realvaluetype;
108 #define REAL_VALUE_TYPE realvaluetype
109 #else
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
113 #endif
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,
141 enum machine_mode));
142 extern void ereal_from_uint PROTO((REAL_VALUE_TYPE *,
143 unsigned HOST_WIDE_INT,
144 unsigned HOST_WIDE_INT,
145 enum machine_mode));
146 extern void ereal_to_int PROTO((HOST_WIDE_INT *, HOST_WIDE_INT *,
147 REAL_VALUE_TYPE));
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,
171 REAL_VALUE_TYPE));
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
178 toward zero. */
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)))
199 #else
200 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT)))
201 #endif
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 */
228 /* old interface */
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
242 typedef struct {
243 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
244 } realvaluetype;
245 #define REAL_VALUE_TYPE realvaluetype
246 #endif /* no REAL_VALUE_TYPE */
247 #endif /* formats differ */
248 #endif /* 0 */
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
257 #else
258 #define REAL_IS_NOT_DOUBLE
259 #endif
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) \
268 do { float f = (float) (IN); \
269 (OUT) = *(long *) &f; \
270 } while (0)
271 #endif
273 /* Convert a type `double' value in host format to a pair of type `long'
274 values which is its bitwise equivalent, but put the two words into
275 proper word order for the target. */
276 #ifndef REAL_VALUE_TO_TARGET_DOUBLE
277 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
278 do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
279 if (HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN) \
281 (OUT)[0] = ((long *) &in)[0]; \
282 (OUT)[1] = ((long *) &in)[1]; \
284 else \
286 (OUT)[1] = ((long *) &in)[0]; \
287 (OUT)[0] = ((long *) &in)[1]; \
289 } while (0)
290 #endif
291 #endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
293 /* In this configuration, double and long double are the same. */
294 #ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
295 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
296 #endif
298 /* Compare two floating-point objects for bitwise identity.
299 This is not the same as comparing for equality on IEEE hosts:
300 -0.0 equals 0.0 but they are not identical, and conversely
301 two NaNs might be identical but they cannot be equal. */
302 #define REAL_VALUES_IDENTICAL(x, y) \
303 (!bcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE)))
305 /* Compare two floating-point values for equality. */
306 #ifndef REAL_VALUES_EQUAL
307 #define REAL_VALUES_EQUAL(x, y) ((x) == (y))
308 #endif
310 /* Compare two floating-point values for less than. */
311 #ifndef REAL_VALUES_LESS
312 #define REAL_VALUES_LESS(x, y) ((x) < (y))
313 #endif
315 /* Truncate toward zero to an integer floating-point value. */
316 #ifndef REAL_VALUE_RNDZINT
317 #define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
318 #endif
320 /* Truncate toward zero to an unsigned integer floating-point value. */
321 #ifndef REAL_VALUE_UNSIGNED_RNDZINT
322 #define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
323 #endif
325 /* Convert a floating-point value to integer, rounding toward zero. */
326 #ifndef REAL_VALUE_FIX
327 #define REAL_VALUE_FIX(x) ((int) (x))
328 #endif
330 /* Convert a floating-point value to unsigned integer, rounding
331 toward zero. */
332 #ifndef REAL_VALUE_UNSIGNED_FIX
333 #define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
334 #endif
336 /* Scale X by Y powers of 2. */
337 #ifndef REAL_VALUE_LDEXP
338 #define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
339 extern double ldexp ();
340 #endif
342 /* Convert the string X to a floating-point value. */
343 #ifndef REAL_VALUE_ATOF
344 #if 1
345 /* Use real.c to convert decimal numbers to binary, ... */
346 REAL_VALUE_TYPE ereal_atof ();
347 #define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
348 #else
349 /* ... or, if you like the host computer's atof, go ahead and use it: */
350 #define REAL_VALUE_ATOF(x, s) atof (x)
351 #if defined (MIPSEL) || defined (MIPSEB)
352 /* MIPS compiler can't handle parens around the function name.
353 This problem *does not* appear to be connected with any
354 macro definition for atof. It does not seem there is one. */
355 extern double atof ();
356 #else
357 extern double (atof) ();
358 #endif
359 #endif
360 #endif
362 /* Negate the floating-point value X. */
363 #ifndef REAL_VALUE_NEGATE
364 #define REAL_VALUE_NEGATE(x) (- (x))
365 #endif
367 /* Truncate the floating-point value X to mode MODE. This is correct only
368 for the most common case where the host and target have objects of the same
369 size and where `float' is SFmode. */
371 /* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
372 extern REAL_VALUE_TYPE real_value_truncate PROTO((enum machine_mode, REAL_VALUE_TYPE));
374 #ifndef REAL_VALUE_TRUNCATE
375 #define REAL_VALUE_TRUNCATE(mode, x) \
376 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
377 ? (float) (x) : (x))
378 #endif
380 /* Determine whether a floating-point value X is infinite. */
381 #ifndef REAL_VALUE_ISINF
382 #define REAL_VALUE_ISINF(x) (target_isinf (x))
383 #endif
385 /* Determine whether a floating-point value X is a NaN. */
386 #ifndef REAL_VALUE_ISNAN
387 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
388 #endif
390 /* Determine whether a floating-point value X is negative. */
391 #ifndef REAL_VALUE_NEGATIVE
392 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
393 #endif
395 extern int target_isnan PROTO ((REAL_VALUE_TYPE));
396 extern int target_isinf PROTO ((REAL_VALUE_TYPE));
397 extern int target_negative PROTO ((REAL_VALUE_TYPE));
399 /* Determine whether a floating-point value X is minus 0. */
400 #ifndef REAL_VALUE_MINUS_ZERO
401 #define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
402 #endif
404 /* Constant real values 0, 1, 2, and -1. */
406 extern REAL_VALUE_TYPE dconst0;
407 extern REAL_VALUE_TYPE dconst1;
408 extern REAL_VALUE_TYPE dconst2;
409 extern REAL_VALUE_TYPE dconstm1;
411 /* Union type used for extracting real values from CONST_DOUBLEs
412 or putting them in. */
414 union real_extract
416 REAL_VALUE_TYPE d;
417 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
420 /* For a CONST_DOUBLE:
421 The usual two ints that hold the value.
422 For a DImode, that is all there are;
423 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
424 For a float, the number of ints varies,
425 and CONST_DOUBLE_LOW is the one that should come first *in memory*.
426 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */
427 #define CONST_DOUBLE_LOW(r) XWINT (r, 2)
428 #define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
430 /* Link for chain of all CONST_DOUBLEs in use in current function. */
431 #define CONST_DOUBLE_CHAIN(r) XEXP (r, 1)
432 /* The MEM which represents this CONST_DOUBLE's value in memory,
433 or const0_rtx if no MEM has been made for it yet,
434 or cc0_rtx if it is not on the chain. */
435 #define CONST_DOUBLE_MEM(r) XEXP (r, 0)
437 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
438 /* Function to return a real value (not a tree node)
439 from a given integer constant. */
440 union tree_node;
441 REAL_VALUE_TYPE real_value_from_int_cst PROTO ((union tree_node *,
442 union tree_node *));
444 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
445 do { union real_extract u; \
446 bcopy ((char *) &CONST_DOUBLE_LOW ((from)), (char *) &u, sizeof u); \
447 to = u.d; } while (0)
449 /* Return a CONST_DOUBLE with value R and mode M. */
451 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
452 extern struct rtx_def *immed_real_const_1 PROTO((REAL_VALUE_TYPE,
453 enum machine_mode));
456 /* Convert a floating point value `r', that can be interpreted
457 as a host machine float or double, to a decimal ASCII string `s'
458 using printf format string `fmt'. */
459 #ifndef REAL_VALUE_TO_DECIMAL
460 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
461 #endif
463 /* Replace R by 1/R in the given machine mode, if the result is exact. */
464 extern int exact_real_inverse PROTO((enum machine_mode, REAL_VALUE_TYPE *));
466 extern void debug_real PROTO ((REAL_VALUE_TYPE));
468 /* In varasm.c */
469 extern void assemble_real PROTO ((REAL_VALUE_TYPE,
470 enum machine_mode));
471 #endif /* Not REAL_H_INCLUDED */