summaryrefslogtreecommitdiffstats
path: root/src/import/hwpf/fapi2/include/variable_buffer.H
diff options
context:
space:
mode:
authorRichard J. Knight <rjknight@us.ibm.com>2016-08-05 16:14:26 -0500
committerDaniel M. Crowell <dcrowell@us.ibm.com>2016-08-12 09:21:04 -0400
commit24d2613f8a62e47cfc257e484ec6c71305ab3c30 (patch)
tree78f91a56b8aaccf72908ea55a2444e3ea2707425 /src/import/hwpf/fapi2/include/variable_buffer.H
parentc61d7f1c774442fc0830aa7bc0fd1c41eda0889f (diff)
downloadtalos-hostboot-24d2613f8a62e47cfc257e484ec6c71305ab3c30.tar.gz
talos-hostboot-24d2613f8a62e47cfc257e484ec6c71305ab3c30.zip
Variable buffer api additions
-Added flipBit() and getNumBitsSet() support to fapi2::variable_buffer Change-Id: Ifb0be59520dc6cfa26a060e7981ff27f1e0b4b68 RTC:126566 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/27943 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Tested-by: PPE CI <ppe-ci+hostboot@us.ibm.com> Tested-by: Hostboot CI <hostboot-ci+hostboot@us.ibm.com> Reviewed-by: LUCAS W. MULKEY <lwmulkey@us.ibm.com> Reviewed-by: Brian R. Silver <bsilver@us.ibm.com> Reviewed-by: Matt K. Light <mklight@us.ibm.com> Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com> Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/27951 Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com> Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src/import/hwpf/fapi2/include/variable_buffer.H')
-rw-r--r--src/import/hwpf/fapi2/include/variable_buffer.H56
1 files changed, 44 insertions, 12 deletions
diff --git a/src/import/hwpf/fapi2/include/variable_buffer.H b/src/import/hwpf/fapi2/include/variable_buffer.H
index e4aa547fd..18df380d7 100644
--- a/src/import/hwpf/fapi2/include/variable_buffer.H
+++ b/src/import/hwpf/fapi2/include/variable_buffer.H
@@ -467,17 +467,41 @@ class variable_buffer
}
///
- /// @brief Invert bit
+ /// @brief invert a bit or range of bits in a buffer
/// @tparam SB Start bit in buffer to invert.
/// @tparam L Number of consecutive bits from start bit to
/// invert, defaults to 1
/// @return FAPI2_RC_SUCCESS on success
- /// @note Asserting that all the parameters are known at
- /// 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 = 1 >
- inline fapi2::ReturnCodes flipBit(void);
+ inline fapi2::ReturnCodes flipBit( bits_type SB, bits_type L = 1)
+ {
+ ReturnCodes rc;
+
+ // make sure we are within our container
+ if((SB + L) <= this->iv_perceived_bit_length)
+ {
+ // loop for L bits flipping as you go
+ for( bits_type i = 0; i < L; i++)
+ {
+ bits_type bit = SB + i;
+
+ if(this->isBitSet(bit))
+ {
+ rc = this->clearBit(bit);
+ }
+ else
+ {
+ rc = this->setBit(bit);
+ }
+ }
+ }
+ else
+ {
+ rc = FAPI2_RC_OVERFLOW;
+ }
+
+ return rc;
+ }
///
/// @brief Get the value of a bit in the buffer
@@ -581,13 +605,21 @@ class variable_buffer
/// @tparam SB Start bit in buffer to test.
/// @tparam L Number of consecutive bits from start bit to
/// test, defaults to 1
- /// @note Asserting that all the parameters are known at
- /// compile time so this can be templated only. If that is not
- /// the case we can add a function parameter version.
- /// @return Number of bits set in range
///
- template< bits_type SB, bits_type L = 1 >
- inline bits_type getNumBitsSet(void) const;
+ inline bits_type getNumBitsSet(bits_type SB, bits_type L = 1) const
+ {
+ bits_type number_of_bits_set = 0;
+
+ for(bits_type i = 0; i < L; i++)
+ {
+ if( this->isBitSet(SB + i) )
+ {
+ number_of_bits_set++;
+ }
+ }
+
+ return number_of_bits_set;
+ }
///
/// @brief Set and entire buffer to X's
OpenPOWER on IntegriCloud