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