GCC Middle and Back End API Reference
real.h File Reference

Go to the source code of this file.

Data Structures

struct  real_value
struct  real_format

Enumerations

enum  real_value_class { rvc_zero, rvc_normal, rvc_inf, rvc_nan }

Functions

bool real_arithmetic (REAL_VALUE_TYPE *, int, const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *)
bool real_compare (int, const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *)
bool real_isinf (const REAL_VALUE_TYPE *)
bool real_isnan (const REAL_VALUE_TYPE *)
bool real_isfinite (const REAL_VALUE_TYPE *)
bool real_isneg (const REAL_VALUE_TYPE *)
bool real_isnegzero (const REAL_VALUE_TYPE *)
bool real_identical (const REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *)
void real_convert (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *)
bool exact_real_truncate (enum machine_mode, const REAL_VALUE_TYPE *)
void real_to_decimal (char *, const REAL_VALUE_TYPE *, size_t, size_t, int)
void real_to_decimal_for_mode (char *, const REAL_VALUE_TYPE *, size_t, size_t, int, enum machine_mode)
void real_to_hexadecimal (char *, const REAL_VALUE_TYPE *, size_t, size_t, int)
HOST_WIDE_INT real_to_integer (const REAL_VALUE_TYPE *)
void real_to_integer2 (HOST_WIDE_INT *, HOST_WIDE_INT *, const REAL_VALUE_TYPE *)
int real_from_string (REAL_VALUE_TYPE *, const char *)
void real_from_string3 (REAL_VALUE_TYPE *, const char *, enum machine_mode)
void real_from_integer (REAL_VALUE_TYPE *, enum machine_mode, unsigned HOST_WIDE_INT, HOST_WIDE_INT, int)
long real_to_target_fmt (long *, const REAL_VALUE_TYPE *, const struct real_format *)
long real_to_target (long *, const REAL_VALUE_TYPE *, enum machine_mode)
void real_from_target_fmt (REAL_VALUE_TYPE *, const long *, const struct real_format *)
void real_from_target (REAL_VALUE_TYPE *, const long *, enum machine_mode)
void real_inf (REAL_VALUE_TYPE *)
bool real_nan (REAL_VALUE_TYPE *, const char *, int, enum machine_mode)
void real_maxval (REAL_VALUE_TYPE *, int, enum machine_mode)
void real_2expN (REAL_VALUE_TYPE *, int, enum machine_mode)
unsigned int real_hash (const REAL_VALUE_TYPE *)
REAL_VALUE_TYPE real_value_truncate (enum machine_mode, REAL_VALUE_TYPE)
REAL_VALUE_TYPE real_value_negate (const REAL_VALUE_TYPE *)
REAL_VALUE_TYPE real_value_abs (const REAL_VALUE_TYPE *)
int significand_size (enum machine_mode)
REAL_VALUE_TYPE real_from_string2 (const char *, enum machine_mode)
int real_exponent (const REAL_VALUE_TYPE *)
void real_ldexp (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *, int)
const REAL_VALUE_TYPE * dconst_e_ptr (void)
const REAL_VALUE_TYPE * dconst_third_ptr (void)
const REAL_VALUE_TYPE * dconst_sqrt2_ptr (void)
REAL_VALUE_TYPE real_value_from_int_cst (const_tree, const_tree)
rtx const_double_from_real_value (REAL_VALUE_TYPE, enum machine_mode)
bool exact_real_inverse (enum machine_mode, REAL_VALUE_TYPE *)
bool real_can_shorten_arithmetic (enum machine_mode, enum machine_mode)
tree build_real (tree, REAL_VALUE_TYPE)
bool real_sqrt (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *)
bool real_powi (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *, HOST_WIDE_INT)
void real_trunc (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *)
void real_floor (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *)
void real_ceil (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *)
void real_round (REAL_VALUE_TYPE *, enum machine_mode, const REAL_VALUE_TYPE *)
void real_copysign (REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *)
bool real_isinteger (const REAL_VALUE_TYPE *c, enum machine_mode mode)
void get_max_float (const struct real_format *, char *, size_t)

