summaryrefslogtreecommitdiffstats
path: root/src/import/hwpf/fapi2/include/variable_buffer.H
diff options
context:
space:
mode:
authorBrian Silver <bsilver@us.ibm.com>2015-08-27 15:31:03 -0500
committerPatrick Williams <iawillia@us.ibm.com>2015-12-11 13:40:20 -0600
commitfb04c49892a12e9dbaa6617f15abac8ef56e3dde (patch)
treeb027356d4399bff467a5be18d46a8d585ae62aff /src/import/hwpf/fapi2/include/variable_buffer.H
parentf10330741cfb5b7fd51ce0236493a6cf75b4053f (diff)
downloadtalos-hostboot-fb04c49892a12e9dbaa6617f15abac8ef56e3dde.tar.gz
talos-hostboot-fb04c49892a12e9dbaa6617f15abac8ef56e3dde.zip
Fixed overflow problem in buffers
Change-Id: Idb3349052373cedaa8955b530a00dd7a25e72122 Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/20182 Tested-by: Jenkins Server Reviewed-by: Matt K. Light <mklight@us.ibm.com> Reviewed-by: WILLIAM G. HOFFA <wghoffa@us.ibm.com> Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com>
Diffstat (limited to 'src/import/hwpf/fapi2/include/variable_buffer.H')
-rw-r--r--src/import/hwpf/fapi2/include/variable_buffer.H1045
1 files changed, 539 insertions, 506 deletions
diff --git a/src/import/hwpf/fapi2/include/variable_buffer.H b/src/import/hwpf/fapi2/include/variable_buffer.H
index b1739be94..813409da2 100644
--- a/src/import/hwpf/fapi2/include/variable_buffer.H
+++ b/src/import/hwpf/fapi2/include/variable_buffer.H
@@ -1,25 +1,19 @@
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
-/* $Source: $ */
+/* $Source: hwpf/fapi2/include/variable_buffer.H $ */
/* */
-/* OpenPOWER HostBoot Project */
-/* */
-/* Contributors Listed Below - COPYRIGHT 2012,2014 */
-/* [+] International Business Machines Corp. */
+/* IBM CONFIDENTIAL */
/* */
+/* EKB Project */
/* */
-/* Licensed under the Apache License, Version 2.0 (the "License"); */
-/* you may not use this file except in compliance with the License. */
-/* You may obtain a copy of the License at */
+/* COPYRIGHT 2012,2015 */
+/* [+] International Business Machines Corp. */
/* */
-/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
-/* Unless required by applicable law or agreed to in writing, software */
-/* distributed under the License is distributed on an "AS IS" BASIS, */
-/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
-/* implied. See the License for the specific language governing */
-/* permissions and limitations under the License. */
+/* The source code for this program is not published or otherwise */
+/* divested of its trade secrets, irrespective of what has been */
+/* deposited with the U.S. Copyright Office. */
/* */
/* IBM_PROLOG_END_TAG */
/**
@@ -37,141 +31,143 @@
namespace fapi2
{
- /// @brief Get a 32 bit mask quickly
- // This is one of the main reasons we static_assert in the ctor's
- // to ensure the unit_type is 32 bits.
- inline uint32_t fast_mask32(int32_t i_pos, int32_t i_len)
- {
- // generates an arbitrary 32-bit mask using two operations, not too shabby
-
- static const uint32_t l_mask32[] = {
- 0x00000000,
- 0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
- 0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
- 0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
- 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
- 0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
- 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
- 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
- 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF,
- };
- return l_mask32[i_len] >> i_pos;
- }
+/// @brief Get a 32 bit mask quickly
+// This is one of the main reasons we static_assert in the ctor's
+// to ensure the unit_type is 32 bits.
+inline uint32_t fast_mask32(int32_t i_pos, int32_t i_len)
+{
+ // generates an arbitrary 32-bit mask using two operations, not too shabby
- //
- // General set a series of bits in the buffer.
- //
-
- ///
- /// @cond
- /// @brief Internal bit inserting method.
- /// @tparam unit_type The type of a unit of the arrays
- /// @tparam bits_type The type of the bit counting values
- /// @param[in] i_source The incoming data
- /// @param[in] i_source_length The length in bits of the incoming data
- /// @param[in] i_target The outgoing data
- /// @param[in] i_target_length The length in bits of the outgoing data
- /// @param[in] i_source_start_bit The starting bit location in the
- /// incoming data
- /// @param[in] i_target_start_bit The starting bit position in this
- /// @param[in] i_length The length, in bits, the user wants copied.
- ///
- template<typename unit_type, typename bits_type, typename output_type>
- inline fapi2::ReturnCodes _insert(const unit_type* i_source,
- bits_type i_source_length,
- output_type* i_target,
- bits_type i_target_length,
- bits_type i_source_start_bit,
- bits_type i_target_start_bit,
- bits_type i_length)
+ static const uint32_t l_mask32[] =
{
- const bits_type bits_per_input_unit = parameterTraits<unit_type>::bit_length();
- const bits_type bits_per_output_unit =parameterTraits<output_type>::bit_length();
+ 0x00000000,
+ 0x80000000, 0xC0000000, 0xE0000000, 0xF0000000,
+ 0xF8000000, 0xFC000000, 0xFE000000, 0xFF000000,
+ 0xFF800000, 0xFFC00000, 0xFFE00000, 0xFFF00000,
+ 0xFFF80000, 0xFFFC0000, 0xFFFE0000, 0xFFFF0000,
+ 0xFFFF8000, 0xFFFFC000, 0xFFFFE000, 0xFFFFF000,
+ 0xFFFFF800, 0xFFFFFC00, 0xFFFFFE00, 0xFFFFFF00,
+ 0xFFFFFF80, 0xFFFFFFC0, 0xFFFFFFE0, 0xFFFFFFF0,
+ 0xFFFFFFF8, 0xFFFFFFFC, 0xFFFFFFFE, 0xFFFFFFFF,
+ };
+ return l_mask32[i_len] >> i_pos;
+}
- // targetStart is defaulted to the sizeof(target) - (sizeof(source) - i_source_start_bit)
- // which makes this act like insert from right
- if (i_target_start_bit == static_cast<bits_type>(~0))
- {
- i_target_start_bit = (i_target_length - (i_source_length - i_source_start_bit));
- }
+//
+// General set a series of bits in the buffer.
+//
+
+///
+/// @cond
+/// @brief Internal bit inserting method.
+/// @tparam unit_type The type of a unit of the arrays
+/// @tparam bits_type The type of the bit counting values
+/// @param[in] i_source The incoming data
+/// @param[in] i_source_length The length in bits of the incoming data
+/// @param[in] i_target The outgoing data
+/// @param[in] i_target_length The length in bits of the outgoing data
+/// @param[in] i_source_start_bit The starting bit location in the
+/// incoming data
+/// @param[in] i_target_start_bit The starting bit position in this
+/// @param[in] i_length The length, in bits, the user wants copied.
+///
+template<typename unit_type, typename bits_type, typename output_type>
+inline fapi2::ReturnCodes _insert(const unit_type* i_source,
+ bits_type i_source_length,
+ output_type* i_target,
+ bits_type i_target_length,
+ bits_type i_source_start_bit,
+ bits_type i_target_start_bit,
+ bits_type i_length)
+{
+ const bits_type bits_per_input_unit = parameterTraits<unit_type>::bit_length();
+ const bits_type bits_per_output_unit = parameterTraits<output_type>::bit_length();
- // len defaults to (sizeof(OT) * 8) - i_source_start_bit
- if (i_length == static_cast<bits_type>(~0))
- {
- i_length = i_source_length - i_source_start_bit;
- }
+ // targetStart is defaulted to the sizeof(target) - (sizeof(source) - i_source_start_bit)
+ // which makes this act like insert from right
+ if (i_target_start_bit == static_cast<bits_type>(~0))
+ {
+ i_target_start_bit = (i_target_length - (i_source_length - i_source_start_bit));
+ }
- // Check for overflow
- if ((i_length + i_target_start_bit > i_target_length) ||
- (i_length + i_source_start_bit > i_source_length))
- {
- return fapi2::FAPI2_RC_OVERFLOW;
- }
+ // len defaults to (sizeof(OT) * 8) - i_source_start_bit
+ if (i_length == static_cast<bits_type>(~0))
+ {
+ i_length = i_source_length - i_source_start_bit;
+ }
- do
- {
- const bits_type src_idx = i_source_start_bit / bits_per_input_unit;
- const bits_type trg_idx = i_target_start_bit / bits_per_output_unit;
+ // Check for overflow
+ if ((i_length + i_target_start_bit > i_target_length) ||
+ (i_length + i_source_start_bit > i_source_length))
+ {
+ return fapi2::FAPI2_RC_OVERFLOW;
+ }
- // "slop" = unaligned bits
- const bits_type src_slop = i_source_start_bit % bits_per_input_unit;
- const bits_type trg_slop = i_target_start_bit % bits_per_output_unit;
+ do
+ {
+ const bits_type src_idx = i_source_start_bit / bits_per_input_unit;
+ const bits_type trg_idx = i_target_start_bit / bits_per_output_unit;
- // "cnt" = largest number of bits to be moved each pass
- bits_type cnt = std::min(i_length, bits_per_input_unit);
- cnt = std::min(cnt, bits_per_input_unit - src_slop);
- cnt = std::min(cnt, bits_per_output_unit - trg_slop);
+ // "slop" = unaligned bits
+ const bits_type src_slop = i_source_start_bit % bits_per_input_unit;
+ const bits_type trg_slop = i_target_start_bit % bits_per_output_unit;
- // generate the source mask only once
- bits_type mask = fast_mask32(src_slop, cnt);
+ // "cnt" = largest number of bits to be moved each pass
+ bits_type cnt = std::min(i_length, bits_per_input_unit);
+ cnt = std::min(cnt, bits_per_input_unit - src_slop);
+ cnt = std::min(cnt, bits_per_output_unit - trg_slop);
- // read the source bits only once
- bits_type src_bits = i_source[src_idx] & mask;
+ // generate the source mask only once
+ bits_type mask = fast_mask32(src_slop, cnt);
- // "shift" = amount of shifting needed for target alignment
- int32_t shift = trg_slop - src_slop;
+ // read the source bits only once
+ bits_type src_bits = i_source[src_idx] & mask;
- if (shift < 0)
- {
- src_bits <<= -shift;
- mask <<= -shift;
- }
- else
- {
- src_bits >>= shift;
- mask >>= shift;
- }
+ // "shift" = amount of shifting needed for target alignment
+ int32_t shift = trg_slop - src_slop;
- // clear source '0' bits in the target
- i_target[trg_idx] &= ~mask;
+ if (shift < 0)
+ {
+ src_bits <<= -shift;
+ mask <<= -shift;
+ }
+ else
+ {
+ src_bits >>= shift;
+ mask >>= shift;
+ }
- // set source '1' bits in the target
- i_target[trg_idx] |= src_bits;
+ // clear source '0' bits in the target
+ i_target[trg_idx] &= ~mask;
- i_source_start_bit += cnt;
- i_target_start_bit += cnt;
+ // set source '1' bits in the target
+ i_target[trg_idx] |= src_bits;
- i_length -= cnt;
+ i_source_start_bit += cnt;
+ i_target_start_bit += cnt;
- } while (0 < i_length);
+ i_length -= cnt;
- return fapi2::FAPI2_RC_SUCCESS;
}
- /// @endcond
-
- /// @brief Class representing a FAPI variable_buffer.
- /// @remark Variable buffers are buffers which can be variable in length
- /// (and "odd sized.") These best represent the FAPI 1.X ecmdDataBuffer,
- /// however they are implemented using the same template techniques
- /// as the new fapi::buffer.
- /// @note Variable buffers are not (presently) declared as std::bitset
- /// as bitsets' size is fixed at runtime. It is not clear if this is
- /// acceptable for variable_buffers at this time.
- /// @note Variable buffers are implemented as a std::vecor of uint32_t
- /// as this keeps simple compatibility with ecmdDataBuffers. Cronus (at
- //least) need to interwork the two.
- class variable_buffer
- {
+ while (0 < i_length);
+
+ return fapi2::FAPI2_RC_SUCCESS;
+}
+/// @endcond
+
+/// @brief Class representing a FAPI variable_buffer.
+/// @remark Variable buffers are buffers which can be variable in length
+/// (and "odd sized.") These best represent the FAPI 1.X ecmdDataBuffer,
+/// however they are implemented using the same template techniques
+/// as the new fapi::buffer.
+/// @note Variable buffers are not (presently) declared as std::bitset
+/// as bitsets' size is fixed at runtime. It is not clear if this is
+/// acceptable for variable_buffers at this time.
+/// @note Variable buffers are implemented as a std::vecor of uint32_t
+/// as this keeps simple compatibility with ecmdDataBuffers. Cronus (at
+//least) need to interwork the two.
+class variable_buffer
+{
public:
@@ -187,10 +183,10 @@ namespace fapi2
inline variable_buffer(bits_type i_value = 0):
iv_data(_vector_size(i_value)),
iv_perceived_bit_length(i_value)
- {
- static_assert(std::is_same<unit_type, uint32_t>::value,
- "code currently needs unit_type to be a unit32_t");
- }
+ {
+ static_assert(std::is_same<unit_type, uint32_t>::value,
+ "code currently needs unit_type to be a unit32_t");
+ }
///
/// @brief Variable buffer list constructor
@@ -200,31 +196,31 @@ namespace fapi2
inline variable_buffer(const std::initializer_list<unit_type>& i_value):
iv_data(i_value),
iv_perceived_bit_length(i_value.size() * sizeof(unit_type) * 8)
- {
- static_assert(std::is_same<unit_type, uint32_t>::value,
- "code currently needs unit_type to be a unit32_t");
- }
+ {
+ static_assert(std::is_same<unit_type, uint32_t>::value,
+ "code currently needs unit_type to be a unit32_t");
+ }
///
/// @brief Variable buffer copy constructor
/// @param[in] i_buffer the buffer to copy from
///
inline variable_buffer(const variable_buffer& i_buffer)
- {
- iv_perceived_bit_length = i_buffer.iv_perceived_bit_length;
- iv_data = i_buffer.iv_data;
- }
+ {
+ iv_perceived_bit_length = i_buffer.iv_perceived_bit_length;
+ iv_data = i_buffer.iv_data;
+ }
///
/// @brief Variable buffer move constructor
/// @param[in] i_buffer the buffer to move
///
inline variable_buffer(variable_buffer&& i_buffer)
- {
- iv_perceived_bit_length = i_buffer.iv_perceived_bit_length;
- i_buffer.iv_perceived_bit_length = 0;
- iv_data = std::move(i_buffer.iv_data);
- }
+ {
+ iv_perceived_bit_length = i_buffer.iv_perceived_bit_length;
+ i_buffer.iv_perceived_bit_length = 0;
+ iv_data = std::move(i_buffer.iv_data);
+ }
///
/// @brief Variable buffer array constructor
@@ -240,44 +236,58 @@ namespace fapi2
inline variable_buffer(const uint32_t* i_value, const uint32_t i_length,
const uint32_t i_bit_length):
iv_perceived_bit_length(i_bit_length)
- {
- static_assert(std::is_same<unit_type, uint32_t>::value,
- "code currently needs unit_type to be a unit32_t");
+ {
+ static_assert(std::is_same<unit_type, uint32_t>::value,
+ "code currently needs unit_type to be a unit32_t");
- // Copy the array in to our vector.
- iv_data.insert(iv_data.end(), i_value, &i_value[i_length]);
- }
+ // Copy the array in to our vector.
+ iv_data.insert(iv_data.end(), i_value, &i_value[i_length]);
+ }
#if !defined(DOXYGEN) && defined(FAPI2_DEBUG)
/// @brief Print the contents of the buffer to stdout
inline void print(void) const
- { bufferTraits<bits_container>::print(iv_data); }
+ {
+ bufferTraits<bits_container>::print(iv_data);
+ }
#endif
///
/// @brief Get the contents of the buffer
/// @return The contents of the buffer
///
- inline operator bits_container() const { return iv_data; }
+ inline operator bits_container() const
+ {
+ return iv_data;
+ }
///
/// @brief Get the contents of the buffer
/// @return The contents of the buffer
///
- inline operator bits_container&() { return iv_data; }
+ inline operator bits_container& ()
+ {
+ return iv_data;
+ }
///
/// @brief Get the contents of the buffer
/// @return The contents of the buffer
///
- inline bits_container& operator()(void) { return iv_data; }
+ inline bits_container& operator()(void)
+ {
+ return iv_data;
+ }
///
/// @brief Get the contents of the buffer
/// @return Reference to the contents of the buffer
///
- inline const bits_container& operator()(void) const { return iv_data; }
+ inline const bits_container& operator()(void) const
+ {
+ return iv_data;
+ }
/// @name Buffer Manipulation Functions
///@{
@@ -300,7 +310,7 @@ namespace fapi2
static const bits_type bits_in_value = parameterTraits<OT>::bit_length();
const bits_type bit_length = bufferTraits<bits_container>::bit_length(iv_data);
- if ((i_offset + bits_in_value) >= iv_perceived_bit_length)
+ if ((i_offset + bits_in_value) > iv_perceived_bit_length)
{
return FAPI2_RC_OVERFLOW;
}
@@ -308,11 +318,13 @@ namespace fapi2
// Create mask if part of this byte is not in the valid part of the buffer,
// Shift it left by the amount of unused bits,
// Clear the unused bits (doesn't use fastmask as OT isn't always 32 bits)
- if (((i_offset + 1) == length) && (bit_length % bits_in_value)) {
+ if (((i_offset + 1) == length) && (bit_length % bits_in_value))
+ {
i_value &= parameterTraits<OT>::mask() << ((bits_in_value * length) - bit_length);
}
- parameterTraits<OT>::template write_element<unit_type>(bufferTraits<bits_container>::get_address(iv_data), i_value, i_offset);
+ parameterTraits<OT>::template write_element<unit_type>(bufferTraits<bits_container>::get_address(iv_data), i_value,
+ i_offset);
return FAPI2_RC_SUCCESS;
}
@@ -335,7 +347,9 @@ namespace fapi2
/// @return Length in bits
///
inline uint32_t getBitLength(void) const
- { return iv_perceived_bit_length; }
+ {
+ return iv_perceived_bit_length;
+ }
///
/// @brief Return the length of the buffer in OT units
@@ -362,24 +376,24 @@ namespace fapi2
{
ReturnCodes rc;
- // make sure we stay within our container
+ // make sure we stay within our container
assert((L > 0) && ((SB + L) <= this->iv_perceived_bit_length) );
uint32_t mask = 0;
// last bit to check
- bits_type EB = SB + L -1;
+ bits_type EB = SB + L - 1;
// index where first bit to check is located
- bits_type start_index = SB/bits_per_unit;
+ bits_type start_index = SB / bits_per_unit;
// index where last bit is located
- bits_type end_index = EB/bits_per_unit;
+ bits_type end_index = EB / bits_per_unit;
if( start_index == end_index )
{
// normalize our SB to be within a unit
- bits_type TempSB = SB - (start_index*bits_per_unit);
+ bits_type TempSB = SB - (start_index * bits_per_unit);
// grab a mask from SB for L number of bits.
mask = fast_mask32(TempSB, L);
@@ -406,10 +420,10 @@ namespace fapi2
{
// now check the bits in the previous index up to the next index.
// normalize our SB to be within a unit
- TempSB = SB - (start_index*bits_per_unit);
+ TempSB = SB - (start_index * bits_per_unit);
// get a mask for the new SB location to the end of this unit.
- mask = fast_mask32(TempSB, L-TempL);
+ mask = fast_mask32(TempSB, L - TempL);
// merge theses bits with the others.
iv_data[start_index] |= mask;
@@ -432,7 +446,7 @@ namespace fapi2
///
inline fapi2::ReturnCodes clearBit(bits_type SB, bits_type L = 0)
{
- ReturnCodes rc = invert().setBit(SB,L);
+ ReturnCodes rc = invert().setBit(SB, L);
invert();
@@ -465,7 +479,7 @@ namespace fapi2
{
const bits_type index = B / bits_per_unit;
const unit_type mask = unit_type(1) <<
- ((bits_per_unit - 1) - (B - (index * bits_per_unit)));
+ ((bits_per_unit - 1) - (B - (index * bits_per_unit)));
return iv_data[index] & mask;
}
@@ -489,15 +503,15 @@ namespace fapi2
bits_type EB = SB + L - 1;
// index where first bit to check is located
- bits_type start_index = SB/bits_per_unit;
+ bits_type start_index = SB / bits_per_unit;
// index where last bit is located
- bits_type end_index = EB/bits_per_unit;
+ bits_type end_index = EB / bits_per_unit;
if( start_index == end_index )
{
// normalize our SB to be within a unit
- bits_type TempSB = SB - (start_index*bits_per_unit);
+ bits_type TempSB = SB - (start_index * bits_per_unit);
// grab a mask from SB for L number of bits.
mask = fast_mask32(TempSB, L);
@@ -521,10 +535,10 @@ namespace fapi2
// now check the bits in the previous index up to the next index.
// normalize our SB to be within a unit
- TempSB = SB - (start_index*bits_per_unit);
+ TempSB = SB - (start_index * bits_per_unit);
// get a mask for the new SB location to the end of this unit.
- mask = fast_mask32(TempSB, L-TempL);
+ mask = fast_mask32(TempSB, L - TempL);
// test these bits against the others..
is_set &=
@@ -542,11 +556,11 @@ namespace fapi2
/// test, defaults to 1
/// @return true if bit is clear - false if bit is set
///
- inline bool isBitClear( bits_type SB, bits_type L =1 ) const
+ inline bool isBitClear( bits_type SB, bits_type L = 1 ) const
{
variable_buffer l_buf = *this;
- return l_buf.invert().isBitSet(SB,L);
+ return l_buf.invert().isBitSet(SB, L);
}
///
@@ -570,18 +584,21 @@ namespace fapi2
///
template< uint8_t X >
inline variable_buffer& flush(void)
- {
- static_assert( (X == 1) || (X == 0), "bad argument to flush" );
- (0 == X) ? bufferTraits<bits_container>::clear(iv_data) : bufferTraits<bits_container>::set(iv_data);
- return *this;
- }
+ {
+ static_assert( (X == 1) || (X == 0), "bad argument to flush" );
+ (0 == X) ? bufferTraits<bits_container>::clear(iv_data) : bufferTraits<bits_container>::set(iv_data);
+ return *this;
+ }
///
/// @brief Invert entire buffer
/// @return variable_buffer&, Useful for method chaining
///
inline variable_buffer& invert(void)
- { bufferTraits<bits_container>::invert(iv_data); return *this; }
+ {
+ bufferTraits<bits_container>::invert(iv_data);
+ return *this;
+ }
///@}
@@ -615,52 +632,52 @@ namespace fapi2
/// destroyed and no copy will be made (moved)
///
inline variable_buffer& operator=(variable_buffer&& other)
- {
- iv_perceived_bit_length = other.iv_perceived_bit_length;
- other.iv_perceived_bit_length = 0;
- iv_data = std::move(other.iv_data);
- return *this;
- }
+ {
+ iv_perceived_bit_length = other.iv_perceived_bit_length;
+ other.iv_perceived_bit_length = 0;
+ iv_data = std::move(other.iv_data);
+ return *this;
+ }
///
/// @brief operator=()
///
inline variable_buffer& operator=(const variable_buffer& other)
- {
- iv_perceived_bit_length = other.iv_perceived_bit_length;
- iv_data = other.iv_data;
- return *this;
- }
+ {
+ iv_perceived_bit_length = other.iv_perceived_bit_length;
+ iv_data = other.iv_data;
+ return *this;
+ }
///
/// @brief operator>>()
///
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;
- }
+ {
+ // 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<<()
///
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;
- }
+ {
+ // 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;
+ }
///
@@ -668,34 +685,35 @@ namespace fapi2
/// @param[in] A variable_buffer to append to this
///
inline variable_buffer& operator+(const variable_buffer& rhs)
- {
- iv_perceived_bit_length += rhs.iv_perceived_bit_length;
- iv_data.insert(iv_data.end(), rhs.iv_data.begin(), rhs.iv_data.end());
- return *this;
- }
+ {
+ iv_perceived_bit_length += rhs.iv_perceived_bit_length;
+ iv_data.insert(iv_data.end(), rhs.iv_data.begin(), rhs.iv_data.end());
+ return *this;
+ }
///
/// @brief operator+()
/// @param[in] A number of bits to add to this buffer
///
inline variable_buffer& operator+(const bits_type& rhs)
+ {
+ if (rhs != 0)
{
- if (rhs != 0)
- {
- iv_perceived_bit_length += rhs;
- iv_data.resize(_vector_size(iv_perceived_bit_length));
- }
- return *this;
+ iv_perceived_bit_length += rhs;
+ iv_data.resize(_vector_size(iv_perceived_bit_length));
}
+ return *this;
+ }
+
///
/// @brief resize()
/// @param[in] Desired resulting size of the buffer, in bits
///
inline variable_buffer& resize(const bits_type& rhs)
- {
- return operator+(rhs - iv_perceived_bit_length);
- }
+ {
+ return operator+(rhs - iv_perceived_bit_length);
+ }
///
/// @brief operator+=()
@@ -743,13 +761,18 @@ namespace fapi2
/// @brief Get a pointer to the buffer bits
/// @return Pointer to the buffer itself
///
- inline unit_type* pointer(void) { return &(iv_data[0]); }
+ inline unit_type* pointer(void)
+ {
+ return &(iv_data[0]);
+ }
///
/// @brief operator!=()
///
inline bool operator!=(const variable_buffer& rhs) const
- { return ! operator==(rhs); }
+ {
+ return ! operator==(rhs);
+ }
///
/// @brief operator==()
@@ -763,7 +786,7 @@ namespace fapi2
}
return (iv_data == rhs.iv_data) &&
- (iv_perceived_bit_length == rhs.iv_perceived_bit_length);
+ (iv_perceived_bit_length == rhs.iv_perceived_bit_length);
}
///
@@ -776,20 +799,20 @@ namespace fapi2
///
template<typename OT>
inline fapi2::ReturnCodes insert(const OT& i_data,
- bits_type i_targetStart = 0,
- bits_type i_len = ~0,
- bits_type i_sourceStart = 0)
- {
- // _insert likes 32-bit sources. So lets make our source 32 bits.
- uint32_t l_source = static_cast<uint32_t>(i_data);
- bits_type l_sourceStart = i_sourceStart +
- parameterTraits<uint32_t>::bit_length() -
- parameterTraits<OT>::bit_length();
-
- return _insert(&l_source, parameterTraits<uint32_t>::bit_length(),
- &(iv_data[0]), getBitLength(),
- l_sourceStart, i_targetStart, i_len);
- }
+ bits_type i_targetStart = 0,
+ bits_type i_len = ~0,
+ bits_type i_sourceStart = 0)
+ {
+ // _insert likes 32-bit sources. So lets make our source 32 bits.
+ uint32_t l_source = static_cast<uint32_t>(i_data);
+ bits_type l_sourceStart = i_sourceStart +
+ parameterTraits<uint32_t>::bit_length() -
+ parameterTraits<OT>::bit_length();
+
+ return _insert(&l_source, parameterTraits<uint32_t>::bit_length(),
+ &(iv_data[0]), getBitLength(),
+ l_sourceStart, i_targetStart, i_len);
+ }
///
/// @brief Copy in a right aligned (decimal) element
@@ -803,12 +826,12 @@ namespace fapi2
///
template<typename OT>
inline fapi2::ReturnCodes insertFromRight(const OT& i_data,
- bits_type i_targetStart = 0,
- bits_type i_len = ~0)
- {
- return _insertFromRight(i_data, parameterTraits<OT>::bit_length(),
- i_targetStart, i_len);
- }
+ bits_type i_targetStart = 0,
+ bits_type i_len = ~0)
+ {
+ return _insertFromRight(i_data, parameterTraits<OT>::bit_length(),
+ i_targetStart, i_len);
+ }
///
/// @brief Copy data from this buffer into an OT
@@ -824,40 +847,41 @@ namespace fapi2
// Generic extract. Extract is an insert with the arguments reversed.
template< typename OT >
inline fapi2::ReturnCodes extract(OT& o_out,
- bits_type i_start = 0,
- bits_type i_len = ~0) const
+ bits_type i_start = 0,
+ bits_type i_len = ~0) const
+ {
+ // If thy didn't pass an i_len, assume they want all the data
+ // which will fit.
+ if (i_len == static_cast<bits_type>(~0))
{
- // If thy didn't pass an i_len, assume they want all the data
- // which will fit.
- if (i_len == static_cast<bits_type>(~0))
- {
- i_len = std::min(getBitLength(),
- parameterTraits<OT>::bit_length());
- }
+ i_len = std::min(getBitLength(),
+ parameterTraits<OT>::bit_length());
+ }
- if (i_len > getBitLength())
- {
- return FAPI2_RC_INVALID_PARAMETER;
- }
+ 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);
+ // _insert likes 32-bit targets. So lets make our target 32 bits.
+ uint32_t l_data = static_cast<uint32_t>(o_out);
- ReturnCodes rc;
- if ((rc = _insert((container_unit*)&iv_data[0], getBitLength(),
- &l_data,
- parameterTraits<uint32_t>::bit_length(),
- i_start, 0U, i_len)) != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+ ReturnCodes rc;
- // Shift back to the original bit width.
- o_out = l_data >> (parameterTraits<uint32_t>::bit_length() -
- parameterTraits<OT>::bit_length());
- return FAPI2_RC_SUCCESS;
+ if ((rc = _insert((container_unit*)&iv_data[0], getBitLength(),
+ &l_data,
+ parameterTraits<uint32_t>::bit_length(),
+ i_start, 0U, i_len)) != FAPI2_RC_SUCCESS)
+ {
+ return rc;
}
+ // Shift back to the original bit width.
+ o_out = l_data >> (parameterTraits<uint32_t>::bit_length() -
+ parameterTraits<OT>::bit_length());
+ return FAPI2_RC_SUCCESS;
+ }
+
///
/// @brief Copy data from this buffer into an OT and right justify
/// @tparam OT the type of the outgoing data
@@ -869,38 +893,39 @@ namespace fapi2
// Extract is an insert with the arguments reversed.
template< typename OT >
inline fapi2::ReturnCodes extractToRight(OT& o_out,
- bits_type i_start = 0,
- bits_type i_len = ~0) const
+ bits_type i_start = 0,
+ bits_type i_len = ~0) const
+ {
+ // If thy didn't pass an i_len, assume they want all the data
+ // which will fit.
+ if ((i_len == static_cast<bits_type>(~0)) ||
+ (i_len > parameterTraits<OT>::bit_length()))
{
- // If thy didn't pass an i_len, assume they want all the data
- // which will fit.
- if ((i_len == static_cast<bits_type>(~0)) ||
- (i_len > parameterTraits<OT>::bit_length()))
- {
- i_len = std::min(getBitLength(),
- parameterTraits<OT>::bit_length());
- }
+ i_len = std::min(getBitLength(),
+ parameterTraits<OT>::bit_length());
+ }
- // _insert likes 32-bit targets. So lets make our target 32 bits.
- uint32_t l_data = static_cast<uint32_t>(o_out);
-
- ReturnCodes rc;
- if ((rc = _insert(
- reinterpret_cast<const container_unit*>(&iv_data[0]),
- getBitLength(),
- &l_data,
- parameterTraits<uint32_t>::bit_length(),
- i_start,
- parameterTraits<uint32_t>::bit_length() -
- i_len, i_len)) != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+ // _insert likes 32-bit targets. So lets make our target 32 bits.
+ uint32_t l_data = static_cast<uint32_t>(o_out);
- o_out = l_data;
- return FAPI2_RC_SUCCESS;
+ ReturnCodes rc;
+
+ if ((rc = _insert(
+ reinterpret_cast<const container_unit*>(&iv_data[0]),
+ getBitLength(),
+ &l_data,
+ parameterTraits<uint32_t>::bit_length(),
+ i_start,
+ parameterTraits<uint32_t>::bit_length() -
+ i_len, i_len)) != FAPI2_RC_SUCCESS)
+ {
+ return rc;
}
+ o_out = l_data;
+ return FAPI2_RC_SUCCESS;
+ }
+
///@}
private:
@@ -914,22 +939,22 @@ namespace fapi2
/// @return The size in units.
///
inline bits_type _vector_size(const bits_type& bits_size)
+ {
+ // If we fit in one unit, we allocate one unit.
+ if (bits_size < parameterTraits<unit_type>::bit_length())
{
- // If we fit in one unit, we allocate one unit.
- if (bits_size < parameterTraits<unit_type>::bit_length())
- {
- return 1;
- }
+ return 1;
+ }
- // Otherwise, the number of units is calculates - add one if
- // we cross the unit boundary.
- else
- {
- bits_type my_size = bits_type(bits_size / 8 / sizeof(unit_type));
- my_size += (bits_size % parameterTraits<unit_type>::bit_length() == 0) ? 0 : 1;
- return my_size;
- }
+ // Otherwise, the number of units is calculates - add one if
+ // we cross the unit boundary.
+ else
+ {
+ bits_type my_size = bits_type(bits_size / 8 / sizeof(unit_type));
+ my_size += (bits_size % parameterTraits<unit_type>::bit_length() == 0) ? 0 : 1;
+ return my_size;
}
+ }
///@endcond
/// The contents of the buffer
@@ -948,9 +973,9 @@ namespace fapi2
///
template<typename OT>
inline fapi2::ReturnCodes _insertFromRight(const OT& i_data,
- bits_type i_data_length,
- bits_type i_targetStart,
- bits_type i_len)
+ bits_type i_data_length,
+ bits_type i_targetStart,
+ bits_type i_len)
{
// If they didn't pass in a length, assume they want all the i_data
// which will fit.
@@ -966,233 +991,241 @@ namespace fapi2
return insert(i_data, i_targetStart, i_len, i_data_length - i_len);
}
- };
-
- // If the source is 64-bits, treat that as 2x32
- template<>
- inline fapi2::ReturnCodes variable_buffer::insert(const uint64_t& i_source,
- bits_type i_targetStart,
- bits_type i_len,
- bits_type i_sourceStart)
- {
- // _insert wants 32 bit chunks, so lets turn our uint64_t into a
- // uint32_t array (of 64 bits in length). Looks like a 64 bit
- // variable_buffer.
- uint32_t l_source[2] =
- {static_cast<uint32_t>((i_source & 0xFFFFFFFF00000000) >> 32),
- static_cast<uint32_t>((i_source & 0x00000000FFFFFFFF))};
-
- return _insert(l_source, parameterTraits<uint64_t>::bit_length(),
- &(iv_data[0]), getBitLength(),
- i_sourceStart, i_targetStart, i_len);
- }
+};
- // Insert another variable_bufer
- template<>
- inline fapi2::ReturnCodes variable_buffer::insert(
- const variable_buffer& i_data,
+// If the source is 64-bits, treat that as 2x32
+template<>
+inline fapi2::ReturnCodes variable_buffer::insert(const uint64_t& i_source,
bits_type i_targetStart,
bits_type i_len,
bits_type i_sourceStart)
+{
+ // _insert wants 32 bit chunks, so lets turn our uint64_t into a
+ // uint32_t array (of 64 bits in length). Looks like a 64 bit
+ // variable_buffer.
+ uint32_t l_source[2] =
{
- return _insert(reinterpret_cast<const unit_type*>(&(i_data()[0])),
- i_data.getBitLength(),
- &(iv_data[0]), getBitLength(),
- i_sourceStart, i_targetStart, i_len);
- }
+ static_cast<uint32_t>((i_source & 0xFFFFFFFF00000000) >> 32),
+ static_cast<uint32_t>((i_source & 0x00000000FFFFFFFF))
+ };
- // variable_buffer insert from right
- template<>
- inline fapi2::ReturnCodes variable_buffer::insertFromRight(
- const variable_buffer& i_data,
- bits_type i_targetStart,
- bits_type i_len)
+ return _insert(l_source, parameterTraits<uint64_t>::bit_length(),
+ &(iv_data[0]), getBitLength(),
+ i_sourceStart, i_targetStart, i_len);
+}
+
+// Insert another variable_bufer
+template<>
+inline fapi2::ReturnCodes variable_buffer::insert(
+ const variable_buffer& i_data,
+ bits_type i_targetStart,
+ bits_type i_len,
+ bits_type i_sourceStart)
+{
+ return _insert(reinterpret_cast<const unit_type*>(&(i_data()[0])),
+ i_data.getBitLength(),
+ &(iv_data[0]), getBitLength(),
+ i_sourceStart, i_targetStart, i_len);
+}
+
+// variable_buffer insert from right
+template<>
+inline fapi2::ReturnCodes variable_buffer::insertFromRight(
+ const variable_buffer& i_data,
+ bits_type i_targetStart,
+ bits_type i_len)
+{
+ const bits_type bit_length_of_source = i_data.getBitLength();
+ return _insertFromRight(i_data, bit_length_of_source,
+ i_targetStart, i_len);
+}
+
+template<>
+inline fapi2::ReturnCodes variable_buffer::extract(
+ uint64_t& i_data,
+ bits_type i_start,
+ bits_type i_len) const
+{
+ // If thy didn't pass an i_len, assume they want all the data
+ // which will fit.
+ if ((i_len == static_cast<bits_type>(~0)) ||
+ (i_len > parameterTraits<uint64_t>::bit_length()))
{
- const bits_type bit_length_of_source = i_data.getBitLength();
- return _insertFromRight(i_data, bit_length_of_source,
- i_targetStart, i_len);
+ i_len = std::min(getBitLength(),
+ parameterTraits<uint64_t>::bit_length());
}
- template<>
- inline fapi2::ReturnCodes variable_buffer::extract(
- uint64_t& i_data,
- bits_type i_start,
- bits_type i_len) const
+ // _insert wants 32 bit chunks, so lets turn our uint64_t into a
+ // uint32_t array (of 64 bits in length). Looks like a 64 bit
+ // variable_buffer.
+ uint32_t l_data[2] =
{
- // If thy didn't pass an i_len, assume they want all the data
- // which will fit.
- if ((i_len == static_cast<bits_type>(~0)) ||
- (i_len > parameterTraits<uint64_t>::bit_length()))
- {
- i_len = std::min(getBitLength(),
- parameterTraits<uint64_t>::bit_length());
- }
-
- // _insert wants 32 bit chunks, so lets turn our uint64_t into a
- // uint32_t array (of 64 bits in length). Looks like a 64 bit
- // variable_buffer.
- uint32_t l_data[2] =
- {static_cast<uint32_t>((i_data & 0xFFFFFFFF00000000) >> 32),
- static_cast<uint32_t>((i_data & 0x00000000FFFFFFFF))};
-
- ReturnCodes rc;
- if ((rc = _insert((container_unit*)&iv_data[0], getBitLength(),
- l_data, parameterTraits<uint64_t>::bit_length(),
- i_start, 0U, i_len)) != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+ static_cast<uint32_t>((i_data & 0xFFFFFFFF00000000) >> 32),
+ static_cast<uint32_t>((i_data & 0x00000000FFFFFFFF))
+ };
- i_data = static_cast<uint64_t>(l_data[0]) << 32;
- i_data |= l_data[1];
+ ReturnCodes rc;
- return FAPI2_RC_SUCCESS;
+ if ((rc = _insert((container_unit*)&iv_data[0], getBitLength(),
+ l_data, parameterTraits<uint64_t>::bit_length(),
+ i_start, 0U, i_len)) != FAPI2_RC_SUCCESS)
+ {
+ return rc;
}
- // Extract in to another variable_bufer
- template<>
- inline fapi2::ReturnCodes variable_buffer::extract(
- variable_buffer& i_data,
- bits_type i_start,
- bits_type i_len) const
- {
- // If thy didn't pass an i_len, assume they want all the data
- // which will fit.
- if (i_len == static_cast<bits_type>(~0))
- {
- i_len = i_data.getBitLength();
- }
+ i_data = static_cast<uint64_t>(l_data[0]) << 32;
+ i_data |= l_data[1];
- return _insert(reinterpret_cast<const container_unit*>(
- &iv_data[0]),
- getBitLength(),
- &(i_data()[0]), i_data.getBitLength(),
- i_start, 0U, i_len);
- }
+ return FAPI2_RC_SUCCESS;
+}
- template<>
- inline fapi2::ReturnCodes variable_buffer::extractToRight(
- uint64_t& i_data,
- bits_type i_start,
- bits_type i_len) const
+// Extract in to another variable_bufer
+template<>
+inline fapi2::ReturnCodes variable_buffer::extract(
+ variable_buffer& i_data,
+ bits_type i_start,
+ bits_type i_len) const
+{
+ // If thy didn't pass an i_len, assume they want all the data
+ // which will fit.
+ if (i_len == static_cast<bits_type>(~0))
{
- // If thy didn't pass an i_len, assume they want all the data
- // which will fit.
- if ((i_len == static_cast<bits_type>(~0)) ||
- (i_len > parameterTraits<uint64_t>::bit_length()))
- {
- i_len = std::min(getBitLength(),
- parameterTraits<uint64_t>::bit_length());
- }
-
- // _insert wants 32 bit chunks, so lets turn our uint64_t into a
- // uint32_t array (of 64 bits in length).
- uint32_t l_data[2] =
- {static_cast<uint32_t>((i_data & 0xFFFFFFFF00000000) >> 32),
- static_cast<uint32_t>((i_data & 0x00000000FFFFFFFF))};
-
- ReturnCodes rc;
- if ((rc = _insert(
- reinterpret_cast<const container_unit*>(&iv_data[0]),
- getBitLength(),
- l_data, parameterTraits<uint64_t>::bit_length(),
- i_start,
- parameterTraits<uint64_t>::bit_length() - i_len, i_len))
- != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+ i_len = i_data.getBitLength();
+ }
- i_data = static_cast<uint64_t>(l_data[0]) << 32;
- i_data |= l_data[1];
+ return _insert(reinterpret_cast<const container_unit*>(
+ &iv_data[0]),
+ getBitLength(),
+ &(i_data()[0]), i_data.getBitLength(),
+ i_start, 0U, i_len);
+}
- return FAPI2_RC_SUCCESS;
+template<>
+inline fapi2::ReturnCodes variable_buffer::extractToRight(
+ uint64_t& i_data,
+ bits_type i_start,
+ bits_type i_len) const
+{
+ // If thy didn't pass an i_len, assume they want all the data
+ // which will fit.
+ if ((i_len == static_cast<bits_type>(~0)) ||
+ (i_len > parameterTraits<uint64_t>::bit_length()))
+ {
+ i_len = std::min(getBitLength(),
+ parameterTraits<uint64_t>::bit_length());
}
- inline fapi2::ReturnCodes variable_buffer::shiftLeft(
- bits_type i_shiftNum,
- bits_type i_offset)
+ // _insert wants 32 bit chunks, so lets turn our uint64_t into a
+ // uint32_t array (of 64 bits in length).
+ uint32_t l_data[2] =
{
- if (i_offset == 0)
- {
- return FAPI2_RC_SUCCESS;
- }
+ static_cast<uint32_t>((i_data & 0xFFFFFFFF00000000) >> 32),
+ static_cast<uint32_t>((i_data & 0x00000000FFFFFFFF))
+ };
- if (i_offset == static_cast<bits_type>(~0))
- {
- i_offset = getBitLength();
- }
+ ReturnCodes rc;
- else if (i_offset > getBitLength())
- {
- return FAPI2_RC_INVALID_PARAMETER;
- }
+ if ((rc = _insert(
+ reinterpret_cast<const container_unit*>(&iv_data[0]),
+ getBitLength(),
+ l_data, parameterTraits<uint64_t>::bit_length(),
+ i_start,
+ parameterTraits<uint64_t>::bit_length() - i_len, i_len))
+ != FAPI2_RC_SUCCESS)
+ {
+ return rc;
+ }
- /* 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;
+ i_data = static_cast<uint64_t>(l_data[0]) << 32;
+ i_data |= l_data[1];
- // Get the hunk of data
- if ((rc = extract(shiftData, 0, i_offset)) != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+ return FAPI2_RC_SUCCESS;
+}
- // Clear the hole that was opened
- if ((rc = clearBit((i_offset - i_shiftNum), i_shiftNum)) != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+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();
+ }
- // Stick the data back in
- rc = insert(shiftData, 0, (shiftData.getBitLength() - i_shiftNum), i_shiftNum);
+ 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;
}
- inline fapi2::ReturnCodes variable_buffer::shiftRight(
- bits_type i_shiftNum,
- bits_type i_offset)
+ // Clear the hole that was opened
+ if ((rc = clearBit((i_offset - i_shiftNum), i_shiftNum)) != FAPI2_RC_SUCCESS)
{
- if (i_offset == getBitLength())
- {
- return FAPI2_RC_SUCCESS;
- }
+ return rc;
+ }
- if (i_offset > getBitLength())
- {
- return FAPI2_RC_INVALID_PARAMETER;
- }
+ // Stick the data back in
+ rc = insert(shiftData, 0, (shiftData.getBitLength() - i_shiftNum), i_shiftNum);
- /* 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;
+ return rc;
+}
- // Get the hunk of data
- if ((rc = extract(shiftData, i_offset, getBitLength() - i_offset)) != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+inline fapi2::ReturnCodes variable_buffer::shiftRight(
+ bits_type i_shiftNum,
+ bits_type i_offset)
+{
+ if (i_offset == getBitLength())
+ {
+ return FAPI2_RC_SUCCESS;
+ }
- // Clear the hole that was opened
- if ((rc = clearBit(i_offset, i_shiftNum)) != FAPI2_RC_SUCCESS)
- {
- return rc;
- }
+ if (i_offset > getBitLength())
+ {
+ return FAPI2_RC_INVALID_PARAMETER;
+ }
- // Stick the data back in
- rc = insert(shiftData, (i_offset + i_shiftNum), (shiftData.getBitLength() - i_shiftNum));
+ /* 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;
}
- template< typename OT>
- inline OT variable_buffer::get(const bits_type i_offset)
+ // Clear the hole that was opened
+ if ((rc = clearBit(i_offset, i_shiftNum)) != FAPI2_RC_SUCCESS)
{
- // Get is just an extract.
- OT l_tmp;
- extract(l_tmp, parameterTraits<OT>::bit_length() * i_offset, parameterTraits<OT>::bit_length());
- return l_tmp;
+ return rc;
}
+
+ // Stick the data back in
+ rc = insert(shiftData, (i_offset + i_shiftNum), (shiftData.getBitLength() - i_shiftNum));
+
+ return rc;
+}
+
+template< typename OT>
+inline OT variable_buffer::get(const bits_type i_offset)
+{
+ // Get is just an extract.
+ OT l_tmp;
+ extract(l_tmp, parameterTraits<OT>::bit_length() * i_offset, parameterTraits<OT>::bit_length());
+ return l_tmp;
+}
}
#endif
OpenPOWER on IntegriCloud