CIRCT 22.0.0git
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
circt::FVInt Class Reference

Four-valued arbitrary precision integers. More...

#include <FVInt.h>

Collaboration diagram for circt::FVInt:
Collaboration graph
[legend]

Public Types

enum  Bit { V0 = 0b00 , V1 = 0b01 , X = 0b10 , Z = 0b11 }
 The value of an individual bit. Can be 0, 1, X, or Z. More...
 

Public Member Functions

 FVInt ()
 Default constructor that creates an zero-bit zero value.
 
 FVInt (unsigned numBits, uint64_t value, bool isSigned=false)
 Construct an FVInt from a 64-bit value. The result has no X or Z bits.
 
 FVInt (APInt &&value)
 Construct an FVInt from an APInt. The result has no X or Z bits.
 
 FVInt (const APInt &value)
 Construct an FVInt from an APInt. The result has no X or Z bits.
 
 FVInt (APInt &&rawValue, APInt &&rawUnknown)
 Construct an FVInt from two APInts used internally to store the bit data.
 
unsigned getBitWidth () const
 Return the number of bits this integer has.
 
unsigned getActiveBits () const
 Compute the number of active bits in the value.
 
unsigned getSignificantBits () const
 Compute the minimum bit width necessary to accurately represent this integer's value and sign.
 
const APInt & getRawValue () const
 Return the underlying APInt used to store whether a bit is 0/X or 1/Z.
 
const APInt & getRawUnknown () const
 Return the underlying APInt used to store whether a bit is unknown (X or Z).
 
APInt toAPInt (bool unknownBitMapping) const
 Convert the four-valued FVInt to a two-valued APInt by mapping X and Z bits to either 0 or 1.
 
FVInt trunc (unsigned bitWidth) const
 Truncate the integer to a smaller bit width.
 
FVInt zext (unsigned bitWidth) const
 Zero-extend the integer to a new bit width.
 
FVInt sext (unsigned bitWidth) const
 Sign-extend the integer to a new bit width.
 
FVInt zextOrTrunc (unsigned bitWidth) const
 Truncate or zero-extend to a target bit width.
 
FVInt sextOrTrunc (unsigned bitWidth) const
 Truncate or sign-extend to a target bit width.
 
bool hasUnknown () const
 Determine if any bits are X or Z.
 
bool isZero () const
 Determine if all bits are 0. This is true for zero-width values.
 
bool isAllOnes () const
 Determine if all bits are 1. This is true for zero-width values.
 
bool isAllX () const
 Determine if all bits are X. This is true for zero-width values.
 
bool isAllZ () const
 Determine if all bits are Z. This is true for zero-width values.
 
bool isNegative () const
 Determine whether the integer interpreted as a signed number would be negative.
 
Bit getBit (unsigned index) const
 Get the value of an individual bit.
 
void setBit (unsigned index, Bit bit)
 Set the value of an individual bit.
 
void setBit (unsigned index, bool val)
 
APInt getZeroBits () const
 Compute a mask of all the 0 bits in this integer.
 
APInt getOneBits () const
 Compute a mask of all the 1 bits in this integer.
 
APInt getXBits () const
 Compute a mask of all the X bits in this integer.
 
APInt getZBits () const
 Compute a mask of all the Z bits in this integer.
 
APInt getUnknownBits () const
 Compute a mask of all the X and Z bits in this integer.
 
template<typename T >
void setZeroBits (const T &mask)
 Set the value of all bits in the mask to 0.
 
template<typename T >
void setOneBits (const T &mask)
 Set the value of all bits in the mask to 1.
 
template<typename T >
void setXBits (const T &mask)
 Set the value of all bits in the mask to X.
 
template<typename T >
void setZBits (const T &mask)
 Set the value of all bits in the mask to Z.
 
void setAllZero ()
 Set all bits to 0.
 
void setAllOne ()
 Set all bits to 1.
 
void setAllX ()
 Set all bits to X.
 
void setAllZ ()
 Set all bits to Z.
 
void replaceZWithX ()
 Replace all Z bits with X.
 
