]> gcc.gnu.org Git - gcc.git/blame - gcc/real.h
(FUNCTION_PROFILER): Use $28 instead of $27.
[gcc.git] / gcc / real.h
CommitLineData
0694b47c 1/* Front-end tree definitions for GNU compiler.
fca04441 2 Copyright (C) 1989, 1991, 1994 Free Software Foundation, Inc.
0694b47c
RS
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20#ifndef REAL_H_INCLUDED
21#define REAL_H_INCLUDED
22
23/* Define codes for all the float formats that we know of. */
24#define UNKNOWN_FLOAT_FORMAT 0
25#define IEEE_FLOAT_FORMAT 1
26#define VAX_FLOAT_FORMAT 2
fd76a739 27#define IBM_FLOAT_FORMAT 3
0694b47c
RS
28
29/* Default to IEEE float if not specified. Nearly all machines use it. */
30
31#ifndef TARGET_FLOAT_FORMAT
32#define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT
33#endif
34
35#ifndef HOST_FLOAT_FORMAT
36#define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
37#endif
38
39#if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
40#define REAL_INFINITY
41#endif
42
91d61207
RK
43/* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined
44 in the header files, then this implies the word-endianness is the same as
45 for integers. */
46
47/* This is defined 0 or 1, like WORDS_BIG_ENDIAN. */
48#ifndef FLOAT_WORDS_BIG_ENDIAN
49#define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
50#endif
51
52/* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN. */
53#ifndef HOST_FLOAT_WORDS_BIG_ENDIAN
54#ifdef HOST_WORDS_BIG_ENDIAN
55#define HOST_FLOAT_WORDS_BIG_ENDIAN 1
56#else
57#define HOST_FLOAT_WORDS_BIG_ENDIAN 0
58#endif
59#endif
60
fd76a739
RS
61/* Defining REAL_ARITHMETIC invokes a floating point emulator
62 that can produce a target machine format differing by more
63 than just endian-ness from the host's format. The emulator
64 is also used to support extended real XFmode. */
65#ifndef LONG_DOUBLE_TYPE_SIZE
66#define LONG_DOUBLE_TYPE_SIZE 64
67#endif
7bb5d01e
JW
68#if (LONG_DOUBLE_TYPE_SIZE == 96) || (LONG_DOUBLE_TYPE_SIZE == 128)
69#ifndef REAL_ARITHMETIC
70#define REAL_ARITHMETIC
71#endif
72#endif
73#ifdef REAL_ARITHMETIC
fd76a739
RS
74/* **** Start of software floating point emulator interface macros **** */
75
76/* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE
77 has been defined to be 96 in the tm.h machine file. */
78#if (LONG_DOUBLE_TYPE_SIZE == 96)
79#define REAL_IS_NOT_DOUBLE
80#define REAL_ARITHMETIC
81typedef struct {
82 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
83} realvaluetype;
84#define REAL_VALUE_TYPE realvaluetype
85
86#else /* no XFmode support */
87
7bb5d01e
JW
88#if (LONG_DOUBLE_TYPE_SIZE == 128)
89
90#define REAL_IS_NOT_DOUBLE
91#define REAL_ARITHMETIC
92typedef struct {
93 HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
94} realvaluetype;
95#define REAL_VALUE_TYPE realvaluetype
96
97#else /* not TFmode */
98
fd76a739
RS
99#if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
100/* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide
101 but it is not necessarily a host machine double. */
102#define REAL_IS_NOT_DOUBLE
103typedef struct {
104 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))];
105} realvaluetype;
106#define REAL_VALUE_TYPE realvaluetype
107#else
108/* If host and target formats are compatible, then a REAL_VALUE_TYPE
109 is actually a host machine double. */
110#define REAL_VALUE_TYPE double
111#endif
7bb5d01e
JW
112
113#endif /* no TFmode support */
fd76a739
RS
114#endif /* no XFmode support */
115
84f9b8e9
RK
116extern int significand_size PROTO((enum machine_mode));
117
fd76a739 118/* If emulation has been enabled by defining REAL_ARITHMETIC or by
7bb5d01e 119 setting LONG_DOUBLE_TYPE_SIZE to 96 or 128, then define macros so that
fd76a739
RS
120 they invoke emulator functions. This will succeed only if the machine
121 files have been updated to use these macros in place of any
122 references to host machine `double' or `float' types. */
123#ifdef REAL_ARITHMETIC
124#undef REAL_ARITHMETIC
125#define REAL_ARITHMETIC(value, code, d1, d2) \
126 earith (&(value), (code), &(d1), &(d2))
127
fca04441
RK
128/* Declare functions in real.c. */
129extern void earith PROTO((REAL_VALUE_TYPE *, int,
130 REAL_VALUE_TYPE *, REAL_VALUE_TYPE *));
131extern REAL_VALUE_TYPE etrunci PROTO((REAL_VALUE_TYPE));
132extern REAL_VALUE_TYPE etruncui PROTO((REAL_VALUE_TYPE));
133extern REAL_VALUE_TYPE ereal_atof PROTO((char *, enum machine_mode));
134extern REAL_VALUE_TYPE ereal_negate PROTO((REAL_VALUE_TYPE));
135extern HOST_WIDE_INT efixi PROTO((REAL_VALUE_TYPE));
136extern unsigned HOST_WIDE_INT efixui PROTO((REAL_VALUE_TYPE));
137extern void ereal_from_int PROTO((REAL_VALUE_TYPE *,
138 HOST_WIDE_INT, HOST_WIDE_INT));
139extern void ereal_from_uint PROTO((REAL_VALUE_TYPE *,
140 unsigned HOST_WIDE_INT,
141 unsigned HOST_WIDE_INT));
142extern void ereal_to_int PROTO((HOST_WIDE_INT *, HOST_WIDE_INT *,
143 REAL_VALUE_TYPE));
144extern REAL_VALUE_TYPE ereal_ldexp PROTO((REAL_VALUE_TYPE, int));
145
146extern void etartdouble PROTO((REAL_VALUE_TYPE, long *));
147extern void etarldouble PROTO((REAL_VALUE_TYPE, long *));
148extern void etardouble PROTO((REAL_VALUE_TYPE, long *));
149extern long etarsingle PROTO((REAL_VALUE_TYPE));
150extern void ereal_to_decimal PROTO((REAL_VALUE_TYPE, char *));
151extern int ereal_cmp PROTO((REAL_VALUE_TYPE, REAL_VALUE_TYPE));
152extern int ereal_isneg PROTO((REAL_VALUE_TYPE));
403cd5d7
RK
153extern REAL_VALUE_TYPE ereal_from_float PROTO((HOST_WIDE_INT));
154extern REAL_VALUE_TYPE ereal_from_double PROTO((HOST_WIDE_INT *));
fd76a739
RS
155
156#define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
157/* true if x < y : */
265b1bae 158#define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
fd76a739
RS
159#define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
160
161/* These return REAL_VALUE_TYPE: */
162#define REAL_VALUE_RNDZINT(x) (etrunci (x))
163#define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
164extern REAL_VALUE_TYPE real_value_truncate ();
165#define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
166
91d61207 167/* These return HOST_WIDE_INT: */
7bb5d01e
JW
168/* Convert a floating-point value to integer, rounding toward zero. */
169#define REAL_VALUE_FIX(x) (efixi (x))
170/* Convert a floating-point value to unsigned integer, rounding
171 toward zero. */
172#define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
fd76a739
RS
173
174#define REAL_VALUE_ATOF ereal_atof
175#define REAL_VALUE_NEGATE ereal_negate
176
177#define REAL_VALUE_MINUS_ZERO(x) \
178 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
179
180#define REAL_VALUE_TO_INT ereal_to_int
91d61207
RK
181
182/* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */
183#define REAL_VALUE_FROM_INT(d, lo, hi) \
184 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi))
185
186#define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi) (ereal_from_uint (&d, lo, hi))
fd76a739
RS
187
188/* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
7bb5d01e 189#if LONG_DOUBLE_TYPE_SIZE == 96
fd76a739 190#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT)))
7bb5d01e
JW
191#else
192#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT)))
193#endif
fd76a739 194#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
7bb5d01e 195
fd76a739
RS
196/* IN is a REAL_VALUE_TYPE. OUT is a long. */
197#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
7bb5d01e 198
403cd5d7
RK
199/* d is an array of HOST_WIDE_INT that holds a double precision
200 value in the target computer's floating point format. */
7bb5d01e
JW
201#define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d))
202
403cd5d7 203/* f is a HOST_WIDE_INT containing a single precision target float value. */
543758c6 204#define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f))
fd76a739
RS
205
206/* Conversions to decimal ASCII string. */
207#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
208
209#endif /* REAL_ARITHMETIC defined */
210
211/* **** End of software floating point emulator interface macros **** */
7bb5d01e 212#else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */
fd76a739
RS
213
214/* old interface */
0694b47c
RS
215#ifdef REAL_ARITHMETIC
216/* Defining REAL_IS_NOT_DOUBLE breaks certain initializations
217 when REAL_ARITHMETIC etc. are not defined. */
218
219/* Now see if the host and target machines use the same format.
220 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing
221 reals as doubles because we have no better way in this cross compiler.)
222 This turns off various optimizations that can happen when we know the
223 compiler's float format matches the target's float format.
224 */
225#if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT
226#define REAL_IS_NOT_DOUBLE
227#ifndef REAL_VALUE_TYPE
fd76a739
RS
228typedef struct {
229 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)];
230 } realvaluetype;
231#define REAL_VALUE_TYPE realvaluetype
0694b47c
RS
232#endif /* no REAL_VALUE_TYPE */
233#endif /* formats differ */
234#endif /* 0 */
235
fd76a739
RS
236#endif /* emulator not used */
237
0694b47c
RS
238/* If we are not cross-compiling, use a `double' to represent the
239 floating-point value. Otherwise, use some other type
240 (probably a struct containing an array of longs). */
241#ifndef REAL_VALUE_TYPE
242#define REAL_VALUE_TYPE double
243#else
244#define REAL_IS_NOT_DOUBLE
245#endif
246
f9250555
RS
247#if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT
248
249/* Convert a type `double' value in host format first to a type `float'
250 value in host format and then to a single type `long' value which
251 is the bitwise equivalent of the `float' value. */
fd76a739 252#ifndef REAL_VALUE_TO_TARGET_SINGLE
f9250555
RS
253#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
254do { float f = (float) (IN); \
255 (OUT) = *(long *) &f; \
fd76a739
RS
256 } while (0)
257#endif
f9250555
RS
258
259/* Convert a type `double' value in host format to a pair of type `long'
260 values which is its bitwise equivalent, but put the two words into
261 proper word order for the target. */
fd76a739 262#ifndef REAL_VALUE_TO_TARGET_DOUBLE
91d61207 263#if HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN
f9250555
RS
264#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
265do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
266 (OUT)[0] = ((long *) &in)[0]; \
267 (OUT)[1] = ((long *) &in)[1]; \
268 } while (0)
269#else
270#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
271do { REAL_VALUE_TYPE in = (IN); /* Make sure it's not in a register. */\
272 (OUT)[1] = ((long *) &in)[0]; \
273 (OUT)[0] = ((long *) &in)[1]; \
274 } while (0)
275#endif
fd76a739 276#endif
f9250555
RS
277#endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */
278
fd76a739
RS
279/* In this configuration, double and long double are the same. */
280#ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE
281#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b)
282#endif
283
0694b47c
RS
284/* Compare two floating-point values for equality. */
285#ifndef REAL_VALUES_EQUAL
fd76a739 286#define REAL_VALUES_EQUAL(x, y) ((x) == (y))
0694b47c
RS
287#endif
288
289/* Compare two floating-point values for less than. */
290#ifndef REAL_VALUES_LESS
fd76a739 291#define REAL_VALUES_LESS(x, y) ((x) < (y))
0694b47c
RS
292#endif
293
fd76a739
RS
294/* Truncate toward zero to an integer floating-point value. */
295#ifndef REAL_VALUE_RNDZINT
296#define REAL_VALUE_RNDZINT(x) ((double) ((int) (x)))
0694b47c
RS
297#endif
298
fd76a739
RS
299/* Truncate toward zero to an unsigned integer floating-point value. */
300#ifndef REAL_VALUE_UNSIGNED_RNDZINT
301#define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x)))
0694b47c
RS
302#endif
303
7bb5d01e 304/* Convert a floating-point value to integer, rounding toward zero. */
0694b47c
RS
305#ifndef REAL_VALUE_FIX
306#define REAL_VALUE_FIX(x) ((int) (x))
307#endif
308
7bb5d01e
JW
309/* Convert a floating-point value to unsigned integer, rounding
310 toward zero. */
0694b47c
RS
311#ifndef REAL_VALUE_UNSIGNED_FIX
312#define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x))
313#endif
314
315/* Scale X by Y powers of 2. */
316#ifndef REAL_VALUE_LDEXP
fd76a739 317#define REAL_VALUE_LDEXP(x, y) ldexp (x, y)
0694b47c
RS
318extern double ldexp ();
319#endif
320
321/* Convert the string X to a floating-point value. */
322#ifndef REAL_VALUE_ATOF
fd76a739
RS
323#if 1
324/* Use real.c to convert decimal numbers to binary, ... */
325REAL_VALUE_TYPE ereal_atof ();
326#define REAL_VALUE_ATOF(x, s) ereal_atof (x, s)
327#else
328/* ... or, if you like the host computer's atof, go ahead and use it: */
329#define REAL_VALUE_ATOF(x, s) atof (x)
0694b47c
RS
330#if defined (MIPSEL) || defined (MIPSEB)
331/* MIPS compiler can't handle parens around the function name.
332 This problem *does not* appear to be connected with any
333 macro definition for atof. It does not seem there is one. */
334extern double atof ();
335#else
336extern double (atof) ();
337#endif
338#endif
fd76a739 339#endif
0694b47c
RS
340
341/* Negate the floating-point value X. */
342#ifndef REAL_VALUE_NEGATE
343#define REAL_VALUE_NEGATE(x) (- (x))
344#endif
345
346/* Truncate the floating-point value X to mode MODE. This is correct only
347 for the most common case where the host and target have objects of the same
348 size and where `float' is SFmode. */
349
5352b11a
RS
350/* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */
351extern REAL_VALUE_TYPE real_value_truncate ();
352
0694b47c
RS
353#ifndef REAL_VALUE_TRUNCATE
354#define REAL_VALUE_TRUNCATE(mode, x) \
161ca48c
RS
355 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \
356 ? (float) (x) : (x))
0694b47c
RS
357#endif
358
359/* Determine whether a floating-point value X is infinite. */
360#ifndef REAL_VALUE_ISINF
361#define REAL_VALUE_ISINF(x) (target_isinf (x))
362#endif
363
3dd4b517
TW
364/* Determine whether a floating-point value X is a NaN. */
365#ifndef REAL_VALUE_ISNAN
366#define REAL_VALUE_ISNAN(x) (target_isnan (x))
367#endif
368
11030a60
RS
369/* Determine whether a floating-point value X is negative. */
370#ifndef REAL_VALUE_NEGATIVE
371#define REAL_VALUE_NEGATIVE(x) (target_negative (x))
372#endif
373
0694b47c
RS
374/* Determine whether a floating-point value X is minus 0. */
375#ifndef REAL_VALUE_MINUS_ZERO
11030a60 376#define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x))
0694b47c
RS
377#endif
378\f
379/* Constant real values 0, 1, 2, and -1. */
380
381extern REAL_VALUE_TYPE dconst0;
382extern REAL_VALUE_TYPE dconst1;
383extern REAL_VALUE_TYPE dconst2;
384extern REAL_VALUE_TYPE dconstm1;
385
386/* Union type used for extracting real values from CONST_DOUBLEs
387 or putting them in. */
388
389union real_extract
390{
391 REAL_VALUE_TYPE d;
3245eea0 392 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)];
0694b47c
RS
393};
394
395/* For a CONST_DOUBLE:
396 The usual two ints that hold the value.
397 For a DImode, that is all there are;
398 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order.
399 For a float, the number of ints varies,
400 and CONST_DOUBLE_LOW is the one that should come first *in memory*.
401 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */
3245eea0
CH
402#define CONST_DOUBLE_LOW(r) XWINT (r, 2)
403#define CONST_DOUBLE_HIGH(r) XWINT (r, 3)
0694b47c
RS
404
405/* Link for chain of all CONST_DOUBLEs in use in current function. */
406#define CONST_DOUBLE_CHAIN(r) XEXP (r, 1)
407/* The MEM which represents this CONST_DOUBLE's value in memory,
408 or const0_rtx if no MEM has been made for it yet,
409 or cc0_rtx if it is not on the chain. */
410#define CONST_DOUBLE_MEM(r) XEXP (r, 0)
411
412/* Function to return a real value (not a tree node)
413 from a given integer constant. */
414REAL_VALUE_TYPE real_value_from_int_cst ();
415
416/* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
417
418#define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
419do { union real_extract u; \
4c9a05bc 420 bcopy ((char *) &CONST_DOUBLE_LOW ((from)), (char *) &u, sizeof u); \
0694b47c
RS
421 to = u.d; } while (0)
422
423/* Return a CONST_DOUBLE with value R and mode M. */
424
fd76a739 425#define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
fca04441
RK
426extern struct rtx_def *immed_real_const_1 PROTO((REAL_VALUE_TYPE,
427 enum machine_mode));
428
fd76a739
RS
429
430/* Convert a floating point value `r', that can be interpreted
431 as a host machine float or double, to a decimal ASCII string `s'
432 using printf format string `fmt'. */
433#ifndef REAL_VALUE_TO_DECIMAL
434#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r))
435#endif
0694b47c
RS
436
437#endif /* Not REAL_H_INCLUDED */
This page took 0.299246 seconds and 5 git commands to generate.