diff options
Diffstat (limited to 'src/import/generic/memory/lib/utils/buffer_ops.H')
-rw-r--r-- | src/import/generic/memory/lib/utils/buffer_ops.H | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/src/import/generic/memory/lib/utils/buffer_ops.H b/src/import/generic/memory/lib/utils/buffer_ops.H index 31e7f11a2..42b02b5d1 100644 --- a/src/import/generic/memory/lib/utils/buffer_ops.H +++ b/src/import/generic/memory/lib/utils/buffer_ops.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2018 */ +/* Contributors Listed Below - COPYRIGHT 2015,2019 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -103,6 +103,32 @@ static inline void reverse( T& io_buffer ) } /// +/// @brief Reverse a given bit range of a buffer +/// @tparam S start bit +/// @tparam L length of bits to reverse +/// @tparam T buffer type +/// @param[in] io_buffer +/// +template<uint64_t S, uint64_t L, typename T> +static inline void reverse_range(fapi2::buffer<T>& io_buffer) +{ + const auto target_length = fapi2::parameterTraits<T>::bit_length(); + + static_assert(S < target_length, + "reverse_range(): Start is out of bounds"); + + static_assert((S + L) <= target_length, + "reverse_range(): (Start + Len) is out of bounds"); + + fapi2::buffer<T> l_tmp; + + io_buffer.template extractToRight<S, L>(l_tmp); + + l_tmp.reverse(); + io_buffer.template insert<S, L>(l_tmp); +} + +/// /// @brief Swizzle bits between two fapi2 buffers, and insert from source to destination /// @tparam DS the start bit in the destination buffer - swizzle will count up from here /// @tparam L how many bits to swizzle |