void setAllXIfAnyUnknown ()
 If any bits are X or Z, set the entire integer to X.
 
void setAllXIfAnyUnknown (const FVInt &other)
 If any bits in this integer or another integer are X or Z, set the entire integer to X.
 
FVIntoperator<<= (const FVInt &amount)
 Perform a logical left-shift.
 
template<typename T >
FVIntoperator<<= (const T &amount)
 Perform a logical left-shift by a two-valued amount.
 
void flipAllBits ()
 Compute the logical NOT of this integer.
 
FVInt operator~ () const
 Compute the logical NOT.
 
FVIntoperator&= (const FVInt &other)
 Compute the logical AND of this integer and another.
 
template<typename T >
FVIntoperator&= (T other)
 Compute the logical AND of this integer and a two-valued integer.
 
template<typename T >
FVInt operator& (const T &other) const
 Compute the logical AND.
 
FVIntoperator|= (const FVInt &other)
 Compute the logical OR of this integer and another.
 
template<typename T >
FVIntoperator|= (T other)
 Compute the logical OR of this integer and a two-valued integer.
 
template<typename T >
FVInt operator| (const T &other) const
 Compute the logical OR.
 
FVIntoperator^= (const FVInt &other)
 Compute the logical XOR of this integer and another.
 
template<typename T >
FVIntoperator^= (const T &other)
 Compute the logical XOR of this integer and a two-valued integer.
 
template<typename T >
FVInt operator^ (const T &other) const
 Compute the logical XOR.
 
void negate ()
 Compute the negation of this integer.
 
FVInt operator- () const
 Compute the negation of this integer.
 
FVIntoperator+= (const FVInt &other)
 Compute the addition of this integer and another.
 
template<typename T >
FVIntoperator+= (const T &other)
 Compute the addition of this integer and a two-valued integer.
 
template<typename T >
FVInt operator+ (const T &other) const
 Compute an addition.
 
FVIntoperator-= (const FVInt &other)
 Compute the subtraction of this integer and another.
 
template<typename T >
FVIntoperator-= (const T &other)
 Compute the subtraction of this integer and a two-valued integer.
 
template<typename T >
FVInt operator- (const T &other) const
 Compute an subtraction.
 
FVIntoperator*= (const FVInt &other)
 Compute the multiplication of this integer and another.
 
template<typename T >
FVIntoperator*= (const T &other)
 Compute the multiplication of this integer and a two-valued integer.
 
template<typename T >
FVInt operator* (const T &other) const
 Compute a multiplication.
 
FVInt udiv (const FVInt &other) const
 Compute an unsigned division.
 
FVInt udiv (uint64_t other) const
 
FVInt sdiv (const FVInt &other) const
 Compute a signed division.
 
FVInt sdiv (int64_t other) const
 
bool operator== (const FVInt &other) const
 Determine whether this integer is equal to another.
 
template<typename T >
bool operator== (const T &other) const
 Determine whether this integer is equal to a two-valued integer.
 
bool operator!= (const FVInt &other) const
 Determine whether this integer is not equal to another.
 
template<typename T >
bool operator!= (const T &other) const
 Determine whether this integer is not equal to a two-valued integer.
 
bool tryToString (SmallVectorImpl< char > &str, unsigned radix=10, bool uppercase=true) const
 Convert an FVInt to a string.
 
SmallString< 16 > toString (unsigned radix=10, bool uppercase=true) const
 Convert an FVInt to a string.
 
void print (raw_ostream &os) const
 Print an FVInt to an output stream.
 

Static Public Member Functions

static FVInt getZero (unsigned numBits)
 Construct an FVInt with all bits set to 0.
 
static FVInt getAllOnes (unsigned numBits)
 Construct an FVInt with all bits set to 1.
 
static FVInt getAllX (unsigned numBits)
 Construct an FVInt with all bits set to X.
 
static FVInt getAllZ (unsigned numBits)
 Construct an FVInt with all bits set to Z.
 
static std::optional< FVInttryFromString (StringRef str, unsigned radix=10)
 Convert a string into an FVInt.
 
static FVInt fromString (StringRef str, unsigned radix=10)
 Convert a string into an FVInt.
 

