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