summaryrefslogtreecommitdiffstats
path: root/src/import/hwpf/fapi2/include/variable_buffer.H
diff options
context:
space:
mode:
authorBrian Silver <bsilver@us.ibm.com>2015-05-11 08:31:13 -0500
committerPatrick Williams <iawillia@us.ibm.com>2015-12-11 13:40:20 -0600
commitc0dca0999cb7e39e52decb3e7cf3b8e8610e2298 (patch)
tree86efbe63b7a0aa9f70392e997385c053734ff2ca /src/import/hwpf/fapi2/include/variable_buffer.H
parent5b6533eb23e36ce3f51b910a60d184dd38fa636a (diff)
downloadtalos-hostboot-c0dca0999cb7e39e52decb3e7cf3b8e8610e2298.tar.gz
talos-hostboot-c0dca0999cb7e39e52decb3e7cf3b8e8610e2298.zip
Add variable_buffer shiftLeft(), shiftRight()
Change-Id: I29692c971987f8fdf71b31d1200718c097085ede Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/17676 Tested-by: Jenkins Server Reviewed-by: Richard J. Knight <rjknight@us.ibm.com> Reviewed-by: PRACHI GUPTA <pragupta@us.ibm.com> Reviewed-by: Brian Silver <bsilver@us.ibm.com>
Diffstat (limited to 'src/import/hwpf/fapi2/include/variable_buffer.H')
-rw-r--r--src/import/hwpf/fapi2/include/variable_buffer.H135
1 files changed, 129 insertions, 6 deletions
diff --git a/src/import/hwpf/fapi2/include/variable_buffer.H b/src/import/hwpf/fapi2/include/variable_buffer.H
index 5cde584f4..2af09a83b 100644
--- a/src/import/hwpf/fapi2/include/variable_buffer.H
+++ b/src/import/hwpf/fapi2/include/variable_buffer.H
@@ -580,6 +580,27 @@ namespace fapi2
///@{
///
+ /// @brief Shift a buffer left a defined number of bits, from a start bit
+ /// @param[in] number of bits to shift
+ /// @param[in] offset from 0 to start shift, defaults to ~0 (see operator<<())
+ /// @note an offset of ~(0) implies "end of the buffer"
+ /// @warning there is no shiftLeftandResize - resizing the buffer is left to
+ /// the caller to alight the operations with integral buffers.
+ /// @return FAPI2_RC_SUCCESS on success
+ ///
+ inline ReturnCodes shiftLeft(bits_type i_shiftNum, bits_type i_offset = ~0);
+
+ ///
+ /// @brief Shift a buffer right a defined number of bits, from a start bit
+ /// @param[in] number of bits to shift
+ /// @param[in] offset from 0 to start shift, defaults to 0 (see operator>>())
+ /// @warning there is no shiftRightandResize - resizing the buffer is left to
+ /// the caller to alight the operations with integral buffers.
+ /// @return FAPI2_RC_SUCCESS on success
+ ///
+ inline ReturnCodes shiftRight(bits_type i_shiftNum, bits_type i_offset = 0);
+
+ ///
/// @brief move operator=()
/// @note To use: new_buffer = std::move(old_buffer). old_buffer will be
/// destroyed and no copy will be made (moved)
@@ -605,16 +626,33 @@ namespace fapi2
///
/// @brief operator>>()
///
-#ifdef DOXYGEN
- inline variable_buffer<T>& operator>>(bits_type i_shiftnum);
-#endif
+ inline variable_buffer& operator>>(bits_type i_shiftnum)
+ {
+ // This is just a right shift from the begining of the buffer
+ // Why void? Well, there's no place to return the return
+ // code and in reality the only problem which can arise
+ // is the offset is out of bounds. But since we're hard-wiring it
+ // to 0, it can't be out of bounds. So there's no real problem
+ // which can arise here.
+ static_cast<void>(shiftRight(i_shiftnum));
+ return *this;
+ }
///
/// @brief operator<<()
///
-#ifdef DOXYGEN
- inline variable_buffer<T>& operator<<(bits_type i_shiftnum);
-#endif
+ inline variable_buffer& operator<<(bits_type i_shiftnum)
+ {
+ // This is just a left shift from the end of the buffer
+ // Why void? Well, there's no place to return the return
+ // code and in reality the only problem which can arise
+ // is the offset is out of bounds. But since we're hard-wiring it
+ // to 0, it can't be out of bounds. So there's no real problem
+ // which can arise here.
+ static_cast<void>(shiftLeft(i_shiftnum));
+ return *this;
+ }
+
///
/// @brief operator+()
@@ -770,6 +808,9 @@ namespace fapi2
/// @param[in] i_start Start bit to copy from - defaults to 0
/// @param[in] i_len Length of bits to copy - defaults to filling o_out
/// @return FAPI2_RC_SUCCESS on success
+ /// @warning fapi2::extract() does not extend the argument buffer. The caller
+ /// should adjust the size proir to calling extract() (resize()). This is to
+ /// keep the semantics the same with integral buffers, which can't be resized.
///
// Generic extract. Extract is an insert with the arguments reversed.
template< typename OT >
@@ -785,6 +826,11 @@ namespace fapi2
parameterTraits<OT>::bit_length());
}
+ if (i_len > getBitLength())
+ {
+ return FAPI2_RC_INVALID_PARAMETER;
+ }
+
// _insert likes 32-bit targets. So lets make our target 32 bits.
uint32_t l_data = static_cast<uint32_t>(o_out);
@@ -1007,6 +1053,7 @@ namespace fapi2
{
i_len = i_data.getBitLength();
}
+
return _insert(reinterpret_cast<const container_unit*>(
&iv_data[0]),
getBitLength(),
@@ -1053,6 +1100,82 @@ namespace fapi2
return FAPI2_RC_SUCCESS;
}
+ inline fapi2::ReturnCodes variable_buffer::shiftLeft(
+ bits_type i_shiftNum,
+ bits_type i_offset)
+ {
+ if (i_offset == 0)
+ {
+ return FAPI2_RC_SUCCESS;
+ }
+
+ if (i_offset == static_cast<bits_type>(~0))
+ {
+ i_offset = getBitLength();
+ }
+
+ else if (i_offset > getBitLength())
+ {
+ return FAPI2_RC_INVALID_PARAMETER;
+ }
+
+ /* To shift the data, extact the piece being shifted and then re-insert it at the new location */
+ variable_buffer shiftData(i_offset);
+ ReturnCodes rc;
+
+ // Get the hunk of data
+ if ((rc = extract(shiftData, 0, i_offset)) != FAPI2_RC_SUCCESS)
+ {
+ return rc;
+ }
+
+ // Clear the hole that was opened
+ if ((rc = clearBit((i_offset - i_shiftNum), i_shiftNum)) != FAPI2_RC_SUCCESS)
+ {
+ return rc;
+ }
+
+ // Stick the data back in
+ rc = insert(shiftData, 0, (shiftData.getBitLength() - i_shiftNum), i_shiftNum);
+
+ return rc;
+ }
+
+ inline fapi2::ReturnCodes variable_buffer::shiftRight(
+ bits_type i_shiftNum,
+ bits_type i_offset)
+ {
+ if (i_offset == getBitLength())
+ {
+ return FAPI2_RC_SUCCESS;
+ }
+
+ if (i_offset > getBitLength())
+ {
+ return FAPI2_RC_INVALID_PARAMETER;
+ }
+
+ /* To shift the data, extact the piece being shifted and then re-insert it at the new location */
+ variable_buffer shiftData(getBitLength() - i_offset);
+ ReturnCodes rc;
+
+ // Get the hunk of data
+ if ((rc = extract(shiftData, i_offset, getBitLength() - i_offset)) != FAPI2_RC_SUCCESS)
+ {
+ return rc;
+ }
+
+ // Clear the hole that was opened
+ if ((rc = clearBit(i_offset, i_shiftNum)) != FAPI2_RC_SUCCESS)
+ {
+ return rc;
+ }
+
+ // Stick the data back in
+ rc = insert(shiftData, (i_offset + i_shiftNum), (shiftData.getBitLength() - i_shiftNum));
+
+ return rc;
+ }
}
#endif
OpenPOWER on IntegriCloud