Private Attributes

APInt value
 
APInt unknown
 

Detailed Description

Four-valued arbitrary precision integers.

Each bit of the integer can be 0, 1, X, or Z. Internally the bits are stored in a pair of APInts, one of which specifies the value of each bit (0/X or 1/Z), and the other whether the bit is unknown (X or Z).

Definition at line 37 of file FVInt.h.

Member Enumeration Documentation

◆ Bit

The value of an individual bit. Can be 0, 1, X, or Z.

Enumerator
V0 
V1 

Definition at line 195 of file FVInt.h.

Constructor & Destructor Documentation

◆ FVInt() [1/5]

circt::FVInt::FVInt ( )
inlineexplicit

Default constructor that creates an zero-bit zero value.

Definition at line 40 of file FVInt.h.

Referenced by getAllOnes(), getAllX(), getAllZ(), getZero(), sext(), trunc(), and zext().

◆ FVInt() [2/5]

circt::FVInt::FVInt ( unsigned  numBits,
uint64_t  value,
bool  isSigned = false 
)
inline

Construct an FVInt from a 64-bit value. The result has no X or Z bits.

Definition at line 43 of file FVInt.h.

◆ FVInt() [3/5]

circt::FVInt::FVInt ( APInt &&  value)
inline

Construct an FVInt from an APInt. The result has no X or Z bits.

Definition at line 47 of file FVInt.h.

◆ FVInt() [4/5]

circt::FVInt::FVInt ( const APInt &  value)
inline

Construct an FVInt from an APInt. The result has no X or Z bits.

Definition at line 51 of file FVInt.h.

◆ FVInt() [5/5]

circt::FVInt::FVInt ( APInt &&  rawValue,
APInt &&  rawUnknown 
)
inline

Construct an FVInt from two APInts used internally to store the bit data.

The first argument specifies whether each bit is 0/X or 1/Z. The second argument specifies whether each bit is 0/1 or X/Z. Both APInts must have the same bitwidth. The two arguments correspond to the results of getRawValue() and getRawUnknown().

Definition at line 59 of file FVInt.h.

References assert().

Member Function Documentation

◆ flipAllBits()

void circt::FVInt::flipAllBits ( )
inline

Compute the logical NOT of this integer.

This implements the following bit-wise truth table:

0 | 1
1 | 0
X | X
Z | X

Definition at line 340 of file FVInt.h.

References replaceZWithX(), and value.

Referenced by operator~().

◆ fromString()

static FVInt circt::FVInt::fromString ( StringRef  str,
unsigned  radix = 10 
)
inlinestatic

Convert a string into an FVInt.

Same as tryFromString, but aborts if the string is malformed.

Definition at line 628 of file FVInt.h.

References assert(), and tryFromString().

◆ getActiveBits()

unsigned circt::FVInt::getActiveBits ( ) const
inline

Compute the number of active bits in the value.

This is the smallest bit width to which the value can be truncated without losing information in the most significant bits. Or put differently, the value truncated to its active bits and zero-extended back to its original width produces the original value.

Definition at line 92 of file FVInt.h.

References unknown, and value.

◆ getAllOnes()

static FVInt circt::FVInt::getAllOnes ( unsigned  numBits)
inlinestatic

Construct an FVInt with all bits set to 1.

Definition at line 70 of file FVInt.h.

References FVInt().

◆ getAllX()

static FVInt circt::FVInt::getAllX ( unsigned  numBits)
inlinestatic

Construct an FVInt with all bits set to X.

Definition at line 75 of file FVInt.h.

References FVInt().

Referenced by sdiv(), sdiv(), udiv(), and udiv().

◆ getAllZ()

static FVInt circt::FVInt::getAllZ ( unsigned  numBits)
inlinestatic

Construct an FVInt with all bits set to Z.

Definition at line 80 of file FVInt.h.

References FVInt().

◆ getBit()

Bit circt::FVInt::getBit ( unsigned  index) const
inline

Get the value of an individual bit.

Definition at line 198 of file FVInt.h.

References unknown, and value.

◆ getBitWidth()

unsigned circt::FVInt::getBitWidth ( ) const
inline

Return the number of bits this integer has.

Definition at line 85 of file FVInt.h.

References value.

Referenced by isNegative(), circt::operator-(), operator==(), circt::printFVInt(), sdiv(), sdiv(), sext(), sextOrTrunc(), trunc(), tryToString(), udiv(), udiv(), zext(), and zextOrTrunc().

◆ getOneBits()

APInt circt::FVInt::getOneBits ( ) const
inline

Compute a mask of all the 1 bits in this integer.

Definition at line 216 of file FVInt.h.

References value.

Referenced by operator|=().

◆ getRawUnknown()

const APInt & circt::FVInt::getRawUnknown ( ) const
inline

Return the underlying APInt used to store whether a bit is unknown (X or Z).

Definition at line 111 of file FVInt.h.

References unknown.

Referenced by circt::hash_value().

◆ getRawValue()

const APInt & circt::FVInt::getRawValue ( ) const
inline

Return the underlying APInt used to store whether a bit is 0/X or 1/Z.

Definition at line 107 of file FVInt.h.

References value.

Referenced by circt::hash_value().

◆ getSignificantBits()

unsigned circt::FVInt::getSignificantBits ( ) const
inline

Compute the minimum bit width necessary to accurately represent this integer's value and sign.

This is the smallest bit width to which the value can be truncated without losing information in the most significant bits and without flipping from negative to positive or vice versa. Or put differently, the value truncated to its significant bits and sign-extended back to its original width produces the original value.

Definition at line 102 of file FVInt.h.

References unknown, and value.

◆ getUnknownBits()

APInt circt::FVInt::getUnknownBits ( ) const
inline

Compute a mask of all the X and Z bits in this integer.

Definition at line 225 of file FVInt.h.

References unknown.

◆ getXBits()

APInt circt::FVInt::getXBits ( ) const
inline

Compute a mask of all the X bits in this integer.

Definition at line 219 of file FVInt.h.

References unknown.

◆ getZBits()

APInt circt::FVInt::getZBits ( ) const
inline

Compute a mask of all the Z bits in this integer.

Definition at line 222 of file FVInt.h.

References unknown, and value.

◆ getZero()

static FVInt circt::FVInt::getZero ( unsigned  numBits)
inlinestatic

Construct an FVInt with all bits set to 0.

Definition at line 65 of file FVInt.h.

References FVInt().

Referenced by tryFromString().

◆ getZeroBits()

APInt circt::FVInt::getZeroBits ( ) const
inline

Compute a mask of all the 0 bits in this integer.

Definition at line 213 of file FVInt.h.

Referenced by operator&=().

◆ hasUnknown()

bool circt::FVInt::hasUnknown ( ) const
inline

Determine if any bits are X or Z.

Definition at line 168 of file FVInt.h.

References unknown.

Referenced by operator<<=(), operator==(), sdiv(), sdiv(), setAllXIfAnyUnknown(), setAllXIfAnyUnknown(), tryToString(), udiv(), and udiv().

◆ isAllOnes()

bool circt::FVInt::isAllOnes ( ) const
inline

Determine if all bits are 1. This is true for zero-width values.

Definition at line 174 of file FVInt.h.

References unknown, and value.

◆ isAllX()

bool circt::FVInt::isAllX ( ) const
inline

Determine if all bits are X. This is true for zero-width values.

Definition at line 177 of file FVInt.h.

References unknown, and value.

◆ isAllZ()

bool circt::FVInt::isAllZ ( ) const
inline

Determine if all bits are Z. This is true for zero-width values.

Definition at line 180 of file FVInt.h.

References unknown, and value.

◆ isNegative()

bool circt::FVInt::isNegative ( ) const
inline

Determine whether the integer interpreted as a signed number would be negative.

Returns true if the sign bit is 1, and false if it is 0, X, or Z.

Definition at line 185 of file FVInt.h.

References getBitWidth(), unknown, and value.

Referenced by circt::printFVInt().

◆ isZero()

bool circt::FVInt::isZero ( ) const
inline

