From 061be34b12456d1b1e46f5a65fe9c74b80b59738 Mon Sep 17 00:00:00 2001 From: Andre Marin Date: Tue, 4 Apr 2017 12:48:15 -0500 Subject: Add another writeBit API, modify getBit. Add unit tests. Change-Id: I9bd9efdc4b2c8a2eac26b7b1f1e1ef183d81f9b6 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/38817 Tested-by: Jenkins Server Tested-by: PPE CI Tested-by: Hostboot CI Reviewed-by: STEPHEN GLANCY Reviewed-by: JACOB L. HARVEY Reviewed-by: Matt K. Light Reviewed-by: Thi N. Tran Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/38823 Reviewed-by: Hostboot Team Reviewed-by: Sachin Gupta --- src/import/hwpf/fapi2/include/buffer.H | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/import/hwpf/fapi2') diff --git a/src/import/hwpf/fapi2/include/buffer.H b/src/import/hwpf/fapi2/include/buffer.H index 8ee35cbd..eee15f3b 100644 --- a/src/import/hwpf/fapi2/include/buffer.H +++ b/src/import/hwpf/fapi2/include/buffer.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER sbe Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* Contributors Listed Below - COPYRIGHT 2015,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -263,6 +263,7 @@ class buffer /// @brief Write a bit in buffer to a given value /// @tparam B Bit in buffer to write /// @tparam C the count of bits to write, defaults to 1 + /// @param[in] i_value the value to write /// @return buffer& Useful for method chaining /// @note Asserting that all the parameters are known at /// compile time so this can be templated only. If that is not @@ -278,6 +279,24 @@ class buffer return *this; } + /// + /// @brief Write a bit in buffer to a given value + /// @param[in] i_value the value to write + /// @param[in] i_bit the bit number to set. + /// @param[in] i_count the count of bits to set, defaults to 1 + /// @return FAPI2_RC_SUCCESS if OK + /// + inline fapi2::ReturnCodes writeBit(const bool i_value, + const bits_type& i_bit, + const bits_type& i_count = 1) + { + if(i_value == 0) + { + return clearBit(i_bit, i_count); + } + + return setBit(i_bit, i_count); + } /// /// @brief Invert bit @@ -315,14 +334,21 @@ class buffer /// @brief Get the value of a bit in the buffer /// @param[in] i_bit the bit number to set. /// @param[in] i_count the count of bits to set, defaults to 1 - /// @return true if *any* bit is on, false if *every* bit is off + /// @return true if *any* bit is on, + /// false if *every* bit is off or if invalid input received /// @note 0 is left-most /// inline bool getBit(const bits_type& i_bit, - const bits_type& i_count = 1) + const bits_type& i_count = 1) const { buffer l_temp; - l_temp.setBit(i_bit, i_count); + + if(l_temp.setBit(i_bit, i_count) != fapi2::FAPI2_RC_SUCCESS) + { + FAPI_ERR("input out-of-bounds! (bit + count - 1) > %d", TT::bits_per_unit()); + return false; + } + return l_temp & iv_data; } -- cgit v1.2.1