Variables

char test_real_width [sizeof(REAL_VALUE_TYPE)<=REAL_WIDTH *sizeof(HOST_WIDE_INT)?1:-1]
struct real_formatreal_format_for_mode [MAX_MODE_FLOAT-MIN_MODE_FLOAT+1+MAX_MODE_DECIMAL_FLOAT-MIN_MODE_DECIMAL_FLOAT+1]
struct real_format ieee_single_format
struct real_format mips_single_format
struct real_format motorola_single_format
struct real_format spu_single_format
struct real_format ieee_double_format
struct real_format mips_double_format
struct real_format motorola_double_format
struct real_format ieee_extended_motorola_format
struct real_format ieee_extended_intel_96_format
struct real_format ieee_extended_intel_96_round_53_format
struct real_format ieee_extended_intel_128_format
struct real_format ibm_extended_format
struct real_format mips_extended_format
struct real_format ieee_quad_format
struct real_format mips_quad_format
struct real_format vax_f_format
struct real_format vax_d_format
struct real_format vax_g_format
struct real_format real_internal_format
struct real_format decimal_single_format
struct real_format decimal_double_format
struct real_format decimal_quad_format
struct real_format ieee_half_format
struct real_format arm_half_format
REAL_VALUE_TYPE dconst0
REAL_VALUE_TYPE dconst1
REAL_VALUE_TYPE dconst2
REAL_VALUE_TYPE dconstm1
REAL_VALUE_TYPE dconsthalf

Enumeration Type Documentation

   An expanded form of the represented number.  
   Enumerate the special cases of numbers that we encounter.  
Enumerator:
rvc_zero 
rvc_normal 
rvc_inf 
rvc_nan 

Function Documentation

rtx const_double_from_real_value ( REAL_VALUE_TYPE  ,
enum  machine_mode 
)
const REAL_VALUE_TYPE* dconst_e_ptr ( void  )
   Function to return the real value special constant 'e'.  
   Returns the special REAL_VALUE_TYPE corresponding to 'e'.  
     Initialize mathematical constants for constant folding builtins.
     These constants need to be given to at least 160 bits precision.  
const REAL_VALUE_TYPE* dconst_sqrt2_ptr ( void  )
   Returns the special REAL_VALUE_TYPE corresponding to sqrt(2).  
     Initialize mathematical constants for constant folding builtins.
     These constants need to be given to at least 160 bits precision.  
const REAL_VALUE_TYPE* dconst_third_ptr ( void  )
   Returns the special REAL_VALUE_TYPE corresponding to 1/3.  
     Initialize mathematical constants for constant folding builtins.
     These constants need to be given to at least 160 bits precision.  

Referenced by integer_valued_real_p().

bool exact_real_inverse ( enum  machine_mode,
REAL_VALUE_TYPE *   
)
   Replace R by 1/R in the given machine mode, if the result is exact.  
bool exact_real_truncate ( enum  machine_mode,
const REAL_VALUE_TYPE *   
)
   Return true if truncating to NEW is exact.  
void get_max_float ( const struct real_format ,
char *  ,
size_t   
)
   Write into BUF the maximum representable finite floating-point
   number, (1 - b**-p) * b**emax for a given FP format FMT as a hex
   float string.  BUF must be large enough to contain the result.  
void real_2expN ( REAL_VALUE_TYPE *  ,
int  ,
enum  machine_mode 
)
bool real_arithmetic ( REAL_VALUE_TYPE *  r,
int  icode,
const REAL_VALUE_TYPE *  op0,
const REAL_VALUE_TYPE *  op1 
)
   Declare functions in real.c.  
   Binary or unary arithmetic on tree_code.  
   Perform the binary or unary operation described by CODE.
   For a unary operation, leave OP1 NULL.  This function returns
   true if the result may be inexact due to loss of precision.  
         Clear any padding areas in *r if it isn't equal to one of the
         operands so that we can later do bitwise comparisons later on.  

