GCC Middle and Back End API Reference
double_int Struct Reference

#include <double-int.h>

Public Member Functions

double_intoperator++ ()
 
double_intoperator-- ()
 
double_intoperator*= (double_int)
 
double_intoperator+= (double_int)
 
double_intoperator-= (double_int)
 
double_intoperator&= (double_int)
 
double_intoperator^= (double_int)
 
double_intoperator|= (double_int)
 
HOST_WIDE_INT to_shwi () const
 
unsigned HOST_WIDE_INT to_uhwi () const
 
bool fits_uhwi () const
 
bool fits_shwi () const
 
bool fits_hwi (bool uns) const
 
int trailing_zeros () const
 
int popcount () const
 
bool multiple_of (double_int, bool, double_int *) const
 
double_int set_bit (unsigned) const
 
double_int mul_with_sign (double_int, bool unsigned_p, bool *overflow) const
 
double_int wide_mul_with_sign (double_int, bool unsigned_p, double_int *higher, bool *overflow) const
 
double_int add_with_sign (double_int, bool unsigned_p, bool *overflow) const
 
double_int sub_with_overflow (double_int, bool *overflow) const
 
double_int neg_with_overflow (bool *overflow) const
 
double_int operator* (double_int) const
 
double_int operator+ (double_int) const
 
double_int operator- (double_int) const
 
double_int operator- () const
 
double_int operator~ () const
 
double_int operator& (double_int) const
 
double_int operator| (double_int) const
 
double_int operator^ (double_int) const
 
double_int and_not (double_int) const
 
double_int lshift (HOST_WIDE_INT count) const
 
double_int lshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const
 
double_int rshift (HOST_WIDE_INT count) const
 
double_int rshift (HOST_WIDE_INT count, unsigned int prec, bool arith) const
 
double_int alshift (HOST_WIDE_INT count, unsigned int prec) const
 
double_int arshift (HOST_WIDE_INT count, unsigned int prec) const
 
double_int llshift (HOST_WIDE_INT count, unsigned int prec) const
 
double_int lrshift (HOST_WIDE_INT count, unsigned int prec) const
 
double_int lrotate (HOST_WIDE_INT count, unsigned int prec) const
 
double_int rrotate (HOST_WIDE_INT count, unsigned int prec) const
 
double_int div (double_int, bool, unsigned) const
 
double_int sdiv (double_int, unsigned) const
 
double_int udiv (double_int, unsigned) const
 
double_int mod (double_int, bool, unsigned) const
 
double_int smod (double_int, unsigned) const
 
double_int umod (double_int, unsigned) const
 
double_int divmod_with_overflow (double_int, bool, unsigned, double_int *, bool *) const
 
double_int divmod (double_int, bool, unsigned, double_int *) const
 
double_int sdivmod (double_int, unsigned, double_int *) const
 
double_int udivmod (double_int, unsigned, double_int *) const
 
double_int ext (unsigned prec, bool uns) const
 
double_int zext (unsigned prec) const
 
double_int sext (unsigned prec) const
 
bool is_zero () const
 
bool is_one () const
 
bool is_minus_one () const
 
bool is_negative () const
 
int cmp (double_int b, bool uns) const
 
int ucmp (double_int b) const
 
int scmp (double_int b) const
 
bool ult (double_int b) const
 
bool ule (double_int b) const
 
bool ugt (double_int b) const
 
bool slt (double_int b) const
 
bool sle (double_int b) const
 
bool sgt (double_int b) const
 
double_int max (double_int b, bool uns)
 
double_int smax (double_int b)
 
double_int umax (double_int b)
 
double_int min (double_int b, bool uns)
 
double_int smin (double_int b)
 
double_int umin (double_int b)
 
bool operator== (double_int cst2) const
 
bool operator!= (double_int cst2) const
 

Static Public Member Functions

static double_int from_uhwi (unsigned HOST_WIDE_INT cst)
 
