The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::RegisterBits Class Reference

#include <RegisterBits.hpp>

Public Member Functions

 RegisterBits (const uint64_t num_bytes)
 Create an empty class with the given number of bytes.
 
template<class DataT >
 RegisterBits (const uint64_t num_bytes, const DataT &data)
 Create a class with the given number of bytes and initialize it to the given data.
 
 RegisterBits (uint8_t *data_ptr, const size_t num_bytes)
 Create a class pointing into the given data, of the given size.
 
 RegisterBits (const uint8_t *data, const size_t num_bytes)
 Create a class pointing into the given data constantly, of the given size.
 
 RegisterBits (std::nullptr_t)
 Create a nullptr version of the data. This would be an invalid class.
 
 RegisterBits (const RegisterBits &orig)
 Make a copy.
 
 RegisterBits (RegisterBits &&orig)
 Move.
 
RegisterBits operator| (const RegisterBits &rh_bits) const
 "or" together two classes
 
RegisterBits operator& (const RegisterBits &rh_bits) const
 "and" together two classes
 
RegisterBits operator~ () const
 "not" this class
 
RegisterBits operator>> (uint32_t shift) const
 Shift this instance right and return a copy.
 
RegisterBits operator<< (uint32_t shift) const
 Shift this instance left and return a copy.
 
void operator|= (const RegisterBits &rh_bits)
 
void operator<<= (uint32_t shift)
 Shift this instance left.
 
template<class DataT >
std::enable_if_t< std::is_integral_v< DataT >, bool > operator== (const DataT dat) const
 Compare the register bits to the given data.
 
bool operator== (const RegisterBits &other) const
 Compare the register bits to another.
 
template<class DataT >
void set (const DataT &masked_bits)
 Set the given masked_bits in this RegisterBits instance.
 
void fill (const uint8_t fill_data)
 Fill the RegisterBits with the given fill_data.
 
const uint8_t * operator[] (const uint32_t idx) const
 Get the data offset at the given index.
 
const uint8_t * data () const
 Get the internal data pointer.
 
uint8_t * data ()
 Get the internal data pointer.
 
template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
dataAs () const
 Get the internal data as the given dta type.
 
uint32_t getSize () const
 Get the number of bytes.
 
bool none () const
 Returns true if no bits are set.
 
bool any () const
 Returns true if any bit is set.
 

Detailed Description

This class is used in conjuntion with sparta::RegisterBase to quickly write masked registers. This class replaces the use of BitArray.

The class works by assuming register data is handed to it via a char array. The class will "view" into this data until it's requested to modify it. When it's modified, the data will be copied to local storage within this class. The user of the class is responsible for writing the data back to the original storage.

Definition at line 29 of file RegisterBits.hpp.

Constructor & Destructor Documentation

◆ RegisterBits() [1/7]

sparta::RegisterBits::RegisterBits ( const uint64_t  num_bytes)
inlineexplicit

Create an empty class with the given number of bytes.

Parameters
num_bytesThe number of bytes to allocate

Definition at line 86 of file RegisterBits.hpp.

◆ RegisterBits() [2/7]

template<class DataT >
sparta::RegisterBits::RegisterBits ( const uint64_t  num_bytes,
const DataT &  data 
)
inline

Create a class with the given number of bytes and initialize it to the given data.

Parameters
num_bytesThe number of bytes to allocate
dataThe data to write to the lower portion of memory

The data is copied

Definition at line 108 of file RegisterBits.hpp.

Here is the call graph for this function:

◆ RegisterBits() [3/7]

sparta::RegisterBits::RegisterBits ( uint8_t *  data_ptr,
const size_t  num_bytes 
)
inline

Create a class pointing into the given data, of the given size.

Parameters
data_ptrThe data to view
num_bytesThe number of bytes available to view

No data is copied

Definition at line 131 of file RegisterBits.hpp.

◆ RegisterBits() [4/7]

sparta::RegisterBits::RegisterBits ( const uint8_t *  data,
const size_t  num_bytes 
)
inline

Create a class pointing into the given data constantly, of the given size.

Parameters
data_ptrThe data to view
num_bytesThe number of bytes available to view

No data is copied

Definition at line 144 of file RegisterBits.hpp.

◆ RegisterBits() [5/7]

sparta::RegisterBits::RegisterBits ( std::nullptr_t  )
inline

Create a nullptr version of the data. This would be an invalid class.

Definition at line 152 of file RegisterBits.hpp.

◆ RegisterBits() [6/7]

sparta::RegisterBits::RegisterBits ( const RegisterBits orig)
inline

Make a copy.

Parameters
origThe original to copy

If the original is pointing to its own memory, that will be copied

Definition at line 160 of file RegisterBits.hpp.

Here is the call graph for this function:

◆ RegisterBits() [7/7]

sparta::RegisterBits::RegisterBits ( RegisterBits &&  orig)
inline

Move.

