summaryrefslogtreecommitdiffstats
path: root/import
diff options
context:
space:
mode:
authorRichard J. Knight <rjknight@us.ibm.com>2016-08-05 16:14:26 -0500
committerSachin Gupta <sgupta2m@in.ibm.com>2016-08-11 00:50:29 -0400
commitf71d052be44bc8af2c4431f4f26fbe2331ce5954 (patch)
tree80f68536bb14c13161be91940ea301b0daa08b03 /import
parentff6b7f28ab36cc838a040d54b6b7fea2b9ea73c6 (diff)
downloadtalos-sbe-f71d052be44bc8af2c4431f4f26fbe2331ce5954.tar.gz
talos-sbe-f71d052be44bc8af2c4431f4f26fbe2331ce5954.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/27950 Reviewed-by: Sachin Gupta <sgupta2m@in.ibm.com>
Diffstat (limited to 'import')
-rw-r--r--import/hwpf/fapi2/include/variable_buffer.H56
1 files changed, 44 insertions, 12 deletions
diff --git a/import/hwpf/fapi2/include/variable_buffer.H b/import/hwpf/fapi2/include/variable_buffer.H
index 9805a53e..46f3e7b3 100644
--- a/import/hwpf/fapi2/include/variable_buffer.H
+++ b/import/hwpf/fapi2/include/variable_buffer.H
@@ -461,17 +461,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
@@ -575,13 +599,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