OSDN Git Service

* tree.h: Forward-declare struct realvaluetype.
[pf3gnuchains/gcc-fork.git] / gcc / real.h
1 /* Definitions of floating-point access for GNU compiler.
2    Copyright (C) 1989, 1991, 1994, 1996, 1997, 1998,
3    1999, 2000, 2002 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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.
11
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.
16
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.  */
21
22 #ifndef GCC_REAL_H
23 #define GCC_REAL_H
24
25 #include "machmode.h"
26
27 /* Define codes for all the float formats that we know of.  */
28 #define UNKNOWN_FLOAT_FORMAT 0
29 #define IEEE_FLOAT_FORMAT 1
30 #define VAX_FLOAT_FORMAT 2
31 #define IBM_FLOAT_FORMAT 3
32 #define C4X_FLOAT_FORMAT 4
33
34 /* Default to IEEE float if not specified.  Nearly all machines use it.  */
35
36 #ifndef TARGET_FLOAT_FORMAT
37 #define TARGET_FLOAT_FORMAT     IEEE_FLOAT_FORMAT
38 #endif
39
40 #ifndef HOST_FLOAT_FORMAT
41 #define HOST_FLOAT_FORMAT       IEEE_FLOAT_FORMAT
42 #endif
43
44 #ifndef INTEL_EXTENDED_IEEE_FORMAT
45 #define INTEL_EXTENDED_IEEE_FORMAT 0
46 #endif
47
48 /* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined
49    in the header files, then this implies the word-endianness is the same as
50    for integers.  */
51
52 /* This is defined 0 or 1, like WORDS_BIG_ENDIAN.  */
53 #ifndef FLOAT_WORDS_BIG_ENDIAN
54 #define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
55 #endif
56
57 /* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN.  */
58 #ifndef HOST_FLOAT_WORDS_BIG_ENDIAN
59 #ifdef HOST_WORDS_BIG_ENDIAN
60 #define HOST_FLOAT_WORDS_BIG_ENDIAN 1
61 #else
62 #define HOST_FLOAT_WORDS_BIG_ENDIAN 0
63 #endif
64 #endif
65
66 #ifndef LONG_DOUBLE_TYPE_SIZE
67 #define LONG_DOUBLE_TYPE_SIZE 64
68 #endif
69 /* MAX_LONG_DOUBLE_TYPE_SIZE is a constant tested by #if.
70    LONG_DOUBLE_TYPE_SIZE can vary at compiler run time.
71    So long as macros like REAL_VALUE_TO_TARGET_LONG_DOUBLE cannot
72    vary too, however, then XFmode and TFmode long double
73    cannot both be supported at the same time.  */
74 #ifndef MAX_LONG_DOUBLE_TYPE_SIZE
75 #define MAX_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
76 #endif
77
78 /* **** Start of software floating point emulator interface macros **** */
79
80 /* REAL_VALUE_TYPE is an array of the minimum number of HOST_WIDE_INTs
81    required to hold either a 96- or 160-bit extended precision floating
82    point type.  This is true even if the maximum precision floating
83    point type on the target is smaller.  */
84 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !INTEL_EXTENDED_IEEE_FORMAT
85 #define REAL_VALUE_TYPE_SIZE 160
86 #else
87 #define REAL_VALUE_TYPE_SIZE 96
88 #endif
89 #define REAL_WIDTH \
90   (REAL_VALUE_TYPE_SIZE/HOST_BITS_PER_WIDE_INT \
91    + (REAL_VALUE_TYPE_SIZE%HOST_BITS_PER_WIDE_INT ? 1 : 0)) /* round up */
92 struct realvaluetype {
93   HOST_WIDE_INT r[REAL_WIDTH];
94 };
95 /* Various headers condition prototypes on #ifdef REAL_VALUE_TYPE, so it needs
96    to be a macro.  realvaluetype cannot be a typedef as this interferes with
97    other headers declaring opaque pointers to it.  */
98 #define REAL_VALUE_TYPE struct realvaluetype
99
100 /* Calculate the format for CONST_DOUBLE.  We need as many slots as
101    are necessary to overlay a REAL_VALUE_TYPE on them.  This could be
102    as many as five (32-bit HOST_WIDE_INT, 160-bit REAL_VALUE_TYPE).
103
104    A number of places assume that there are always at least two 'w'
105    slots in a CONST_DOUBLE, so we provide them even if one would suffice.  */
106
107 #if REAL_WIDTH == 1
108 # define CONST_DOUBLE_FORMAT     "ww"
109 #else
110 # if REAL_WIDTH == 2
111 #  define CONST_DOUBLE_FORMAT    "ww"
112 # else
113 #  if REAL_WIDTH == 3
114 #   define CONST_DOUBLE_FORMAT   "www"
115 #  else
116 #   if REAL_WIDTH == 4
117 #    define CONST_DOUBLE_FORMAT  "wwww"
118 #   else
119 #    if REAL_WIDTH == 5
120 #     define CONST_DOUBLE_FORMAT "wwwww"
121 #    else
122       #error "REAL_WIDTH > 5 not supported"
123 #    endif
124 #   endif
125 #  endif
126 # endif
127 #endif
128
129 extern unsigned int significand_size    PARAMS ((enum machine_mode));
130
131 #define REAL_ARITHMETIC(value, code, d1, d2) \
132   earith (&(value), (code), &(d1), &(d2))
133
134 /* Declare functions in real.c.  */
135 extern void earith              PARAMS ((REAL_VALUE_TYPE *, int,
136                                        REAL_VALUE_TYPE *, REAL_VALUE_TYPE *));
137 extern REAL_VALUE_TYPE etrunci  PARAMS ((REAL_VALUE_TYPE));
138 extern REAL_VALUE_TYPE etruncui PARAMS ((REAL_VALUE_TYPE));
139 extern REAL_VALUE_TYPE ereal_negate PARAMS ((REAL_VALUE_TYPE));
140 extern HOST_WIDE_INT efixi      PARAMS ((REAL_VALUE_TYPE));
141 extern unsigned HOST_WIDE_INT efixui PARAMS ((REAL_VALUE_TYPE));
142 extern void ereal_from_int      PARAMS ((REAL_VALUE_TYPE *,
143                                        HOST_WIDE_INT, HOST_WIDE_INT,
144                                        enum machine_mode));
145 extern void ereal_from_uint     PARAMS ((REAL_VALUE_TYPE *,
146                                        unsigned HOST_WIDE_INT,
147                                        unsigned HOST_WIDE_INT,
148                                        enum machine_mode));
149 extern void ereal_to_int        PARAMS ((HOST_WIDE_INT *, HOST_WIDE_INT *,
150                                        REAL_VALUE_TYPE));
151 extern REAL_VALUE_TYPE ereal_ldexp PARAMS ((REAL_VALUE_TYPE, int));
152
153 extern void etartdouble         PARAMS ((REAL_VALUE_TYPE, long *));
154 extern void etarldouble         PARAMS ((REAL_VALUE_TYPE, long *));
155 extern void etardouble          PARAMS ((REAL_VALUE_TYPE, long *));
156 extern long etarsingle          PARAMS ((REAL_VALUE_TYPE));
157 extern void ereal_to_decimal    PARAMS ((REAL_VALUE_TYPE, char *));
158 extern int ereal_cmp            PARAMS ((REAL_VALUE_TYPE, REAL_VALUE_TYPE));
159 extern int ereal_isneg          PARAMS ((REAL_VALUE_TYPE));
160 extern REAL_VALUE_TYPE ereal_unto_float PARAMS ((long));
161 extern REAL_VALUE_TYPE ereal_unto_double PARAMS ((long *));
162 extern REAL_VALUE_TYPE ereal_from_float PARAMS ((HOST_WIDE_INT));
163 extern REAL_VALUE_TYPE ereal_from_double PARAMS ((HOST_WIDE_INT *));
164
165 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
166 /* true if x < y : */
167 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
168 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
169
170 /* Compare two floating-point objects for bitwise identity.
171    This is not the same as comparing for equality on IEEE hosts:
172    -0.0 equals 0.0 but they are not identical, and conversely
173    two NaNs might be identical but they cannot be equal.  */
174 #define REAL_VALUES_IDENTICAL(x, y) \
175   (!memcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE)))
176
177 /* These return REAL_VALUE_TYPE: */
178 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
179 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
180
181 /* Truncate the floating-point value X to mode MODE.  */
182 #define REAL_VALUE_TRUNCATE(mode, x)  real_value_truncate (mode, x)
183 extern REAL_VALUE_TYPE real_value_truncate PARAMS ((enum machine_mode,
184                                                  REAL_VALUE_TYPE));
185
186 /* Expansion of REAL_VALUE_TRUNCATE.
187    The result is in floating point, rounded to nearest or even.  */
188 extern bool exact_real_truncate PARAMS ((enum machine_mode,
189                                          REAL_VALUE_TYPE *));
190
191 /* These return HOST_WIDE_INT: */
192 /* Convert a floating-point value to integer, rounding toward zero.  */
193 #define REAL_VALUE_FIX(x) (efixi (x))
194 /* Convert a floating-point value to unsigned integer, rounding
195    toward zero.  */
196 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
197
198 /* Convert ASCII string S to floating point in mode M.
199    Decimal input uses ATOF.  Hexadecimal uses HTOF.  */
200 #define REAL_VALUE_ATOF(s,m) ereal_atof(s,m)
201 #define REAL_VALUE_HTOF(s,m) ereal_atof(s,m)
202
203 #define REAL_VALUE_NEGATE ereal_negate
204
205 /* Compute the absolute value of a floating-point value X.  */
206 #define REAL_VALUE_ABS(x) \
207    (REAL_VALUE_NEGATIVE (x) ? REAL_VALUE_NEGATE (x) : (x))
208
209 /* Determine whether a floating-point value X is infinite.  */
210 #define REAL_VALUE_ISINF(x) (target_isinf (x))
211
212 /* Determine whether a floating-point value X is a NaN.  */
213 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
214
215 /* Determine whether a floating-point value X is negative.  */
216 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
217
218 /* Determine whether a floating-point value X is minus zero.  */
219 #define REAL_VALUE_MINUS_ZERO(x) \
220  ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
221
222 #define REAL_VALUE_TO_INT ereal_to_int
223
224 /* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0.  */
225 #define REAL_VALUE_FROM_INT(d, lo, hi, mode) \
226   ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode)
227
228 #define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \
229   ereal_from_uint (&d, lo, hi, mode)
230
231 /* IN is a REAL_VALUE_TYPE.  OUT is an array of longs.  */
232 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT)               \
233    (LONG_DOUBLE_TYPE_SIZE == 64 ? etardouble ((IN), (OUT))      \
234     : LONG_DOUBLE_TYPE_SIZE == 96 ? etarldouble ((IN), (OUT))   \
235     : LONG_DOUBLE_TYPE_SIZE == 128 ? etartdouble ((IN), (OUT))  \
236     : abort ())
237 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
238
239 /* IN is a REAL_VALUE_TYPE.  OUT is a long.  */
240 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
241
242 /* Inverse of REAL_VALUE_TO_TARGET_DOUBLE.  */
243 #define REAL_VALUE_UNTO_TARGET_DOUBLE(d)  (ereal_unto_double (d))
244
245 /* Inverse of REAL_VALUE_TO_TARGET_SINGLE.  */
246 #define REAL_VALUE_UNTO_TARGET_SINGLE(f)  (ereal_unto_float (f))
247
248 /* d is an array of HOST_WIDE_INT that holds a double precision
249    value in the target computer's floating point format.  */
250 #define REAL_VALUE_FROM_TARGET_DOUBLE(d)  (ereal_from_double (d))
251
252 /* f is a HOST_WIDE_INT containing a single precision target float value.  */
253 #define REAL_VALUE_FROM_TARGET_SINGLE(f)  (ereal_from_float (f))
254
255 /* Conversions to decimal ASCII string.  */
256 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
257
258 /* **** End of software floating point emulator interface macros **** */
259 \f
260 /* Constant real values 0, 1, 2, and -1.  */
261
262 extern REAL_VALUE_TYPE dconst0;
263 extern REAL_VALUE_TYPE dconst1;
264 extern REAL_VALUE_TYPE dconst2;
265 extern REAL_VALUE_TYPE dconstm1;
266
267 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents.  */
268 /* Function to return a real value (not a tree node)
269    from a given integer constant.  */
270 union tree_node;
271 REAL_VALUE_TYPE real_value_from_int_cst PARAMS ((union tree_node *,
272                                                 union tree_node *));
273
274 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from)          \
275   memcpy (&(to), &CONST_DOUBLE_LOW ((from)), sizeof (REAL_VALUE_TYPE))
276
277 /* Return a CONST_DOUBLE with value R and mode M.  */
278
279 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) \
280   const_double_from_real_value (r, m)
281 extern rtx const_double_from_real_value PARAMS ((REAL_VALUE_TYPE,
282                                                  enum machine_mode));
283
284 /* Shorthand; can be handy in machine descriptions.  */
285 #define CONST_DOUBLE_ATOF(s, m) \
286   CONST_DOUBLE_FROM_REAL_VALUE (REAL_VALUE_ATOF (s, m), m)
287
288 /* Replace R by 1/R in the given machine mode, if the result is exact.  */
289 extern int exact_real_inverse   PARAMS ((enum machine_mode, REAL_VALUE_TYPE *));
290 extern int target_isnan         PARAMS ((REAL_VALUE_TYPE));
291 extern int target_isinf         PARAMS ((REAL_VALUE_TYPE));
292 extern int target_negative      PARAMS ((REAL_VALUE_TYPE));
293 extern void debug_real          PARAMS ((REAL_VALUE_TYPE));
294 extern REAL_VALUE_TYPE ereal_atof PARAMS ((const char *, enum machine_mode));
295
296 /* In tree.c: wrap up a REAL_VALUE_TYPE in a tree node.  */
297 extern tree build_real                  PARAMS ((tree, REAL_VALUE_TYPE));
298
299
300 #endif /* ! GCC_REAL_H */