Determine if all bits are 0. This is true for zero-width values.

Definition at line 171 of file FVInt.h.

References unknown, and value.

Referenced by sdiv(), and udiv().

◆ negate()

void circt::FVInt::negate ( )
inline

Compute the negation of this integer.

If any bits are unknown, the entire result is X.

Definition at line 463 of file FVInt.h.

References setAllXIfAnyUnknown(), and value.

Referenced by operator-().

◆ operator!=() [1/2]

bool circt::FVInt::operator!= ( const FVInt other) const
inline

Determine whether this integer is not equal to another.

Returns true if the two integers have different bit width.

Definition at line 602 of file FVInt.h.

◆ operator!=() [2/2]

template<typename T >
bool circt::FVInt::operator!= ( const T &  other) const
inline

Determine whether this integer is not equal to a two-valued integer.

Definition at line 606 of file FVInt.h.

◆ operator&()

template<typename T >
FVInt circt::FVInt::operator& ( const T &  other) const
inline

Compute the logical AND.

Definition at line 382 of file FVInt.h.

◆ operator&=() [1/2]

FVInt & circt::FVInt::operator&= ( const FVInt other)
inline

Compute the logical AND of this integer and another.

This implements the following bit-wise truth table:

0 1 X Z
+--------
0 | 0 0 0 0
1 | 0 1 X X
X | 0 X X X
Z | 0 X X X

Definition at line 362 of file FVInt.h.

References getZeroBits(), replaceZWithX(), unknown, and value.

◆ operator&=() [2/2]

template<typename T >
FVInt & circt::FVInt::operator&= ( other)
inline

Compute the logical AND of this integer and a two-valued integer.

Definition at line 373 of file FVInt.h.

References replaceZWithX(), unknown, and value.

◆ operator*()

template<typename T >
FVInt circt::FVInt::operator* ( const T &  other) const
inline

Compute a multiplication.

Definition at line 544 of file FVInt.h.

◆ operator*=() [1/2]

FVInt & circt::FVInt::operator*= ( const FVInt other)
inline

Compute the multiplication of this integer and another.

If any bits in either integer are unknown, the entire result is X.

Definition at line 527 of file FVInt.h.

References setAllXIfAnyUnknown(), and value.

◆ operator*=() [2/2]

template<typename T >
FVInt & circt::FVInt::operator*= ( const T &  other)
inline

Compute the multiplication of this integer and a two-valued integer.

If any bit in the integer is unknown, the entire result is X.

Definition at line 536 of file FVInt.h.

References setAllXIfAnyUnknown(), and value.

◆ operator+()

template<typename T >
FVInt circt::FVInt::operator+ ( const T &  other) const
inline

Compute an addition.

Definition at line 494 of file FVInt.h.

◆ operator+=() [1/2]

FVInt & circt::FVInt::operator+= ( const FVInt other)
inline

Compute the addition of this integer and another.

If any bits in either integer are unknown, the entire result is X.

Definition at line 477 of file FVInt.h.

References setAllXIfAnyUnknown(), and value.

◆ operator+=() [2/2]

template<typename T >
FVInt & circt::FVInt::operator+= ( const T &  other)
inline

Compute the addition of this integer and a two-valued integer.

If any bit in the integer is unknown, the entire result is X.

Definition at line 486 of file FVInt.h.

References setAllXIfAnyUnknown(), and value.

◆ operator-() [1/2]

FVInt circt::FVInt::operator- ( ) const
inline

Compute the negation of this integer.

Definition at line 469 of file FVInt.h.

References negate().

◆ operator-() [2/2]

template<typename T >
FVInt circt::FVInt::operator- ( const T &  other) const
inline

Compute an subtraction.

Definition at line 519 of file FVInt.h.

◆ operator-=() [1/2]

FVInt & circt::FVInt::operator-= ( const FVInt other)
inline

Compute the subtraction of this integer and another.

If any bits in either integer are unknown, the entire result is X.

Definition at line 502 of file FVInt.h.

References setAllXIfAnyUnknown(), and value.

◆ operator-=() [2/2]