static double_int from_shwi (HOST_WIDE_INT cst)
 
static double_int from_pair (HOST_WIDE_INT high, unsigned HOST_WIDE_INT low)
 
static double_int from_buffer (const unsigned char *buffer, int len)
 
static double_int mask (unsigned prec)
 
static double_int max_value (unsigned int prec, bool uns)
 
static double_int min_value (unsigned int prec, bool uns)
 

Data Fields

unsigned HOST_WIDE_INT low
 
HOST_WIDE_INT high
 

Detailed Description

Operations with long integers.
   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/>.   
A large integer is currently represented as a pair of HOST_WIDE_INTs.
It therefore represents a number with precision of
2 * HOST_BITS_PER_WIDE_INT bits (it is however possible that the
internal representation will change, if numbers with greater precision
are needed, so the users should not rely on it).  The representation does
not contain any information about signedness of the represented value, so
it can be used to represent both signed and unsigned numbers.  For
operations where the results depend on signedness (division, comparisons),
it must be specified separately.  For each such operation, there are three
versions of the function -- double_int_op, that takes an extra UNS argument
giving the signedness of the values, and double_int_sop and double_int_uop
that stand for its specializations for signed and unsigned values.

You may also represent with numbers in smaller precision using double_int.
You however need to use double_int_ext (that fills in the bits of the
number over the prescribed precision with zeros or with the sign bit) before
operations that do not perform arithmetics modulo 2^precision (comparisons,
division), and possibly before storing the results, if you want to keep
them in some canonical form).  In general, the signedness of double_int_ext
should match the signedness of the operation.

??? The components of double_int differ in signedness mostly for
historical reasons (they replace an older structure used to represent
numbers with precision higher than HOST_WIDE_INT).  It might be less
confusing to have them both signed or both unsigned.   

Member Function Documentation

◆ add_with_sign()

double_int double_int::add_with_sign ( double_int b,
bool unsigned_p,
bool * overflow ) const
Returns A + B. If the operation overflows according to UNSIGNED_P,
*OVERFLOW is set to nonzero.   

References a, add_double_with_sign(), b, and ggc_alloc().

◆ alshift()

double_int double_int::alshift ( HOST_WIDE_INT count,
unsigned int prec ) const
Arithmetic shift A left by COUNT places keeping only PREC bits of result.
Shift right if COUNT is negative.   

References absu_hwi(), count, high, low, lshift_double(), r, and rshift_double().

◆ and_not()

double_int double_int::and_not ( double_int b) const
inline
Returns A & ~B.   

References ggc_alloc(), high, and low.

◆ arshift()

double_int double_int::arshift ( HOST_WIDE_INT count,
unsigned int prec ) const
Arithmetic shift A right by COUNT places keeping only PREC bits of result.
Shift left if COUNT is negative.   

References absu_hwi(), count, high, low, lshift_double(), r, and rshift_double().

◆ cmp()

int double_int::cmp ( double_int b,
bool uns ) const
Returns -1 if A < B, 0 if A == B and 1 if A > B.  Signedness of the
comparison is given by UNS.   

References ggc_alloc(), scmp(), and ucmp().

Referenced by max(), and min().

◆ div()

double_int double_int::div ( double_int b,
bool uns,
unsigned code ) const
Returns A / B (computed as unsigned depending on UNS, and rounded as
specified by CODE).  CODE is enum tree_code in fact, but double_int.h
must be included before tree.h.   

References divmod(), ggc_alloc(), and mod().

Referenced by sdiv(), and udiv().

◆ divmod()

double_int double_int::divmod ( double_int b,
bool uns,
unsigned code,
double_int * mod ) const

◆ divmod_with_overflow()

double_int double_int::divmod_with_overflow ( double_int b,
bool uns,
unsigned code,
double_int * mod,
bool * overflow ) const
Returns A / B (computed as unsigned depending on UNS, and rounded as
specified by CODE).  CODE is enum tree_code in fact, but double_int.h
must be included before tree.h.  The remainder after the division is
stored to MOD.   

