summaryrefslogtreecommitdiffstats
path: root/src/import/hwpf/fapi2/include/variable_buffer.H
diff options
context:
space:
mode:
authorRichard Knight <rjknight@us.ibm.com>2015-04-22 10:49:31 -0500
committerPatrick Williams <iawillia@us.ibm.com>2015-12-11 13:40:20 -0600
commitab70d6014c019ad6fa0be2440c26e9728cdc7114 (patch)
treef9611b2276c8addd2ef0bc8d9a09b34916fb52fa /src/import/hwpf/fapi2/include/variable_buffer.H
parentac8f40cddb17c29ed6fc00e8f5551d78467c7914 (diff)
downloadtalos-hostboot-ab70d6014c019ad6fa0be2440c26e9728cdc7114.tar.gz
talos-hostboot-ab70d6014c019ad6fa0be2440c26e9728cdc7114.zip
Add support for variable_buffer setBit/clearBit
Change-Id: Ia45b4163af6a893faa9a3f63b368c693e52b6181 RTC:126648 Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/17547 Tested-by: Jenkins Server Reviewed-by: Matt K. Light <mklight@us.ibm.com> Reviewed-by: Brian Silver <bsilver@us.ibm.com>
Diffstat (limited to 'src/import/hwpf/fapi2/include/variable_buffer.H')
-rw-r--r--src/import/hwpf/fapi2/include/variable_buffer.H83
1 files changed, 68 insertions, 15 deletions
diff --git a/src/import/hwpf/fapi2/include/variable_buffer.H b/src/import/hwpf/fapi2/include/variable_buffer.H
index 24edccb61..5cde584f4 100644
--- a/src/import/hwpf/fapi2/include/variable_buffer.H
+++ b/src/import/hwpf/fapi2/include/variable_buffer.H
@@ -248,6 +248,7 @@ namespace fapi2
iv_data.insert(iv_data.end(), i_value, &i_value[i_length]);
}
+
#if !defined(DOXYGEN) && defined(FAPI2_DEBUG)
/// @brief Print the contents of the buffer to stdout
inline void print(void) const
@@ -343,25 +344,71 @@ namespace fapi2
}
///
- /// @brief Set a bit in the buffer
- /// @param[in] i_bit the bit number to set.
- /// @note 0 is left-most
- /// @return FAPI2_RC_SUCCESS if OK
- ///
- inline fapi2::ReturnCodes setBit(const bits_type& i_bit)
+ /// @brief Set a bit in buffer
+ /// @tparam SB Start bit in buffer to clear.
+ /// @tparam L Number of consecutive bits from start bit to
+ /// clear
+ /// @return FAPI2_RC_SUCCESS on success
+ inline fapi2::ReturnCodes setBit( const bits_type SB, bits_type L = 1)
{
- const bits_type index = i_bit / bits_per_unit;
- // setting a bit outside our container?
- if( i_bit >= this->iv_perceived_bit_length )
+ ReturnCodes rc;
+ // make sure we stay within our container
+ assert((L > 0) && ((SB + L) <= this->iv_perceived_bit_length) );
+
+ uint32_t mask = 0;
+
+ // last bit to check
+ bits_type EB = SB + L -1;
+
+ // index where first bit to check is located
+ bits_type start_index = SB/bits_per_unit;
+
+ // index where last bit is located
+ bits_type end_index = EB/bits_per_unit;
+
+ if( start_index == end_index )
{
- return FAPI2_RC_INVALID_PARAMETER;
+ // normalize our SB to be within a unit
+ bits_type TempSB = SB - (start_index*bits_per_unit);
+
+ // grab a mask from SB for L number of bits.
+ mask = fast_mask32(TempSB, L);
+
+ iv_data[start_index] |= mask;
+
+ rc = FAPI2_RC_SUCCESS;
+
}
+ else
+ {
+ // the bits span more than one internal unit, need to break
+ // it up to process it.
- iv_data[index] |=
- unit_type(1) << ((bits_per_unit - 1) - (i_bit - (index * bits_per_unit)));
+ // make TempSB point to the start of the next unit, adjust the
+ // length and go again, process the bits in the previous index
+ // when we get back.
+ bits_type TempSB = (start_index + 1) * bits_per_unit;
+ bits_type TempL = EB - TempSB + 1;
- return FAPI2_RC_SUCCESS;
+ rc = this->setBit( TempSB, TempL );
+
+ if(rc == FAPI2_RC_SUCCESS)
+ {
+ // now check the bits in the previous index up to the next index.
+ // normalize our SB to be within a unit
+ TempSB = SB - (start_index*bits_per_unit);
+
+ // get a mask for the new SB location to the end of this unit.
+ mask = fast_mask32(TempSB, L-TempL);
+
+ // merge theses bits with the others.
+ iv_data[start_index] |= mask;
+ }
+
+ }
+
+ return rc;
}
///
@@ -374,8 +421,14 @@ namespace fapi2
/// compile time so this can be templated only. If that is not
/// the case we can add a function parameter version.
///
- template< bits_type SB, bits_type L >
- inline fapi2::ReturnCodes clearBit(void);
+ inline fapi2::ReturnCodes clearBit(bits_type SB, bits_type L = 0)
+ {
+ ReturnCodes rc = invert().setBit(SB,L);
+
+ invert();
+
+ return rc;
+ }
///
/// @brief Invert bit
OpenPOWER on IntegriCloud