template<typename T >
FVInt & circt::FVInt::operator-= ( const T &  other)
inline

Compute the subtraction of this integer and a two-valued integer.

If any bit in the integer is unknown, the entire result is X.

Definition at line 511 of file FVInt.h.

References setAllXIfAnyUnknown(), and value.

◆ operator<<=() [1/2]

FVInt & circt::FVInt::operator<<= ( const FVInt amount)
inline

Perform a logical left-shift.

If any bits in the shift amount are unknown, the entire result is X.

Definition at line 310 of file FVInt.h.

References hasUnknown(), setAllX(), unknown, and value.

◆ operator<<=() [2/2]

template<typename T >
FVInt & circt::FVInt::operator<<= ( const T &  amount)
inline

Perform a logical left-shift by a two-valued amount.

Definition at line 322 of file FVInt.h.

References unknown, and value.

◆ operator==() [1/2]

bool circt::FVInt::operator== ( const FVInt other) const
inline

Determine whether this integer is equal to another.

Note that this corresponds to SystemVerilog's === operator. Returns false if the two integers have different bit width.

Definition at line 587 of file FVInt.h.

References getBitWidth(), unknown, and value.

◆ operator==() [2/2]

template<typename T >
bool circt::FVInt::operator== ( const T &  other) const
inline

Determine whether this integer is equal to a two-valued integer.

Note that this corresponds to SystemVerilog's === operator.

Definition at line 596 of file FVInt.h.

References hasUnknown(), and value.

◆ operator^()

template<typename T >
FVInt circt::FVInt::operator^ ( const T &  other) const
inline

Compute the logical XOR.

Definition at line 451 of file FVInt.h.

◆ operator^=() [1/2]

FVInt & circt::FVInt::operator^= ( const FVInt other)
inline

Compute the logical XOR of this integer and another.

This implements the following bit-wise truth table:

0 1 X Z
+--------
0 | 0 1 X X
1 | 1 0 X X
X | X X X X
Z | X X X X

Definition at line 434 of file FVInt.h.

References replaceZWithX(), unknown, and value.

◆ operator^=() [2/2]

template<typename T >
FVInt & circt::FVInt::operator^= ( const T &  other)
inline

Compute the logical XOR of this integer and a two-valued integer.

Definition at line 443 of file FVInt.h.

References replaceZWithX(), and value.

◆ operator|()

template<typename T >
FVInt circt::FVInt::operator| ( const T &  other) const
inline

Compute the logical OR.

Definition at line 418 of file FVInt.h.

◆ operator|=() [1/2]

FVInt & circt::FVInt::operator|= ( const FVInt other)
inline

Compute the logical OR of this integer and another.

This implements the following bit-wise truth table:

0 1 X Z
+--------
0 | 0 1 X X
1 | 1 1 1 1
X | X 1 X X
Z | X 1 X X

Definition at line 398 of file FVInt.h.

References getOneBits(), replaceZWithX(), unknown, and value.

◆ operator|=() [2/2]

template<typename T >
FVInt & circt::FVInt::operator|= ( other)
inline

Compute the logical OR of this integer and a two-valued integer.

Definition at line 409 of file FVInt.h.

References replaceZWithX(), unknown, and value.

◆ operator~()

FVInt circt::FVInt::operator~ ( ) const
inline

Compute the logical NOT.

Definition at line 346 of file FVInt.h.

References flipAllBits().

◆ print()

void FVInt::print ( raw_ostream &  os) const

Print an FVInt to an output stream.

Definition at line 135 of file FVInt.cpp.

References tryToString().

Referenced by circt::operator<<().

◆ replaceZWithX()

void circt::FVInt::replaceZWithX ( )
inline

Replace all Z bits with X.

This is useful since most logic operations will treat X and Z bits the same way and produce an X bit in the output. By mapping Z bits to X, these operations can then just handle 0, 1, and X bits.

Definition at line 283 of file FVInt.h.

References value.

Referenced by flipAllBits(), operator&=(), operator&=(), operator^=(), operator^=(), operator|=(), and operator|=().

◆ sdiv() [1/2]

