1*38fd1498Szrj /* Definitions of floating-point access for GNU compiler.
2*38fd1498Szrj Copyright (C) 1989-2018 Free Software Foundation, Inc.
3*38fd1498Szrj
4*38fd1498Szrj This file is part of GCC.
5*38fd1498Szrj
6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
7*38fd1498Szrj the terms of the GNU General Public License as published by the Free
8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
9*38fd1498Szrj version.
10*38fd1498Szrj
11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14*38fd1498Szrj for more details.
15*38fd1498Szrj
16*38fd1498Szrj You should have received a copy of the GNU General Public License
17*38fd1498Szrj along with GCC; see the file COPYING3. If not see
18*38fd1498Szrj <http://www.gnu.org/licenses/>. */
19*38fd1498Szrj
20*38fd1498Szrj #ifndef GCC_REAL_H
21*38fd1498Szrj #define GCC_REAL_H
22*38fd1498Szrj
23*38fd1498Szrj /* An expanded form of the represented number. */
24*38fd1498Szrj
25*38fd1498Szrj /* Enumerate the special cases of numbers that we encounter. */
26*38fd1498Szrj enum real_value_class {
27*38fd1498Szrj rvc_zero,
28*38fd1498Szrj rvc_normal,
29*38fd1498Szrj rvc_inf,
30*38fd1498Szrj rvc_nan
31*38fd1498Szrj };
32*38fd1498Szrj
33*38fd1498Szrj #define SIGNIFICAND_BITS (128 + HOST_BITS_PER_LONG)
34*38fd1498Szrj #define EXP_BITS (32 - 6)
35*38fd1498Szrj #define MAX_EXP ((1 << (EXP_BITS - 1)) - 1)
36*38fd1498Szrj #define SIGSZ (SIGNIFICAND_BITS / HOST_BITS_PER_LONG)
37*38fd1498Szrj #define SIG_MSB ((unsigned long)1 << (HOST_BITS_PER_LONG - 1))
38*38fd1498Szrj
39*38fd1498Szrj struct GTY(()) real_value {
40*38fd1498Szrj /* Use the same underlying type for all bit-fields, so as to make
41*38fd1498Szrj sure they're packed together, otherwise REAL_VALUE_TYPE_SIZE will
42*38fd1498Szrj be miscomputed. */
43*38fd1498Szrj unsigned int /* ENUM_BITFIELD (real_value_class) */ cl : 2;
44*38fd1498Szrj unsigned int decimal : 1;
45*38fd1498Szrj unsigned int sign : 1;
46*38fd1498Szrj unsigned int signalling : 1;
47*38fd1498Szrj unsigned int canonical : 1;
48*38fd1498Szrj unsigned int uexp : EXP_BITS;
49*38fd1498Szrj unsigned long sig[SIGSZ];
50*38fd1498Szrj };
51*38fd1498Szrj
52*38fd1498Szrj #define REAL_EXP(REAL) \
53*38fd1498Szrj ((int)((REAL)->uexp ^ (unsigned int)(1 << (EXP_BITS - 1))) \
54*38fd1498Szrj - (1 << (EXP_BITS - 1)))
55*38fd1498Szrj #define SET_REAL_EXP(REAL, EXP) \
56*38fd1498Szrj ((REAL)->uexp = ((unsigned int)(EXP) & (unsigned int)((1 << EXP_BITS) - 1)))
57*38fd1498Szrj
58*38fd1498Szrj /* Various headers condition prototypes on #ifdef REAL_VALUE_TYPE, so it
59*38fd1498Szrj needs to be a macro. We do need to continue to have a structure tag
60*38fd1498Szrj so that other headers can forward declare it. */
61*38fd1498Szrj #define REAL_VALUE_TYPE struct real_value
62*38fd1498Szrj
63*38fd1498Szrj /* We store a REAL_VALUE_TYPE into an rtx, and we do this by putting it in
64*38fd1498Szrj consecutive "w" slots. Moreover, we've got to compute the number of "w"
65*38fd1498Szrj slots at preprocessor time, which means we can't use sizeof. Guess. */
66*38fd1498Szrj
67*38fd1498Szrj #define REAL_VALUE_TYPE_SIZE (SIGNIFICAND_BITS + 32)
68*38fd1498Szrj #define REAL_WIDTH \
69*38fd1498Szrj (REAL_VALUE_TYPE_SIZE/HOST_BITS_PER_WIDE_INT \
70*38fd1498Szrj + (REAL_VALUE_TYPE_SIZE%HOST_BITS_PER_WIDE_INT ? 1 : 0)) /* round up */
71*38fd1498Szrj
72*38fd1498Szrj /* Verify the guess. */
73*38fd1498Szrj extern char test_real_width
74*38fd1498Szrj [sizeof (REAL_VALUE_TYPE) <= REAL_WIDTH * sizeof (HOST_WIDE_INT) ? 1 : -1];
75*38fd1498Szrj
76*38fd1498Szrj /* Calculate the format for CONST_DOUBLE. We need as many slots as
77*38fd1498Szrj are necessary to overlay a REAL_VALUE_TYPE on them. This could be
78*38fd1498Szrj as many as four (32-bit HOST_WIDE_INT, 128-bit REAL_VALUE_TYPE).
79*38fd1498Szrj
80*38fd1498Szrj A number of places assume that there are always at least two 'w'
81*38fd1498Szrj slots in a CONST_DOUBLE, so we provide them even if one would suffice. */
82*38fd1498Szrj
83*38fd1498Szrj #if REAL_WIDTH == 1
84*38fd1498Szrj # define CONST_DOUBLE_FORMAT "ww"
85*38fd1498Szrj #else
86*38fd1498Szrj # if REAL_WIDTH == 2
87*38fd1498Szrj # define CONST_DOUBLE_FORMAT "ww"
88*38fd1498Szrj # else
89*38fd1498Szrj # if REAL_WIDTH == 3
90*38fd1498Szrj # define CONST_DOUBLE_FORMAT "www"
91*38fd1498Szrj # else
92*38fd1498Szrj # if REAL_WIDTH == 4
93*38fd1498Szrj # define CONST_DOUBLE_FORMAT "wwww"
94*38fd1498Szrj # else
95*38fd1498Szrj # if REAL_WIDTH == 5
96*38fd1498Szrj # define CONST_DOUBLE_FORMAT "wwwww"
97*38fd1498Szrj # else
98*38fd1498Szrj # if REAL_WIDTH == 6
99*38fd1498Szrj # define CONST_DOUBLE_FORMAT "wwwwww"
100*38fd1498Szrj # else
101*38fd1498Szrj #error "REAL_WIDTH > 6 not supported"
102*38fd1498Szrj # endif
103*38fd1498Szrj # endif
104*38fd1498Szrj # endif
105*38fd1498Szrj # endif
106*38fd1498Szrj # endif
107*38fd1498Szrj #endif
108*38fd1498Szrj
109*38fd1498Szrj
110*38fd1498Szrj /* Describes the properties of the specific target format in use. */
111*38fd1498Szrj struct real_format
112*38fd1498Szrj {
113*38fd1498Szrj /* Move to and from the target bytes. */
114*38fd1498Szrj void (*encode) (const struct real_format *, long *,
115*38fd1498Szrj const REAL_VALUE_TYPE *);
116*38fd1498Szrj void (*decode) (const struct real_format *, REAL_VALUE_TYPE *,
117*38fd1498Szrj const long *);
118*38fd1498Szrj
119*38fd1498Szrj /* The radix of the exponent and digits of the significand. */
120*38fd1498Szrj int b;
121*38fd1498Szrj
122*38fd1498Szrj /* Size of the significand in digits of radix B. */
123*38fd1498Szrj int p;
124*38fd1498Szrj
125*38fd1498Szrj /* Size of the significant of a NaN, in digits of radix B. */
126*38fd1498Szrj int pnan;
127*38fd1498Szrj
128*38fd1498Szrj /* The minimum negative integer, x, such that b**(x-1) is normalized. */
129*38fd1498Szrj int emin;
130*38fd1498Szrj
131*38fd1498Szrj /* The maximum integer, x, such that b**(x-1) is representable. */
132*38fd1498Szrj int emax;
133*38fd1498Szrj
134*38fd1498Szrj /* The bit position of the sign bit, for determining whether a value
135*38fd1498Szrj is positive/negative, or -1 for a complex encoding. */
136*38fd1498Szrj int signbit_ro;
137*38fd1498Szrj
138*38fd1498Szrj /* The bit position of the sign bit, for changing the sign of a number,
139*38fd1498Szrj or -1 for a complex encoding. */
140*38fd1498Szrj int signbit_rw;
141*38fd1498Szrj
142*38fd1498Szrj /* If this is an IEEE interchange format, the number of bits in the
143*38fd1498Szrj format; otherwise, if it is an IEEE extended format, one more
144*38fd1498Szrj than the greatest number of bits in an interchange format it
145*38fd1498Szrj extends; otherwise 0. Formats need not follow the IEEE 754-2008
146*38fd1498Szrj recommended practice regarding how signaling NaNs are identified,
147*38fd1498Szrj and may vary in the choice of default NaN, but must follow other
148*38fd1498Szrj IEEE practice regarding having NaNs, infinities and subnormal
149*38fd1498Szrj values, and the relation of minimum and maximum exponents, and,
150*38fd1498Szrj for interchange formats, the details of the encoding. */
151*38fd1498Szrj int ieee_bits;
152*38fd1498Szrj
153*38fd1498Szrj /* Default rounding mode for operations on this format. */
154*38fd1498Szrj bool round_towards_zero;
155*38fd1498Szrj bool has_sign_dependent_rounding;
156*38fd1498Szrj
157*38fd1498Szrj /* Properties of the format. */
158*38fd1498Szrj bool has_nans;
159*38fd1498Szrj bool has_inf;
160*38fd1498Szrj bool has_denorm;
161*38fd1498Szrj bool has_signed_zero;
162*38fd1498Szrj bool qnan_msb_set;
163*38fd1498Szrj bool canonical_nan_lsbs_set;
164*38fd1498Szrj const char *name;
165*38fd1498Szrj };
166*38fd1498Szrj
167*38fd1498Szrj
168*38fd1498Szrj /* The target format used for each floating point mode.
169*38fd1498Szrj Float modes are followed by decimal float modes, with entries for
170*38fd1498Szrj float modes indexed by (MODE - first float mode), and entries for
171*38fd1498Szrj decimal float modes indexed by (MODE - first decimal float mode) +
172*38fd1498Szrj the number of float modes. */
173*38fd1498Szrj extern const struct real_format *
174*38fd1498Szrj real_format_for_mode[MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1
175*38fd1498Szrj + MAX_MODE_DECIMAL_FLOAT - MIN_MODE_DECIMAL_FLOAT + 1];
176*38fd1498Szrj
177*38fd1498Szrj #define REAL_MODE_FORMAT(MODE) \
178*38fd1498Szrj (real_format_for_mode[DECIMAL_FLOAT_MODE_P (MODE) \
179*38fd1498Szrj ? (((MODE) - MIN_MODE_DECIMAL_FLOAT) \
180*38fd1498Szrj + (MAX_MODE_FLOAT - MIN_MODE_FLOAT + 1)) \
181*38fd1498Szrj : GET_MODE_CLASS (MODE) == MODE_FLOAT \
182*38fd1498Szrj ? ((MODE) - MIN_MODE_FLOAT) \
183*38fd1498Szrj : (gcc_unreachable (), 0)])
184*38fd1498Szrj
185*38fd1498Szrj #define FLOAT_MODE_FORMAT(MODE) \
186*38fd1498Szrj (REAL_MODE_FORMAT (as_a <scalar_float_mode> (GET_MODE_INNER (MODE))))
187*38fd1498Szrj
188*38fd1498Szrj /* The following macro determines whether the floating point format is
189*38fd1498Szrj composite, i.e. may contain non-consecutive mantissa bits, in which
190*38fd1498Szrj case compile-time FP overflow may not model run-time overflow. */
191*38fd1498Szrj #define MODE_COMPOSITE_P(MODE) \
192*38fd1498Szrj (FLOAT_MODE_P (MODE) \
193*38fd1498Szrj && FLOAT_MODE_FORMAT (MODE)->pnan < FLOAT_MODE_FORMAT (MODE)->p)
194*38fd1498Szrj
195*38fd1498Szrj /* Accessor macros for format properties. */
196*38fd1498Szrj #define MODE_HAS_NANS(MODE) \
197*38fd1498Szrj (FLOAT_MODE_P (MODE) && FLOAT_MODE_FORMAT (MODE)->has_nans)
198*38fd1498Szrj #define MODE_HAS_INFINITIES(MODE) \
199*38fd1498Szrj (FLOAT_MODE_P (MODE) && FLOAT_MODE_FORMAT (MODE)->has_inf)
200*38fd1498Szrj #define MODE_HAS_SIGNED_ZEROS(MODE) \
201*38fd1498Szrj (FLOAT_MODE_P (MODE) && FLOAT_MODE_FORMAT (MODE)->has_signed_zero)
202*38fd1498Szrj #define MODE_HAS_SIGN_DEPENDENT_ROUNDING(MODE) \
203*38fd1498Szrj (FLOAT_MODE_P (MODE) \
204*38fd1498Szrj && FLOAT_MODE_FORMAT (MODE)->has_sign_dependent_rounding)
205*38fd1498Szrj
206*38fd1498Szrj /* This class allows functions in this file to accept a floating-point
207*38fd1498Szrj format as either a mode or an explicit real_format pointer. In the
208*38fd1498Szrj former case the mode must be VOIDmode (which means "no particular
209*38fd1498Szrj format") or must satisfy SCALAR_FLOAT_MODE_P. */
210*38fd1498Szrj class format_helper
211*38fd1498Szrj {
212*38fd1498Szrj public:
format_helper(const real_format * format)213*38fd1498Szrj format_helper (const real_format *format) : m_format (format) {}
214*38fd1498Szrj template<typename T> format_helper (const T &);
215*38fd1498Szrj const real_format *operator-> () const { return m_format; }
216*38fd1498Szrj operator const real_format *() const { return m_format; }
217*38fd1498Szrj
decimal_p()218*38fd1498Szrj bool decimal_p () const { return m_format && m_format->b == 10; }
219*38fd1498Szrj
220*38fd1498Szrj private:
221*38fd1498Szrj const real_format *m_format;
222*38fd1498Szrj };
223*38fd1498Szrj
224*38fd1498Szrj template<typename T>
format_helper(const T & m)225*38fd1498Szrj inline format_helper::format_helper (const T &m)
226*38fd1498Szrj : m_format (m == VOIDmode ? 0 : REAL_MODE_FORMAT (m))
227*38fd1498Szrj {}
228*38fd1498Szrj
229*38fd1498Szrj /* Declare functions in real.c. */
230*38fd1498Szrj
231*38fd1498Szrj /* True if the given mode has a NaN representation and the treatment of
232*38fd1498Szrj NaN operands is important. Certain optimizations, such as folding
233*38fd1498Szrj x * 0 into 0, are not correct for NaN operands, and are normally
234*38fd1498Szrj disabled for modes with NaNs. The user can ask for them to be
235*38fd1498Szrj done anyway using the -funsafe-math-optimizations switch. */
236*38fd1498Szrj extern bool HONOR_NANS (machine_mode);
237*38fd1498Szrj extern bool HONOR_NANS (const_tree);
238*38fd1498Szrj extern bool HONOR_NANS (const_rtx);
239*38fd1498Szrj
240*38fd1498Szrj /* Like HONOR_NANs, but true if we honor signaling NaNs (or sNaNs). */
241*38fd1498Szrj extern bool HONOR_SNANS (machine_mode);
242*38fd1498Szrj extern bool HONOR_SNANS (const_tree);
243*38fd1498Szrj extern bool HONOR_SNANS (const_rtx);
244*38fd1498Szrj
245*38fd1498Szrj /* As for HONOR_NANS, but true if the mode can represent infinity and
246*38fd1498Szrj the treatment of infinite values is important. */
247*38fd1498Szrj extern bool HONOR_INFINITIES (machine_mode);
248*38fd1498Szrj extern bool HONOR_INFINITIES (const_tree);
249*38fd1498Szrj extern bool HONOR_INFINITIES (const_rtx);
250*38fd1498Szrj
251*38fd1498Szrj /* Like HONOR_NANS, but true if the given mode distinguishes between
252*38fd1498Szrj positive and negative zero, and the sign of zero is important. */
253*38fd1498Szrj extern bool HONOR_SIGNED_ZEROS (machine_mode);
254*38fd1498Szrj extern bool HONOR_SIGNED_ZEROS (const_tree);
255*38fd1498Szrj extern bool HONOR_SIGNED_ZEROS (const_rtx);
256*38fd1498Szrj
257*38fd1498Szrj /* Like HONOR_NANS, but true if given mode supports sign-dependent rounding,
258*38fd1498Szrj and the rounding mode is important. */
259*38fd1498Szrj extern bool HONOR_SIGN_DEPENDENT_ROUNDING (machine_mode);
260*38fd1498Szrj extern bool HONOR_SIGN_DEPENDENT_ROUNDING (const_tree);
261*38fd1498Szrj extern bool HONOR_SIGN_DEPENDENT_ROUNDING (const_rtx);
262*38fd1498Szrj
263*38fd1498Szrj /* Binary or unary arithmetic on tree_code. */
264*38fd1498Szrj extern bool real_arithmetic (REAL_VALUE_TYPE *, int, const REAL_VALUE_TYPE *,
265*38fd1498Szrj const REAL_VALUE_TYPE *);
266*38fd1498Szrj
267*38fd1498Szrj /* Compare reals by tree_code. */
268*38fd1498Szrj extern bool real_compare (int, const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
269*38fd1498Szrj
270*38fd1498Szrj /* Determine whether a floating-point value X is infinite. */
271*38fd1498Szrj extern bool real_isinf (const REAL_VALUE_TYPE *);
272*38fd1498Szrj
273*38fd1498Szrj /* Determine whether a floating-point value X is a NaN. */
274*38fd1498Szrj extern bool real_isnan (const REAL_VALUE_TYPE *);
275*38fd1498Szrj
276*38fd1498Szrj /* Determine whether a floating-point value X is a signaling NaN. */
277*38fd1498Szrj extern bool real_issignaling_nan (const REAL_VALUE_TYPE *);
278*38fd1498Szrj
279*38fd1498Szrj /* Determine whether a floating-point value X is finite. */
280*38fd1498Szrj extern bool real_isfinite (const REAL_VALUE_TYPE *);
281*38fd1498Szrj
282*38fd1498Szrj /* Determine whether a floating-point value X is negative. */
283*38fd1498Szrj extern bool real_isneg (const REAL_VALUE_TYPE *);
284*38fd1498Szrj
285*38fd1498Szrj /* Determine whether a floating-point value X is minus zero. */
286*38fd1498Szrj extern bool real_isnegzero (const REAL_VALUE_TYPE *);
287*38fd1498Szrj
288*38fd1498Szrj /* Test relationships between reals. */
289*38fd1498Szrj extern bool real_identical (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
290*38fd1498Szrj extern bool real_equal (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
291*38fd1498Szrj extern bool real_less (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
292*38fd1498Szrj
293*38fd1498Szrj /* Extend or truncate to a new format. */
294*38fd1498Szrj extern void real_convert (REAL_VALUE_TYPE *, format_helper,
295*38fd1498Szrj const REAL_VALUE_TYPE *);
296*38fd1498Szrj
297*38fd1498Szrj /* Return true if truncating to NEW is exact. */
298*38fd1498Szrj extern bool exact_real_truncate (format_helper, const REAL_VALUE_TYPE *);
299*38fd1498Szrj
300*38fd1498Szrj /* Render R as a decimal floating point constant. */
301*38fd1498Szrj extern void real_to_decimal (char *, const REAL_VALUE_TYPE *, size_t,
302*38fd1498Szrj size_t, int);
303*38fd1498Szrj
304*38fd1498Szrj /* Render R as a decimal floating point constant, rounded so as to be
305*38fd1498Szrj parsed back to the same value when interpreted in mode MODE. */
306*38fd1498Szrj extern void real_to_decimal_for_mode (char *, const REAL_VALUE_TYPE *, size_t,
307*38fd1498Szrj size_t, int, machine_mode);
308*38fd1498Szrj
309*38fd1498Szrj /* Render R as a hexadecimal floating point constant. */
310*38fd1498Szrj extern void real_to_hexadecimal (char *, const REAL_VALUE_TYPE *,
311*38fd1498Szrj size_t, size_t, int);
312*38fd1498Szrj
313*38fd1498Szrj /* Render R as an integer. */
314*38fd1498Szrj extern HOST_WIDE_INT real_to_integer (const REAL_VALUE_TYPE *);
315*38fd1498Szrj
316*38fd1498Szrj /* Initialize R from a decimal or hexadecimal string. Return -1 if
317*38fd1498Szrj the value underflows, +1 if overflows, and 0 otherwise. */
318*38fd1498Szrj extern int real_from_string (REAL_VALUE_TYPE *, const char *);
319*38fd1498Szrj /* Wrapper to allow different internal representation for decimal floats. */
320*38fd1498Szrj extern void real_from_string3 (REAL_VALUE_TYPE *, const char *, format_helper);
321*38fd1498Szrj
322*38fd1498Szrj extern long real_to_target (long *, const REAL_VALUE_TYPE *, format_helper);
323*38fd1498Szrj
324*38fd1498Szrj extern void real_from_target (REAL_VALUE_TYPE *, const long *,
325*38fd1498Szrj format_helper);
326*38fd1498Szrj
327*38fd1498Szrj extern void real_inf (REAL_VALUE_TYPE *);
328*38fd1498Szrj
329*38fd1498Szrj extern bool real_nan (REAL_VALUE_TYPE *, const char *, int, format_helper);
330*38fd1498Szrj
331*38fd1498Szrj extern void real_maxval (REAL_VALUE_TYPE *, int, machine_mode);
332*38fd1498Szrj
333*38fd1498Szrj extern void real_2expN (REAL_VALUE_TYPE *, int, format_helper);
334*38fd1498Szrj
335*38fd1498Szrj extern unsigned int real_hash (const REAL_VALUE_TYPE *);
336*38fd1498Szrj
337*38fd1498Szrj
338*38fd1498Szrj /* Target formats defined in real.c. */
339*38fd1498Szrj extern const struct real_format ieee_single_format;
340*38fd1498Szrj extern const struct real_format mips_single_format;
341*38fd1498Szrj extern const struct real_format motorola_single_format;
342*38fd1498Szrj extern const struct real_format spu_single_format;
343*38fd1498Szrj extern const struct real_format ieee_double_format;
344*38fd1498Szrj extern const struct real_format mips_double_format;
345*38fd1498Szrj extern const struct real_format motorola_double_format;
346*38fd1498Szrj extern const struct real_format ieee_extended_motorola_format;
347*38fd1498Szrj extern const struct real_format ieee_extended_intel_96_format;
348*38fd1498Szrj extern const struct real_format ieee_extended_intel_96_round_53_format;
349*38fd1498Szrj extern const struct real_format ieee_extended_intel_128_format;
350*38fd1498Szrj extern const struct real_format ibm_extended_format;
351*38fd1498Szrj extern const struct real_format mips_extended_format;
352*38fd1498Szrj extern const struct real_format ieee_quad_format;
353*38fd1498Szrj extern const struct real_format mips_quad_format;
354*38fd1498Szrj extern const struct real_format vax_f_format;
355*38fd1498Szrj extern const struct real_format vax_d_format;
356*38fd1498Szrj extern const struct real_format vax_g_format;
357*38fd1498Szrj extern const struct real_format real_internal_format;
358*38fd1498Szrj extern const struct real_format decimal_single_format;
359*38fd1498Szrj extern const struct real_format decimal_double_format;
360*38fd1498Szrj extern const struct real_format decimal_quad_format;
361*38fd1498Szrj extern const struct real_format ieee_half_format;
362*38fd1498Szrj extern const struct real_format arm_half_format;
363*38fd1498Szrj
364*38fd1498Szrj
365*38fd1498Szrj /* ====================================================================== */
366*38fd1498Szrj /* Crap. */
367*38fd1498Szrj
368*38fd1498Szrj /* Determine whether a floating-point value X is infinite. */
369*38fd1498Szrj #define REAL_VALUE_ISINF(x) real_isinf (&(x))
370*38fd1498Szrj
371*38fd1498Szrj /* Determine whether a floating-point value X is a NaN. */
372*38fd1498Szrj #define REAL_VALUE_ISNAN(x) real_isnan (&(x))
373*38fd1498Szrj
374*38fd1498Szrj /* Determine whether a floating-point value X is a signaling NaN. */
375*38fd1498Szrj #define REAL_VALUE_ISSIGNALING_NAN(x) real_issignaling_nan (&(x))
376*38fd1498Szrj
377*38fd1498Szrj /* Determine whether a floating-point value X is negative. */
378*38fd1498Szrj #define REAL_VALUE_NEGATIVE(x) real_isneg (&(x))
379*38fd1498Szrj
380*38fd1498Szrj /* Determine whether a floating-point value X is minus zero. */
381*38fd1498Szrj #define REAL_VALUE_MINUS_ZERO(x) real_isnegzero (&(x))
382*38fd1498Szrj
383*38fd1498Szrj /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
384*38fd1498Szrj #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) \
385*38fd1498Szrj real_to_target (OUT, &(IN), \
386*38fd1498Szrj float_mode_for_size (LONG_DOUBLE_TYPE_SIZE).require ())
387*38fd1498Szrj
388*38fd1498Szrj #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \
389*38fd1498Szrj real_to_target (OUT, &(IN), float_mode_for_size (64).require ())
390*38fd1498Szrj
391*38fd1498Szrj /* IN is a REAL_VALUE_TYPE. OUT is a long. */
392*38fd1498Szrj #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \
393*38fd1498Szrj ((OUT) = real_to_target (NULL, &(IN), float_mode_for_size (32).require ()))
394*38fd1498Szrj
395*38fd1498Szrj /* Real values to IEEE 754 decimal floats. */
396*38fd1498Szrj
397*38fd1498Szrj /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */
398*38fd1498Szrj #define REAL_VALUE_TO_TARGET_DECIMAL128(IN, OUT) \
399*38fd1498Szrj real_to_target (OUT, &(IN), decimal_float_mode_for_size (128).require ())
400*38fd1498Szrj
401*38fd1498Szrj #define REAL_VALUE_TO_TARGET_DECIMAL64(IN, OUT) \
402*38fd1498Szrj real_to_target (OUT, &(IN), decimal_float_mode_for_size (64).require ())
403*38fd1498Szrj
404*38fd1498Szrj /* IN is a REAL_VALUE_TYPE. OUT is a long. */
405*38fd1498Szrj #define REAL_VALUE_TO_TARGET_DECIMAL32(IN, OUT) \
406*38fd1498Szrj ((OUT) = real_to_target (NULL, &(IN), \
407*38fd1498Szrj decimal_float_mode_for_size (32).require ()))
408*38fd1498Szrj
409*38fd1498Szrj extern REAL_VALUE_TYPE real_value_truncate (format_helper, REAL_VALUE_TYPE);
410*38fd1498Szrj
411*38fd1498Szrj extern REAL_VALUE_TYPE real_value_negate (const REAL_VALUE_TYPE *);
412*38fd1498Szrj extern REAL_VALUE_TYPE real_value_abs (const REAL_VALUE_TYPE *);
413*38fd1498Szrj
414*38fd1498Szrj extern int significand_size (format_helper);
415*38fd1498Szrj
416*38fd1498Szrj extern REAL_VALUE_TYPE real_from_string2 (const char *, format_helper);
417*38fd1498Szrj
418*38fd1498Szrj #define REAL_VALUE_ATOF(s, m) \
419*38fd1498Szrj real_from_string2 (s, m)
420*38fd1498Szrj
421*38fd1498Szrj #define CONST_DOUBLE_ATOF(s, m) \
422*38fd1498Szrj const_double_from_real_value (real_from_string2 (s, m), m)
423*38fd1498Szrj
424*38fd1498Szrj #define REAL_VALUE_FIX(r) \
425*38fd1498Szrj real_to_integer (&(r))
426*38fd1498Szrj
427*38fd1498Szrj /* ??? Not quite right. */
428*38fd1498Szrj #define REAL_VALUE_UNSIGNED_FIX(r) \
429*38fd1498Szrj real_to_integer (&(r))
430*38fd1498Szrj
431*38fd1498Szrj /* ??? These were added for Paranoia support. */
432*38fd1498Szrj
433*38fd1498Szrj /* Return floor log2(R). */
434*38fd1498Szrj extern int real_exponent (const REAL_VALUE_TYPE *);
435*38fd1498Szrj
436*38fd1498Szrj /* R = A * 2**EXP. */
437*38fd1498Szrj extern void real_ldexp (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *, int);
438*38fd1498Szrj
439*38fd1498Szrj /* **** End of software floating point emulator interface macros **** */
440*38fd1498Szrj
441*38fd1498Szrj /* Constant real values 0, 1, 2, -1 and 0.5. */
442*38fd1498Szrj
443*38fd1498Szrj extern REAL_VALUE_TYPE dconst0;
444*38fd1498Szrj extern REAL_VALUE_TYPE dconst1;
445*38fd1498Szrj extern REAL_VALUE_TYPE dconst2;
446*38fd1498Szrj extern REAL_VALUE_TYPE dconstm1;
447*38fd1498Szrj extern REAL_VALUE_TYPE dconsthalf;
448*38fd1498Szrj
449*38fd1498Szrj #define dconst_e() (*dconst_e_ptr ())
450*38fd1498Szrj #define dconst_third() (*dconst_third_ptr ())
451*38fd1498Szrj #define dconst_quarter() (*dconst_quarter_ptr ())
452*38fd1498Szrj #define dconst_sixth() (*dconst_sixth_ptr ())
453*38fd1498Szrj #define dconst_ninth() (*dconst_ninth_ptr ())
454*38fd1498Szrj #define dconst_sqrt2() (*dconst_sqrt2_ptr ())
455*38fd1498Szrj
456*38fd1498Szrj /* Function to return the real value special constant 'e'. */
457*38fd1498Szrj extern const REAL_VALUE_TYPE * dconst_e_ptr (void);
458*38fd1498Szrj
459*38fd1498Szrj /* Returns a cached REAL_VALUE_TYPE corresponding to 1/n, for various n. */
460*38fd1498Szrj extern const REAL_VALUE_TYPE *dconst_third_ptr (void);
461*38fd1498Szrj extern const REAL_VALUE_TYPE *dconst_quarter_ptr (void);
462*38fd1498Szrj extern const REAL_VALUE_TYPE *dconst_sixth_ptr (void);
463*38fd1498Szrj extern const REAL_VALUE_TYPE *dconst_ninth_ptr (void);
464*38fd1498Szrj
465*38fd1498Szrj /* Returns the special REAL_VALUE_TYPE corresponding to sqrt(2). */
466*38fd1498Szrj extern const REAL_VALUE_TYPE * dconst_sqrt2_ptr (void);
467*38fd1498Szrj
468*38fd1498Szrj /* Function to return a real value (not a tree node)
469*38fd1498Szrj from a given integer constant. */
470*38fd1498Szrj REAL_VALUE_TYPE real_value_from_int_cst (const_tree, const_tree);
471*38fd1498Szrj
472*38fd1498Szrj /* Return a CONST_DOUBLE with value R and mode M. */
473*38fd1498Szrj extern rtx const_double_from_real_value (REAL_VALUE_TYPE, machine_mode);
474*38fd1498Szrj
475*38fd1498Szrj /* Replace R by 1/R in the given format, if the result is exact. */
476*38fd1498Szrj extern bool exact_real_inverse (format_helper, REAL_VALUE_TYPE *);
477*38fd1498Szrj
478*38fd1498Szrj /* Return true if arithmetic on values in IMODE that were promoted
479*38fd1498Szrj from values in TMODE is equivalent to direct arithmetic on values
480*38fd1498Szrj in TMODE. */
481*38fd1498Szrj bool real_can_shorten_arithmetic (machine_mode, machine_mode);
482*38fd1498Szrj
483*38fd1498Szrj /* In tree.c: wrap up a REAL_VALUE_TYPE in a tree node. */
484*38fd1498Szrj extern tree build_real (tree, REAL_VALUE_TYPE);
485*38fd1498Szrj
486*38fd1498Szrj /* Likewise, but first truncate the value to the type. */
487*38fd1498Szrj extern tree build_real_truncate (tree, REAL_VALUE_TYPE);
488*38fd1498Szrj
489*38fd1498Szrj /* Calculate R as X raised to the integer exponent N in format FMT. */
490*38fd1498Szrj extern bool real_powi (REAL_VALUE_TYPE *, format_helper,
491*38fd1498Szrj const REAL_VALUE_TYPE *, HOST_WIDE_INT);
492*38fd1498Szrj
493*38fd1498Szrj /* Standard round to integer value functions. */
494*38fd1498Szrj extern void real_trunc (REAL_VALUE_TYPE *, format_helper,
495*38fd1498Szrj const REAL_VALUE_TYPE *);
496*38fd1498Szrj extern void real_floor (REAL_VALUE_TYPE *, format_helper,
497*38fd1498Szrj const REAL_VALUE_TYPE *);
498*38fd1498Szrj extern void real_ceil (REAL_VALUE_TYPE *, format_helper,
499*38fd1498Szrj const REAL_VALUE_TYPE *);
500*38fd1498Szrj extern void real_round (REAL_VALUE_TYPE *, format_helper,
501*38fd1498Szrj const REAL_VALUE_TYPE *);
502*38fd1498Szrj
503*38fd1498Szrj /* Set the sign of R to the sign of X. */
504*38fd1498Szrj extern void real_copysign (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *);
505*38fd1498Szrj
506*38fd1498Szrj /* Check whether the real constant value given is an integer. */
507*38fd1498Szrj extern bool real_isinteger (const REAL_VALUE_TYPE *, format_helper);
508*38fd1498Szrj extern bool real_isinteger (const REAL_VALUE_TYPE *, HOST_WIDE_INT *);
509*38fd1498Szrj
510*38fd1498Szrj /* Write into BUF the maximum representable finite floating-point
511*38fd1498Szrj number, (1 - b**-p) * b**emax for a given FP format FMT as a hex
512*38fd1498Szrj float string. BUF must be large enough to contain the result. */
513*38fd1498Szrj extern void get_max_float (const struct real_format *, char *, size_t);
514*38fd1498Szrj
515*38fd1498Szrj #ifndef GENERATOR_FILE
516*38fd1498Szrj /* real related routines. */
517*38fd1498Szrj extern wide_int real_to_integer (const REAL_VALUE_TYPE *, bool *, int);
518*38fd1498Szrj extern void real_from_integer (REAL_VALUE_TYPE *, format_helper,
519*38fd1498Szrj const wide_int_ref &, signop);
520*38fd1498Szrj #endif
521*38fd1498Szrj
522*38fd1498Szrj #endif /* ! GCC_REAL_H */
523