References real_arithmetic().

Referenced by integer_valued_real_p(), maybe_lookup_ctx(), and real_arithmetic().

bool real_can_shorten_arithmetic ( enum  machine_mode,
enum  machine_mode 
)
   Return true if arithmetic on values in IMODE that were promoted
   from values in TMODE is equivalent to direct arithmetic on values
   in TMODE.  
void real_ceil ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
const REAL_VALUE_TYPE *  x 
)
   Round X to the smallest integer not less then argument, i.e. round
   up, placing the result in R in mode MODE.  
bool real_compare ( int  ,
const REAL_VALUE_TYPE *  ,
const REAL_VALUE_TYPE *   
)
   Compare reals by tree_code.  

Referenced by fold_builtin_strncat_chk().

void real_convert ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
const REAL_VALUE_TYPE *  a 
)
   Extend or truncate to a new mode.  
     round_for_format de-normalizes denormals.  Undo just that part.  
void real_copysign ( REAL_VALUE_TYPE *  ,
const REAL_VALUE_TYPE *   
)
   Set the sign of R to the sign of X.  
int real_exponent ( const REAL_VALUE_TYPE *  )
   ??? These were added for Paranoia support.  
   Return floor log2(R).  
void real_floor ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
const REAL_VALUE_TYPE *  x 
)
   Round X to the largest integer not greater in value, i.e. round
   down, placing the result in R in mode MODE.  

Referenced by build_complex_cproj().

void real_from_integer ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
unsigned HOST_WIDE_INT  low,
HOST_WIDE_INT  high,
int  unsigned_p 
)
   Initialize R from an integer pair HIGH/LOW.  
   Initialize R from the integer pair HIGH+LOW.  

Referenced by fold_builtin_sincos().

int real_from_string ( REAL_VALUE_TYPE *  ,
const char *   
)
   Initialize R from a decimal or hexadecimal string.  Return -1 if
   the value underflows, +1 if overflows, and 0 otherwise.  
REAL_VALUE_TYPE real_from_string2 ( const char *  ,
enum  machine_mode 
)
void real_from_string3 ( REAL_VALUE_TYPE *  ,
const char *  ,
enum  machine_mode 
)
   Wrapper to allow different internal representation for decimal floats. 
void real_from_target ( REAL_VALUE_TYPE *  ,
const long *  ,
enum  machine_mode 
)
void real_from_target_fmt ( REAL_VALUE_TYPE *  r,
const long *  buf,
const struct real_format fmt 
)
   Read R from the given target format.  Read the words of the result
   in target word order in BUF.  There are always 32 bits in each
   long, no matter the size of the host long.  
unsigned int real_hash ( const REAL_VALUE_TYPE *  )
bool real_identical ( const REAL_VALUE_TYPE *  ,
const REAL_VALUE_TYPE *   
)
   Compare two floating-point objects for bitwise identity.  
void real_inf ( REAL_VALUE_TYPE *  )
bool real_isfinite ( const REAL_VALUE_TYPE *  )
   Determine whether a floating-point value X is finite.  
bool real_isinf ( const REAL_VALUE_TYPE *  )
   Determine whether a floating-point value X is infinite.  
bool real_isinteger ( const REAL_VALUE_TYPE *  c,
enum machine_mode  mode 
)
   Check whether the real constant value given is an integer.  
bool real_isnan ( const REAL_VALUE_TYPE *  )
   Determine whether a floating-point value X is a NaN.  
bool real_isneg ( const REAL_VALUE_TYPE *  )
   Determine whether a floating-point value X is negative.  