FVInt circt::FVInt::sdiv ( const FVInt other) const
inline

Compute a signed division.

If any bits in either integer are unknown, the entire result is X. On division by zero the entire result is X. See IEEE 1800-2017 § 11.4.3 Arithmetic operators.

Definition at line 568 of file FVInt.h.

References getAllX(), getBitWidth(), hasUnknown(), isZero(), and value.

◆ sdiv() [2/2]

FVInt circt::FVInt::sdiv ( int64_t  other) const
inline

Definition at line 574 of file FVInt.h.

References getAllX(), getBitWidth(), hasUnknown(), and value.

◆ setAllOne()

void circt::FVInt::setAllOne ( )
inline

Set all bits to 1.

Definition at line 262 of file FVInt.h.

References unknown, and value.

◆ setAllX()

void circt::FVInt::setAllX ( )
inline

Set all bits to X.

Definition at line 268 of file FVInt.h.

References unknown, and value.

Referenced by operator<<=(), setAllXIfAnyUnknown(), and setAllXIfAnyUnknown().

◆ setAllXIfAnyUnknown() [1/2]

void circt::FVInt::setAllXIfAnyUnknown ( )
inline

If any bits are X or Z, set the entire integer to X.

Definition at line 291 of file FVInt.h.

References hasUnknown(), and setAllX().

Referenced by negate(), operator*=(), operator*=(), operator+=(), operator+=(), operator-=(), and operator-=().

◆ setAllXIfAnyUnknown() [2/2]

void circt::FVInt::setAllXIfAnyUnknown ( const FVInt other)
inline

If any bits in this integer or another integer are X or Z, set the entire integer to X.

This is useful for binary operators which want to set their result to X if either of the two inputs contained an X or Z bit.

Definition at line 299 of file FVInt.h.

References hasUnknown(), and setAllX().

◆ setAllZ()

void circt::FVInt::setAllZ ( )
inline

Set all bits to Z.

Definition at line 274 of file FVInt.h.

References unknown, and value.

◆ setAllZero()

void circt::FVInt::setAllZero ( )
inline

Set all bits to 0.

Definition at line 256 of file FVInt.h.

References unknown, and value.

◆ setBit() [1/2]

void circt::FVInt::setBit ( unsigned  index,
Bit  bit 
)
inline

Set the value of an individual bit.

Definition at line 203 of file FVInt.h.

References unknown, and value.

Referenced by setBit().

◆ setBit() [2/2]

void circt::FVInt::setBit ( unsigned  index,
bool  val 
)
inline

Definition at line 208 of file FVInt.h.

References setBit().

◆ setOneBits()

template<typename T >
void circt::FVInt::setOneBits ( const T &  mask)
inline

Set the value of all bits in the mask to 1.

Definition at line 236 of file FVInt.h.

References unknown, and value.

◆ setXBits()

template<typename T >
void circt::FVInt::setXBits ( const T &  mask)
inline

Set the value of all bits in the mask to X.

Definition at line 243 of file FVInt.h.

References unknown, and value.

◆ setZBits()

template<typename T >
void circt::FVInt::setZBits ( const T &  mask)
inline

Set the value of all bits in the mask to Z.

Definition at line 250 of file FVInt.h.

References unknown, and value.

◆ setZeroBits()

template<typename T >
void circt::FVInt::setZeroBits ( const T &  mask)
inline

Set the value of all bits in the mask to 0.

Definition at line 229 of file FVInt.h.

References unknown, and value.

◆ sext()

FVInt circt::FVInt::sext ( unsigned  bitWidth) const
inline

Sign-extend the integer to a new bit width.

The additional high-order bits are filled in with the sign bit (top-most bit) of the original number, also when that sign bit is X or Z. Zero-width integers are extended with zeros.

Definition at line 148 of file FVInt.h.

References assert(), FVInt(), getBitWidth(), unknown, and value.

Referenced by sextOrTrunc().

◆ sextOrTrunc()

FVInt circt::FVInt::sextOrTrunc ( unsigned  bitWidth) const
inline

Truncate or sign-extend to a target bit width.

Definition at line 159 of file FVInt.h.

