GCC Middle and Back End API Reference
fixed-value.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "diagnostic-core.h"
Include dependency graph for fixed-value.c:

Enumerations

enum  fixed_value_range_code { FIXED_OK, FIXED_UNDERFLOW, FIXED_GT_MAX_EPS, FIXED_MAX_EPS }

Functions

bool fixed_identical ()
unsigned int fixed_hash ()
static enum fixed_value_range_code check_real_for_fixed_mode ()
FIXED_VALUE_TYPE fixed_from_double_int ()
void fixed_from_string ()
void fixed_to_decimal (char *str, const FIXED_VALUE_TYPE *f_orig, size_t buf_size)
static bool fixed_saturate1 (enum machine_mode mode, double_int a, double_int *f, bool sat_p)
static bool fixed_saturate2 (enum machine_mode mode, double_int a_high, double_int a_low, double_int *f, bool sat_p)
static int get_fixed_sign_bit ()
static bool do_fixed_add (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, const FIXED_VALUE_TYPE *b, bool subtract_p, bool sat_p)
static bool do_fixed_multiply (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, const FIXED_VALUE_TYPE *b, bool sat_p)
static bool do_fixed_divide (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, const FIXED_VALUE_TYPE *b, bool sat_p)
static bool do_fixed_shift (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, const FIXED_VALUE_TYPE *b, bool left_p, bool sat_p)
static bool do_fixed_neg ()
bool fixed_arithmetic (FIXED_VALUE_TYPE *f, int icode, const FIXED_VALUE_TYPE *op0, const FIXED_VALUE_TYPE *op1, bool sat_p)
bool fixed_compare (int icode, const FIXED_VALUE_TYPE *op0, const FIXED_VALUE_TYPE *op1)
bool fixed_convert (FIXED_VALUE_TYPE *f, enum machine_mode mode, const FIXED_VALUE_TYPE *a, bool sat_p)
bool fixed_convert_from_int (FIXED_VALUE_TYPE *f, enum machine_mode mode, double_int a, bool unsigned_p, bool sat_p)
bool fixed_convert_from_real (FIXED_VALUE_TYPE *f, enum machine_mode mode, const REAL_VALUE_TYPE *a, bool sat_p)
void real_convert_from_fixed (REAL_VALUE_TYPE *r, enum machine_mode mode, const FIXED_VALUE_TYPE *f)
bool fixed_isneg ()

Enumeration Type Documentation

Define the enum code for the range of the fixed-point value.

Enumerator:
FIXED_OK 
FIXED_UNDERFLOW 
FIXED_GT_MAX_EPS 
FIXED_MAX_EPS 

Function Documentation

static enum fixed_value_range_code check_real_for_fixed_mode ( )
static

Check REAL_VALUE against the range of the fixed-point mode. Return FIXED_OK, if it is within the range. FIXED_UNDERFLOW, if it is less than the minimum. FIXED_GT_MAX_EPS, if it is greater than the maximum, but not equal to the maximum plus the epsilon. FIXED_MAX_EPS, if it is equal to the maximum plus the epsilon.

static bool do_fixed_add ( FIXED_VALUE_TYPE f,
const FIXED_VALUE_TYPE a,
const FIXED_VALUE_TYPE b,
bool  subtract_p,
bool  sat_p 
)
static

Calculate F = A + (SUBTRACT_P ? -B : B). If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

This was a conditional expression but it triggered a bug in Sun C 5.5.

static bool do_fixed_divide ( FIXED_VALUE_TYPE f,
const FIXED_VALUE_TYPE a,
const FIXED_VALUE_TYPE b,
bool  sat_p 
)
static

Calculate F = A / B. If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

     If a < 0, negate a.   
     If b < 0, negate b.   
     Left shift pos_a to {r, s} by FBIT.   
     Divide r by pos_b to quo_r.  The remainder is in mod.   
         Record the leftmost bit of mod.   
         Shift left mod by 1 bit.   
         Test the leftmost bit of s to add to mod.   
         Shift left quo_s by 1 bit.   
         Try to calculate (mod - pos_b).   
         Shift left s by 1 bit.   
static bool do_fixed_multiply ( FIXED_VALUE_TYPE f,
const FIXED_VALUE_TYPE a,
const FIXED_VALUE_TYPE b,
bool  sat_p 
)
static

Calculate F = A * B. If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

     The result of multiplication expands to two double_int.   
     Decompose a and b to four double_int.   
     Perform four multiplications.   
     Accumulate four results to {r, s}.   
     We need to subtract b from r, if a < 0.   
     We need to subtract a from r, if b < 0.   
     Shift right the result by FBIT.   

References double_int::high, and double_int::low.

static bool do_fixed_neg ( )
static

Calculate F = -A. If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

Saturate to the maximum by subtracting f->data by one.

static bool do_fixed_shift ( FIXED_VALUE_TYPE f,
const FIXED_VALUE_TYPE a,
const FIXED_VALUE_TYPE b,
bool  left_p,
bool  sat_p 
)
static

Calculate F = A << B if LEFT_P. Otherwise, F = A >> B. If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

Logical shift right to temp_high.

bool fixed_arithmetic ( FIXED_VALUE_TYPE f,
int  icode,
const FIXED_VALUE_TYPE op0,
const FIXED_VALUE_TYPE op1,
bool  sat_p 
)

Perform the binary or unary operation described by CODE. Note that OP0 and OP1 must have the same mode for binary operators. For a unary operation, leave OP1 NULL. Return true, if !SAT_P and overflow.

Referenced by tree_unary_nonnegative_warnv_p().

bool fixed_compare ( int  icode,
const FIXED_VALUE_TYPE op0,
const FIXED_VALUE_TYPE op1 
)

Compare fixed-point values by tree_code. Note that OP0 and OP1 must have the same mode.

References fixed_saturate2(), GET_MODE_FBIT, double_int::llshift(), double_int::lshift(), double_int::sext(), and SIGNED_FIXED_POINT_MODE_P.

bool fixed_convert ( FIXED_VALUE_TYPE f,
enum machine_mode  mode,
const FIXED_VALUE_TYPE a,
bool  sat_p 
)

Extend or truncate to a new mode. If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

     Left shift a to temp_high, temp_low based on a->mode.   
     Logical shift right to temp_high.   
         Take care of the cases when converting between signed and
         unsigned.   
             Signed -> Unsigned.   
             Unsigned -> Signed.   
                     Set to maximum.   
                                               Clear the sign.   
     Right shift a to temp based on a->mode.   
         Take care of the cases when converting between signed and
         unsigned.   
             Signed -> Unsigned.   
             Unsigned -> Signed.   
                     Set to maximum.   
                                               Clear the sign.   

Referenced by fold_convert_const_int_from_fixed().

bool fixed_convert_from_int ( FIXED_VALUE_TYPE f,
enum machine_mode  mode,
double_int  a,
bool  unsigned_p,
bool  sat_p 
)

Convert to a new fixed-point mode from an integer. If UNSIGNED_P, this integer is unsigned. If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

 Left shift a to temp_high, temp_low.   
     Logical shift right to temp_high.   
     Take care of the cases when converting between signed and unsigned.   
         Signed -> Unsigned.   
         Unsigned -> Signed.   
                 Set to maximum.   
                                           Clear the sign.   

References GET_MODE_FBIT, and GET_MODE_IBIT.

bool fixed_convert_from_real ( FIXED_VALUE_TYPE f,
enum machine_mode  mode,
const REAL_VALUE_TYPE a,
bool  sat_p 
)

Convert to a new fixed-point mode from a real. If SAT_P, saturate the result to the max or the min. Return true, if !SAT_P and overflow.

FIXED_VALUE_TYPE fixed_from_double_int ( )

Construct a CONST_FIXED from a bit payload and machine mode MODE. The bits in PAYLOAD are sign-extended/zero-extended according to MODE.

Referenced by build_string().

void fixed_from_string ( )

Initialize from a decimal or hexadecimal string.

We don't want to warn the case when the _Fract value is 1.0.

     From the spec, we need to evaluate 1 to the maximal value.   
unsigned int fixed_hash ( )

Calculate a hash value.

Referenced by const_double_htab_eq(), and default_assemble_integer().

bool fixed_identical ( )

Fixed-point arithmetic support. Copyright (C) 2006-2013 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. Compare two fixed objects for bitwise identity.

bool fixed_isneg ( )

Determine whether a fixed-point value F is negative.

static bool fixed_saturate1 ( enum machine_mode  mode,
double_int  a,
double_int f,
bool  sat_p 
)
static

If SAT_P, saturate A to the maximum or the minimum, and save to *F based on the machine mode MODE. Do not modify *F otherwise. This function assumes the width of double_int is greater than the width of the fixed-point value (the sum of a possible sign bit, possible ibits, and fbits). Return true, if !SAT_P and overflow.

static bool fixed_saturate2 ( enum machine_mode  mode,
double_int  a_high,
double_int  a_low,
double_int f,
bool  sat_p 
)
static

If SAT_P, saturate {A_HIGH, A_LOW} to the maximum or the minimum, and save to *F based on the machine mode MODE. Do not modify *F otherwise. This function assumes the width of two double_int is greater than the width of the fixed-point value (the sum of a possible sign bit, possible ibits, and fbits). Return true, if !SAT_P and overflow.

Referenced by fixed_compare().

void fixed_to_decimal ( char *  str,
const FIXED_VALUE_TYPE f_orig,
size_t  buf_size 
)

Render F as a decimal floating point constant.

Referenced by dump_int(), and print_value().

static int get_fixed_sign_bit ( )
inlinestatic

Return the sign bit based on I_F_BITS.

void real_convert_from_fixed ( REAL_VALUE_TYPE r,
enum machine_mode  mode,
const FIXED_VALUE_TYPE f 
)

Convert to a new real mode from a fixed-point.