diff options
| author | Brian Silver <bsilver@us.ibm.com> | 2015-03-13 10:50:16 -0500 |
|---|---|---|
| committer | Joshua Hunsberger <jahunsbe@us.ibm.com> | 2017-10-23 15:50:55 -0500 |
| commit | 6a295a9a34aedea8cc60a0247500cd2e083c411e (patch) | |
| tree | 839a43c0f5166f125dee291393977c6faa6fb840 /import/hwpf/fapi2/include | |
| parent | 2cb6e4bc7949ea1846bb11c8e0f3ced3d7112837 (diff) | |
| download | talos-hcode-6a295a9a34aedea8cc60a0247500cd2e083c411e.tar.gz talos-hcode-6a295a9a34aedea8cc60a0247500cd2e083c411e.zip | |
Buffer, targeting updates
Update target types for ex, l2/l3
Add variable_buffer resize
Update, fix, variable_buffer insert/extract
variable_buffer array constructor
-Wall clean up
Refactor buffer::insert, bit_lengths
Change-Id: I2bbec294f275a80c33917dc2df2f8b8220f6d8d6
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/16359
Reviewed-by: Matt K. Light <mklight@us.ibm.com>
Reviewed-by: MATTHEW A. PLOETZ <maploetz@us.ibm.com>
Reviewed-by: Brian Silver <bsilver@us.ibm.com>
Tested-by: Brian Silver <bsilver@us.ibm.com>
Diffstat (limited to 'import/hwpf/fapi2/include')
| -rw-r--r-- | import/hwpf/fapi2/include/buffer.H | 82 | ||||
| -rw-r--r-- | import/hwpf/fapi2/include/buffer_parameters.H | 19 | ||||
| -rw-r--r-- | import/hwpf/fapi2/include/buffer_traits.H | 13 |
3 files changed, 53 insertions, 61 deletions
diff --git a/import/hwpf/fapi2/include/buffer.H b/import/hwpf/fapi2/include/buffer.H index dbc20a95..69c5c9ff 100644 --- a/import/hwpf/fapi2/include/buffer.H +++ b/import/hwpf/fapi2/include/buffer.H @@ -108,11 +108,11 @@ namespace fapi2 inline buffer& setBit(void) { static_assert((B >= 0) && - (B < bufferTraits<T>::bits_per_unit), "failed range check"); + (B < bufferTraits<T>::bits_per_unit()), "failed range check"); // Force iv_data to be dependent on the template type to force // its look up in the second phase - this->iv_data |= (static_cast<T>(1)) << (bufferTraits<T>::bits_per_unit - B - 1); + this->iv_data |= (static_cast<T>(1)) << (bufferTraits<T>::bits_per_unit() - B - 1); return *this; } @@ -128,7 +128,7 @@ namespace fapi2 inline buffer& clearBit(void) { static_assert((B >= 0) && - (B < bufferTraits<T>::bits_per_unit), "failed range check"); + (B < bufferTraits<T>::bits_per_unit()), "failed range check"); this->iv_data &= buffer<T>().setBit<B>().invert(); return *this; @@ -146,7 +146,7 @@ namespace fapi2 inline buffer& flipBit(void) { static_assert((B >= 0) && - (B < bufferTraits<T>::bits_per_unit), "failed range check"); + (B < bufferTraits<T>::bits_per_unit()), "failed range check"); this->iv_data ^= buffer<T>().setBit<B>(); return *this; @@ -160,7 +160,7 @@ namespace fapi2 /// inline fapi2::ReturnCode setBit(const bits_type& i_bit) { - if (i_bit >= bufferTraits<T>::bits_per_unit) + if (i_bit >= bufferTraits<T>::bits_per_unit()) { return FAPI2_RC_INVALID_PARAMETER; } @@ -168,7 +168,7 @@ namespace fapi2 // Force iv_data to be dependent on the template type to force // its look up in the second phase this->iv_data |= - (static_cast<T>(1)) << (bufferTraits<T>::bits_per_unit - i_bit - 1); + (static_cast<T>(1)) << (bufferTraits<T>::bits_per_unit() - i_bit - 1); return FAPI2_RC_SUCCESS; } @@ -280,7 +280,7 @@ namespace fapi2 /// @brief Copy part of a OT into the DataBuffer /// @tparam TS Start bit to insert into (target start) /// @tparam L Length of bits to insert - /// @tparam SS Start bit in source + /// @tparam SS Start bit in source - defaults to bit 0 /// @tparam OT the type of the incoming (origin) data /// @param[in] i_datain OT value to copy into DataBuffer /// - data is taken left aligned @@ -288,11 +288,11 @@ namespace fapi2 /// compile time so this can be templated only. If that is not /// the case we can add a function parameter version. /// - template<bits_type TS, bits_type L, bits_type SS, typename OT> + template<bits_type TS, bits_type L, bits_type SS = 0, typename OT> inline void insert(const OT i_datain) { - const bits_type target_length = parameterTraits<T>::bit_length; - const bits_type source_length = parameterTraits<OT>::bit_length; + const bits_type target_length = parameterTraits<T>::bit_length(); + const bits_type source_length = parameterTraits<OT>::bit_length(); // Error if input data don't make sense static_assert((TS + L) <= target_length, @@ -304,48 +304,30 @@ namespace fapi2 static_assert(SS < source_length, "insert(): Source Start is out of bounds"); - // Get mask value for Target buffer - // Note: Need "& ((T)-1) because bit shift left for Target buffer doesn't roll off - T mask =((T(~0) << (target_length - L)) & T(~0)) >> TS; + // Normalize the input to 2 64 bit integers and adjust the starts accordingly + uint64_t source = static_cast<uint64_t>(i_datain); + const uint64_t target = static_cast<uint64_t>(this->iv_data); - // Calculate the equivalent position of the input Source start for the size of the Target buffer. + const bits_type source_start = parameterTraits<uint64_t>::bit_length() - (source_length - SS); + const bits_type target_start = parameterTraits<uint64_t>::bit_length() - (target_length - TS); - // Assume OT is smaller (sizeof(T) > sizeof(OT)) - uint64_t sourceShift = abs(TS - ((target_length - source_length) + SS)); - uint64_t sourceAlign = T(i_datain) << sourceShift; + // Get mask value for Target buffer + // Note: Need "& 0UL" because bit shift left for Target buffer doesn't roll off + uint64_t mask = ((~0UL << (parameterTraits<uint64_t>::bit_length() - L)) & ~0UL) >> target_start; - if (sizeof(T) == sizeof(OT)) + // Align the source to the target. Make things signed so we know which way to shift. + int32_t shift = source_start - target_start; + if (shift > 0) { - sourceShift = abs(SS - TS); - sourceAlign = (SS > TS) ? ((T)i_datain) << sourceShift : ((T)i_datain) >> sourceShift; + source <<= shift; } - - if (sizeof(T) < sizeof(OT)) + else { - sourceShift = source_length - target_length; - if (SS <= sourceShift) - { - sourceShift = sourceShift + TS - SS; - sourceAlign = ((OT)i_datain) >> sourceShift; - } - - // (SS > sourceShift) - else - { - if (sourceShift > TS) - { - sourceShift = SS - sourceShift - TS; - sourceAlign = OT(i_datain) << sourceShift; - } - else - { - sourceShift = SS - sourceShift; - sourceAlign = (sourceShift < TS) ? OT(i_datain) >> sourceShift : OT(i_datain); - } - } + shift = target_start - source_start; + source >>= shift; } - this->iv_data = (this->iv_data & ~mask) | (sourceAlign & mask); + this->iv_data = ((target & ~mask) | (source & mask)); return; } @@ -365,14 +347,14 @@ namespace fapi2 inline void insertFromRight(const OT i_datain) { // Error if input data don't make sense - static_assert(L < parameterTraits<OT>::bit_length, + static_assert(L < parameterTraits<OT>::bit_length(), "insertFromRight(): Len >= input buffer"); - static_assert(TS < parameterTraits<T>::bit_length, + static_assert(TS < parameterTraits<T>::bit_length(), "insertFromRight(): Target Start is out of bounds"); - static_assert((TS + L) <= parameterTraits<T>::bit_length, + static_assert((TS + L) <= parameterTraits<T>::bit_length(), "InsertFromRight(): (Target Start + Len) is out of bounds"); - this->insert<TS, L, parameterTraits<OT>::bit_length - L>(i_datain); + this->insert<TS, L, parameterTraits<OT>::bit_length() - L>(i_datain); return; } @@ -411,12 +393,12 @@ namespace fapi2 template<bits_type SS, bits_type L, typename OT> inline void extractToRight(OT& o_out) { - extract<parameterTraits<OT>::bit_length - L, L, SS>(o_out); + extract<parameterTraits<OT>::bit_length() - L, L, SS>(o_out); return; } ///@} }; -}; +} #endif diff --git a/import/hwpf/fapi2/include/buffer_parameters.H b/import/hwpf/fapi2/include/buffer_parameters.H index 90b3db45..49d5444d 100644 --- a/import/hwpf/fapi2/include/buffer_parameters.H +++ b/import/hwpf/fapi2/include/buffer_parameters.H @@ -41,12 +41,17 @@ namespace fapi2 class parameterTraits { public: - enum - { - mask = T(~0), - bit_length = sizeof(T) * 8, - byte_length = sizeof(T), - }; + // Why constexpr functions? Enums are hard to do math on, and + // static const doesn't work without -O1 (or greater.) That might + // be a bug in g++ but this works just the same. + constexpr static uint32_t mask(void) + { return T(~0); } + + constexpr static uint32_t byte_length(void) + { return sizeof(T); } + + constexpr static uint32_t bit_length(void) + { return sizeof(T) * 8; } template<typename U> inline static void write_element(void* i_data, T i_value, uint32_t i_offset) @@ -60,6 +65,6 @@ namespace fapi2 } }; /// @endcond -}; +} #endif diff --git a/import/hwpf/fapi2/include/buffer_traits.H b/import/hwpf/fapi2/include/buffer_traits.H index b9362386..632c9d2e 100644 --- a/import/hwpf/fapi2/include/buffer_traits.H +++ b/import/hwpf/fapi2/include/buffer_traits.H @@ -43,7 +43,10 @@ namespace fapi2 { /// @cond /// Types representing a container of bits. Used to create - /// variable_buffer. + /// variable_buffer. container_unit must remain 32-bits + /// for now - there will be a lot of code to change if it + /// changes. There are assertions helping to enforce this + /// in places in the code. typedef uint32_t container_unit; typedef std::vector<container_unit> bits_container; @@ -137,7 +140,8 @@ namespace fapi2 typedef B bits_type; typedef T unit_type; - enum { bits_per_unit = sizeof(unit_type) * 8 }; + constexpr static uint32_t bits_per_unit(void) + { return sizeof(unit_type) * 8; } }; // @@ -222,10 +226,11 @@ namespace fapi2 typedef uint32_t bits_type; typedef container_unit unit_type; - enum { bits_per_unit = sizeof(unit_type) * 8 }; + constexpr static uint32_t bits_per_unit(void) + { return sizeof(unit_type) * 8; } }; /// @endcond -}; +} |

