27#include "iceberg/compat/compiler.h"
29namespace iceberg::internal {
31template <std::
unsigned_
integral T>
32constexpr T ByteSwapUnsigned(T value) {
33#if !ICEBERG_CXX20_COMPAT
34 return std::byteswap(value);
36# if defined(__GNUC__) || defined(__clang__)
37 if constexpr (
sizeof(T) ==
sizeof(uint16_t)) {
38 return static_cast<T
>(__builtin_bswap16(value));
39 }
else if constexpr (
sizeof(T) ==
sizeof(uint32_t)) {
40 return static_cast<T
>(__builtin_bswap32(value));
41 }
else if constexpr (
sizeof(T) ==
sizeof(uint64_t)) {
42 return static_cast<T
>(__builtin_bswap64(value));
46 for (
size_t byte = 0;
byte <
sizeof(T); ++byte) {
47 swapped =
static_cast<T
>(swapped << 8) | static_cast<T>(value & 0xFF);
48 value =
static_cast<T
>(value >> 8);