From f71d052be44bc8af2c4431f4f26fbe2331ce5954 Mon Sep 17 00:00:00 2001 From: "Richard J. Knight" Date: Fri, 5 Aug 2016 16:14:26 -0500 Subject: 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 Tested-by: PPE CI Tested-by: Hostboot CI Reviewed-by: LUCAS W. MULKEY Reviewed-by: Brian R. Silver Reviewed-by: Matt K. Light Reviewed-by: Jennifer A. Stofer Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/27950 Reviewed-by: Sachin Gupta --- import/hwpf/fapi2/include/variable_buffer.H | 56 ++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 12 deletions(-) (limited to 'import') 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 -- cgit v1.2.1