Parameters
origThe original to move

If the original is pointing to its own memory, that data will be moved. The original is nullified.

Definition at line 185 of file RegisterBits.hpp.

Member Function Documentation

◆ any()

bool sparta::RegisterBits::any ( ) const
inline

Returns true if any bit is set.

Returns
true if any bit is set

Definition at line 723 of file RegisterBits.hpp.

Here is the call graph for this function:

◆ data() [1/2]

uint8_t * sparta::RegisterBits::data ( )
inline

Get the internal data pointer.

Returns
The data pointer

Definition at line 686 of file RegisterBits.hpp.

◆ data() [2/2]

const uint8_t * sparta::RegisterBits::data ( ) const
inline

Get the internal data pointer.

Returns
The data pointer

Definition at line 678 of file RegisterBits.hpp.

◆ dataAs()

template<typename T , typename = typename std::enable_if<std::is_integral<T>::value>::type>
T sparta::RegisterBits::dataAs ( ) const
inline

Get the internal data as the given dta type.

Returns
The data

Definition at line 697 of file RegisterBits.hpp.

◆ fill()

void sparta::RegisterBits::fill ( const uint8_t  fill_data)
inline

Fill the RegisterBits with the given fill_data.

Parameters
fill_data

If this RegisterBits class was pointing to a remote data view, the data will first be copied then the fill data written

Definition at line 660 of file RegisterBits.hpp.

◆ getSize()

uint32_t sparta::RegisterBits::getSize ( ) const
inline

Get the number of bytes.

Returns
The number of bytes

Definition at line 707 of file RegisterBits.hpp.

◆ none()

bool sparta::RegisterBits::none ( ) const
inline

Returns true if no bits are set.

Returns
true if no bits are set

Definition at line 713 of file RegisterBits.hpp.

◆ operator&()

RegisterBits sparta::RegisterBits::operator& ( const RegisterBits rh_bits) const
inline

"and" together two classes

Parameters
rh_bitsThe other to "and" in
Returns
A new RegisterBits (to be moved) of this instance and'ed with the other

Definition at line 245 of file RegisterBits.hpp.

◆ operator<<()

RegisterBits sparta::RegisterBits::operator<< ( uint32_t  shift) const
inline

Shift this instance left and return a copy.

Parameters
shiftThe shift count
Returns
A new RegisterBits (to be moved) of this instance shifted left

Definition at line 405 of file RegisterBits.hpp.

◆ operator<<=()

void sparta::RegisterBits::operator<<= ( uint32_t  shift)
inline

Shift this instance left.

Parameters
shiftThe shift count

Definition at line 526 of file RegisterBits.hpp.

◆ operator==() [1/2]

template<class DataT >
std::enable_if_t< std::is_integral_v< DataT >, bool > sparta::RegisterBits::operator== ( const DataT  dat) const
inline

Compare the register bits to the given data.

Parameters
datThe data to compare
Returns
True if equivalent

Definition at line 624 of file RegisterBits.hpp.

◆ operator==() [2/2]

bool sparta::RegisterBits::operator== ( const RegisterBits other) const
inline

Compare the register bits to another.

Parameters
otherThe other RegisterBits instance to compare
Returns
True if equivalent

Definition at line 634 of file RegisterBits.hpp.

◆ operator>>()

RegisterBits sparta::RegisterBits::operator>> ( uint32_t  shift) const
inline

Shift this instance right and return a copy.

Parameters
shiftThe shift count
Returns
A new RegisterBits (to be moved) of this instance shifted right

Definition at line 313 of file RegisterBits.hpp.

◆ operator[]()

const uint8_t * sparta::RegisterBits::operator[] ( const uint32_t  idx) const
inline

Get the data offset at the given index.

Parameters
idxThe index offset
Returns
A data pointer at the given index

Definition at line 670 of file RegisterBits.hpp.

◆ operator|()

RegisterBits sparta::RegisterBits::operator| ( const RegisterBits rh_bits) const
inline

"or" together two classes

Parameters
rh_bitsThe other to "or" in
Returns
A new RegisterBits (to be moved) of this instance or'ed with the other

Definition at line 209 of file RegisterBits.hpp.

◆ operator|=()

void sparta::RegisterBits::operator|= ( const RegisterBits rh_bits)
inline

Definition at line 491 of file RegisterBits.hpp.

◆ operator~()

RegisterBits sparta::RegisterBits::operator~ ( ) const
inline

"not" this class

Returns
A new RegisterBits (to be moved) of this instance not-ted

Definition at line 280 of file RegisterBits.hpp.

◆ set()

template<class DataT >
void sparta::RegisterBits::set ( const DataT &  masked_bits)
inline

Set the given masked_bits in this RegisterBits instance.

Parameters
masked_bitsThe bit value to set

If this RegisterBits class was pointing to a remote data view, the data will first be copied then the masked_bits written

Definition at line 647 of file RegisterBits.hpp.


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