Add register cache support in HardwareRegister class
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: Ic671a099fdcd98d1f0158289ef321b968f1908ca
diff --git a/src/util/hei_bit_string.cpp b/src/util/hei_bit_string.cpp
index 2cbb3a1..55da5cd 100755
--- a/src/util/hei_bit_string.cpp
+++ b/src/util/hei_bit_string.cpp
@@ -16,13 +16,13 @@
//##############################################################################
// number of bits in a uint64_t
-constexpr uint32_t BitString::UINT64_BIT_LEN = sizeof(uint64_t) * 8;
+constexpr uint64_t BitString::UINT64_BIT_LEN = sizeof(uint64_t) * 8;
// number of bits in a uint8_t
-constexpr uint32_t BitString::UINT8_BIT_LEN = sizeof(uint8_t) * 8;
+constexpr uint64_t BitString::UINT8_BIT_LEN = sizeof(uint8_t) * 8;
//------------------------------------------------------------------------------
-uint64_t BitString::getFieldRight( uint32_t i_pos, uint32_t i_len ) const
+uint64_t BitString::getFieldRight( uint64_t i_pos, uint64_t i_len ) const
{
HEI_ASSERT( nullptr != getBufAddr() ); // must to have a valid address
HEI_ASSERT( 0 < i_len ); // must have at least one bit
@@ -31,13 +31,13 @@
// Get the relative address of this byte and the relative starting position
// within the byte.
- uint32_t relPos = 0;
+ uint64_t relPos = 0;
uint8_t * relAddr = getRelativePosition( relPos, i_pos );
// Get the length of the target bit field within this byte and the length of
// the bit field for any remaining bits.
- uint32_t bf_len = i_len;
- uint32_t remain_len = 0;
+ uint64_t bf_len = i_len;
+ uint64_t remain_len = 0;
if ( UINT8_BIT_LEN < relPos + i_len )
{
// The target bit field crosses a byte boundary. So truncate the bit
@@ -66,7 +66,7 @@
//------------------------------------------------------------------------------
-void BitString::setFieldLeft( uint32_t i_pos, uint32_t i_len, uint64_t i_val )
+void BitString::setFieldLeft( uint64_t i_pos, uint64_t i_len, uint64_t i_val )
{
HEI_ASSERT( nullptr != getBufAddr() ); // must to have a valid address
HEI_ASSERT( 0 < i_len ); // must have at least one bit
@@ -75,13 +75,13 @@
// Get the relative address of this byte and the relative starting position
// within the byte.
- uint32_t relPos = 0;
+ uint64_t relPos = 0;
uint8_t * relAddr = getRelativePosition( relPos, i_pos );
// Get the length of the target bit field within this byte and the length of
// the bit field for any remaining bits.
- uint32_t bf_len = i_len;
- uint32_t remain_len = 0;
+ uint64_t bf_len = i_len;
+ uint64_t remain_len = 0;
if ( UINT8_BIT_LEN < relPos + i_len )
{
// The target bit field crosses a byte boundary. So truncate the bit
@@ -93,15 +93,15 @@
// It is possible there are bits in this byte on either side of the target
// bit field that must be preserved. Get the length of each of those bit
// fields.
- uint32_t bf_l_len = relPos;
- uint32_t bf_r_len = UINT8_BIT_LEN - (bf_l_len + bf_len);
+ uint64_t bf_l_len = relPos;
+ uint64_t bf_r_len = UINT8_BIT_LEN - (bf_l_len + bf_len);
// Get the target bit field from the left justified inputed value.
uint8_t bf = (i_val >> (UINT64_BIT_LEN - bf_len)) << bf_r_len;
// Get the bit fields on either side of the target bit field.
- uint32_t bf_l_shift = UINT8_BIT_LEN - bf_l_len;
- uint32_t bf_r_shift = UINT8_BIT_LEN - bf_r_len;
+ uint64_t bf_l_shift = UINT8_BIT_LEN - bf_l_len;
+ uint64_t bf_r_shift = UINT8_BIT_LEN - bf_r_len;
uint8_t bf_l = *relAddr; bf_l >>= bf_l_shift; bf_l <<= bf_l_shift;
uint8_t bf_r = *relAddr; bf_r <<= bf_r_shift; bf_r >>= bf_r_shift;
@@ -118,8 +118,8 @@
//------------------------------------------------------------------------------
-void BitString::setPattern( uint32_t i_sPos, uint32_t i_sLen,
- uint64_t i_pattern, uint32_t i_pLen )
+void BitString::setPattern( uint64_t i_sPos, uint64_t i_sLen,
+ uint64_t i_pattern, uint64_t i_pLen )
{
HEI_ASSERT(nullptr != getBufAddr()); // must to have a valid address
@@ -137,11 +137,11 @@
bs.setFieldRight(0, i_pLen, i_pattern);
// Iterate the range in chunks the size of i_pLen.
- uint32_t endPos = i_sPos + i_sLen;
- for ( uint32_t pos = i_sPos; pos < endPos; pos += i_pLen )
+ uint64_t endPos = i_sPos + i_sLen;
+ for ( uint64_t pos = i_sPos; pos < endPos; pos += i_pLen )
{
// The true chunk size is either i_pLen or the leftovers at the end.
- uint32_t len = std::min( i_pLen, endPos - pos );
+ uint64_t len = std::min( i_pLen, endPos - pos );
// Get this chunk's pattern value, truncate (right justified) if needed.
uint64_t pattern = bs.getFieldRight( 0, len );
@@ -153,8 +153,8 @@
//------------------------------------------------------------------------------
-void BitString::setString( const BitString & i_sStr, uint32_t i_sPos,
- uint32_t i_sLen, uint32_t i_dPos )
+void BitString::setString( const BitString & i_sStr, uint64_t i_sPos,
+ uint64_t i_sLen, uint64_t i_dPos )
{
// Ensure the source parameters are valid.
HEI_ASSERT( nullptr != i_sStr.getBufAddr() );
@@ -167,11 +167,11 @@
// If the source length is greater than the destination length than the
// extra source bits are ignored.
- uint32_t actLen = std::min( i_sLen, getBitLen() - i_dPos );
+ uint64_t actLen = std::min( i_sLen, getBitLen() - i_dPos );
// The bit strings may be in overlapping memory spaces. So we need to copy
// the data in the correct direction to prevent overlapping.
- uint32_t sRelOffset = 0, dRelOffset = 0;
+ uint64_t sRelOffset = 0, dRelOffset = 0;
uint8_t * sRelAddr = i_sStr.getRelativePosition( sRelOffset, i_sPos );
uint8_t * dRelAddr = getRelativePosition( dRelOffset, i_dPos );
@@ -184,9 +184,9 @@
((dRelAddr == sRelAddr) && (dRelOffset < sRelOffset)) )
{
// Copy the data forward.
- for ( uint32_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
+ for ( uint64_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
{
- uint32_t len = std::min( actLen - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( actLen - pos, UINT64_BIT_LEN );
uint64_t value = i_sStr.getFieldRight( i_sPos + pos, len );
setFieldRight( i_dPos + pos, len, value );
@@ -195,12 +195,12 @@
else // Copy the data backwards.
{
// Get the first position of the last chunk (byte aligned).
- uint32_t lastPos = ((actLen-1) / UINT64_BIT_LEN) * UINT64_BIT_LEN;
+ uint64_t lastPos = ((actLen-1) / UINT64_BIT_LEN) * UINT64_BIT_LEN;
// Start with the last chunk and work backwards.
for ( int32_t pos = lastPos; 0 <= pos; pos -= UINT64_BIT_LEN )
{
- uint32_t len = std::min( actLen - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( actLen - pos, UINT64_BIT_LEN );
uint64_t value = i_sStr.getFieldRight( i_sPos + pos, len );
setFieldRight( i_dPos + pos, len, value );
}
@@ -212,11 +212,11 @@
void BitString::maskString( const BitString & i_mask )
{
// Get the length of the smallest string.
- uint32_t actLen = std::min( getBitLen(), i_mask.getBitLen() );
+ uint64_t actLen = std::min( getBitLen(), i_mask.getBitLen() );
- for ( uint32_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
+ for ( uint64_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
{
- uint32_t len = std::min( actLen - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( actLen - pos, UINT64_BIT_LEN );
uint64_t dVal = getFieldRight( pos, len );
uint64_t sVal = i_mask.getFieldRight( pos, len );
@@ -232,9 +232,9 @@
if ( getBitLen() != i_str.getBitLen() )
return false; // size not equal
- for ( uint32_t pos = 0; pos < getBitLen(); pos += UINT64_BIT_LEN )
+ for ( uint64_t pos = 0; pos < getBitLen(); pos += UINT64_BIT_LEN )
{
- uint32_t len = std::min( getBitLen() - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( getBitLen() - pos, UINT64_BIT_LEN );
if ( getFieldRight(pos, len) != i_str.getFieldRight(pos, len) )
return false; // bit strings do not match
@@ -247,9 +247,9 @@
bool BitString::isZero() const
{
- for ( uint32_t pos = 0; pos < getBitLen(); pos += UINT64_BIT_LEN )
+ for ( uint64_t pos = 0; pos < getBitLen(); pos += UINT64_BIT_LEN )
{
- uint32_t len = std::min( getBitLen() - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( getBitLen() - pos, UINT64_BIT_LEN );
if ( 0 != getFieldRight(pos, len) )
return false; // something is non-zero
@@ -260,15 +260,15 @@
//------------------------------------------------------------------------------
-uint32_t BitString::getSetCount( uint32_t i_pos, uint32_t i_len ) const
+uint64_t BitString::getSetCount( uint64_t i_pos, uint64_t i_len ) const
{
- uint32_t endPos = i_pos + i_len;
+ uint64_t endPos = i_pos + i_len;
HEI_ASSERT( endPos <= getBitLen() );
- uint32_t count = 0;
+ uint64_t count = 0;
- for ( uint32_t i = i_pos; i < endPos; i++ )
+ for ( uint64_t i = i_pos; i < endPos; i++ )
{
if ( isBitSet(i) ) count++;
}
@@ -282,9 +282,9 @@
{
BitStringBuffer bsb( getBitLen() );
- for ( uint32_t pos = 0; pos < getBitLen(); pos += UINT64_BIT_LEN )
+ for ( uint64_t pos = 0; pos < getBitLen(); pos += UINT64_BIT_LEN )
{
- uint32_t len = std::min( getBitLen() - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( getBitLen() - pos, UINT64_BIT_LEN );
uint64_t dVal = getFieldRight( pos, len );
@@ -299,13 +299,13 @@
BitStringBuffer BitString::operator&( const BitString & i_bs ) const
{
// Get the length of the smallest string.
- uint32_t actLen = std::min( getBitLen(), i_bs.getBitLen() );
+ uint64_t actLen = std::min( getBitLen(), i_bs.getBitLen() );
BitStringBuffer bsb( actLen );
- for ( uint32_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
+ for ( uint64_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
{
- uint32_t len = std::min( actLen - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( actLen - pos, UINT64_BIT_LEN );
uint64_t dVal = getFieldRight( pos, len );
uint64_t sVal = i_bs.getFieldRight( pos, len );
@@ -321,13 +321,13 @@
BitStringBuffer BitString::operator|( const BitString & i_bs ) const
{
// Get the length of the smallest string.
- uint32_t actLen = std::min( getBitLen(), i_bs.getBitLen() );
+ uint64_t actLen = std::min( getBitLen(), i_bs.getBitLen() );
BitStringBuffer bsb( actLen );
- for ( uint32_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
+ for ( uint64_t pos = 0; pos < actLen; pos += UINT64_BIT_LEN )
{
- uint32_t len = std::min( actLen - pos, UINT64_BIT_LEN );
+ uint64_t len = std::min( actLen - pos, UINT64_BIT_LEN );
uint64_t dVal = getFieldRight( pos, len );
uint64_t sVal = i_bs.getFieldRight( pos, len );
@@ -340,7 +340,7 @@
//------------------------------------------------------------------------------
-BitStringBuffer BitString::operator>>( uint32_t i_shift ) const
+BitStringBuffer BitString::operator>>( uint64_t i_shift ) const
{
BitStringBuffer bsb( getBitLen() ); // default all zeros
@@ -358,7 +358,7 @@
//------------------------------------------------------------------------------
-BitStringBuffer BitString::operator<<( uint32_t i_shift ) const
+BitStringBuffer BitString::operator<<( uint64_t i_shift ) const
{
BitStringBuffer bsb( getBitLen() ); // default all zeros
@@ -377,8 +377,8 @@
//------------------------------------------------------------------------------
-uint8_t * BitString::getRelativePosition( uint32_t & o_relPos,
- uint32_t i_absPos ) const
+uint8_t * BitString::getRelativePosition( uint64_t & o_relPos,
+ uint64_t i_absPos ) const
{
HEI_ASSERT( nullptr != getBufAddr() ); // must to have a valid address
HEI_ASSERT( i_absPos < getBitLen() ); // must be a valid position
@@ -392,7 +392,7 @@
// BitStringBuffer class
//##############################################################################
-BitStringBuffer::BitStringBuffer( uint32_t i_bitLen ) :
+BitStringBuffer::BitStringBuffer( uint64_t i_bitLen ) :
BitString( i_bitLen, nullptr )
{
initBuffer();
diff --git a/src/util/hei_bit_string.hpp b/src/util/hei_bit_string.hpp
index 889dc41..127ce61 100755
--- a/src/util/hei_bit_string.hpp
+++ b/src/util/hei_bit_string.hpp
@@ -60,8 +60,8 @@
{
private: // constants
- static const uint32_t UINT64_BIT_LEN;
- static const uint32_t UINT8_BIT_LEN;
+ static const uint64_t UINT64_BIT_LEN;
+ static const uint64_t UINT8_BIT_LEN;
public: // functions
@@ -76,8 +76,8 @@
* @pre Use getMinBytes() to calulate the minimum number of bytes needed
* to allocate sufficient memory space for this bit string.
*/
- BitString( uint32_t i_bitLen, void * i_bufAddr,
- uint32_t i_offset = 0 ) :
+ BitString( uint64_t i_bitLen, void * i_bufAddr,
+ uint64_t i_offset = 0 ) :
iv_bitLen(i_bitLen), iv_bufAddr(i_bufAddr), iv_offset(i_offset)
{}
@@ -85,7 +85,7 @@
virtual ~BitString() {}
/** @return The number of bits in the bit string buffer. */
- uint32_t getBitLen() const { return iv_bitLen; }
+ uint64_t getBitLen() const { return iv_bitLen; }
/** @return The address of the bit string buffer. Note that this may
* return nullptr. */
@@ -98,7 +98,7 @@
* @return The minimum number of bytes required to allocate sufficient
* memory space for a bit string.
*/
- static uint32_t getMinBytes( uint32_t i_bitLen, uint32_t i_offset = 0 )
+ static uint64_t getMinBytes( uint64_t i_bitLen, uint64_t i_offset = 0 )
{
return (i_bitLen + i_offset + UINT8_BIT_LEN-1) / UINT8_BIT_LEN;
}
@@ -114,7 +114,7 @@
* @pre i_len <= UINT64_BIT_LEN
* @pre i_pos + i_len <= getBitLen()
*/
- uint64_t getFieldLeft( uint32_t i_pos, uint32_t i_len ) const
+ uint64_t getFieldLeft( uint64_t i_pos, uint64_t i_len ) const
{
return getFieldRight(i_pos, i_len) << (UINT64_BIT_LEN - i_len);
}
@@ -130,7 +130,7 @@
* @pre i_len <= UINT64_BIT_LEN
* @pre i_pos + i_len <= getBitLen()
*/
- uint64_t getFieldRight( uint32_t i_pos, uint32_t i_len ) const;
+ uint64_t getFieldRight( uint64_t i_pos, uint64_t i_len ) const;
/**
* @brief Sets a left-justified value of the given length into the bit
@@ -143,7 +143,7 @@
* @pre i_len <= UINT64_BIT_LEN
* @pre i_pos + i_len <= getBitLen()
*/
- void setFieldLeft( uint32_t i_pos, uint32_t i_len, uint64_t i_val );
+ void setFieldLeft( uint64_t i_pos, uint64_t i_len, uint64_t i_val );
/**
* @brief Sets a right-justified value of the given length into the bit
@@ -156,7 +156,7 @@
* @pre i_len <= UINT64_BIT_LEN
* @pre i_pos + i_len <= getBitLen()
*/
- void setFieldRight( uint32_t i_pos, uint32_t i_len, uint64_t i_val )
+ void setFieldRight( uint64_t i_pos, uint64_t i_len, uint64_t i_val )
{
setFieldLeft( i_pos, i_len, i_val << (UINT64_BIT_LEN - i_len) );
}
@@ -166,7 +166,7 @@
* @return True if the bit at the given position is set(1), false otherwise.
* @pre i_pos < getBitLen().
*/
- bool isBitSet( uint32_t i_pos ) const
+ bool isBitSet( uint64_t i_pos ) const
{
return 0 != getFieldRight(i_pos, 1);
}
@@ -176,7 +176,7 @@
* @param i_pos The target position.
* @pre i_pos < getBitLen().
*/
- void setBit( uint32_t i_pos ) { setFieldRight( i_pos, 1, 1 ); }
+ void setBit( uint64_t i_pos ) { setFieldRight( i_pos, 1, 1 ); }
/** @brief Sets the entire bit string to 1's. */
void setAll() { setPattern(UINT64_MAX); }
@@ -186,7 +186,7 @@
* @param i_pos The target position.
* @pre i_pos < getBitLen().
*/
- void clearBit( uint32_t i_pos ) { setFieldRight( i_pos, 1, 0 ); }
+ void clearBit( uint64_t i_pos ) { setFieldRight( i_pos, 1, 0 ); }
/** @brief Sets the entire bit string to 0's. */
void clearAll() { setPattern(0); }
@@ -212,8 +212,8 @@
* Old String: 0001001000
* New String: 0000110000
*/
- void setPattern( uint32_t i_sPos, uint32_t i_sLen,
- uint64_t i_pattern, uint32_t i_pLen );
+ void setPattern( uint64_t i_sPos, uint64_t i_sLen,
+ uint64_t i_pattern, uint64_t i_pLen );
/**
* @brief Sets entire string based on the pattern and length provided.
@@ -223,7 +223,7 @@
* @post The entire string is filled with the pattern.
* @post The pattern is repeated/truncated as needed.
*/
- void setPattern( uint64_t i_pattern, uint32_t i_pLen )
+ void setPattern( uint64_t i_pattern, uint64_t i_pLen )
{
setPattern( 0, getBitLen(), i_pattern, i_pLen );
}
@@ -258,8 +258,8 @@
* string, then the extra bits in this string are not modified.
* @note This string and the source string may specify overlapping memory.
*/
- void setString( const BitString & i_sStr, uint32_t i_sPos,
- uint32_t i_sLen, uint32_t i_dPos = 0 );
+ void setString( const BitString & i_sStr, uint64_t i_sPos,
+ uint64_t i_sLen, uint64_t i_dPos = 0 );
/**
* @brief Set bits in this string based on the provided string.
@@ -304,10 +304,10 @@
* @pre nullptr != getBufAddr()
* @pre i_pos + i_len <= getBitLen()
*/
- uint32_t getSetCount( uint32_t i_pos, uint32_t i_len ) const;
+ uint64_t getSetCount( uint64_t i_pos, uint64_t i_len ) const;
/** @return The number of bits that are set(1) in this string. */
- uint32_t getSetCount() const { return getSetCount( 0, getBitLen() ); }
+ uint64_t getSetCount() const { return getSetCount( 0, getBitLen() ); }
/** @brief Comparison operator. */
bool operator==( const BitString & i_str ) const { return isEqual(i_str); }
@@ -322,10 +322,18 @@
BitStringBuffer operator|( const BitString & i_bs ) const;
/** @brief Right shift operator. */
- BitStringBuffer operator>>( uint32_t i_shift ) const;
+ BitStringBuffer operator>>( uint64_t i_shift ) const;
/** @brief Left shift operator. */
- BitStringBuffer operator<<( uint32_t i_shift ) const;
+ BitStringBuffer operator<<( uint64_t i_shift ) const;
+
+ /**
+ * @brief Explicitly disables copy from BitString.
+ *
+ * Prevents assigning a BitString & to a BitString, which would strip
+ * polymorphism.
+ */
+ BitString( const BitString & i_bs ) = delete;
/**
* @brief Explicitly disables assignment from BitStringBuffer.
@@ -353,7 +361,7 @@
void setBufAddr( void * i_newBufAddr ) { iv_bufAddr = i_newBufAddr; }
/** @param i_newBitLen The new bit length of this bit string buffer. */
- void setBitLen( uint32_t i_newBitLen ) { iv_bitLen = i_newBitLen; }
+ void setBitLen( uint64_t i_newBitLen ) { iv_bitLen = i_newBitLen; }
private: // functions
@@ -367,14 +375,14 @@
* @pre nullptr != getBufAddr()
* @pre i_absPos < getBitLen()
*/
- uint8_t * getRelativePosition( uint32_t & o_relPos,
- uint32_t i_absPos ) const;
+ uint8_t * getRelativePosition( uint64_t & o_relPos,
+ uint64_t i_absPos ) const;
private: // instance variables
- uint32_t iv_bitLen; ///< The bit length of this buffer.
+ uint64_t iv_bitLen; ///< The bit length of this buffer.
void * iv_bufAddr; ///< The beginning address of this buffer.
- uint32_t iv_offset; ///< Start position offset
+ uint64_t iv_offset; ///< Start position offset
};
//##############################################################################
@@ -394,7 +402,7 @@
* @brief Constructor
* @param i_bitLen Number of bits in the string.
*/
- explicit BitStringBuffer( uint32_t i_bitLen );
+ explicit BitStringBuffer( uint64_t i_bitLen );
/** @brief Destructor */
~BitStringBuffer();