real.h revision 50397
1/* Definitions of floating-point access for GNU compiler. 2 Copyright (C) 1989, 1991, 1994, 1996, 1997 Free Software Foundation, Inc. 3 4This file is part of GNU CC. 5 6GNU CC is free software; you can redistribute it and/or modify 7it under the terms of the GNU General Public License as published by 8the Free Software Foundation; either version 2, or (at your option) 9any later version. 10 11GNU CC is distributed in the hope that it will be useful, 12but WITHOUT ANY WARRANTY; without even the implied warranty of 13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14GNU General Public License for more details. 15 16You should have received a copy of the GNU General Public License 17along with GNU CC; see the file COPYING. If not, write to 18the Free Software Foundation, 59 Temple Place - Suite 330, 19Boston, MA 02111-1307, USA. */ 20 21#ifndef REAL_H_INCLUDED 22#define REAL_H_INCLUDED 23 24/* Define codes for all the float formats that we know of. */ 25#define UNKNOWN_FLOAT_FORMAT 0 26#define IEEE_FLOAT_FORMAT 1 27#define VAX_FLOAT_FORMAT 2 28#define IBM_FLOAT_FORMAT 3 29#define C4X_FLOAT_FORMAT 4 30 31/* Default to IEEE float if not specified. Nearly all machines use it. */ 32 33#ifndef TARGET_FLOAT_FORMAT 34#define TARGET_FLOAT_FORMAT IEEE_FLOAT_FORMAT 35#endif 36 37#ifndef HOST_FLOAT_FORMAT 38#define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT 39#endif 40 41#if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT 42#define REAL_INFINITY 43#endif 44 45/* If FLOAT_WORDS_BIG_ENDIAN and HOST_FLOAT_WORDS_BIG_ENDIAN are not defined 46 in the header files, then this implies the word-endianness is the same as 47 for integers. */ 48 49/* This is defined 0 or 1, like WORDS_BIG_ENDIAN. */ 50#ifndef FLOAT_WORDS_BIG_ENDIAN 51#define FLOAT_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN 52#endif 53 54/* This is defined 0 or 1, unlike HOST_WORDS_BIG_ENDIAN. */ 55#ifndef HOST_FLOAT_WORDS_BIG_ENDIAN 56#ifdef HOST_WORDS_BIG_ENDIAN 57#define HOST_FLOAT_WORDS_BIG_ENDIAN 1 58#else 59#define HOST_FLOAT_WORDS_BIG_ENDIAN 0 60#endif 61#endif 62 63/* Defining REAL_ARITHMETIC invokes a floating point emulator 64 that can produce a target machine format differing by more 65 than just endian-ness from the host's format. The emulator 66 is also used to support extended real XFmode. */ 67#ifndef LONG_DOUBLE_TYPE_SIZE 68#define LONG_DOUBLE_TYPE_SIZE 64 69#endif 70#if (LONG_DOUBLE_TYPE_SIZE == 96) || (LONG_DOUBLE_TYPE_SIZE == 128) 71#ifndef REAL_ARITHMETIC 72#define REAL_ARITHMETIC 73#endif 74#endif 75#ifdef REAL_ARITHMETIC 76/* **** Start of software floating point emulator interface macros **** */ 77 78/* Support 80-bit extended real XFmode if LONG_DOUBLE_TYPE_SIZE 79 has been defined to be 96 in the tm.h machine file. */ 80#if (LONG_DOUBLE_TYPE_SIZE == 96) 81#define REAL_IS_NOT_DOUBLE 82#define REAL_ARITHMETIC 83typedef struct { 84 HOST_WIDE_INT r[(11 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))]; 85} realvaluetype; 86#define REAL_VALUE_TYPE realvaluetype 87 88#else /* no XFmode support */ 89 90#if (LONG_DOUBLE_TYPE_SIZE == 128) 91 92#define REAL_IS_NOT_DOUBLE 93#define REAL_ARITHMETIC 94typedef struct { 95 HOST_WIDE_INT r[(19 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))]; 96} realvaluetype; 97#define REAL_VALUE_TYPE realvaluetype 98 99#else /* not TFmode */ 100 101#if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT 102/* If no XFmode support, then a REAL_VALUE_TYPE is 64 bits wide 103 but it is not necessarily a host machine double. */ 104#define REAL_IS_NOT_DOUBLE 105typedef struct { 106 HOST_WIDE_INT r[(7 + sizeof (HOST_WIDE_INT))/(sizeof (HOST_WIDE_INT))]; 107} realvaluetype; 108#define REAL_VALUE_TYPE realvaluetype 109#else 110/* If host and target formats are compatible, then a REAL_VALUE_TYPE 111 is actually a host machine double. */ 112#define REAL_VALUE_TYPE double 113#endif 114 115#endif /* no TFmode support */ 116#endif /* no XFmode support */ 117 118extern int significand_size PROTO((enum machine_mode)); 119 120/* If emulation has been enabled by defining REAL_ARITHMETIC or by 121 setting LONG_DOUBLE_TYPE_SIZE to 96 or 128, then define macros so that 122 they invoke emulator functions. This will succeed only if the machine 123 files have been updated to use these macros in place of any 124 references to host machine `double' or `float' types. */ 125#ifdef REAL_ARITHMETIC 126#undef REAL_ARITHMETIC 127#define REAL_ARITHMETIC(value, code, d1, d2) \ 128 earith (&(value), (code), &(d1), &(d2)) 129 130/* Declare functions in real.c. */ 131extern void earith PROTO((REAL_VALUE_TYPE *, int, 132 REAL_VALUE_TYPE *, REAL_VALUE_TYPE *)); 133extern REAL_VALUE_TYPE etrunci PROTO((REAL_VALUE_TYPE)); 134extern REAL_VALUE_TYPE etruncui PROTO((REAL_VALUE_TYPE)); 135extern REAL_VALUE_TYPE ereal_atof PROTO((char *, enum machine_mode)); 136extern REAL_VALUE_TYPE ereal_negate PROTO((REAL_VALUE_TYPE)); 137extern HOST_WIDE_INT efixi PROTO((REAL_VALUE_TYPE)); 138extern unsigned HOST_WIDE_INT efixui PROTO((REAL_VALUE_TYPE)); 139extern void ereal_from_int PROTO((REAL_VALUE_TYPE *, 140 HOST_WIDE_INT, HOST_WIDE_INT, 141 enum machine_mode)); 142extern void ereal_from_uint PROTO((REAL_VALUE_TYPE *, 143 unsigned HOST_WIDE_INT, 144 unsigned HOST_WIDE_INT, 145 enum machine_mode)); 146extern void ereal_to_int PROTO((HOST_WIDE_INT *, HOST_WIDE_INT *, 147 REAL_VALUE_TYPE)); 148extern REAL_VALUE_TYPE ereal_ldexp PROTO((REAL_VALUE_TYPE, int)); 149 150extern void etartdouble PROTO((REAL_VALUE_TYPE, long *)); 151extern void etarldouble PROTO((REAL_VALUE_TYPE, long *)); 152extern void etardouble PROTO((REAL_VALUE_TYPE, long *)); 153extern long etarsingle PROTO((REAL_VALUE_TYPE)); 154extern void ereal_to_decimal PROTO((REAL_VALUE_TYPE, char *)); 155extern int ereal_cmp PROTO((REAL_VALUE_TYPE, REAL_VALUE_TYPE)); 156extern int ereal_isneg PROTO((REAL_VALUE_TYPE)); 157extern REAL_VALUE_TYPE ereal_unto_float PROTO((long)); 158extern REAL_VALUE_TYPE ereal_unto_double PROTO((long *)); 159extern REAL_VALUE_TYPE ereal_from_float PROTO((HOST_WIDE_INT)); 160extern REAL_VALUE_TYPE ereal_from_double PROTO((HOST_WIDE_INT *)); 161 162#define REAL_VALUES_EQUAL(x, y) (ereal_cmp ((x), (y)) == 0) 163/* true if x < y : */ 164#define REAL_VALUES_LESS(x, y) (ereal_cmp ((x), (y)) == -1) 165#define REAL_VALUE_LDEXP(x, n) ereal_ldexp (x, n) 166 167/* These return REAL_VALUE_TYPE: */ 168#define REAL_VALUE_RNDZINT(x) (etrunci (x)) 169#define REAL_VALUE_UNSIGNED_RNDZINT(x) (etruncui (x)) 170extern REAL_VALUE_TYPE real_value_truncate PROTO ((enum machine_mode, 171 REAL_VALUE_TYPE)); 172#define REAL_VALUE_TRUNCATE(mode, x) real_value_truncate (mode, x) 173 174/* These return HOST_WIDE_INT: */ 175/* Convert a floating-point value to integer, rounding toward zero. */ 176#define REAL_VALUE_FIX(x) (efixi (x)) 177/* Convert a floating-point value to unsigned integer, rounding 178 toward zero. */ 179#define REAL_VALUE_UNSIGNED_FIX(x) (efixui (x)) 180 181#define REAL_VALUE_ATOF ereal_atof 182#define REAL_VALUE_NEGATE ereal_negate 183 184#define REAL_VALUE_MINUS_ZERO(x) \ 185 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 )) 186 187#define REAL_VALUE_TO_INT ereal_to_int 188 189/* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */ 190#define REAL_VALUE_FROM_INT(d, lo, hi, mode) \ 191 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode) 192 193#define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \ 194 ereal_from_uint (&d, lo, hi, mode) 195 196/* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */ 197#if LONG_DOUBLE_TYPE_SIZE == 96 198#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT))) 199#else 200#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT))) 201#endif 202#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT))) 203 204/* IN is a REAL_VALUE_TYPE. OUT is a long. */ 205#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN))) 206 207/* Inverse of REAL_VALUE_TO_TARGET_DOUBLE. */ 208#define REAL_VALUE_UNTO_TARGET_DOUBLE(d) (ereal_unto_double (d)) 209 210/* Inverse of REAL_VALUE_TO_TARGET_SINGLE. */ 211#define REAL_VALUE_UNTO_TARGET_SINGLE(f) (ereal_unto_float (f)) 212 213/* d is an array of HOST_WIDE_INT that holds a double precision 214 value in the target computer's floating point format. */ 215#define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d)) 216 217/* f is a HOST_WIDE_INT containing a single precision target float value. */ 218#define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f)) 219 220/* Conversions to decimal ASCII string. */ 221#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s)) 222 223#endif /* REAL_ARITHMETIC defined */ 224 225/* **** End of software floating point emulator interface macros **** */ 226#else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */ 227 228/* old interface */ 229#ifdef REAL_ARITHMETIC 230/* Defining REAL_IS_NOT_DOUBLE breaks certain initializations 231 when REAL_ARITHMETIC etc. are not defined. */ 232 233/* Now see if the host and target machines use the same format. 234 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing 235 reals as doubles because we have no better way in this cross compiler.) 236 This turns off various optimizations that can happen when we know the 237 compiler's float format matches the target's float format. 238 */ 239#if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT 240#define REAL_IS_NOT_DOUBLE 241#ifndef REAL_VALUE_TYPE 242typedef struct { 243 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)]; 244 } realvaluetype; 245#define REAL_VALUE_TYPE realvaluetype 246#endif /* no REAL_VALUE_TYPE */ 247#endif /* formats differ */ 248#endif /* 0 */ 249 250#endif /* emulator not used */ 251 252/* If we are not cross-compiling, use a `double' to represent the 253 floating-point value. Otherwise, use some other type 254 (probably a struct containing an array of longs). */ 255#ifndef REAL_VALUE_TYPE 256#define REAL_VALUE_TYPE double 257#else 258#define REAL_IS_NOT_DOUBLE 259#endif 260 261#if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT 262 263/* Convert a type `double' value in host format first to a type `float' 264 value in host format and then to a single type `long' value which 265 is the bitwise equivalent of the `float' value. */ 266#ifndef REAL_VALUE_TO_TARGET_SINGLE 267#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \ 268do { \ 269 union { \ 270 float f; \ 271 HOST_WIDE_INT l; \ 272 } u; \ 273 if (sizeof(HOST_WIDE_INT) < sizeof(float)) \ 274 abort(); \ 275 u.l = 0; \ 276 u.f = (IN); \ 277 (OUT) = u.l; \ 278} while (0) 279#endif 280 281/* Convert a type `double' value in host format to a pair of type `long' 282 values which is its bitwise equivalent, but put the two words into 283 proper word order for the target. */ 284#ifndef REAL_VALUE_TO_TARGET_DOUBLE 285#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \ 286do { \ 287 union { \ 288 REAL_VALUE_TYPE f; \ 289 HOST_WIDE_INT l[2]; \ 290 } u; \ 291 if (sizeof(HOST_WIDE_INT) * 2 < sizeof(REAL_VALUE_TYPE)) \ 292 abort(); \ 293 u.l[0] = u.l[1] = 0; \ 294 u.f = (IN); \ 295 if (HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN) \ 296 (OUT)[0] = u.l[0], (OUT)[1] = u.l[1]; \ 297 else \ 298 (OUT)[1] = u.l[0], (OUT)[0] = u.l[1]; \ 299} while (0) 300#endif 301#endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */ 302 303/* In this configuration, double and long double are the same. */ 304#ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE 305#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b) 306#endif 307 308/* Compare two floating-point objects for bitwise identity. 309 This is not the same as comparing for equality on IEEE hosts: 310 -0.0 equals 0.0 but they are not identical, and conversely 311 two NaNs might be identical but they cannot be equal. */ 312#define REAL_VALUES_IDENTICAL(x, y) \ 313 (!bcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE))) 314 315/* Compare two floating-point values for equality. */ 316#ifndef REAL_VALUES_EQUAL 317#define REAL_VALUES_EQUAL(x, y) ((x) == (y)) 318#endif 319 320/* Compare two floating-point values for less than. */ 321#ifndef REAL_VALUES_LESS 322#define REAL_VALUES_LESS(x, y) ((x) < (y)) 323#endif 324 325/* Truncate toward zero to an integer floating-point value. */ 326#ifndef REAL_VALUE_RNDZINT 327#define REAL_VALUE_RNDZINT(x) ((double) ((int) (x))) 328#endif 329 330/* Truncate toward zero to an unsigned integer floating-point value. */ 331#ifndef REAL_VALUE_UNSIGNED_RNDZINT 332#define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x))) 333#endif 334 335/* Convert a floating-point value to integer, rounding toward zero. */ 336#ifndef REAL_VALUE_FIX 337#define REAL_VALUE_FIX(x) ((int) (x)) 338#endif 339 340/* Convert a floating-point value to unsigned integer, rounding 341 toward zero. */ 342#ifndef REAL_VALUE_UNSIGNED_FIX 343#define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x)) 344#endif 345 346/* Scale X by Y powers of 2. */ 347#ifndef REAL_VALUE_LDEXP 348#define REAL_VALUE_LDEXP(x, y) ldexp (x, y) 349extern double ldexp (); 350#endif 351 352/* Convert the string X to a floating-point value. */ 353#ifndef REAL_VALUE_ATOF 354#if 1 355/* Use real.c to convert decimal numbers to binary, ... */ 356REAL_VALUE_TYPE ereal_atof (); 357#define REAL_VALUE_ATOF(x, s) ereal_atof (x, s) 358#else 359/* ... or, if you like the host computer's atof, go ahead and use it: */ 360#define REAL_VALUE_ATOF(x, s) atof (x) 361#if defined (MIPSEL) || defined (MIPSEB) 362/* MIPS compiler can't handle parens around the function name. 363 This problem *does not* appear to be connected with any 364 macro definition for atof. It does not seem there is one. */ 365extern double atof (); 366#else 367extern double (atof) (); 368#endif 369#endif 370#endif 371 372/* Negate the floating-point value X. */ 373#ifndef REAL_VALUE_NEGATE 374#define REAL_VALUE_NEGATE(x) (- (x)) 375#endif 376 377/* Truncate the floating-point value X to mode MODE. This is correct only 378 for the most common case where the host and target have objects of the same 379 size and where `float' is SFmode. */ 380 381/* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */ 382extern REAL_VALUE_TYPE real_value_truncate PROTO((enum machine_mode, REAL_VALUE_TYPE)); 383 384#ifndef REAL_VALUE_TRUNCATE 385#define REAL_VALUE_TRUNCATE(mode, x) \ 386 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \ 387 ? (float) (x) : (x)) 388#endif 389 390/* Determine whether a floating-point value X is infinite. */ 391#ifndef REAL_VALUE_ISINF 392#define REAL_VALUE_ISINF(x) (target_isinf (x)) 393#endif 394 395/* Determine whether a floating-point value X is a NaN. */ 396#ifndef REAL_VALUE_ISNAN 397#define REAL_VALUE_ISNAN(x) (target_isnan (x)) 398#endif 399 400/* Determine whether a floating-point value X is negative. */ 401#ifndef REAL_VALUE_NEGATIVE 402#define REAL_VALUE_NEGATIVE(x) (target_negative (x)) 403#endif 404 405extern int target_isnan PROTO ((REAL_VALUE_TYPE)); 406extern int target_isinf PROTO ((REAL_VALUE_TYPE)); 407extern int target_negative PROTO ((REAL_VALUE_TYPE)); 408 409/* Determine whether a floating-point value X is minus 0. */ 410#ifndef REAL_VALUE_MINUS_ZERO 411#define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x)) 412#endif 413 414/* Constant real values 0, 1, 2, and -1. */ 415 416extern REAL_VALUE_TYPE dconst0; 417extern REAL_VALUE_TYPE dconst1; 418extern REAL_VALUE_TYPE dconst2; 419extern REAL_VALUE_TYPE dconstm1; 420 421/* Union type used for extracting real values from CONST_DOUBLEs 422 or putting them in. */ 423 424union real_extract 425{ 426 REAL_VALUE_TYPE d; 427 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)]; 428}; 429 430/* For a CONST_DOUBLE: 431 The usual two ints that hold the value. 432 For a DImode, that is all there are; 433 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order. 434 For a float, the number of ints varies, 435 and CONST_DOUBLE_LOW is the one that should come first *in memory*. 436 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */ 437#define CONST_DOUBLE_LOW(r) XWINT (r, 2) 438#define CONST_DOUBLE_HIGH(r) XWINT (r, 3) 439 440/* Link for chain of all CONST_DOUBLEs in use in current function. */ 441#define CONST_DOUBLE_CHAIN(r) XEXP (r, 1) 442/* The MEM which represents this CONST_DOUBLE's value in memory, 443 or const0_rtx if no MEM has been made for it yet, 444 or cc0_rtx if it is not on the chain. */ 445#define CONST_DOUBLE_MEM(r) XEXP (r, 0) 446 447/* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */ 448/* Function to return a real value (not a tree node) 449 from a given integer constant. */ 450union tree_node; 451REAL_VALUE_TYPE real_value_from_int_cst PROTO ((union tree_node *, 452 union tree_node *)); 453 454#define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \ 455do { union real_extract u; \ 456 bcopy ((char *) &CONST_DOUBLE_LOW ((from)), (char *) &u, sizeof u); \ 457 to = u.d; } while (0) 458 459/* Return a CONST_DOUBLE with value R and mode M. */ 460 461#define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m) 462extern struct rtx_def *immed_real_const_1 PROTO((REAL_VALUE_TYPE, 463 enum machine_mode)); 464 465 466/* Convert a floating point value `r', that can be interpreted 467 as a host machine float or double, to a decimal ASCII string `s' 468 using printf format string `fmt'. */ 469#ifndef REAL_VALUE_TO_DECIMAL 470#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r)) 471#endif 472 473/* Replace R by 1/R in the given machine mode, if the result is exact. */ 474extern int exact_real_inverse PROTO((enum machine_mode, REAL_VALUE_TYPE *)); 475 476extern void debug_real PROTO ((REAL_VALUE_TYPE)); 477 478/* In varasm.c */ 479extern void assemble_real PROTO ((REAL_VALUE_TYPE, 480 enum machine_mode)); 481#endif /* Not REAL_H_INCLUDED */ 482