diff options
author | Richard Knight <rjknight@us.ibm.com> | 2015-09-29 13:21:41 -0500 |
---|---|---|
committer | Patrick Williams <iawillia@us.ibm.com> | 2015-12-11 13:40:20 -0600 |
commit | d99346a49f0d9aaa47368aec541185f615a1a13d (patch) | |
tree | 42d25cdf2e3344c957fb86570da6c1b4d77fef97 /src | |
parent | 90d11342ac451cf0e199b557edb88e1986ce56e9 (diff) | |
download | talos-hostboot-d99346a49f0d9aaa47368aec541185f615a1a13d.tar.gz talos-hostboot-d99346a49f0d9aaa47368aec541185f615a1a13d.zip |
buffer reverse not working correctly
-Incomplete function to reverse buffer, modified
code to loop though bits and reverse them for all
cases.
Change-Id: I1bca6a6f67a5aec7681d5b581b07e35c7e103dc0
RTC:137890
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/20862
Tested-by: Jenkins Server
Reviewed-by: Brian Silver <bsilver@us.ibm.com>
Reviewed-by: Matt K. Light <mklight@us.ibm.com>
Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/import/hwpf/fapi2/include/buffer_traits.H | 181 |
1 files changed, 105 insertions, 76 deletions
diff --git a/src/import/hwpf/fapi2/include/buffer_traits.H b/src/import/hwpf/fapi2/include/buffer_traits.H index c1f5df541..3fd78d681 100644 --- a/src/import/hwpf/fapi2/include/buffer_traits.H +++ b/src/import/hwpf/fapi2/include/buffer_traits.H @@ -1,25 +1,19 @@ /* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ -/* $Source: $ */ +/* $Source: hwpf/fapi2/include/buffer_traits.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 */ /** @@ -36,31 +30,31 @@ #include <buffer_parameters.H> #ifdef FAPI2_DEBUG -#include <iostream> + #include <iostream> #endif #include <iterator> namespace fapi2 { - /// @cond - /// Types representing a container of bits. Used to create - /// 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; - - /// @brief Traits of buffers - // In general, we try to give buffers traits reflecting integral types. If - // this fails, the compiler will let someone know. - /// - /// @tparam T is the type of iv_data (std::vector, etc) - /// @tparam B is the type of the bit-specifier, typically uint32_t - template<typename T, typename B = uint32_t> - class bufferTraits - { +/// @cond +/// Types representing a container of bits. Used to create +/// 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; + +/// @brief Traits of buffers +// In general, we try to give buffers traits reflecting integral types. If +// this fails, the compiler will let someone know. +/// +/// @tparam T is the type of iv_data (std::vector, etc) +/// @tparam B is the type of the bit-specifier, typically uint32_t +template<typename T, typename B = uint32_t> +class bufferTraits +{ public: #if !defined(DOXYGEN) && defined(FAPI2_DEBUG) @@ -87,11 +81,11 @@ namespace fapi2 /// template<typename E> constexpr static B size(const T& i_buffer) - { - return (bit_length(i_buffer) + - (parameterTraits<E>::bit_length() - 1)) / - parameterTraits<E>::bit_length(); - } + { + return (bit_length(i_buffer) + + (parameterTraits<E>::bit_length() - 1)) / + parameterTraits<E>::bit_length(); + } /// /// @brief Return the size of the buffer itself @@ -99,62 +93,86 @@ namespace fapi2 /// @return The size of the buffer in bits (not units) /// constexpr static B bit_length(const T&) - { return sizeof(T) * 8; } + { + return sizeof(T) * 8; + } /// /// @brief Clear the buffer /// @param[in,out] io_buffer the buffer which to clear /// static inline void clear(T& io_buffer) - { io_buffer = static_cast<T>(0); } + { + io_buffer = static_cast<T>(0); + } /// /// @brief Set the buffer /// @param[in,out] io_buffer the buffer which to set /// static inline void set(T& io_buffer) - { io_buffer = static_cast<T>(~0); } + { + io_buffer = static_cast<T>(~0); + } /// /// @brief Invert the buffer /// @param[in,out] io_buffer the buffer which to invert /// static inline void invert(T& io_buffer) - { io_buffer = ~io_buffer; } + { + io_buffer = ~io_buffer; + } /// /// @brief Reverse the buffer /// @param[in,out] io_buffer the buffer which to reverse + // + // @note from + // http://stackoverflow.com/questions/746171/best-algorithm-for-bit-reversal-from-msb-lsb-to-lsb-msb-in-c /// - static inline void reverse(T& io_buffer) + static inline void reverse( T& io_buffer) + { + T l_result = io_buffer; + size_t l_s = sizeof(T) * 8 - 1; + + for( io_buffer >>= 1; io_buffer; io_buffer >>= 1) { - io_buffer = - ((io_buffer & 0xAAAAAAAAAAAAAAAA) >> 1) | - ((io_buffer & 0x5555555555555555) << 1); + l_result <<= 1; + l_result |= io_buffer & 1; + l_s--; } + l_result <<= l_s; + + io_buffer = l_result; + } /// /// @brief Get the address of the buffer as an array /// @param[in] i_buffer the buffer which to invert /// @return The address of the first element of the buffer /// static inline void* get_address(T& i_buffer) - { return (void*)&i_buffer; } + { + return (void*)&i_buffer; + } typedef B bits_type; typedef T unit_type; constexpr static uint32_t bits_per_unit(void) - { return sizeof(unit_type) * 8; } - }; - - // - // - /// @brief Traits for buffers which are a container of bits - // - // - template<> - class bufferTraits<bits_container, uint32_t> - { + { + return sizeof(unit_type) * 8; + } +}; + +// +// +/// @brief Traits for buffers which are a container of bits +// +// +template<> +class bufferTraits<bits_container, uint32_t> +{ public: #if !defined(DOXYGEN) && defined(FAPI2_DEBUG) /// @@ -178,11 +196,11 @@ namespace fapi2 /// template<typename E> constexpr static uint32_t size(const bits_container& i_buffer) - { - return (bit_length(i_buffer) + - (parameterTraits<E>::bit_length() - 1)) / - parameterTraits<E>::bit_length(); - } + { + return (bit_length(i_buffer) + + (parameterTraits<E>::bit_length() - 1)) / + parameterTraits<E>::bit_length(); + } /// /// @brief Return the size of the buffer itself @@ -190,32 +208,41 @@ namespace fapi2 /// @return The size of the buffer in bits (not units) /// static inline uint32_t bit_length(const bits_container& i_buffer) - { return i_buffer.size() * sizeof(container_unit) * 8; } + { + return i_buffer.size() * sizeof(container_unit) * 8; + } /// /// @brief Clear the buffer /// @param[in,out] io_buffer the buffer which to clear /// static inline void clear(bits_container& io_buffer) - { io_buffer.assign(io_buffer.size(), 0); } + { + io_buffer.assign(io_buffer.size(), 0); + } /// /// @brief Set the buffer /// @param[in,out] io_buffer the buffer which to set /// static inline void set(bits_container& io_buffer) - { io_buffer.assign(io_buffer.size(), ~0); } + { + io_buffer.assign(io_buffer.size(), ~0); + } /// /// @brief Invert the buffer /// @param[in,out] io_buffer the buffer which to invert /// static inline void invert(bits_container& io_buffer) + { + std::transform(io_buffer.begin(), io_buffer.end(), + io_buffer.begin(), + [](container_unit u) { - std::transform(io_buffer.begin(), io_buffer.end(), - io_buffer.begin(), - [](container_unit u) { return ~u; }); - } + return ~u; + }); + } /// /// @brief Get the address of the buffer as an array @@ -223,16 +250,18 @@ namespace fapi2 /// @return The address of the first element of the buffer /// static inline void* get_address(bits_container& i_buffer) - { - return (void*)&(i_buffer[0]); - } + { + return (void*) & (i_buffer[0]); + } typedef uint32_t bits_type; typedef container_unit unit_type; constexpr static uint32_t bits_per_unit(void) - { return sizeof(unit_type) * 8; } - }; - /// @endcond + { + return sizeof(unit_type) * 8; + } +}; +/// @endcond } |