References a, b, div_and_round_double(), ggc_alloc(), high, low, and mod().

◆ ext()

double_int double_int::ext ( unsigned prec,
bool uns ) const
Clears the bits of CST over the precision PREC.  If UNS is false, the bits
outside of the precision are set to the sign bit (i.e., the PREC-th one),
otherwise they are set to zero.

This corresponds to returning the value represented by PREC lowermost bits
of CST, with the given signedness.   

References ggc_alloc(), sext(), and zext().

Referenced by mpz_get_double_int().

◆ fits_hwi()

bool double_int::fits_hwi ( bool uns) const
Returns true if CST fits in HOST_WIDE_INT if UNS is false, or in
unsigned HOST_WIDE_INT if UNS is true.   

References fits_shwi(), fits_uhwi(), and ggc_alloc().

◆ fits_shwi()

bool double_int::fits_shwi ( ) const
Returns true if CST fits in signed HOST_WIDE_INT.   

References ggc_alloc().

Referenced by fits_hwi(), and pp_double_int().

◆ fits_uhwi()

bool double_int::fits_uhwi ( ) const
inline
Returns true if CST fits in unsigned HOST_WIDE_INT.   

References high.

Referenced by fits_hwi(), and pp_double_int().

◆ from_buffer()

double_int double_int::from_buffer ( const unsigned char * buffer,
int len )
static
Construct from a buffer of length LEN.  BUFFER will be read according
to byte endianness and word endianness.  Only the lower LEN bytes
of the result are set; the remaining high bytes are cleared.   

References double_int_zero, gcc_assert, ggc_alloc(), high, HOST_BITS_PER_DOUBLE_INT, HOST_BITS_PER_WIDE_INT, low, and offset.

Referenced by native_interpret_fixed().

◆ from_pair()

double_int double_int::from_pair ( HOST_WIDE_INT high,
unsigned HOST_WIDE_INT low )
inlinestatic

References high, low, and r.

◆ from_shwi()

double_int double_int::from_shwi ( HOST_WIDE_INT cst)
inlinestatic
Constructors and conversions.   
Constructs double_int from integer CST.  The bits over the precision of
HOST_WIDE_INT are filled with the sign bit.   

References ggc_alloc(), low, and r.

Referenced by mem_loc_descriptor(), and rtx_to_double_int().

◆ from_uhwi()

double_int double_int::from_uhwi ( unsigned HOST_WIDE_INT cst)
inlinestatic
Constructs double_int from unsigned integer CST.  The bits over the
precision of HOST_WIDE_INT are filled with zeros.   

References ggc_alloc(), low, and r.

◆ is_minus_one()

bool double_int::is_minus_one ( ) const
inline
Returns true if CST is minus one.   

References ALL_ONES, high, and low.

◆ is_negative()

bool double_int::is_negative ( ) const
inline
Returns true if CST is negative.   

References high.

Referenced by fold_convert_const_int_from_fixed(), mpz_set_double_int(), and pp_double_int().

◆ is_one()

bool double_int::is_one ( ) const
inline
Returns true if CST is one.   

References high, and low.

◆ is_zero()

bool double_int::is_zero ( ) const
inline
The operands of the following comparison functions must be processed
with double_int_ext, if their precision is less than
HOST_BITS_PER_DOUBLE_INT bits.   
Returns true if CST is zero.   

References high, and low.

◆ llshift()

double_int double_int::llshift ( HOST_WIDE_INT count,
unsigned int prec ) const
Logical shift A left by COUNT places keeping only PREC bits of result.
Shift right if COUNT is negative.   

References absu_hwi(), count, high, low, lshift_double(), r, and rshift_double().

Referenced by do_fixed_multiply(), lrotate(), and rrotate().

◆ lrotate()

