1/* Definitions of floating-point access for GNU compiler. 2 Copyright (C) 1989, 91, 94, 96-98, 1999 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((const 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/* Convert ASCII string S to floating point in mode M. 182 Decimal input uses ATOF. Hexadecimal uses HTOF. */ 183#define REAL_VALUE_ATOF ereal_atof 184#define REAL_VALUE_HTOF ereal_atof 185 186#define REAL_VALUE_NEGATE ereal_negate 187 188#define REAL_VALUE_MINUS_ZERO(x) \ 189 ((ereal_cmp (x, dconst0) == 0) && (ereal_isneg (x) != 0 )) 190 191#define REAL_VALUE_TO_INT ereal_to_int 192 193/* Here the cast to HOST_WIDE_INT sign-extends arguments such as ~0. */ 194#define REAL_VALUE_FROM_INT(d, lo, hi, mode) \ 195 ereal_from_int (&d, (HOST_WIDE_INT) (lo), (HOST_WIDE_INT) (hi), mode) 196 197#define REAL_VALUE_FROM_UNSIGNED_INT(d, lo, hi, mode) \ 198 ereal_from_uint (&d, lo, hi, mode) 199 200/* IN is a REAL_VALUE_TYPE. OUT is an array of longs. */ 201#if LONG_DOUBLE_TYPE_SIZE == 96 202#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etarldouble ((IN), (OUT))) 203#else 204#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(IN, OUT) (etartdouble ((IN), (OUT))) 205#endif 206#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) (etardouble ((IN), (OUT))) 207 208/* IN is a REAL_VALUE_TYPE. OUT is a long. */ 209#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) ((OUT) = etarsingle ((IN))) 210 211/* Inverse of REAL_VALUE_TO_TARGET_DOUBLE. */ 212#define REAL_VALUE_UNTO_TARGET_DOUBLE(d) (ereal_unto_double (d)) 213 214/* Inverse of REAL_VALUE_TO_TARGET_SINGLE. */ 215#define REAL_VALUE_UNTO_TARGET_SINGLE(f) (ereal_unto_float (f)) 216 217/* d is an array of HOST_WIDE_INT that holds a double precision 218 value in the target computer's floating point format. */ 219#define REAL_VALUE_FROM_TARGET_DOUBLE(d) (ereal_from_double (d)) 220 221/* f is a HOST_WIDE_INT containing a single precision target float value. */ 222#define REAL_VALUE_FROM_TARGET_SINGLE(f) (ereal_from_float (f)) 223 224/* Conversions to decimal ASCII string. */ 225#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (ereal_to_decimal (r, s)) 226 227#endif /* REAL_ARITHMETIC defined */ 228 229/* **** End of software floating point emulator interface macros **** */ 230#else /* No XFmode or TFmode and REAL_ARITHMETIC not defined */ 231 232/* old interface */ 233#ifdef REAL_ARITHMETIC 234/* Defining REAL_IS_NOT_DOUBLE breaks certain initializations 235 when REAL_ARITHMETIC etc. are not defined. */ 236 237/* Now see if the host and target machines use the same format. 238 If not, define REAL_IS_NOT_DOUBLE (even if we end up representing 239 reals as doubles because we have no better way in this cross compiler.) 240 This turns off various optimizations that can happen when we know the 241 compiler's float format matches the target's float format. 242 */ 243#if HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT 244#define REAL_IS_NOT_DOUBLE 245#ifndef REAL_VALUE_TYPE 246typedef struct { 247 HOST_WIDE_INT r[sizeof (double)/sizeof (HOST_WIDE_INT)]; 248 } realvaluetype; 249#define REAL_VALUE_TYPE realvaluetype 250#endif /* no REAL_VALUE_TYPE */ 251#endif /* formats differ */ 252#endif /* 0 */ 253 254#endif /* emulator not used */ 255 256/* If we are not cross-compiling, use a `double' to represent the 257 floating-point value. Otherwise, use some other type 258 (probably a struct containing an array of longs). */ 259#ifndef REAL_VALUE_TYPE 260#define REAL_VALUE_TYPE double 261#else 262#define REAL_IS_NOT_DOUBLE 263#endif 264 265#if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT 266 267/* Convert a type `double' value in host format first to a type `float' 268 value in host format and then to a single type `long' value which 269 is the bitwise equivalent of the `float' value. */ 270#ifndef REAL_VALUE_TO_TARGET_SINGLE 271#define REAL_VALUE_TO_TARGET_SINGLE(IN, OUT) \ 272do { \ 273 union { \ 274 float f; \ 275 HOST_WIDE_INT l; \ 276 } u; \ 277 if (sizeof(HOST_WIDE_INT) < sizeof(float)) \ 278 abort(); \ 279 u.l = 0; \ 280 u.f = (IN); \ 281 (OUT) = u.l; \ 282} while (0) 283#endif 284 285/* Convert a type `double' value in host format to a pair of type `long' 286 values which is its bitwise equivalent, but put the two words into 287 proper word order for the target. */ 288#ifndef REAL_VALUE_TO_TARGET_DOUBLE 289#define REAL_VALUE_TO_TARGET_DOUBLE(IN, OUT) \ 290do { \ 291 union { \ 292 REAL_VALUE_TYPE f; \ 293 HOST_WIDE_INT l[2]; \ 294 } u; \ 295 if (sizeof(HOST_WIDE_INT) * 2 < sizeof(REAL_VALUE_TYPE)) \ 296 abort(); \ 297 u.l[0] = u.l[1] = 0; \ 298 u.f = (IN); \ 299 if (HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN) \ 300 (OUT)[0] = u.l[0], (OUT)[1] = u.l[1]; \ 301 else \ 302 (OUT)[1] = u.l[0], (OUT)[0] = u.l[1]; \ 303} while (0) 304#endif 305#endif /* HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT */ 306 307/* In this configuration, double and long double are the same. */ 308#ifndef REAL_VALUE_TO_TARGET_LONG_DOUBLE 309#define REAL_VALUE_TO_TARGET_LONG_DOUBLE(a, b) REAL_VALUE_TO_TARGET_DOUBLE (a, b) 310#endif 311 312/* Compare two floating-point objects for bitwise identity. 313 This is not the same as comparing for equality on IEEE hosts: 314 -0.0 equals 0.0 but they are not identical, and conversely 315 two NaNs might be identical but they cannot be equal. */ 316#define REAL_VALUES_IDENTICAL(x, y) \ 317 (!bcmp ((char *) &(x), (char *) &(y), sizeof (REAL_VALUE_TYPE))) 318 319/* Compare two floating-point values for equality. */ 320#ifndef REAL_VALUES_EQUAL 321#define REAL_VALUES_EQUAL(x, y) ((x) == (y)) 322#endif 323 324/* Compare two floating-point values for less than. */ 325#ifndef REAL_VALUES_LESS 326#define REAL_VALUES_LESS(x, y) ((x) < (y)) 327#endif 328 329/* Truncate toward zero to an integer floating-point value. */ 330#ifndef REAL_VALUE_RNDZINT 331#define REAL_VALUE_RNDZINT(x) ((double) ((int) (x))) 332#endif 333 334/* Truncate toward zero to an unsigned integer floating-point value. */ 335#ifndef REAL_VALUE_UNSIGNED_RNDZINT 336#define REAL_VALUE_UNSIGNED_RNDZINT(x) ((double) ((unsigned int) (x))) 337#endif 338 339/* Convert a floating-point value to integer, rounding toward zero. */ 340#ifndef REAL_VALUE_FIX 341#define REAL_VALUE_FIX(x) ((int) (x)) 342#endif 343 344/* Convert a floating-point value to unsigned integer, rounding 345 toward zero. */ 346#ifndef REAL_VALUE_UNSIGNED_FIX 347#define REAL_VALUE_UNSIGNED_FIX(x) ((unsigned int) (x)) 348#endif 349 350/* Scale X by Y powers of 2. */ 351#ifndef REAL_VALUE_LDEXP 352#define REAL_VALUE_LDEXP(x, y) ldexp (x, y) 353extern double ldexp (); 354#endif 355 356/* Convert the string X to a floating-point value. */ 357#ifndef REAL_VALUE_ATOF 358#if 1 359/* Use real.c to convert decimal numbers to binary, ... */ 360REAL_VALUE_TYPE ereal_atof (); 361#define REAL_VALUE_ATOF(x, s) ereal_atof (x, s) 362/* Could use ereal_atof here for hexadecimal floats too, but real_hex_to_f 363 is OK and it uses faster native fp arithmetic. */ 364/* #define REAL_VALUE_HTOF(x, s) ereal_atof (x, s) */ 365#else 366/* ... or, if you like the host computer's atof, go ahead and use it: */ 367#define REAL_VALUE_ATOF(x, s) atof (x) 368#if defined (MIPSEL) || defined (MIPSEB) 369/* MIPS compiler can't handle parens around the function name. 370 This problem *does not* appear to be connected with any 371 macro definition for atof. It does not seem there is one. */ 372extern double atof (); 373#else 374extern double (atof) (); 375#endif 376#endif 377#endif 378 379/* Hexadecimal floating constant input for use with host computer's 380 fp arithmetic. */ 381#ifndef REAL_VALUE_HTOF 382extern REAL_VALUE_TYPE real_hex_to_f PROTO((char *, enum machine_mode)); 383#define REAL_VALUE_HTOF(s,m) real_hex_to_f(s,m) 384#endif 385 386/* Negate the floating-point value X. */ 387#ifndef REAL_VALUE_NEGATE 388#define REAL_VALUE_NEGATE(x) (- (x)) 389#endif 390 391/* Truncate the floating-point value X to mode MODE. This is correct only 392 for the most common case where the host and target have objects of the same 393 size and where `float' is SFmode. */ 394 395/* Don't use REAL_VALUE_TRUNCATE directly--always call real_value_truncate. */ 396extern REAL_VALUE_TYPE real_value_truncate PROTO((enum machine_mode, REAL_VALUE_TYPE)); 397 398#ifndef REAL_VALUE_TRUNCATE 399#define REAL_VALUE_TRUNCATE(mode, x) \ 400 (GET_MODE_BITSIZE (mode) == sizeof (float) * HOST_BITS_PER_CHAR \ 401 ? (float) (x) : (x)) 402#endif 403 404/* Determine whether a floating-point value X is infinite. */ 405#ifndef REAL_VALUE_ISINF 406#define REAL_VALUE_ISINF(x) (target_isinf (x)) 407#endif 408 409/* Determine whether a floating-point value X is a NaN. */ 410#ifndef REAL_VALUE_ISNAN 411#define REAL_VALUE_ISNAN(x) (target_isnan (x)) 412#endif 413 414/* Determine whether a floating-point value X is negative. */ 415#ifndef REAL_VALUE_NEGATIVE 416#define REAL_VALUE_NEGATIVE(x) (target_negative (x)) 417#endif 418 419extern int target_isnan PROTO ((REAL_VALUE_TYPE)); 420extern int target_isinf PROTO ((REAL_VALUE_TYPE)); 421extern int target_negative PROTO ((REAL_VALUE_TYPE)); 422 423/* Determine whether a floating-point value X is minus 0. */ 424#ifndef REAL_VALUE_MINUS_ZERO 425#define REAL_VALUE_MINUS_ZERO(x) ((x) == 0 && REAL_VALUE_NEGATIVE (x)) 426#endif 427 428/* Constant real values 0, 1, 2, and -1. */ 429 430extern REAL_VALUE_TYPE dconst0; 431extern REAL_VALUE_TYPE dconst1; 432extern REAL_VALUE_TYPE dconst2; 433extern REAL_VALUE_TYPE dconstm1; 434 435/* Union type used for extracting real values from CONST_DOUBLEs 436 or putting them in. */ 437 438union real_extract 439{ 440 REAL_VALUE_TYPE d; 441 HOST_WIDE_INT i[sizeof (REAL_VALUE_TYPE) / sizeof (HOST_WIDE_INT)]; 442}; 443 444/* For a CONST_DOUBLE: 445 The usual two ints that hold the value. 446 For a DImode, that is all there are; 447 and CONST_DOUBLE_LOW is the low-order word and ..._HIGH the high-order. 448 For a float, the number of ints varies, 449 and CONST_DOUBLE_LOW is the one that should come first *in memory*. 450 So use &CONST_DOUBLE_LOW(r) as the address of an array of ints. */ 451#define CONST_DOUBLE_LOW(r) XWINT (r, 2) 452#define CONST_DOUBLE_HIGH(r) XWINT (r, 3) 453 454/* Link for chain of all CONST_DOUBLEs in use in current function. */ 455#define CONST_DOUBLE_CHAIN(r) XEXP (r, 1) 456/* The MEM which represents this CONST_DOUBLE's value in memory, 457 or const0_rtx if no MEM has been made for it yet, 458 or cc0_rtx if it is not on the chain. */ 459#define CONST_DOUBLE_MEM(r) XEXP (r, 0) 460 461/* Given a CONST_DOUBLE in FROM, store into TO the value it represents. */ 462/* Function to return a real value (not a tree node) 463 from a given integer constant. */ 464union tree_node; 465REAL_VALUE_TYPE real_value_from_int_cst PROTO ((union tree_node *, 466 union tree_node *)); 467 468#define REAL_VALUE_FROM_CONST_DOUBLE(to, from) \ 469do { union real_extract u; \ 470 bcopy ((char *) &CONST_DOUBLE_LOW ((from)), (char *) &u, sizeof u); \ 471 to = u.d; } while (0) 472 473/* Return a CONST_DOUBLE with value R and mode M. */ 474 475#define CONST_DOUBLE_FROM_REAL_VALUE(r, m) immed_real_const_1 (r, m) 476extern struct rtx_def *immed_real_const_1 PROTO((REAL_VALUE_TYPE, 477 enum machine_mode)); 478 479 480/* Convert a floating point value `r', that can be interpreted 481 as a host machine float or double, to a decimal ASCII string `s' 482 using printf format string `fmt'. */ 483#ifndef REAL_VALUE_TO_DECIMAL 484#define REAL_VALUE_TO_DECIMAL(r, fmt, s) (sprintf (s, fmt, r)) 485#endif 486 487/* Replace R by 1/R in the given machine mode, if the result is exact. */ 488extern int exact_real_inverse PROTO((enum machine_mode, REAL_VALUE_TYPE *)); 489 490extern void debug_real PROTO ((REAL_VALUE_TYPE)); 491 492/* In varasm.c */ 493extern void assemble_real PROTO ((REAL_VALUE_TYPE, 494 enum machine_mode)); 495#endif /* Not REAL_H_INCLUDED */ 496