diff options
| author | Andre Marin <aamarin@us.ibm.com> | 2017-04-04 12:48:15 -0500 |
|---|---|---|
| committer | Joshua Hunsberger <jahunsbe@us.ibm.com> | 2017-10-23 17:23:55 -0500 |
| commit | 7e974bdfce2fcfca88981a0a103bd061d2da6a1c (patch) | |
| tree | b03baceed2dd170f3b1248c6beba00d4dff2e749 /import/hwpf/fapi2/include | |
| parent | c87a1cbfacb9712feb5f3711f9b04ab1b65ebedb (diff) | |
| download | talos-hcode-7e974bdfce2fcfca88981a0a103bd061d2da6a1c.tar.gz talos-hcode-7e974bdfce2fcfca88981a0a103bd061d2da6a1c.zip | |
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 <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: STEPHEN GLANCY <sglancy@us.ibm.com>
Reviewed-by: JACOB L. HARVEY <jlharvey@us.ibm.com>
Reviewed-by: Matt K. Light <mklight@us.ibm.com>
Reviewed-by: Thi N. Tran <thi@us.ibm.com>
Diffstat (limited to 'import/hwpf/fapi2/include')
| -rw-r--r-- | import/hwpf/fapi2/include/buffer.H | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/import/hwpf/fapi2/include/buffer.H b/import/hwpf/fapi2/include/buffer.H index d3fa45ab..43019030 100644 --- a/import/hwpf/fapi2/include/buffer.H +++ b/import/hwpf/fapi2/include/buffer.H @@ -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<T> 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; } |

