1*c87b03e5Sespie /* Definitions of floating-point access for GNU compiler. 2*c87b03e5Sespie Copyright (C) 1989, 1991, 1994, 1996, 1997, 1998, 3*c87b03e5Sespie 1999, 2000, 2002 Free Software Foundation, Inc. 4*c87b03e5Sespie 5*c87b03e5Sespie This file is part of GCC. 6*c87b03e5Sespie 7*c87b03e5Sespie GCC is free software; you can redistribute it and/or modify it under 8*c87b03e5Sespie the terms of the GNU General Public License as published by the Free 9*c87b03e5Sespie Software Foundation; either version 2, or (at your option) any later 10*c87b03e5Sespie version. 11*c87b03e5Sespie 12*c87b03e5Sespie GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13*c87b03e5Sespie WARRANTY; without even the implied warranty of MERCHANTABILITY or 14*c87b03e5Sespie FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15*c87b03e5Sespie for more details. 16*c87b03e5Sespie 17*c87b03e5Sespie You should have received a copy of the GNU General Public License 18*c87b03e5Sespie along with GCC; see the file COPYING. If not, write to the Free 19*c87b03e5Sespie Software Foundation, 59 Temple Place - Suite 330, Boston, MA 20*c87b03e5Sespie 02111-1307, USA. */ 21*c87b03e5Sespie 22*c87b03e5Sespie #ifndef GCC_REAL_H 23*c87b03e5Sespie #define GCC_REAL_H 24*c87b03e5Sespie 25*c87b03e5Sespie #include "machmode.h" 26*c87b03e5Sespie 27*c87b03e5Sespie /* An expanded form of the represented number. */ 28*c87b03e5Sespie 29*c87b03e5Sespie /* Enumerate the special cases of numbers that we encounter. */ 30*c87b03e5Sespie enum real_value_class { 31*c87b03e5Sespie rvc_zero, 32*c87b03e5Sespie rvc_normal, 33*c87b03e5Sespie rvc_inf, 34*c87b03e5Sespie rvc_nan 35*c87b03e5Sespie }; 36*c87b03e5Sespie 37*c87b03e5Sespie #define SIGNIFICAND_BITS (128 + HOST_BITS_PER_LONG) 38*c87b03e5Sespie #define EXP_BITS (32 - 3) 39*c87b03e5Sespie #define MAX_EXP ((1 << (EXP_BITS - 1)) - 1) 40*c87b03e5Sespie #define SIGSZ (SIGNIFICAND_BITS / HOST_BITS_PER_LONG) 41*c87b03e5Sespie #define SIG_MSB ((unsigned long)1 << (HOST_BITS_PER_LONG - 1)) 42*c87b03e5Sespie 43*c87b03e5Sespie struct real_value GTY(()) 44*c87b03e5Sespie { 45*c87b03e5Sespie ENUM_BITFIELD (real_value_class) class : 2; 46*c87b03e5Sespie unsigned int sign : 1; 47*c87b03e5Sespie signed int exp : EXP_BITS; 48*c87b03e5Sespie unsigned long sig[SIGSZ]; 49*c87b03e5Sespie }; 50*c87b03e5Sespie 51*c87b03e5Sespie /* Various headers condition prototypes on #ifdef REAL_VALUE_TYPE, so it 52*c87b03e5Sespie needs to be a macro. We do need to continue to have a structure tag 53*c87b03e5Sespie so that other headers can forward declare it. */ 54*c87b03e5Sespie #define REAL_VALUE_TYPE struct real_value 55*c87b03e5Sespie 56*c87b03e5Sespie /* We store a REAL_VALUE_TYPE into an rtx, and we do this by putting it in 57*c87b03e5Sespie consecutive "w" slots. Moreover, we've got to compute the number of "w" 58*c87b03e5Sespie slots at preprocessor time, which means we can't use sizeof. Guess. */ 59*c87b03e5Sespie 60*c87b03e5Sespie #define REAL_VALUE_TYPE_SIZE (SIGNIFICAND_BITS + 32) 61*c87b03e5Sespie #define REAL_WIDTH \ 62*c87b03e5Sespie (REAL_VALUE_TYPE_SIZE/HOST_BITS_PER_WIDE_INT \ 63*c87b03e5Sespie + (REAL_VALUE_TYPE_SIZE%HOST_BITS_PER_WIDE_INT ? 1 : 0)) /* round up */ 64*c87b03e5Sespie 65*c87b03e5Sespie /* Verify the guess. */ 66*c87b03e5Sespie extern char test_real_width 67*c87b03e5Sespie [sizeof(REAL_VALUE_TYPE) <= REAL_WIDTH*sizeof(HOST_WIDE_INT) ? 1 : -1]; 68*c87b03e5Sespie 69*c87b03e5Sespie /* Calculate the format for CONST_DOUBLE. We need as many slots as 70*c87b03e5Sespie are necessary to overlay a REAL_VALUE_TYPE on them. This could be 71*c87b03e5Sespie as many as four (32-bit HOST_WIDE_INT, 128-bit REAL_VALUE_TYPE). 72*c87b03e5Sespie 73*c87b03e5Sespie A number of places assume that there are always at least two 'w' 74*c87b03e5Sespie slots in a CONST_DOUBLE, so we provide them even if one would suffice. */ 75*c87b03e5Sespie 76*c87b03e5Sespie #if REAL_WIDTH == 1 77*c87b03e5Sespie # define CONST_DOUBLE_FORMAT "ww" 78*c87b03e5Sespie #else 79*c87b03e5Sespie # if REAL_WIDTH == 2 80*c87b03e5Sespie # define CONST_DOUBLE_FORMAT "ww" 81*c87b03e5Sespie # else 82*c87b03e5Sespie # if REAL_WIDTH == 3 83*c87b03e5Sespie # define CONST_DOUBLE_FORMAT "www" 84*c87b03e5Sespie # else 85*c87b03e5Sespie # if REAL_WIDTH == 4 86*c87b03e5Sespie # define CONST_DOUBLE_FORMAT "wwww" 87*c87b03e5Sespie # else 88*c87b03e5Sespie # if REAL_WIDTH == 5 89*c87b03e5Sespie # define CONST_DOUBLE_FORMAT "wwwww" 90*c87b03e5Sespie # else 91*c87b03e5Sespie # if REAL_WIDTH == 6 92*c87b03e5Sespie # define CONST_DOUBLE_FORMAT "wwwwww" 93*c87b03e5Sespie # else 94*c87b03e5Sespie #error "REAL_WIDTH > 6 not supported" 95*c87b03e5Sespie # endif 96*c87b03e5Sespie # endif 97*c87b03e5Sespie # endif 98*c87b03e5Sespie # endif 99*c87b03e5Sespie # endif 100*c87b03e5Sespie #endif 101*c87b03e5Sespie 102*c87b03e5Sespie 103*c87b03e5Sespie /* Describes the properties of the specific target format in use. */ 104*c87b03e5Sespie struct real_format 105*c87b03e5Sespie { 106*c87b03e5Sespie /* Move to and from the target bytes. */ 107*c87b03e5Sespie void (*encode) PARAMS ((const struct real_format *, long *, 108*c87b03e5Sespie const REAL_VALUE_TYPE *)); 109*c87b03e5Sespie void (*decode) PARAMS ((const struct real_format *, REAL_VALUE_TYPE *, 110*c87b03e5Sespie const long *)); 111*c87b03e5Sespie 112*c87b03e5Sespie /* The radix of the exponent and digits of the significand. */ 113*c87b03e5Sespie int b; 114*c87b03e5Sespie 115*c87b03e5Sespie /* log2(b). */ 116*c87b03e5Sespie int log2_b; 117*c87b03e5Sespie 118*c87b03e5Sespie /* Size of the significand in digits of radix B. */ 119*c87b03e5Sespie int p; 120*c87b03e5Sespie 121*c87b03e5Sespie /* The minimum negative integer, x, such that b**(x-1) is normalized. */ 122*c87b03e5Sespie int emin; 123*c87b03e5Sespie 124*c87b03e5Sespie /* The maximum integer, x, such that b**(x-1) is representable. */ 125*c87b03e5Sespie int emax; 126*c87b03e5Sespie 127*c87b03e5Sespie /* Properties of the format. */ 128*c87b03e5Sespie bool has_nans; 129*c87b03e5Sespie bool has_inf; 130*c87b03e5Sespie bool has_denorm; 131*c87b03e5Sespie bool has_signed_zero; 132*c87b03e5Sespie bool qnan_msb_set; 133*c87b03e5Sespie }; 134*c87b03e5Sespie 135*c87b03e5Sespie 136*c87b03e5Sespie /* The target format used for each floating floating point mode. 137*c87b03e5Sespie Indexed by MODE - QFmode. */ 138*c87b03e5Sespie extern const struct real_format *real_format_for_mode[TFmode - QFmode + 1]; 139*c87b03e5Sespie 140*c87b03e5Sespie 141*c87b03e5Sespie /* Declare functions in real.c. */ 142*c87b03e5Sespie 143*c87b03e5Sespie /* Binary or unary arithmetic on tree_code. */ 144*c87b03e5Sespie extern void real_arithmetic PARAMS ((REAL_VALUE_TYPE *, int, 145*c87b03e5Sespie const REAL_VALUE_TYPE *, 146*c87b03e5Sespie const REAL_VALUE_TYPE *)); 147*c87b03e5Sespie 148*c87b03e5Sespie /* Compare reals by tree_code. */ 149*c87b03e5Sespie extern bool real_compare PARAMS ((int, const REAL_VALUE_TYPE *, 150*c87b03e5Sespie const REAL_VALUE_TYPE *)); 151*c87b03e5Sespie 152*c87b03e5Sespie /* Determine whether a floating-point value X is infinite. */ 153*c87b03e5Sespie extern bool real_isinf PARAMS ((const REAL_VALUE_TYPE *)); 154*c87b03e5Sespie 155*c87b03e5Sespie /* Determine whether a floating-point value X is a NaN. */ 156*c87b03e5Sespie extern bool real_isnan PARAMS ((const REAL_VALUE_TYPE *)); 157*c87b03e5Sespie 158*c87b03e5Sespie /* Determine whether a floating-point value X is negative. */ 159*c87b03e5Sespie extern bool real_isneg PARAMS ((const REAL_VALUE_TYPE *)); 160*c87b03e5Sespie 161*c87b03e5Sespie /* Determine whether a floating-point value X is minus zero. */ 162*c87b03e5Sespie extern bool real_isnegzero PARAMS ((const REAL_VALUE_TYPE *)); 163*c87b03e5Sespie 164*c87b03e5Sespie /* Compare two floating-point objects for bitwise identity. */ 165*c87b03e5Sespie extern bool real_identical PARAMS ((const REAL_VALUE_TYPE *, 166*c87b03e5Sespie const REAL_VALUE_TYPE *)); 167*c87b03e5Sespie 168*c87b03e5Sespie /* Extend or truncate to a new mode. */ 169*c87b03e5Sespie extern void real_convert PARAMS ((REAL_VALUE_TYPE *, 170*c87b03e5Sespie enum machine_mode, 171*c87b03e5Sespie const REAL_VALUE_TYPE *)); 172*c87b03e5Sespie 173*c87b03e5Sespie /* Return true if truncating to NEW is exact. */ 174*c87b03e5Sespie extern bool exact_real_truncate PARAMS ((enum machine_mode, 175*c87b03e5Sespie const REAL_VALUE_TYPE *)); 176*c87b03e5Sespie 177*c87b03e5Sespie /* Render R as a decimal floating point constant. */ 178*c87b03e5Sespie extern void real_to_decimal PARAMS ((char *, const REAL_VALUE_TYPE *, 179*c87b03e5Sespie size_t, size_t, int)); 180*c87b03e5Sespie 181*c87b03e5Sespie /* Render R as a hexadecimal floating point constant. */ 182*c87b03e5Sespie extern void real_to_hexadecimal PARAMS ((char *, const REAL_VALUE_TYPE *, 183*c87b03e5Sespie size_t, size_t, int)); 184*c87b03e5Sespie 185*c87b03e5Sespie /* Render R as an integer. */ 186*c87b03e5Sespie extern HOST_WIDE_INT real_to_integer PARAMS ((const REAL_VALUE_TYPE *)); 187*c87b03e5Sespie extern void real_to_integer2 PARAMS ((HOST_WIDE_INT *, HOST_WIDE_INT *, 188*c87b03e5Sespie const REAL_VALUE_TYPE *)); 189*c87b03e5Sespie 190*c87b03e5Sespie /* Initialize R from a decimal or hexadecimal string. */ 191*c87b03e5Sespie extern void real_from_string PARAMS ((REAL_VALUE_TYPE *, const char *)); 192*c87b03e5Sespie 193*c87b03e5Sespie /* Initialize R from an integer pair HIGH/LOW. */ 194*c87b03e5Sespie extern void real_from_integer PARAMS ((REAL_VALUE_TYPE *, 195*c87b03e5Sespie enum machine_mode, 196*c87b03e5Sespie unsigned HOST_WIDE_INT, 197*c87b03e5Sespie HOST_WIDE_INT, int)); 198*c87b03e5Sespie 199*c87b03e5Sespie extern long real_to_target_fmt PARAMS ((long *, const REAL_VALUE_TYPE *, 200*c87b03e5Sespie const struct real_format *)); 201*c87b03e5Sespie extern long real_to_target PARAMS ((long *, const REAL_VALUE_TYPE *, 202*c87b03e5Sespie enum machine_mode)); 203*c87b03e5Sespie 204*c87b03e5Sespie extern void real_from_target_fmt PARAMS ((REAL_VALUE_TYPE *, const long *, 205*c87b03e5Sespie const struct real_format *)); 206*c87b03e5Sespie extern void real_from_target PARAMS ((REAL_VALUE_TYPE *, const long *, 207*c87b03e5Sespie enum machine_mode)); 208*c87b03e5Sespie 209*c87b03e5Sespie extern void real_inf PARAMS ((REAL_VALUE_TYPE *)); 210*c87b03e5Sespie 211*c87b03e5Sespie extern bool real_nan PARAMS ((REAL_VALUE_TYPE *, const char *, 212*c87b03e5Sespie int, enum machine_mode)); 213*c87b03e5Sespie 214*c87b03e5Sespie extern void real_2expN PARAMS ((REAL_VALUE_TYPE *, int)); 215*c87b03e5Sespie 216*c87b03e5Sespie extern unsigned int real_hash PARAMS ((const REAL_VALUE_TYPE *)); 217*c87b03e5Sespie 218*c87b03e5Sespie 219*c87b03e5Sespie /* Target formats defined in real.c. */ 220*c87b03e5Sespie extern const struct real_format ieee_single_format; 221*c87b03e5Sespie extern const struct real_format ieee_double_format; 222*c87b03e5Sespie extern const struct real_format ieee_extended_motorola_format; 223*c87b03e5Sespie extern const struct real_format ieee_extended_intel_96_format; 224*c87b03e5Sespie extern const struct real_format ieee_extended_intel_96_round_53_format; 225*c87b03e5Sespie extern const struct real_format ieee_extended_intel_128_format; 226*c87b03e5Sespie extern const struct real_format ibm_extended_format; 227*c87b03e5Sespie extern const struct real_format ieee_quad_format; 228*c87b03e5Sespie extern const struct real_format vax_f_format; 229*c87b03e5Sespie extern const struct real_format vax_d_format; 230*c87b03e5Sespie extern const struct real_format vax_g_format; 231*c87b03e5Sespie extern const struct real_format i370_single_format; 232*c87b03e5Sespie extern const struct real_format i370_double_format; 233*c87b03e5Sespie extern const struct real_format c4x_single_format; 234*c87b03e5Sespie extern const struct real_format c4x_extended_format; 235*c87b03e5Sespie extern const struct real_format real_internal_format; 236*c87b03e5Sespie 237*c87b03e5Sespie 238*c87b03e5Sespie /* ====================================================================== */ 239*c87b03e5Sespie /* Crap. */ 240*c87b03e5Sespie 241*c87b03e5Sespie #define REAL_ARITHMETIC(value, code, d1, d2) \ 242*c87b03e5Sespie real_arithmetic (&(value), code, &(d1), &(d2)) 243*c87b03e5Sespie 244*c87b03e5Sespie #define REAL_VALUES_IDENTICAL(x, y) real_identical (&(x), &(y)) 245*c87b03e5Sespie #define REAL_VALUES_EQUAL(x, y) real_compare (EQ_EXPR, &(x), &(y)) 246*c87b03e5Sespie #define REAL_VALUES_LESS(x, y) real_compare (LT_EXPR, &(x), &(y)) 247*c87b03e5Sespie 248*c87b03e5Sespie /* Determine whether a floating-point value X is infinite. */ 249*c87b03e5Sespie #define REAL_VALUE_ISINF(x) real_isinf (&(x)) 250*c87b03e5Sespie 251*c87b03e5Sespie /* Determine whether a floating-point value X is a NaN. */ 252*c87b03e5Sespie #define REAL_VALUE_ISNAN(x) real_isnan (&(x)) 253*c87b03e5Sespie 254*c87b03e5Sespie /* Determine whether a floating-point value X is negative. */ 255*c87b03e5Sespie #define REAL_VALUE_NEGATIVE(x) real_isneg (&(x)) 256*c87b03e5Sespie 257*c87b03e5Sespie /* Determine whether a floating-point value X is minus zero. */ 258*c87b03e5Sespie #define REAL_VALUE_MINUS_ZERO(x) real_isnegzero (&(x)) 259*c87b03e5Sespie 260*c87b03e5Sespie /* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */ 261*c87b03e5Sespie #define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) \ 262*c87b03e5Sespie real_to_target (OUT, &(IN), \ 263*c87b03e5Sespie mode_for_size (LONG_DOUBLE_TYPE_SIZE, MODE_FLOAT, 0)) 264*c87b03e5Sespie 265*c87b03e5Sespie #define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \ 266*c87b03e5Sespie real_to_target (OUT, &(IN), mode_for_size (64, MODE_FLOAT, 0)) 267*c87b03e5Sespie 268*c87b03e5Sespie /* IN is a REAL_VALUE_TYPE. OUT is a long. */ 269*c87b03e5Sespie #define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \ 270*c87b03e5Sespie ((OUT) = real_to_target (NULL, &(IN), mode_for_size (32, MODE_FLOAT, 0))) 271*c87b03e5Sespie 272*c87b03e5Sespie #define REAL_VALUE_FROM_INT(r, lo, hi, mode) \ 273*c87b03e5Sespie real_from_integer (&(r), mode, lo, hi, 0) 274*c87b03e5Sespie 275*c87b03e5Sespie #define REAL_VALUE_FROM_UNSIGNED_INT(r, lo, hi, mode) \ 276*c87b03e5Sespie real_from_integer (&(r), mode, lo, hi, 1) 277*c87b03e5Sespie 278*c87b03e5Sespie extern REAL_VALUE_TYPE real_value_truncate PARAMS ((enum machine_mode, 279*c87b03e5Sespie REAL_VALUE_TYPE)); 280*c87b03e5Sespie 281*c87b03e5Sespie #define REAL_VALUE_TO_INT(plow, phigh, r) \ 282*c87b03e5Sespie real_to_integer2 (plow, phigh, &(r)) 283*c87b03e5Sespie 284*c87b03e5Sespie extern REAL_VALUE_TYPE real_arithmetic2 PARAMS ((int, const REAL_VALUE_TYPE *, 285*c87b03e5Sespie const REAL_VALUE_TYPE *)); 286*c87b03e5Sespie 287*c87b03e5Sespie #define REAL_VALUE_NEGATE(X) \ 288*c87b03e5Sespie real_arithmetic2 (NEGATE_EXPR, &(X), NULL) 289*c87b03e5Sespie 290*c87b03e5Sespie #define REAL_VALUE_ABS(X) \ 291*c87b03e5Sespie real_arithmetic2 (ABS_EXPR, &(X), NULL) 292*c87b03e5Sespie 293*c87b03e5Sespie extern int significand_size PARAMS ((enum machine_mode)); 294*c87b03e5Sespie 295*c87b03e5Sespie extern REAL_VALUE_TYPE real_from_string2 PARAMS ((const char *, 296*c87b03e5Sespie enum machine_mode)); 297*c87b03e5Sespie 298*c87b03e5Sespie #define REAL_VALUE_ATOF(s, m) \ 299*c87b03e5Sespie real_from_string2 (s, m) 300*c87b03e5Sespie 301*c87b03e5Sespie #define CONST_DOUBLE_ATOF(s, m) \ 302*c87b03e5Sespie CONST_DOUBLE_FROM_REAL_VALUE (real_from_string2 (s, m), m) 303*c87b03e5Sespie 304*c87b03e5Sespie #define REAL_VALUE_FIX(r) \ 305*c87b03e5Sespie real_to_integer (&(r)) 306*c87b03e5Sespie 307*c87b03e5Sespie /* ??? Not quite right. */ 308*c87b03e5Sespie #define REAL_VALUE_UNSIGNED_FIX(r) \ 309*c87b03e5Sespie real_to_integer (&(r)) 310*c87b03e5Sespie 311*c87b03e5Sespie /* ??? These were added for Paranoia support. */ 312*c87b03e5Sespie 313*c87b03e5Sespie /* Return floor log2(R). */ 314*c87b03e5Sespie extern int real_exponent PARAMS ((const REAL_VALUE_TYPE *)); 315*c87b03e5Sespie 316*c87b03e5Sespie /* R = A * 2**EXP. */ 317*c87b03e5Sespie extern void real_ldexp PARAMS ((REAL_VALUE_TYPE *, 318*c87b03e5Sespie const REAL_VALUE_TYPE *, int)); 319*c87b03e5Sespie 320*c87b03e5Sespie /* **** End of software floating point emulator interface macros **** */ 321*c87b03e5Sespie 322*c87b03e5Sespie /* Constant real values 0, 1, 2, and -1. */ 323*c87b03e5Sespie 324*c87b03e5Sespie extern REAL_VALUE_TYPE dconst0; 325*c87b03e5Sespie extern REAL_VALUE_TYPE dconst1; 326*c87b03e5Sespie extern REAL_VALUE_TYPE dconst2; 327*c87b03e5Sespie extern REAL_VALUE_TYPE dconstm1; 328*c87b03e5Sespie 329*c87b03e5Sespie /* Function to return a real value (not a tree node) 330*c87b03e5Sespie from a given integer constant. */ 331*c87b03e5Sespie REAL_VALUE_TYPE real_value_from_int_cst PARAMS ((union tree_node *, 332*c87b03e5Sespie union tree_node *)); 333*c87b03e5Sespie 334*c87b03e5Sespie /* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */ 335*c87b03e5Sespie #define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \ 336*c87b03e5Sespie memcpy (&(to), &CONST_DOUBLE_LOW ((from)), sizeof (REAL_VALUE_TYPE)) 337*c87b03e5Sespie 338*c87b03e5Sespie /* Return a CONST_DOUBLE with value R and mode M. */ 339*c87b03e5Sespie #define CONST_DOUBLE_FROM_REAL_VALUE(r, m) \ 340*c87b03e5Sespie const_double_from_real_value (r, m) 341*c87b03e5Sespie extern rtx const_double_from_real_value PARAMS ((REAL_VALUE_TYPE, 342*c87b03e5Sespie enum machine_mode)); 343*c87b03e5Sespie 344*c87b03e5Sespie /* Replace R by 1/R in the given machine mode, if the result is exact. */ 345*c87b03e5Sespie extern bool exact_real_inverse PARAMS ((enum machine_mode, REAL_VALUE_TYPE *)); 346*c87b03e5Sespie 347*c87b03e5Sespie /* In tree.c: wrap up a REAL_VALUE_TYPE in a tree node. */ 348*c87b03e5Sespie extern tree build_real PARAMS ((tree, REAL_VALUE_TYPE)); 349*c87b03e5Sespie 350*c87b03e5Sespie 351*c87b03e5Sespie #endif /* ! GCC_REAL_H */ 352