bool real_isnegzero ( const REAL_VALUE_TYPE *  )
   Determine whether a floating-point value X is minus zero.  
void real_ldexp ( REAL_VALUE_TYPE *  ,
const REAL_VALUE_TYPE *  ,
int   
)
   R = A * 2**EXP.  
void real_maxval ( REAL_VALUE_TYPE *  ,
int  ,
enum  machine_mode 
)
bool real_nan ( REAL_VALUE_TYPE *  r,
const char *  str,
int  quiet,
enum machine_mode  mode 
)
   Fills R with a NaN whose significand is described by STR.  If QUIET,
   we force a QNaN, else we force an SNaN.  The string, if not empty,
   is parsed as a number and placed in the significand.  Return true
   if the string was successfully parsed.  
         Parse akin to strtol into the significand of R.  
         Must have consumed the entire string for success.  
         Shift the significand into place such that the bits
         are in the most significant bits for the format.  
         Our MSB is always unset for NaNs.  
         Force quiet or signalling NaN.  

References real_format::b, decimal_real_convert(), and decimal_round_for_format().

bool real_powi ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
const REAL_VALUE_TYPE *  x,
HOST_WIDE_INT  n 
)
   Calculate R as X raised to the integer exponent N in mode MODE.  
   Calculate X raised to the integer exponent N in mode MODE and store
   the result in R.  Return true if the result may be inexact due to
   loss of precision.  The algorithm is the classic "left-to-right binary
   method" described in section 4.6.3 of Donald Knuth's "Seminumerical
   Algorithms", "The Art of Computer Programming", Volume 2.  
         Don't worry about overflow, from now on n is unsigned.  

Referenced by fold_builtin_ceil().

void real_round ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
const REAL_VALUE_TYPE *  x 
)
   Round X to the nearest integer, but round halfway cases away from
   zero.  
bool real_sqrt ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
const REAL_VALUE_TYPE *  x 
)
   Calculate R as the square root of X in the given machine mode.  
   Calculate the square root of X in mode MODE, and store the result
   in R.  Return TRUE if the operation does not raise an exception.
   For details see "High Precision Division and Square Root",
   Alan H. Karp and Peter Markstein, HP Lab Report 93-93-42, June
   1993.  http://www.hpl.hp.com/techreports/93/HPL-93-42.pdf.  
     sqrt(-0.0) is -0.0.  
     Negative arguments return NaN.  
     Infinity and NaN return themselves.  
     Initial guess for reciprocal sqrt, i.  
     Newton's iteration for reciprocal sqrt, i.  
         i(n+1) = i(n) * (1.5 - 0.5*i(n)*i(n)*x).  
         Check for early convergence.  
         ??? Unroll loop to avoid copying.  
     Final iteration: r = i*x + 0.5*i*x*(1.0 - i*(i*x)).  
     ??? We need a Tuckerman test to get the last bit.  
void real_to_decimal ( char *  str,
const REAL_VALUE_TYPE *  r_orig,
size_t  buf_size,
size_t  digits,
int  crop_trailing_zeros 
)
   Render R as a decimal floating point constant.  
   Likewise, except always uses round-to-nearest.  

References HOST_BITS_PER_LONG.

Referenced by decimal_to_binary(), dump_pointer(), and print_value().

