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

Static Public Member Functions

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

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 191 of file FVInt.h.

Constructor & Destructor Documentation

◆ FVInt() [1/4]

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/4]

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/4]

circt::FVInt::FVInt ( const 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/4]

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 55 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 336 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 594 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 88 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 66 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 71 of file FVInt.h.

References FVInt().

◆ getAllZ()

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

Construct an FVInt with all bits set to Z.

Definition at line 76 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 194 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 81 of file FVInt.h.

References value.

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

◆ getOneBits()

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

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

Definition at line 212 of file FVInt.h.

References unknown, and 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 107 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 103 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 98 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 221 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 215 of file FVInt.h.

References unknown, and value.

◆ getZBits()

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

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

Definition at line 218 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 61 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 209 of file FVInt.h.

References unknown, and value.

Referenced by operator&=().

◆ hasUnknown()

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

Determine if any bits are X or Z.

Definition at line 164 of file FVInt.h.

References unknown.

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

◆ isAllOnes()

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

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

Definition at line 170 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 173 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 176 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 181 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 167 of file FVInt.h.

References unknown, and value.

◆ 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 459 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 568 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 572 of file FVInt.h.

◆ operator&()

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

Compute the logical AND.

Definition at line 378 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 358 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 369 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 540 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 523 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 532 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 490 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 473 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 482 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 465 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 515 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 498 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 507 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 306 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 318 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 553 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 562 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 447 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 430 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 439 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 414 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 394 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 405 of file FVInt.h.

References replaceZWithX(), unknown, and value.

◆ operator~()

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

Compute the logical NOT.

Definition at line 342 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 279 of file FVInt.h.

References unknown, and value.

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

◆ setAllOne()

void circt::FVInt::setAllOne ( )
inline

Set all bits to 1.

Definition at line 258 of file FVInt.h.

References unknown, and value.

◆ setAllX()

void circt::FVInt::setAllX ( )
inline

Set all bits to X.

Definition at line 264 of file FVInt.h.

References unknown, and value.

Referenced by operator<<=(), 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 287 of file FVInt.h.

References hasUnknown(), and setAllX().

Referenced by negate(), 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 295 of file FVInt.h.

References hasUnknown(), and setAllX().

◆ setAllZ()

void circt::FVInt::setAllZ ( )
inline

Set all bits to Z.

Definition at line 270 of file FVInt.h.

References unknown, and value.

◆ setAllZero()

void circt::FVInt::setAllZero ( )
inline

Set all bits to 0.

Definition at line 252 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 199 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 204 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 232 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 239 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 246 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 225 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 144 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 155 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 111 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 616 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 128 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().

◆ 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 135 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 150 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: