summaryrefslogtreecommitdiffstats
path: root/import/hwpf/fapi2
diff options
context:
space:
mode:
Diffstat (limited to 'import/hwpf/fapi2')
-rw-r--r--import/hwpf/fapi2/include/plat_trace.H1
-rw-r--r--import/hwpf/fapi2/include/variable_buffer.H135
2 files changed, 130 insertions, 6 deletions
diff --git a/import/hwpf/fapi2/include/plat_trace.H b/import/hwpf/fapi2/include/plat_trace.H
index 90a8d264..9104e767 100644
--- a/import/hwpf/fapi2/include/plat_trace.H
+++ b/import/hwpf/fapi2/include/plat_trace.H
@@ -36,6 +36,7 @@
#define FAPI2_PLATTRACE_H_
#include <stdio.h>
+#include <stdint.h>
// Why not a #define, why is this in the fapi2 namespace?
// To prevent problems with Cronus and the fapi1 definitions.
diff --git a/import/hwpf/fapi2/include/variable_buffer.H b/import/hwpf/fapi2/include/variable_buffer.H
index 5cde584f..2af09a83 100644
--- a/import/hwpf/fapi2/include/variable_buffer.H
+++ b/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