FLANG
Fortran::evaluate::value::IntegerValue Class Reference

#include <flang/Evaluate/integer-value.h>

Classes

struct  PowerWithErrors
struct  Product
struct  QuotientWithRemainder
struct  ValueWithCarry
struct  ValueWithOverflow

Public Member Functions

 IntegerValue (const IntegerValue &)
 IntegerValue (IntegerValue &&)
IntegerValue & operator= (const IntegerValue &)
IntegerValue & operator= (IntegerValue &&)
 IntegerValue (int kind, const IntegerValue &x)
 IntegerValue (int kind, IntegerValue &&x)
template<typename INT, typename = std::enable_if_t<common::numeric_limits<INT>::is_integer>>
 IntegerValue (int kind, INT v)
void print (llvm::raw_ostream &os) const
LLVM_DUMP_METHOD void dump () const
bool IsNull () const
int kind () const
 The kind of the value currently stored.
int bits () const
std::size_t bytesStored () const
 Number of bytes accessed by FromRawBytes/StoreRawBytes.
bool operator< (const IntegerValue &y) const
bool operator<= (const IntegerValue &y) const
bool operator== (const IntegerValue &y) const
bool operator!= (const IntegerValue &y) const
bool operator>= (const IntegerValue &y) const
bool operator> (const IntegerValue &y) const
std::string UnsignedDecimal () const
std::string SignedDecimal () const
std::string Hexadecimal () const
 Omits a leading "0x".
bool IsZero () const
bool IsNegative () const
Ordering CompareToZeroSigned () const
int LEADZ () const
int POPCNT () const
 Count the number of bit positions that are set.
bool POPPAR () const
 True when POPCNT is odd.
int TRAILZ () const
bool BTEST (int pos) const
Ordering CompareUnsigned (const IntegerValue &y) const
Ordering CompareSigned (const IntegerValue &y) const
bool BGE (const IntegerValue &y) const
bool BGT (const IntegerValue &y) const
bool BLE (const IntegerValue &y) const
bool BLT (const IntegerValue &y) const
std::uint64_t ToUInt64 () const
std::int64_t ToInt64 () const
Fortran::common::uint128_t ToUInt128 () const
Fortran::common::int128_t ToInt128 () const
template<typename INT, typename = std::enable_if_t<std::is_signed_v<INT> || std::is_same_v<INT, Fortran::common::int128_t>>>
INT ToSInt () const
template<typename INT, typename = std::enable_if_t<std::is_unsigned_v<INT> || std::is_same_v<INT, Fortran::common::uint128_t>>>
INT ToUInt () const
IntegerValue NOT () const
 Ones'-complement (i.e., C's ~)
ValueWithOverflow Negate () const
ValueWithOverflow ABS () const
IntegerValue ISHFT (int count) const
IntegerValue SHIFTL (int count) const
 Left shift with zero fill.
IntegerValue ISHFTC (int count, int size) const
IntegerValue ISHFTC (int count) const
IntegerValue DSHIFTL (const IntegerValue &fill, int count) const
 DSHIFTL(I,J) shifts I:J left; the second argument is the right fill.
IntegerValue DSHIFTR (const IntegerValue &v2, int count) const
 DSHIFTR(I,J) shifts I:J right; the first argument is the left fill.
IntegerValue SHIFTR (int count) const
 Vacated upper bits are filled with zeroes.
IntegerValue SHIFTA (int count) const
IntegerValue IBCLR (int pos) const
 Clears a single bit.
IntegerValue IBSET (int pos) const
 Sets a single bit.
IntegerValue IBITS (int pos, int size) const
 Extracts a field.
IntegerValue IAND (const IntegerValue &y) const
IntegerValue IOR (const IntegerValue &y) const
IntegerValue IEOR (const IntegerValue &y) const
IntegerValue MERGE_BITS (const IntegerValue &y, const IntegerValue &mask) const
IntegerValue MAX (const IntegerValue &y) const
IntegerValue MIN (const IntegerValue &y) const
ValueWithCarry AddUnsigned (const IntegerValue &y, bool carryIn=false) const
ValueWithOverflow AddSigned (const IntegerValue &y) const
ValueWithOverflow SubtractSigned (const IntegerValue &y) const
ValueWithOverflow DIM (const IntegerValue &y) const
 DIM(X,Y)=MAX(X-Y, 0)