void real_to_decimal_for_mode ( char *  ,
const REAL_VALUE_TYPE *  ,
size_t  ,
size_t  ,
int  ,
enum  machine_mode 
)
   Render R as a decimal floating point constant, rounded so as to be
   parsed back to the same value when interpreted in mode MODE.  
         ??? Print the significand as well, if not canonical?  
     Bound the number of digits printed by the size of the representation.  
     Estimate the decimal exponent, and compute the length of the string it
     will print as.  Be conservative and add one to account for possible
     overflow or rounding error.  
     Bound the number of digits printed by the size of the output buffer.  
         Number is greater than one.  Convert significand to an integer
         and strip trailing decimal zeros.  
         Largest M, such that 10**2**M fits within SIGNIFICAND_BITS.  
         Iterate over the bits of the possible powers of 10 that might
         be present in U and eliminate them.  That is, if we find that
         10**2**M divides U evenly, keep the division and increase
         DEC_EXP by 2**M.  
         Revert the scaling to integer that we performed earlier.  
         Find power of 10.  Do this by dividing out 10**2**M when
         this is larger than the current remainder.  Fill PTEN with
         the power of 10 that we compute.  
           We managed to divide off enough tens in the above reduction
           loop that we've now got a negative exponent.  Fall into the
           less-than-one code to compute the proper value for PTEN.  
         Number is less than one.  Pad significand with leading
         decimal zeros.  
             Stop if we'd shift bits off the bottom.  
             Stop if we're now >= 1.  
         Find power of 10.  Do this by multiplying in P=10**2**M when
         the current remainder is smaller than 1/P.  Fill PTEN with the
         power of 10 that we compute.  
         Invert the positive power of 10 that we've collected so far.  
     At this point, PTEN should contain the nearest power of 10 smaller
     than R, such that this division produces the first digit.

     Using a divide-step primitive that returns the complete integral
     remainder avoids the rounding error that would be produced if
     we were to use do_divide here and then simply multiply by 10 for
     each subsequent digit.  
     Be prepared for error in that division via underflow ...  
         Multiply by 10 and try again.  
     ... or overflow.  
     Generate subsequent digits.  
     Generate one more digit with which to do rounding.  
     Round the result.  
         If the format uses round towards zero when parsing the string
         back in, we need to always round away from zero here.  
             Round to nearest.  If R is nonzero there are additional
             nonzero digits to be extracted.  
             Round to even.  
         Carry out of the first digit.  This means we had all 9's and
         now have all 0's.  "Prepend" a 1 by overwriting the first 0.  
     Insert the decimal point.  
     If requested, drop trailing zeros.  Never crop past "1.0".  
     Append the exponent.  
     Verify that we can read the original value back in.  
void real_to_hexadecimal ( char *  str,
const REAL_VALUE_TYPE *  r,
size_t  buf_size,
size_t  digits,
int  crop_trailing_zeros 
)
   Render R as a hexadecimal floating point constant.  
   Render R as a hexadecimal floating point constant.  Emit DIGITS
   significant digits in the result, bounded by BUF_SIZE.  If DIGITS is 0,
   choose the maximum for the representation.  If CROP_TRAILING_ZEROS,
   strip trailing zeros.  
         ??? Print the significand as well, if not canonical?  
         Hexadecimal format for decimal floats is not interesting. 
     Bound the number of digits printed by the size of the output buffer.  
HOST_WIDE_INT real_to_integer ( const REAL_VALUE_TYPE *  )
   Render R as an integer.  
void real_to_integer2 ( HOST_WIDE_INT plow,
HOST_WIDE_INT phigh,
const REAL_VALUE_TYPE *  r 
)
   Likewise, but to an integer pair, HI+LOW.  
         Only force overflow for unsigned overflow.  Signed overflow is
         undefined, so it doesn't matter what we return, and some callers
         expect to be able to use this routine for both signed and
         unsigned conversions.  

References cmp_significands(), lshift_significand_1(), and sub_significands().

long real_to_target ( long *  ,
const REAL_VALUE_TYPE *  ,
enum  machine_mode 
)
long real_to_target_fmt ( long *  buf,
const REAL_VALUE_TYPE *  r_orig,
const struct real_format fmt 
)
   Write R to the given target format.  Place the words of the result
   in target word order in BUF.  There are always 32 bits in each
   long, no matter the size of the host long.

   Legacy: return word 0 for implementing REAL_VALUE_TO_TARGET_SINGLE.  