References getBitWidth(), sext(), and trunc().

◆ toAPInt()

APInt circt::FVInt::toAPInt ( bool  unknownBitMapping) const
inline

Convert the four-valued FVInt to a two-valued APInt by mapping X and Z bits to either 0 or 1.

Definition at line 115 of file FVInt.h.

References unknown, and value.

◆ toString()

SmallString< 16 > circt::FVInt::toString ( unsigned  radix = 10,
bool  uppercase = true 
) const
inline

Convert an FVInt to a string.

Same as tryToString, but directly returns the string and aborts if the conversion is unsuccessful.

Definition at line 650 of file FVInt.h.

References assert(), and tryToString().

◆ trunc()

FVInt circt::FVInt::trunc ( unsigned  bitWidth) const
inline

Truncate the integer to a smaller bit width.

This simply discards the high-order bits. If the integer is truncated to a bit width less than its "active bits", information will be lost and the resulting integer will have a different value.

Definition at line 132 of file FVInt.h.

References assert(), FVInt(), getBitWidth(), unknown, and value.

Referenced by sextOrTrunc(), and zextOrTrunc().

◆ tryFromString()

std::optional< FVInt > FVInt::tryFromString ( StringRef  str,
unsigned  radix = 10 
)
static

Convert a string into an FVInt.

The radix can be 2, 8, 10, or 16. For radix 2, the input string may contain the characters x or X to indicate an unknown X bit, and z or Z to indicate an unknown Z bit. For radix 8, each X or Z counts as 3 bits. For radix 16, each X and Z counts as 4 bits. When radix is 10 the input cannot contain any X or Z.

Returns the parsed integer if the string is non-empty and a well-formed number, otherwise returns none.

Definition at line 17 of file FVInt.cpp.

References assert(), and getZero().

Referenced by fromString(), and circt::parseFVInt().

◆ tryToString()

bool FVInt::tryToString ( SmallVectorImpl< char > &  str,
unsigned  radix = 10,
bool  uppercase = true 
) const

Convert an FVInt to a string.

The radix can be 2, 8, 10, or 16. For radix 8 or 16, the integer can only contain unknown bits in groups of 3 or 4, respectively, such that a X or Z can be printed for the entire group of bits. For radix 10, the integer cannot contain any unknown bits. In case the output contains letters, uppercase specifies whether they are printed as uppercase letters.

Appends the output characters to str and returns true if the integer could be printed with the given configuration. Otherwise returns false and leaves str in its original state. Always succeeds for radix 2.

Definition at line 68 of file FVInt.cpp.

References assert(), getBitWidth(), hasUnknown(), unknown, and value.

Referenced by print(), circt::printFVInt(), and toString().

◆ udiv() [1/2]

FVInt circt::FVInt::udiv ( const FVInt other) const
inline

Compute an unsigned division.

If any bits in either integer are unknown, the entire result is X. On division by zero the entire result is X. See IEEE 1800-2017 § 11.4.3 Arithmetic operators.

Definition at line 553 of file FVInt.h.

References getAllX(), getBitWidth(), hasUnknown(), isZero(), and value.

◆ udiv() [2/2]

FVInt circt::FVInt::udiv ( uint64_t  other) const
inline

Definition at line 559 of file FVInt.h.

References getAllX(), getBitWidth(), hasUnknown(), and value.

◆ zext()

FVInt circt::FVInt::zext ( unsigned  bitWidth) const
inline

Zero-extend the integer to a new bit width.

The additional high-order bits are filled in with zero.

Definition at line 139 of file FVInt.h.

References assert(), FVInt(), getBitWidth(), unknown, and value.

Referenced by circt::parseFVInt(), and zextOrTrunc().

◆ zextOrTrunc()

FVInt circt::FVInt::zextOrTrunc ( unsigned  bitWidth) const
inline

Truncate or zero-extend to a target bit width.

Definition at line 154 of file FVInt.h.

References getBitWidth(), trunc(), and zext().

Member Data Documentation

◆ unknown

APInt circt::FVInt::unknown
private

◆ value

APInt circt::FVInt::value
private

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