double_int double_int::lrotate ( HOST_WIDE_INT count,
unsigned int prec ) const
Rotate  A left by COUNT places keeping only PREC bits of result.
Rotate right if COUNT is negative.   

References count, llshift(), and lrshift().

◆ lrshift()

double_int double_int::lrshift ( HOST_WIDE_INT count,
unsigned int prec ) const
Logical shift A right by COUNT places keeping only PREC bits of result.
Shift left if COUNT is negative.   

References absu_hwi(), count, high, low, lshift_double(), r, and rshift_double().

Referenced by lrotate(), and rrotate().

◆ lshift() [1/2]

◆ lshift() [2/2]

double_int double_int::lshift ( HOST_WIDE_INT count,
unsigned int prec,
bool arith ) const
Shift A left by COUNT places keeping only PREC bits of result.  Shift
right if COUNT is negative.  ARITH true specifies arithmetic shifting;
otherwise use logical shift.   

References absu_hwi(), count, ggc_alloc(), high, low, lshift_double(), and rshift_double().

◆ mask()

double_int double_int::mask ( unsigned prec)
static
Returns mask for PREC bits.   

References ALL_ONES, ggc_alloc(), high, HOST_BITS_PER_WIDE_INT, HOST_WIDE_INT_UC, low, and mask().

Referenced by mask(), max_value(), sext(), and zext().

◆ max()

double_int double_int::max ( double_int b,
bool uns )
Compares two values A and B.  Returns max value.  Signedness of the
comparison is given by UNS.   

References b, cmp(), and ggc_alloc().

◆ max_value()

double_int double_int::max_value ( unsigned int prec,
bool uns )
static
Returns a maximum value for signed or unsigned integer
of precision PREC.   

References ggc_alloc(), and mask().

◆ min()

double_int double_int::min ( double_int b,
bool uns )
Compares two values A and B.  Returns mix value.  Signedness of the
comparison is given by UNS.   

References b, cmp(), and ggc_alloc().

◆ min_value()

double_int double_int::min_value ( unsigned int prec,
bool uns )
static
Returns a minimum value for signed or unsigned integer
of precision PREC.   

References double_int_one, double_int_zero, ggc_alloc(), and lshift().

◆ mod()

double_int double_int::mod ( double_int b,
bool uns,
unsigned code ) const
Returns A % B (computed as unsigned depending on UNS, and rounded as
specified by CODE).  CODE is enum tree_code in fact, but double_int.h
must be included before tree.h.   

References divmod(), ggc_alloc(), and mod().

Referenced by div(), divmod(), divmod_with_overflow(), mod(), sdivmod(), smod(), udivmod(), and umod().

◆ mul_with_sign()

double_int double_int::mul_with_sign ( double_int b,
bool unsigned_p,
bool * overflow ) const
Returns A * B. If the operation overflows according to UNSIGNED_P,
*OVERFLOW is set to nonzero.   

References a, b, ggc_alloc(), and mul_double_wide_with_sign().

◆ multiple_of()

bool double_int::multiple_of ( double_int factor,
bool unsigned_p,
double_int * multiple ) const
Return TRUE iff PRODUCT is an integral multiple of FACTOR, and return
the multiple in *MULTIPLE.  Otherwise return FALSE and leave *MULTIPLE
unchanged.   

References divmod(), and ggc_alloc().

◆ neg_with_overflow()

double_int double_int::neg_with_overflow ( bool * overflow) const

References ggc_alloc(), high, low, and neg_double().

◆ operator!=()

bool double_int::operator!= ( double_int cst2) const
inline
Returns true if CST1 != CST2.   

References ggc_alloc(), high, and low.

◆ operator&()

double_int double_int::operator& ( double_int b) const
inline
Returns A & B.   

References b, high, and low.

◆ operator&=()

double_int & double_int::operator&= ( double_int b)
inline

References b.

◆ operator*()

double_int double_int::operator* ( double_int b) const
Returns A * B.   

