1 #ifndef PROTOZERO_BYTESWAP_HPP 2 #define PROTOZERO_BYTESWAP_HPP 26 inline uint32_t byteswap_impl(uint32_t value) noexcept {
27 #ifdef PROTOZERO_USE_BUILTIN_BSWAP 28 return __builtin_bswap32(value);
30 return ((value & 0xff000000) >> 24) |
31 ((value & 0x00ff0000) >> 8) |
32 ((value & 0x0000ff00) << 8) |
33 ((value & 0x000000ff) << 24);
37 inline uint64_t byteswap_impl(uint64_t value) noexcept {
38 #ifdef PROTOZERO_USE_BUILTIN_BSWAP 39 return __builtin_bswap64(value);
41 return ((value & 0xff00000000000000ULL) >> 56) |
42 ((value & 0x00ff000000000000ULL) >> 40) |
43 ((value & 0x0000ff0000000000ULL) >> 24) |
44 ((value & 0x000000ff00000000ULL) >> 8) |
45 ((value & 0x00000000ff000000ULL) << 8) |
46 ((value & 0x0000000000ff0000ULL) << 24) |
47 ((value & 0x000000000000ff00ULL) << 40) |
48 ((value & 0x00000000000000ffULL) << 56);
56 *ptr = detail::byteswap_impl(*ptr);
61 *ptr = detail::byteswap_impl(*ptr);
66 auto bptr =
reinterpret_cast<uint32_t*
>(ptr);
67 *bptr = detail::byteswap_impl(*bptr);
72 auto bptr =
reinterpret_cast<uint64_t*
>(ptr);
73 *bptr = detail::byteswap_impl(*bptr);
78 auto bptr =
reinterpret_cast<uint32_t*
>(ptr);
79 *bptr = detail::byteswap_impl(*bptr);
84 auto bptr =
reinterpret_cast<uint64_t*
>(ptr);
85 *bptr = detail::byteswap_impl(*bptr);
99 #endif // PROTOZERO_BYTESWAP_HPP Contains macro checks for different configurations.
void byteswap_inplace(double *ptr) noexcept
byteswap the data pointed to by ptr in-place.
Definition: byteswap.hpp:83
void byteswap_inplace(uint32_t *ptr) noexcept
byteswap the data pointed to by ptr in-place.
Definition: byteswap.hpp:55
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:23