|
CIRCT 22.0.0git
|
A lightweight, non-owning bit vector view backed by a byte array span. More...
#include <Values.h>


Classes | |
| class | bit_iterator |
| Forward iterator for iterating over bits from LSB (index 0) to MSB. More... | |
Public Types | |
| using | byte = uint8_t |
Public Member Functions | |
| BitVector (std::span< const byte > bytes, std::optional< size_t > width=std::nullopt, uint8_t bitIndex=0) | |
| Construct from an existing span. | |
| BitVector ()=default | |
| BitVector (const BitVector &other) | |
| BitVector & | operator= (const BitVector &other) |
| size_t | width () const |
| size_t | size () const |
| bool | getBit (size_t i) const |
| Return the i-th bit (0 = LSB) as boolean. | |
| std::span< const byte > | getSpan () const |
| Return a handle to the underlying span. | |
| BitVector | operator>> (size_t n) const |
| Logical right shift that drops the least-significant n bits by advancing the byte/bit index and reducing width. | |
| BitVector & | operator>>= (size_t n) |
| BitVector | slice (size_t offset, size_t sliceWidth) const |
| Create a new immutable view of a contiguous bit slice [offset, offset+sliceWidth). | |
| BitVector | lsb (size_t n) const |
| Return a view of the N least-significant bits. | |
| BitVector | msb (size_t n) const |
| Return a view of the N most-significant bits. | |
| std::string | toString (unsigned base=16) const |
| bool | operator== (const BitVector &rhs) const |
| bool | operator!= (const BitVector &rhs) const |
| bit_iterator | begin () const |
| Return an iterator to the first bit (LSB). | |
| bit_iterator | end () const |
| Return an iterator past the last bit. | |
Protected Attributes | |
| std::span< const byte > | data {} |
| size_t | bitWidth = 0 |
| uint8_t | bitIndex = 0 |
Friends | |
| MutableBitVector | operator& (const BitVector &a, const BitVector &b) |
| Bitwise AND: creates a new MutableBitVector with the result. | |
| MutableBitVector | operator| (const BitVector &a, const BitVector &b) |
| Bitwise OR: creates a new MutableBitVector with the result. | |
| MutableBitVector | operator^ (const BitVector &a, const BitVector &b) |
| Bitwise XOR: creates a new MutableBitVector with the result. | |
A lightweight, non-owning bit vector view backed by a byte array span.
BitVector is immutable wrt. modifying the underlying bits, and provides read-only access to bits. It supports bit-level access and returns new views for operations.
| using esi::BitVector::byte = uint8_t |
| BitVector::BitVector | ( | std::span< const byte > | bytes, |
| std::optional< size_t > | width = std::nullopt, |
||
| uint8_t | bitIndex = 0 |
||
| ) |
|
default |
| BitVector::BitVector | ( | const BitVector & | other | ) |
Definition at line 29 of file Values.cpp.
|
inline |
|
inline |
| bool BitVector::getBit | ( | size_t | i | ) | const |
Return the i-th bit (0 = LSB) as boolean.
Definition at line 41 of file Values.cpp.
References bitIndex, bitWidth, and data.
Referenced by esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator&=(), esi::BitVector::bit_iterator::operator*(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator^=(), esi::MutableBitVector::operator|=(), esi::MutableBitVector::operator~(), toDecimalString(), esi::Int::toI64(), toPowerOfTwoString(), toString(), and esi::UInt::toUI64().
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 32 of file Values.cpp.
| bool BitVector::operator== | ( | const BitVector & | rhs | ) | const |
Definition at line 420 of file Values.cpp.
References bitWidth.
| BitVector BitVector::operator>> | ( | size_t | n | ) | const |
| BitVector & BitVector::operator>>= | ( | size_t | n | ) |
Definition at line 78 of file Values.cpp.
|
inline |
Definition at line 55 of file Values.h.
References width().
Referenced by esiaccel.types.ArrayType::bit_width(), esiaccel.types.ArrayType::deserialize(), and esiaccel.types.ArrayType::is_valid().
| BitVector BitVector::slice | ( | size_t | offset, |
| size_t | sliceWidth | ||
| ) | const |
Create a new immutable view of a contiguous bit slice [offset, offset+sliceWidth).
The returned BitVector is a view (not an owning copy) into the same underlying span. Throws if the requested slice exceeds the current width.
Definition at line 83 of file Values.cpp.
| std::string BitVector::toString | ( | unsigned | base = 16 | ) | const |
Definition at line 362 of file Values.cpp.
References bitWidth, getBit(), toDecimalString(), and toPowerOfTwoString().
Referenced by esi::operator<<().
|
inline |
Definition at line 54 of file Values.h.
References bitWidth.
Referenced by esi::Int::Int(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator<<=(), esi::SIntType::serialize(), esi::UIntType::serialize(), esi::StructType::serialize(), esi::ArrayType::serialize(), size(), toDecimalString(), toPowerOfTwoString(), and esi::UInt::UInt().
|
friend |
Bitwise AND: creates a new MutableBitVector with the result.
|
friend |
Bitwise XOR: creates a new MutableBitVector with the result.
|
friend |
Bitwise OR: creates a new MutableBitVector with the result.
|
protected |
Definition at line 180 of file Values.h.
Referenced by BitVector(), getBit(), getSpan(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), operator=(), esi::MutableBitVector::operator=(), operator>>(), and slice().
|
protected |
Definition at line 179 of file Values.h.
Referenced by BitVector(), end(), getBit(), msb(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::Int::MutableBitVector(), esi::MutableBitVector::operator&=(), esi::BitVector::bit_iterator::operator*(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), operator=(), esi::MutableBitVector::operator=(), operator==(), esi::BitVector::bit_iterator::operator==(), operator>>(), esi::MutableBitVector::operator^=(), esi::MutableBitVector::operator|=(), esi::MutableBitVector::operator~(), esi::MutableBitVector::setBit(), slice(), esi::Int::toI64(), toString(), esi::UInt::toUI64(), and width().
|
protected |
Definition at line 178 of file Values.h.
Referenced by BitVector(), getBit(), getSpan(), esi::MutableBitVector::getSpan(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::MutableBitVector(), esi::MutableBitVector::operator<<=(), esi::MutableBitVector::operator<<=(), operator=(), esi::MutableBitVector::operator=(), operator>>(), and slice().