References a, b, ggc_alloc(), and mul_double.

◆ operator*=()

double_int & double_int::operator*= ( double_int b)
Multiplies *this with B and returns a reference to *this.   

References b, high, low, and mul_double.

◆ operator+()

double_int double_int::operator+ ( double_int b) const
Returns A + B.   

References a, add_double, b, and ggc_alloc().

◆ operator++()

double_int & double_int::operator++ ( )
inline

References double_int_one.

◆ operator+=()

double_int & double_int::operator+= ( double_int b)
Adds B to *this and returns a reference to *this.   

References add_double, b, high, and low.

◆ operator-() [1/2]

double_int double_int::operator- ( ) const
Returns -A.   

References a, ggc_alloc(), and neg_double().

◆ operator-() [2/2]

double_int double_int::operator- ( double_int b) const
Returns A - B.   

References a, add_double, b, ggc_alloc(), and neg_double().

◆ operator--()

double_int & double_int::operator-- ( )
inline

References double_int_one.

◆ operator-=()

double_int & double_int::operator-= ( double_int b)
Subtracts B from *this and returns a reference to *this.   

References add_double, b, high, low, and neg_double().

◆ operator==()

bool double_int::operator== ( double_int cst2) const
inline
Returns true if CST1 == CST2.   

References ggc_alloc(), high, and low.

◆ operator^()

double_int double_int::operator^ ( double_int b) const
inline
Returns A ^ B.   

References b, high, and low.

◆ operator^=()

double_int & double_int::operator^= ( double_int b)
inline

References b.

◆ operator|()

double_int double_int::operator| ( double_int b) const
inline
Returns A | B.   

References b, high, and low.

◆ operator|=()

double_int & double_int::operator|= ( double_int b)
inline

References b.

◆ operator~()

double_int double_int::operator~ ( ) const
inline
Logical operations.   
Returns ~A.   

References ggc_alloc(), high, and low.

◆ popcount()

int double_int::popcount ( ) const
inline
Return number of set bits of CST.   

References high, low, and popcount_hwi().

◆ rrotate()

double_int double_int::rrotate ( HOST_WIDE_INT count,
unsigned int prec ) const
Rotate A rigth by COUNT places keeping only PREC bits of result.
Rotate right if COUNT is negative.   

References count, llshift(), and lrshift().

◆ rshift() [1/2]

double_int double_int::rshift ( HOST_WIDE_INT count) const

◆ rshift() [2/2]

double_int double_int::rshift ( HOST_WIDE_INT count,
unsigned int prec,
bool arith ) const
Shift A right by COUNT places keeping only PREC bits of result.  Shift
left if COUNT is negative.  ARITH true specifies arithmetic shifting;
otherwise use logical shift.   

References absu_hwi(), count, ggc_alloc(), high, low, lshift_double(), and rshift_double().

◆ scmp()

int double_int::scmp ( double_int b) const
Compares two signed values A and B.  Returns -1 if A < B, 0 if A == B,
and 1 if A > B.   

References a, and b.

Referenced by cmp(), smax(), and smin().

◆ sdiv()

double_int double_int::sdiv ( double_int b,
unsigned code ) const
The same as double_int::div with UNS = false.   

References div().

◆ sdivmod()

double_int double_int::sdivmod ( double_int b,
unsigned code,
double_int * mod ) const
The same as double_int::divmod with UNS = false.   

References divmod(), and mod().

◆ set_bit()

double_int double_int::set_bit ( unsigned bitpos) const
Set BITPOS bit in A.   

References a, HOST_BITS_PER_WIDE_INT, HOST_WIDE_INT_1, HOST_WIDE_INT_1U, and low.

◆ sext()

double_int double_int::sext ( unsigned prec) const
The same as double_int::ext with UNS = false.   

References ggc_alloc(), high, HOST_BITS_PER_WIDE_INT, low, mask(), and r.

Referenced by ext().

◆ sgt()

bool double_int::sgt ( double_int b) const
Compares two signed values A and B for greater-than.   

References b, high, and low.

◆ sle()

bool double_int::sle ( double_int b) const
Compares two signed values A and B for less-than or equal-to.   

References b, high, and low.

◆ slt()

bool double_int::slt ( double_int b) const
Compares two signed values A and B for less-than.   

References b, high, and low.

◆ smax()

double_int double_int::smax ( double_int b)
Compares two signed values A and B.  Returns max value.   

References b, ggc_alloc(), and scmp().

◆ smin()

double_int double_int::smin ( double_int b)
Compares two signed values A and B.  Returns min value.   

References b, ggc_alloc(), and scmp().

◆ smod()

double_int double_int::smod ( double_int b,
unsigned code ) const
The same as double_int::mod with UNS = false.   

References mod().

◆ sub_with_overflow()

double_int double_int::sub_with_overflow ( double_int b,
bool * overflow ) const
Returns A - B. If the operation overflows via inconsistent sign bits,
*OVERFLOW is set to nonzero.   

References add_double, b, ggc_alloc(), high, low, neg_double(), and OVERFLOW_SUM_SIGN.

◆ to_shwi()

HOST_WIDE_INT double_int::to_shwi ( ) const
inline
Returns value of CST as a signed number.  CST must satisfy
double_int::fits_signed.   

References ggc_alloc(), and low.

◆ to_uhwi()

unsigned HOST_WIDE_INT double_int::to_uhwi ( ) const
inline
Returns value of CST as an unsigned number.  CST must satisfy
double_int::fits_unsigned.   

References low.

◆ trailing_zeros()

int double_int::trailing_zeros ( ) const
Count trailing zeros in A.   

References a, ctz_hwi(), ggc_alloc(), HOST_BITS_PER_DOUBLE_INT, and HOST_BITS_PER_WIDE_INT.

◆ ucmp()

int double_int::ucmp ( double_int b) const
Compares two unsigned values A and B.  Returns -1 if A < B, 0 if A == B,
and 1 if A > B.   

References a, b, and ggc_alloc().

Referenced by cmp(), do_fixed_divide(), umax(), and umin().

◆ udiv()

double_int double_int::udiv ( double_int b,
unsigned code ) const
The same as double_int::div with UNS = true.   

References div().

◆ udivmod()

double_int double_int::udivmod ( double_int b,
unsigned code,
double_int * mod ) const
The same as double_int::divmod with UNS = true.   

References divmod(), and mod().

◆ ugt()

bool double_int::ugt ( double_int b) const
Compares two unsigned values A and B for greater-than.   

References b, ggc_alloc(), high, and low.

◆ ule()

bool double_int::ule ( double_int b) const
Compares two unsigned values A and B for less-than or equal-to.   

References b, ggc_alloc(), high, and low.

◆ ult()

bool double_int::ult ( double_int b) const
Compares two unsigned values A and B for less-than.   

References b, ggc_alloc(), high, and low.

Referenced by do_fixed_multiply().

◆ umax()

double_int double_int::umax ( double_int b)
Compares two unsigned values A and B.  Returns max value.   

References b, ggc_alloc(), and ucmp().

◆ umin()

double_int double_int::umin ( double_int b)
Compares two unsigned values A and B.  Returns min value.   

References b, ggc_alloc(), and ucmp().

◆ umod()

double_int double_int::umod ( double_int b,
unsigned code ) const
The same as double_int::mod with UNS = true.   

References mod().

◆ wide_mul_with_sign()

double_int double_int::wide_mul_with_sign ( double_int b,
bool unsigned_p,
double_int * higher,
bool * overflow ) const

◆ zext()

double_int double_int::zext ( unsigned prec) const
The same as double_int::ext with UNS = true.   

References ggc_alloc(), high, low, mask(), and r.

Referenced by ext().

Field Documentation

◆ high

◆ low


The documentation for this struct was generated from the following files: