diff options
author | Stephen Glancy <sglancy@us.ibm.com> | 2018-08-30 15:54:28 -0500 |
---|---|---|
committer | Sachin Gupta <sgupta2m@in.ibm.com> | 2018-09-16 22:28:00 -0500 |
commit | d103f7adad9db03b0a13878ad9f80bd02b54b4c1 (patch) | |
tree | 9a6dbe6254896a9bd4fdfb010efa9e25e9746118 /src/import/hwpf/fapi2/include/utils.H | |
parent | 3399fd3edb8100271aaa8ce1a51236f6f38a6d0d (diff) | |
download | talos-sbe-d103f7adad9db03b0a13878ad9f80bd02b54b4c1.tar.gz talos-sbe-d103f7adad9db03b0a13878ad9f80bd02b54b4c1.zip |
Adds endian_swap to fapi2
Change-Id: Ie076098cd05ea0ae768d8da142df1b933ab7eb07
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/65525
Dev-Ready: STEPHEN GLANCY <sglancy@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: HWSV CI <hwsv-ci+hostboot@us.ibm.com>
Tested-by: PPE CI <ppe-ci+hostboot@us.ibm.com>
Tested-by: Hostboot CI <hostboot-ci+hostboot@us.ibm.com>
Reviewed-by: Louis Stermole <stermole@us.ibm.com>
Reviewed-by: ANDRE A. MARIN <aamarin@us.ibm.com>
Reviewed-by: Matt K. Light <mklight@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com>
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/65527
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Sachin Gupta <sgupta2m@in.ibm.com>
Diffstat (limited to 'src/import/hwpf/fapi2/include/utils.H')
-rw-r--r-- | src/import/hwpf/fapi2/include/utils.H | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/import/hwpf/fapi2/include/utils.H b/src/import/hwpf/fapi2/include/utils.H index fcbde482..c45e410c 100644 --- a/src/import/hwpf/fapi2/include/utils.H +++ b/src/import/hwpf/fapi2/include/utils.H @@ -38,6 +38,33 @@ namespace fapi2 { + +/// +/// @brief Endian swapping +/// @tparam T input type +/// @param[in,out] io_input integral input +/// @note https://stackoverflow.com/questions/105252/how-do-i-convert-between-big-endian-and-little-endian-values-in-c +/// This function does not take into account the system's endianness, but just does the endian swap +/// +template < typename T > +void endian_swap(T& io_input) +{ + constexpr size_t MIN_BYTES = 2; + static_assert(sizeof(T) >= MIN_BYTES, "Byte swapping requires at least 2 bytes of data"); + + uint8_t* l_varArray = reinterpret_cast<uint8_t*>(&io_input); + + for(size_t i = 0; i < sizeof(io_input) / 2; i++) + { + const size_t BYTE_SWAP_INDEX = sizeof(io_input) - 1 - i; + + // Rolling our own swap as certain downstream libraries do not have std::swap enabled + const auto l_temp = l_varArray[BYTE_SWAP_INDEX]; + l_varArray[BYTE_SWAP_INDEX] = l_varArray[i]; + l_varArray[i] = l_temp; + } +} + #ifndef __PPE__ /// /// @brief Enable/Disable special wakeup on processor chip core(s) |