1 #ifndef PROTOZERO_BYTESWAP_HPP 2 #define PROTOZERO_BYTESWAP_HPP 27 inline uint32_t byteswap_impl(uint32_t value) noexcept {
28 #ifdef PROTOZERO_USE_BUILTIN_BSWAP 29 return __builtin_bswap32(value);
31 return ((value & 0xff000000) >> 24) |
32 ((value & 0x00ff0000) >> 8) |
33 ((value & 0x0000ff00) << 8) |
34 ((value & 0x000000ff) << 24);
38 inline uint64_t byteswap_impl(uint64_t value) noexcept {
39 #ifdef PROTOZERO_USE_BUILTIN_BSWAP 40 return __builtin_bswap64(value);
42 return ((value & 0xff00000000000000ULL) >> 56) |
43 ((value & 0x00ff000000000000ULL) >> 40) |
44 ((value & 0x0000ff0000000000ULL) >> 24) |
45 ((value & 0x000000ff00000000ULL) >> 8) |
46 ((value & 0x00000000ff000000ULL) << 8) |
47 ((value & 0x0000000000ff0000ULL) << 24) |
48 ((value & 0x000000000000ff00ULL) << 40) |
49 ((value & 0x00000000000000ffULL) << 56);
53 inline void byteswap_inplace(uint32_t* ptr) noexcept {
54 *ptr = byteswap_impl(*ptr);
57 inline void byteswap_inplace(uint64_t* ptr) noexcept {
58 *ptr = byteswap_impl(*ptr);
61 inline void byteswap_inplace(int32_t* ptr) noexcept {
62 auto bptr =
reinterpret_cast<uint32_t*
>(ptr);
63 *bptr = byteswap_impl(*bptr);
66 inline void byteswap_inplace(int64_t* ptr) noexcept {
67 auto bptr =
reinterpret_cast<uint64_t*
>(ptr);
68 *bptr = byteswap_impl(*bptr);
71 inline void byteswap_inplace(
float* ptr) noexcept {
72 auto bptr =
reinterpret_cast<uint32_t*
>(ptr);
73 *bptr = byteswap_impl(*bptr);
76 inline void byteswap_inplace(
double* ptr) noexcept {
77 auto bptr =
reinterpret_cast<uint64_t*
>(ptr);
78 *bptr = byteswap_impl(*bptr);
84 #endif // PROTOZERO_BYTESWAP_HPP Contains macro checks for different configurations.
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:24