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.
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
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
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
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 #ifndef INTEL_EXTENDED_IEEE_FORMAT
43 #define INTEL_EXTENDED_IEEE_FORMAT 0
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 #ifndef LONG_DOUBLE_TYPE_SIZE
65 #define LONG_DOUBLE_TYPE_SIZE 64
67 /* MAX_LONG_DOUBLE_TYPE_SIZE is a constant tested by #if.
68 LONG_DOUBLE_TYPE_SIZE can vary at compiler run time.
69 So long as macros like REAL_VALUE_TO_TARGET_LONG_DOUBLE cannot
70 vary too, however, then XFmode and TFmode long double
71 cannot both be supported at the same time. */
72 #ifndef MAX_LONG_DOUBLE_TYPE_SIZE
73 #define MAX_LONG_DOUBLE_TYPE_SIZE LONG_DOUBLE_TYPE_SIZE
76 /* **** Start of software floating point emulator interface macros **** */
78 /* REAL_VALUE_TYPE is an array of the minimum number of HOST_WIDE_INTs
79 required to hold MAX_LONG_DOUBLE_TYPE_SIZE bits. */
80 #define N (MAX_LONG_DOUBLE_TYPE_SIZE / BITS_PER_UNIT)
81 #define S sizeof (HOST_WIDE_INT)
83 HOST_WIDE_INT r[N/S + (N%S ? 1 : 0)]; /* round up */
88 extern unsigned int significand_size PARAMS ((enum machine_mode));
90 #define REAL_ARITHMETIC(value, code, d1, d2) \
91 earith (&(value), (code), &(d1), &(d2))
93 /* Declare functions in real.c. */
94 extern void earith PARAMS ((REAL_VALUE_TYPE *, int,
95 REAL_VALUE_TYPE *, REAL_VALUE_TYPE *));
96 extern REAL_VALUE_TYPE etrunci PARAMS ((REAL_VALUE_TYPE));
97 extern REAL_VALUE_TYPE etruncui PARAMS ((REAL_VALUE_TYPE));
98 extern REAL_VALUE_TYPE ereal_negate PARAMS ((REAL_VALUE_TYPE));
99 extern HOST_WIDE_INT efixi PARAMS ((REAL_VALUE_TYPE));
100 extern unsigned HOST_WIDE_INT efixui PARAMS ((REAL_VALUE_TYPE));
101 extern void ereal_from_int PARAMS ((REAL_VALUE_TYPE *,
102 HOST_WIDE_INT, HOST_WIDE_INT,
104 extern void ereal_from_uint PARAMS ((REAL_VALUE_TYPE *,
105 unsigned HOST_WIDE_INT,
106 unsigned HOST_WIDE_INT,
108 extern void ereal_to_int PARAMS ((HOST_WIDE_INT *, HOST_WIDE_INT *,
110 extern REAL_VALUE_TYPE ereal_ldexp PARAMS ((REAL_VALUE_TYPE, int));
112 extern void etartdouble PARAMS ((REAL_VALUE_TYPE, long *));
113 extern void etarldouble PARAMS ((REAL_VALUE_TYPE, long *));
114 extern void etardouble PARAMS ((REAL_VALUE_TYPE, long *));
115 extern long etarsingle PARAMS ((REAL_VALUE_TYPE));
116 extern void ereal_to_decimal PARAMS ((REAL_VALUE_TYPE, char *));
117 extern int ereal_cmp PARAMS ((REAL_VALUE_TYPE, REAL_VALUE_TYPE));
118 extern int ereal_isneg PARAMS ((REAL_VALUE_TYPE));
119 extern REAL_VALUE_TYPE ereal_unto_float PARAMS ((long));
120 extern REAL_VALUE_TYPE ereal_unto_double PARAMS ((long *));
121 extern REAL_VALUE_TYPE ereal_from_float PARAMS ((HOST_WIDE_INT));
122 extern REAL_VALUE_TYPE ereal_from_double PARAMS ((HOST_WIDE_INT *));
124 #define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0)
125 /* true if x < y : */
126 #define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1)
127 #define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n)
129 /* Compare two floating-point objects for bitwise identity.
130 This is not the same as comparing for equality on IEEE hosts:
131 -0.0 equals 0.0 but they are not identical, and conversely
132 two NaNs might be identical but they cannot be equal. */
133 #define REAL_VALUES_IDENTICAL(x, y) \
134 (!memcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE)))
136 /* These return REAL_VALUE_TYPE: */
137 #define REAL_VALUE_RNDZINT(x) (etrunci (x))
138 #define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x))
140 /* Truncate the floating-point value X to mode MODE. */
141 #define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x)
142 extern REAL_VALUE_TYPE real_value_truncate PARAMS ((enum machine_mode,
145 /* These return HOST_WIDE_INT: */
146 /* Convert a floating-point value to integer, rounding toward zero. */
147 #define REAL_VALUE_FIX(x) (efixi (x))
148 /* Convert a floating-point value to unsigned integer, rounding
150 #define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x))
152 /* Convert ASCII string S to floating point in mode M.
153 Decimal input uses ATOF. Hexadecimal uses HTOF. */
154 #define REAL_VALUE_ATOF(s,m) ereal_atof(s,m)
155 #define REAL_VALUE_HTOF(s,m) ereal_atof(s,m)
157 #define REAL_VALUE_NEGATE ereal_negate
159 /* Determine whether a floating-point value X is infinite. */
160 #define REAL_VALUE_ISINF(x) (target_isinf (x))
162 /* Determine whether a floating-point value X is a NaN. */
163 #define REAL_VALUE_ISNAN(x) (target_isnan (x))
165 /* Determine whether a floating-point value X is negative. */
166 #define REAL_VALUE_NEGATIVE(x) (target_negative (x))
168 /* Determine whether a floating-point value X is minus zero. */
169 #define REAL_VALUE_MINUS_ZERO(x) \
170 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 ))
172 #define REAL_VALUE_TO_INT ereal_to_int
174 /* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */
175 #define REAL_VALUE_FROM_INT(d, lo, hi, mode) \
176 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode)
178 #define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \
179 ereal_from_uint (&d, lo, hi, mode)
181 /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
182 #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) \
183 (LONG_DOUBLE_TYPE_SIZE == 64 ? etardouble ((IN), (OUT)) \
184 : LONG_DOUBLE_TYPE_SIZE == 96 ? etarldouble ((IN), (OUT)) \
185 : LONG_DOUBLE_TYPE_SIZE == 128 ? etartdouble ((IN), (OUT)) \
187 #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT)))
189 /* IN is a REAL_VALUE_TYPE. OUT is a long. */
190 #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN)))
192 /* Inverse of REAL_VALUE_TO_TARGET_DOUBLE. */
193 #define REAL_VALUE_UNTO_TARGET_DOUBLE(d) (ereal_unto_double (d))
195 /* Inverse of REAL_VALUE_TO_TARGET_SINGLE. */
196 #define REAL_VALUE_UNTO_TARGET_SINGLE(f) (ereal_unto_float (f))
198 /* d is an array of HOST_WIDE_INT that holds a double precision
199 value in the target computer's floating point format. */
200 #define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d))
202 /* f is a HOST_WIDE_INT containing a single precision target float value. */
203 #define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f))
205 /* Conversions to decimal ASCII string. */
206 #define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s))
208 /* **** End of software floating point emulator interface macros **** */
210 /* Constant real values 0, 1, 2, and -1. */
212 extern REAL_VALUE_TYPE dconst0;
213 extern REAL_VALUE_TYPE dconst1;
214 extern REAL_VALUE_TYPE dconst2;
215 extern REAL_VALUE_TYPE dconstm1;
217 /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */
218 /* Function to return a real value (not a tree node)
219 from a given integer constant. */
221 REAL_VALUE_TYPE real_value_from_int_cst PARAMS ((union tree_node *,
224 #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \
225 memcpy (&(to), &CONST_DOUBLE_LOW ((from)), sizeof (REAL_VALUE_TYPE))
227 /* Return a CONST_DOUBLE with value R and mode M. */
229 #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m)
230 extern struct rtx_def *immed_real_const_1 PARAMS ((REAL_VALUE_TYPE,
233 /* Replace R by 1/R in the given machine mode, if the result is exact. */
234 extern int exact_real_inverse PARAMS ((enum machine_mode, REAL_VALUE_TYPE *));
235 extern int target_isnan PARAMS ((REAL_VALUE_TYPE));
236 extern int target_isinf PARAMS ((REAL_VALUE_TYPE));
237 extern int target_negative PARAMS ((REAL_VALUE_TYPE));
238 extern void debug_real PARAMS ((REAL_VALUE_TYPE));
239 extern REAL_VALUE_TYPE ereal_atof PARAMS ((const char *, enum machine_mode));
241 #endif /* ! GCC_REAL_H */