GCC Middle and Back End API Reference
fixed-value.cc 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.cc:

Enumerations

enum  fixed_value_range_code { FIXED_OK , FIXED_UNDERFLOW , FIXED_GT_MAX_EPS , FIXED_MAX_EPS }
 

Functions

bool fixed_identical (const FIXED_VALUE_TYPE *a, const FIXED_VALUE_TYPE *b)
 
unsigned int fixed_hash (const FIXED_VALUE_TYPE *f)
 
static enum fixed_value_range_code check_real_for_fixed_mode (REAL_VALUE_TYPE *real_value, machine_mode mode)
 
FIXED_VALUE_TYPE fixed_from_double_int (double_int payload, scalar_mode mode)
 
void fixed_from_string (FIXED_VALUE_TYPE *f, const char *str, scalar_mode mode)
 
void fixed_to_decimal (char *str, const FIXED_VALUE_TYPE *f_orig, size_t buf_size)
 
static bool fixed_saturate1 (machine_mode mode, double_int a, double_int *f, bool sat_p)
 
static bool fixed_saturate2 (machine_mode mode, double_int a_high, double_int a_low, double_int *f, bool sat_p)
 
static int get_fixed_sign_bit (double_int a, int i_f_bits)
 
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 (FIXED_VALUE_TYPE *f, const FIXED_VALUE_TYPE *a, bool sat_p)
 
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, scalar_mode mode, const FIXED_VALUE_TYPE *a, bool sat_p)
 
bool fixed_convert_from_int (FIXED_VALUE_TYPE *f, scalar_mode mode, double_int a, bool unsigned_p, bool sat_p)
 
bool fixed_convert_from_real (FIXED_VALUE_TYPE *f, scalar_mode mode, const REAL_VALUE_TYPE *a, bool sat_p)
 
void real_convert_from_fixed (REAL_VALUE_TYPE *r, scalar_mode mode, const FIXED_VALUE_TYPE *f)
 
bool fixed_isneg (const FIXED_VALUE_TYPE *f)
 

Enumeration Type Documentation

◆ fixed_value_range_code

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

◆ check_real_for_fixed_mode()