void real_trunc ( REAL_VALUE_TYPE *  r,
enum machine_mode  mode,
const REAL_VALUE_TYPE *  x 
)
   Standard round to integer value functions.  
   Round X to the nearest integer not larger in absolute value, i.e.
   towards zero, placing the result in R in mode MODE.  
REAL_VALUE_TYPE real_value_abs ( const REAL_VALUE_TYPE *  )
REAL_VALUE_TYPE real_value_from_int_cst ( const_tree  ,
const_tree   
)
   Function to return a real value (not a tree node)
   from a given integer constant.  
REAL_VALUE_TYPE real_value_negate ( const REAL_VALUE_TYPE *  )
REAL_VALUE_TYPE real_value_truncate ( enum  machine_mode,
REAL_VALUE_TYPE   
)
int significand_size ( enum  machine_mode)

Variable Documentation

struct real_format arm_half_format
   ARM's alternative half-precision format, similar to IEEE but with
   no reserved exponent value for NaNs and infinities; rather, it just
   extends the range of exponents by one.  
REAL_VALUE_TYPE dconst0
   **** End of software floating point emulator interface macros **** 
   Constant real values 0, 1, 2, -1 and 0.5.  

Referenced by associate_equivalences_with_edges(), build_one_cst(), expand_builtin_expect(), fold_builtin_classify(), fold_builtin_tan(), set_value_varying(), and vect_slp_analyze_bb().

REAL_VALUE_TYPE dconst2
REAL_VALUE_TYPE dconsthalf
REAL_VALUE_TYPE dconstm1
struct real_format decimal_double_format
   Double precision decimal floating point (IEEE 754). 
struct real_format decimal_quad_format
   Quad precision decimal floating point (IEEE 754). 
struct real_format decimal_single_format
   Single precision decimal floating point (IEEE 754). 
struct real_format ibm_extended_format
struct real_format ieee_double_format
struct real_format ieee_extended_intel_128_format
struct real_format ieee_extended_intel_96_format
struct real_format ieee_extended_intel_96_round_53_format
   The following caters to i386 systems that set the rounding precision
   to 53 bits instead of 64, e.g. FreeBSD.  
struct real_format ieee_extended_motorola_format
struct real_format ieee_half_format
   Half-precision format, as specified in IEEE 754R.  
struct real_format ieee_quad_format
struct real_format ieee_single_format
   Target formats defined in real.c.  
struct real_format mips_double_format
struct real_format mips_extended_format
struct real_format mips_quad_format
struct real_format mips_single_format
struct real_format motorola_double_format
struct real_format motorola_single_format
struct real_format* real_format_for_mode[MAX_MODE_FLOAT-MIN_MODE_FLOAT+1+MAX_MODE_DECIMAL_FLOAT-MIN_MODE_DECIMAL_FLOAT+1]
   The target format used for each floating point mode.
   Float modes are followed by decimal float modes, with entries for
   float modes indexed by (MODE - first float mode), and entries for
   decimal float modes indexed by (MODE - first decimal float mode) +
   the number of float modes.  
struct real_format real_internal_format
struct real_format spu_single_format
    SPU Single Precision (Extended-Range Mode) format is the same as IEEE
    single precision with the following differences:
      - Infinities are not supported.  Instead MAX_FLOAT or MIN_FLOAT
        are generated.
      - NaNs are not supported.
      - The range of non-zero numbers in binary is
        (001)[1.]000...000 to (255)[1.]111...111.
      - Denormals can be represented, but are treated as +0.0 when
        used as an operand and are never generated as a result.
      - -0.0 can be represented, but a zero result is always +0.0.
      - the only supported rounding mode is trunction (towards zero).  
char test_real_width[sizeof(REAL_VALUE_TYPE)<=REAL_WIDTH *sizeof(HOST_WIDE_INT)?1:-1]
   Verify the guess.  
struct real_format vax_d_format
struct real_format vax_f_format
struct real_format vax_g_format