diff options
-rwxr-xr-x | src/usr/diag/prdf/common/util/prdfBitString.C | 221 | ||||
-rwxr-xr-x | src/usr/diag/prdf/common/util/prdfBitString.H | 110 | ||||
-rw-r--r-- | src/usr/diag/prdf/plat/prdfPlatServices.C | 6 |
3 files changed, 79 insertions, 258 deletions
diff --git a/src/usr/diag/prdf/common/util/prdfBitString.C b/src/usr/diag/prdf/common/util/prdfBitString.C index 127b531a3..fad644a08 100755 --- a/src/usr/diag/prdf/common/util/prdfBitString.C +++ b/src/usr/diag/prdf/common/util/prdfBitString.C @@ -124,7 +124,7 @@ void BitString::SetField if(iv_bufAddr != NULL || value != 0) //dg02a { //dg02a - CPU_WORD * address = GetRelativePositionAlloc(bit_position,bit_position); // dg02c + CPU_WORD * address = GetRelativePosition(bit_position,bit_position); // dg02c CPU_WORD mask = CPU_WORD_MASK; mask <<= (CPU_WORD_BIT_LEN - iLen); @@ -489,15 +489,6 @@ CPU_WORD * BitString::GetRelativePosition(uint32_t & oBitOffset, uint32_t iBitPo } //------------------------------------------------------------------------------------------------- -// dg02a - start -CPU_WORD * BitStringBuffer::GetRelativePositionAlloc(uint32_t & oBitOffset, uint32_t iBitPos) -{ - // The non-constant version of GetRelativePostion - if(getBufAddr() == NULL) SetBuffer(); // alocate memory - return GetRelativePosition(oBitOffset, iBitPos); -} -// dg02a - end -//------------------------------------------------------------------------------------------------- CPU_WORD * BitStringOffset::GetRelativePosition(uint32_t & oBitOffset, uint32_t iBitPos) const { @@ -505,14 +496,6 @@ CPU_WORD * BitStringOffset::GetRelativePosition(uint32_t & oBitOffset, uint32_t return BitString::GetRelativePosition(oBitOffset,iBitPos); } -//dg04a -start -CPU_WORD * BitStringOffset::GetRelativePositionAlloc(uint32_t & oBitOffset, uint32_t iBitPos) -{ - iBitPos += ivOffset; - return BitString::GetRelativePosition(oBitOffset, iBitPos); -} -//dg04a - end - //------------------------------------------------------------------------------------------------- BitStringOffset::~BitStringOffset(void) {} @@ -604,14 +587,14 @@ BitStringBuffer BitString::operator|(const BitString & bs) const BitStringBuffer BitString::operator>>(uint32_t count) const { BitStringBuffer l_bsb(this->getBitLen()); - BitString * l_bsbp = &l_bsb; // dg03a - stupid trick to get to GetRelativePositionAlloc() + BitString * l_bsbp = &l_bsb; // dg03a - stupid trick to get to GetRelativePosition() // l_bsb.Clear(); if(count < this->getBitLen()) { //bso overlays bsb at offset = count uint32_t l_dummy; BitStringOffset bso(count,l_bsb.getBitLen() - count, - l_bsbp->GetRelativePositionAlloc(l_dummy,0)); //dg03c + l_bsbp->GetRelativePosition(l_dummy,0)); //dg03c bso.SetBits(*this); } return l_bsb; @@ -632,186 +615,78 @@ BitStringBuffer BitString::operator<<(uint32_t count) const return l_bsb; } -// Function Specification ////////////////////////////////////////// -// -// Title: BitStringBuffer (Constructor) -// -// Purpose: This constuctor initializes the data members. -// -// Side-effects: This instance is initialized. -// Memory is allocated. -// Bit String values are undefined. -// -// Dependencies: None. -// -// End Function Specification ////////////////////////////////////// +//############################################################################## +// BitStringBuffer class +//############################################################################## -BitStringBuffer::BitStringBuffer -( - uint32_t iLen, - unsigned int ibc - ) -: -BitString(iLen, NULL), -ivByteCapacity(ibc) +BitStringBuffer::BitStringBuffer( uint32_t i_bitLen ) : + BitString( i_bitLen, nullptr ) { -// SetBuffer(); //dg02d + initBuffer(); } -// Function Specification /////////////////////////////////////////// -// -// Title: BitStringBuffer (Copy constructor) -// -// Purpose: This constuctor initializes the data members. This copy -// constructor uses a "deep" copy. This constructor will -// also handle any class derived from the Bit String base -// class. -// -// Side-effects: This instance is initialized. -// Bit String values are are copied. -// -// Dependencies: None. -// -// Time Complexity: Dominated by the time complexity of SetBits() -// -// End Function Specification ////////////////////////////////////// +//------------------------------------------------------------------------------ -BitStringBuffer::BitStringBuffer(const BitString & string) -: -BitString(string.getBitLen(),NULL), -ivByteCapacity(0) +BitStringBuffer::~BitStringBuffer() { - if(!string.IsZero()) //dg02a - only allocate if bits are on - { //dg02a - SetBuffer(); - SetBits(string); - } //dg02a + delete [] getBufAddr(); } -// The True copy constructor mk00a -BitStringBuffer::BitStringBuffer(const BitStringBuffer & string) -: -BitString(string.getBitLen(),NULL), -ivByteCapacity(string.ivByteCapacity) +//------------------------------------------------------------------------------ + +BitStringBuffer::BitStringBuffer( const BitString & i_bs ) : + BitString( i_bs.getBitLen(), nullptr ) { - if(!string.IsZero()) //dg02a - only allocate if bits are on - { //dg02a - SetBuffer(); - SetBits(string); - } //dg02a + initBuffer(); + if ( !i_bs.IsZero() ) SetBits( i_bs ); } -// Function Specification /////////////////////////////////////////// -// -// Title: ~BitStringBuffer (Virtual Destructor) -// -// Purpose: This destructor deallocates the buffer memory. -// -// Side-effects: Memory is deallocated. -// -// Dependencies: None. -// -// End Function Specification ////////////////////////////////////// +//------------------------------------------------------------------------------ -BitStringBuffer::~BitStringBuffer(void) +BitStringBuffer::BitStringBuffer( const BitStringBuffer & i_bsb ) : + BitString( i_bsb.getBitLen(), nullptr ) { - delete [] getBufAddr(); + initBuffer(); + if ( !i_bsb.IsZero() ) SetBits( i_bsb ); } -// Function Specification /////////////////////////////////////////// -// -// Title: operator= (Assignment operator) -// -// Purpose: This assignment operator assigns the offset and length -// data members. A new buffer is allocated for the and -// the assinged Bit String contents are assigned. -// -// Side-effects: Data members are modified. -// Memory is allocated. -// -// Dependencies: None. -// -// Time Complexity: Proportional to time complexity of SetBits() -// -// End Function Specification ////////////////////////////////////// +//------------------------------------------------------------------------------ -BitStringBuffer & BitStringBuffer::operator= -( - const BitStringBuffer & string - ) +BitStringBuffer & BitStringBuffer::operator=( const BitString & i_bs ) { - // Check for assignment to self - if(this != &string) - { - delete[] getBufAddr(); - // Assign base class part - BitString::operator=(string); - setBufAddr(NULL); - - // Assign derived class part - ivByteCapacity = string.ivByteCapacity; - - // Allocate memory and copy the Bits - if(!string.IsZero()) //dg02a - only allocate if bits are on - { //dg02a - SetBuffer(); - SetBits(string); - } //dg02a - } + setBitLen( i_bs.getBitLen() ); + initBuffer(); + if ( !i_bs.IsZero() ) SetBits( i_bs ); - return(*this); + return *this; } -BitStringBuffer & BitStringBuffer::operator=(const BitString & string) -{ - delete [] getBufAddr(); - - // Assign base class part - BitString::operator=(string); //copy it to this - setBufAddr(NULL); - - // Assign derived class part - ivByteCapacity = 0; +//------------------------------------------------------------------------------ - // Allocate memory and copy the Bits - if(!string.IsZero()) //dg02a - only allocate if bits are on - { //dg02a - SetBuffer(); - SetBits(string); - } //dg02a +BitStringBuffer & BitStringBuffer::operator=( const BitStringBuffer & i_bsb ) +{ + if ( this != &i_bsb ) // Check for assignment to self + { + setBitLen( i_bsb.getBitLen() ); + initBuffer(); + if ( !i_bsb.IsZero() ) SetBits( i_bsb ); + } - return(*this); + return *this; } -// Function Specification ////////////////////////////////////////// -// -// Title: Set Buffer -// -// Purpose: This function allocates memory for the buffer. Any -// memory that has been previously allocated is -// deallocated. -// -// Side-effects: Memory is allocated. -// -// Dependencies: This function must be called at least once prior -// to the first Bit String access. -// -// End Function Specification ////////////////////////////////////// -void BitStringBuffer::SetBuffer(void) -{ - uint32_t byte_count = getBitLen() / CPU_WORD_BIT_LEN; +//------------------------------------------------------------------------------ - // Account for remainder of division with an additional byte - if((getBitLen() % CPU_WORD_BIT_LEN) != 0) - { - byte_count++; - } +void BitStringBuffer::initBuffer() +{ + // Deallocate the current buffer. + delete [] getBufAddr(); - byte_count = std::max(ivByteCapacity, byte_count); + // Allocate the new buffer. + setBufAddr( new CPU_WORD[ getNumCpuWords(getBitLen()) ] ); - delete [] getBufAddr(); - setBufAddr(new CPU_WORD[byte_count]); - Clear(); + // Clear the new buffer. + Clear(); } /*--------------------------------------------------------------------*/ diff --git a/src/usr/diag/prdf/common/util/prdfBitString.H b/src/usr/diag/prdf/common/util/prdfBitString.H index c667a94ce..dbc6c2242 100755 --- a/src/usr/diag/prdf/common/util/prdfBitString.H +++ b/src/usr/diag/prdf/common/util/prdfBitString.H @@ -409,18 +409,6 @@ class BitString */ BitStringBuffer operator<<(uint32_t count) const; - /** - * @brief Gets the CPU_WORD bounded memory address and the relative bit offset - * within the CPU_WORD that corresponds to the provided bit position in the - * bit string - * - * @param iBitPos Bit position in the bit string - * @param oBitOffset Relative bit offset in the CPU_WORD - * - * @return memory address of the CPU_WORD - */ - virtual CPU_WORD * GetRelativePositionAlloc(uint32_t & oBitOffset, uint32_t iBitPos);//dg02a - protected: // functions /** @@ -454,78 +442,45 @@ class BitString CPU_WORD * iv_bufAddr; ///< The beginning address of this buffer. }; -//! BitStringBuffer -/*! - BitStringBuffer provides a Bit String in an associated buffer in memory. - \remarks - The Bit String Buffer provides all of the functionality - of the base class along with the maintenance of memory - allocated to hold the Bit String. The buffer is "owned" - by the Bit String Buffer. Sufficient memory - is allocated and deallocted in the constructor and - destructor, respectively. In addition, the assignemnt - operator will adjust the amount of memory needed as - necessary for the assignment. A byte capacity value is also maintained. - The internal buffer is always guaranteed to have this capacity of bytes. -*/ +//############################################################################## +// BitStringBuffer class +//############################################################################## + +/** A BitStringBuffer is a BitString that maintains its own buffer in memory. It + * guarantees that sufficient memory is allocated and deallocated in the + * constructor and destructor, respectively. In addition, the assignment + * operator will adjust the amount of memory needed, as necessary, for the + * assignment. */ class BitStringBuffer : public BitString { -public: - - /*! - Constructor - \param iLen: Number of bits in the string - \param iByteCapacity: The minimum storage size to be allocated. default=0 - \notes If iByteCapcity is zero or too small than the storage size is calculated - from iLen, rounded up to the nearest CPU_WORD. - */ - BitStringBuffer(uint32_t iLen, - unsigned int iByteCapacity = 0); - - /*! - Copy Constructor - \param reference bits string - */ - BitStringBuffer(const BitString & string); - - /*! - Copy Constructor - \param reference bits string - */ - BitStringBuffer (const BitStringBuffer & string); - - /*! - Destructor - */ - virtual ~BitStringBuffer(void); - - /*! - Assignment - \param reference bit string - */ - BitStringBuffer & operator=(const BitStringBuffer & string); + public: // functions - /*! - Assignment - \param reference bit string - */ - virtual BitStringBuffer & operator=(const BitString & string); + /** + * @brief Constructor + * @param i_bitLen Number of bits in the string. + */ + explicit BitStringBuffer( uint32_t i_bitLen ); -protected: // functions dg02a + /** @brief Destructor */ + ~BitStringBuffer(); - virtual CPU_WORD * GetRelativePositionAlloc(uint32_t & oBitOffset, uint32_t iBitPos);//dg02a + /** @brief Copy constructor from BitString */ + BitStringBuffer( const BitString & i_bs ); -private: // functions + /** @brief Copy constructor from BitStringBuffer */ + BitStringBuffer( const BitStringBuffer & i_bsb ); - /*! - allocate or re-allocate buffer - */ - void SetBuffer(void); + /** @brief Assignment from BitString */ + BitStringBuffer & operator=( const BitString & i_bs ); -private: // data + /** @brief Assignment from BitStringBuffer */ + BitStringBuffer & operator=( const BitStringBuffer & i_bsb ); - unsigned int ivByteCapacity; + private: // functions + /** @brief Deallocates the old buffer, if needed, and initializes the new + * buffer. */ + void initBuffer(); }; //! BitStringOffset @@ -580,7 +535,6 @@ protected: // functions \param iBitPos Bit position in the bit string */ virtual CPU_WORD * GetRelativePosition(uint32_t & oBitOffset, uint32_t iBitPos) const; - virtual CPU_WORD * GetRelativePositionAlloc(uint32_t & oBitOffset, uint32_t iBitPos); //dg04a private: // data uint32_t ivOffset; @@ -671,12 +625,6 @@ BitString & BitString::operator= return(*this); } -inline -CPU_WORD * BitString::GetRelativePositionAlloc(uint32_t & oBitOffset, uint32_t iBitPos) -{ - return BitString::GetRelativePosition(oBitOffset,iBitPos); -} - // Function Specification ////////////////////////////////////////// // // Title: Pattern diff --git a/src/usr/diag/prdf/plat/prdfPlatServices.C b/src/usr/diag/prdf/plat/prdfPlatServices.C index 55c11bd47..bea0be17d 100644 --- a/src/usr/diag/prdf/plat/prdfPlatServices.C +++ b/src/usr/diag/prdf/plat/prdfPlatServices.C @@ -120,9 +120,8 @@ uint32_t getScom(TARGETING::TargetHandle_t i_target, BIT_STRING_CLASS& io_bs, { errlHndl_t errl = NULL; uint32_t rc = SUCCESS; - uint32_t tempBitOffset; size_t bsize = (io_bs.getBitLen()+7)/8; - CPU_WORD* buffer = io_bs.GetRelativePositionAlloc(tempBitOffset, 0); + CPU_WORD* buffer = io_bs.getBufAddr(); errl = deviceRead(i_target, buffer, bsize, DEVICE_SCOM_ADDRESS(i_address)); @@ -171,9 +170,8 @@ uint32_t putScom(TARGETING::TargetHandle_t i_target, BIT_STRING_CLASS& io_bs, { errlHndl_t errl = NULL; uint32_t rc = SUCCESS; - uint32_t tempBitOffset; size_t bsize = (io_bs.getBitLen()+7)/8; - CPU_WORD* buffer = io_bs.GetRelativePositionAlloc(tempBitOffset, 0); + CPU_WORD* buffer = io_bs.getBufAddr(); errl = deviceWrite(i_target, buffer, bsize, DEVICE_SCOM_ADDRESS(i_address)); |