ValueWithOverflow SIGN (const IntegerValue &sign) const
Product MultiplyUnsigned (const IntegerValue &y) const
Product MultiplySigned (const IntegerValue &y) const
QuotientWithRemainder DivideUnsigned (const IntegerValue &y) const
QuotientWithRemainder DivideSigned (const IntegerValue &y) const
ValueWithOverflow MODULO (const IntegerValue &y) const
PowerWithErrors Power (const IntegerValue &e) const
void StoreRawBytes (void *dst, size_t size, bool *changed=nullptr) const

Static Public Member Functions

static IntegerValue Zero (int kind)
static constexpr int bits (int kind)
static constexpr std::size_t bytesStored (int kind)
static IntegerValue MASKL (int kind, int places)
 Left-justified mask (e.g., MASKL(1) has only its sign bit set)
static IntegerValue MASKR (int kind, int places)
 Right-justified mask (e.g., MASKR(1) == 1, MASKR(2) == 3, &c.)
static ValueWithOverflow Read (int kind, const char *&pp, int base, bool isSigned)
static ValueWithOverflow ConvertUnsigned (int toKind, const IntegerValue &from)
 ZExt or Trunc.
static ValueWithOverflow ConvertSigned (int toKind, const IntegerValue &from)
 SExt or Trunc.
static constexpr int DIGITS (int kind)
static IntegerValue HUGE (int kind)
static IntegerValue Least (int kind)
static int RANGE (int kind)
static int UnsignedRANGE (int kind)
static IntegerValue FromRawBytes (int kind, const void *raw, std::size_t expectedSize)

Friends

class RealValueImpl

Detailed Description

A two's-complement integer with dynamic bitwidth.

The bitwidth is dynamic, but only a predefined set of Fortran kinds are allowed. It is also kind-aware, i.e. knows which INTEGER kind it currently represents.

The implementation is hidden from this header using a pImpl-like idiom.

Member Function Documentation

◆ DivideSigned()

IntegerValue::QuotientWithRemainder Fortran::evaluate::value::IntegerValue::DivideSigned ( const IntegerValue & y) const

A nonzero remainder has the sign of the dividend, i.e., it computes the MOD intrinsic (X-INT(X/Y)*Y), not MODULO (which is below). 8/5 = 1r3; -8/5 = -1r-3; 8/-5 = -1r3; -8/-5 = 1r-3

◆ ISHFT()

IntegerValue Fortran::evaluate::value::IntegerValue::ISHFT ( int count) const
inline

Shifts the operand left when the count is positive, right when negative. Vacated bit positions are filled with zeroes.

◆ ISHFTC()

IntegerValue Fortran::evaluate::value::IntegerValue::ISHFTC ( int count,
int size ) const

Circular shift of a field of least-significant bits. The least-order "size" bits are shifted circularly in place by "count" positions; the shift is leftward if count is nonnegative, rightward otherwise. Higher-order bits are unchanged.

◆ IsNull()

bool Fortran::evaluate::value::IntegerValue::IsNull ( ) const

Whether this object represents a default-initialized value (zero) of not-yet-known kind.

◆ LEADZ()

int Fortran::evaluate::value::IntegerValue::LEADZ ( ) const

Count the number of contiguous most-significant bit positions that are clear.

◆ MODULO()

IntegerValue::ValueWithOverflow Fortran::evaluate::value::IntegerValue::MODULO ( const IntegerValue & y) const

Result has the sign of the divisor argument. 8 mod 5 = 3; -8 mod 5 = 2; 8 mod -5 = -2; -8 mod -5 = -3

◆ Negate()

IntegerValue::ValueWithOverflow Fortran::evaluate::value::IntegerValue::Negate ( ) const

Two's-complement negation (-x = ~x + 1). An overflow flag accompanies the result, and will be true when the operand is the most negative signed number (MASKL(1)).

◆ SHIFTA()

IntegerValue Fortran::evaluate::value::IntegerValue::SHIFTA ( int count) const

Be advised, an arithmetic (sign-filling) right shift is not the same as a division by a power of two in all cases.

◆ Zero()

IntegerValue Fortran::evaluate::value::IntegerValue::Zero ( int kind)
static

Creates an integer with value 0 of a given kind. This is different from the default-ctor which creates a null state that represents 0 of unknown kind.


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