static enum fixed_value_range_code check_real_for_fixed_mode ( REAL_VALUE_TYPE * real_value,
machine_mode 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.   

References FIXED_GT_MAX_EPS, FIXED_MAX_EPS, FIXED_OK, FIXED_UNDERFLOW, GET_MODE_FBIT, GET_MODE_IBIT, real_2expN(), real_arithmetic(), real_compare(), real_from_string(), real_value_negate(), REAL_VALUE_TYPE, and SIGNED_FIXED_POINT_MODE_P.

Referenced by fixed_convert_from_real(), and fixed_from_string().

◆ do_fixed_add()

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.   

References a, b, double_int::ext(), get_fixed_sign_bit(), GET_MODE_FBIT, GET_MODE_IBIT, HOST_BITS_PER_DOUBLE_INT, and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by fixed_arithmetic().

◆ do_fixed_divide()

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

◆ do_fixed_multiply()

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.   

References a, b, fixed_saturate1(), fixed_saturate2(), GET_MODE_FBIT, GET_MODE_IBIT, GET_MODE_PRECISION(), double_int::high, HOST_BITS_PER_DOUBLE_INT, HOST_BITS_PER_WIDE_INT, double_int::llshift(), double_int::low, r, double_int::ult(), and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by fixed_arithmetic().

◆ do_fixed_neg()

static bool do_fixed_neg ( FIXED_VALUE_TYPE * f,
const FIXED_VALUE_TYPE * a,
bool sat_p )
static
Calculate F = -A.
If SAT_P, saturate the result to the max or the min.
Return true, if !SAT_P and overflow.   

References a, GET_MODE_FBIT, GET_MODE_IBIT, and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by fixed_arithmetic().

◆ do_fixed_shift()

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.   

References a, b, double_int::ext(), fixed_saturate1(), fixed_saturate2(), GET_MODE_FBIT, GET_MODE_IBIT, GET_MODE_PRECISION(), double_int::high, HOST_BITS_PER_DOUBLE_INT, HOST_BITS_PER_WIDE_INT, double_int::llshift(), double_int::low, double_int::lshift(), and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by fixed_arithmetic().

◆ fixed_arithmetic()

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.   

References do_fixed_add(), do_fixed_divide(), do_fixed_multiply(), do_fixed_neg(), do_fixed_shift(), gcc_assert, and gcc_unreachable.

Referenced by const_binop(), and fold_negate_const().

◆ fixed_compare()

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 gcc_assert, gcc_unreachable, and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by fold_relational_const().

◆ fixed_convert()

bool fixed_convert ( FIXED_VALUE_TYPE * f,
scalar_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.   

References a, fixed_saturate1(), fixed_saturate2(), GET_MODE_FBIT, GET_MODE_IBIT, double_int::high, HOST_BITS_PER_DOUBLE_INT, double_int::llshift(), double_int::lshift(), double_int::sext(), SIGNED_FIXED_POINT_MODE_P, and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by fold_convert_const_fixed_from_fixed().

◆ fixed_convert_from_int()

bool fixed_convert_from_int ( FIXED_VALUE_TYPE * f,
scalar_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.   

References a, fixed_saturate2(), GET_MODE_FBIT, GET_MODE_IBIT, double_int::high, HOST_BITS_PER_DOUBLE_INT, double_int::llshift(), double_int::low, double_int::sext(), SIGNED_FIXED_POINT_MODE_P, and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by fold_convert_const_fixed_from_int().

◆ fixed_convert_from_real()

bool fixed_convert_from_real ( FIXED_VALUE_TYPE * f,
scalar_mode mode,
const REAL_VALUE_TYPE * a,
bool sat_p )

◆ fixed_from_double_int()

FIXED_VALUE_TYPE fixed_from_double_int ( double_int payload,
scalar_mode mode )
Construct a CONST_FIXED from a bit payload and machine mode MODE.
The bits in PAYLOAD are sign-extended/zero-extended according to MODE.   

References FIXED_VALUE_TYPE, gcc_assert, gcc_unreachable, GET_MODE_BITSIZE(), GET_MODE_FBIT, GET_MODE_IBIT, HOST_BITS_PER_DOUBLE_INT, double_int::sext(), SIGNED_SCALAR_FIXED_POINT_MODE_P, UNSIGNED_SCALAR_FIXED_POINT_MODE_P, and double_int::zext().

Referenced by build_minus_one_cst(), and native_interpret_fixed().

◆ fixed_from_string()

◆ fixed_hash()

unsigned int fixed_hash ( const FIXED_VALUE_TYPE * f)

◆ fixed_identical()

bool fixed_identical ( const FIXED_VALUE_TYPE * a,
const FIXED_VALUE_TYPE * b )
Fixed-point arithmetic support.
   Copyright (C) 2006-2024 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.   

References a, and b.

Referenced by const_fixed_hasher::equal().

◆ fixed_isneg()

bool fixed_isneg ( const FIXED_VALUE_TYPE * f)
Determine whether a fixed-point value F is negative.   

References get_fixed_sign_bit(), GET_MODE_FBIT, GET_MODE_IBIT, and SIGNED_FIXED_POINT_MODE_P.

◆ fixed_saturate1()

static bool fixed_saturate1 ( 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.   

References a, GET_MODE_FBIT, GET_MODE_IBIT, HOST_BITS_PER_DOUBLE_INT, and UNSIGNED_FIXED_POINT_MODE_P.

Referenced by do_fixed_divide(), do_fixed_multiply(), do_fixed_shift(), and fixed_convert().

◆ fixed_saturate2()

static bool fixed_saturate2 ( 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.   

References double_int::alshift(), GET_MODE_FBIT, GET_MODE_IBIT, double_int::high, HOST_BITS_PER_DOUBLE_INT, double_int::low, double_int::sext(), double_int::sgt(), double_int::slt(), double_int::ugt(), double_int::ult(), UNSIGNED_FIXED_POINT_MODE_P, and double_int::zext().

Referenced by do_fixed_divide(), do_fixed_multiply(), do_fixed_shift(), fixed_convert(), and fixed_convert_from_int().

◆ fixed_to_decimal()

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

◆ get_fixed_sign_bit()

static int get_fixed_sign_bit ( double_int a,
int i_f_bits )
inlinestatic
Return the sign bit based on I_F_BITS.   

References a, and HOST_BITS_PER_WIDE_INT.

Referenced by do_fixed_add(), and fixed_isneg().

◆ real_convert_from_fixed()