6 #define ENABLE_SSE_BSWAP
13 #pragma warning(disable : 4365 4987)
27template<std::
size_t size>
29 using type =
typename std::conditional<(size == 1ul), std::uint8_t,
30 typename std::conditional<(size == 2ul), std::uint16_t,
31 typename std::conditional<(size <= 4ul), std::uint32_t,
42 #if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64)
43 return std::alignment_of<std::max_align_t>::value;
59template<Endianness EByteOrder>
66 static void swap(T& value) {
67 #ifdef TARGET_LITTLE_ENDIAN
68 static_cast<void>(value);
71 static_assert(
sizeof(T) ==
sizeof(UIntType),
"No matching unsigned integral type found for the given type.");
76 std::memcpy(&swapped, &value,
sizeof(T));
77 swapped =
bswap(swapped);
78 std::memcpy(&value, &swapped,
sizeof(T));
83 static void swap(T* values) {
84 #ifdef TARGET_LITTLE_ENDIAN
85 static_cast<void>(values);
88 static_assert(
sizeof(T) ==
sizeof(UIntType),
"No matching unsigned integral type found for the given type.");
93 std::memcpy(
static_cast<UIntType*
>(swapped), values, 16ul);
94 bswap(
static_cast<UIntType*
>(swapped));
95 std::memcpy(values,
static_cast<UIntType*
>(swapped), 16ul);
106 #ifdef TARGET_LITTLE_ENDIAN
108 static_assert(
sizeof(T) ==
sizeof(UIntType),
"No matching unsigned integral type found for the given type.");
113 std::memcpy(&swapped, &value,
sizeof(T));
114 swapped =
bswap(swapped);
115 std::memcpy(&value, &swapped,
sizeof(T));
117 static_cast<void>(value);
123 #ifdef TARGET_LITTLE_ENDIAN
125 static_assert(
sizeof(T) ==
sizeof(UIntType),
"No matching unsigned integral type found for the given type.");
130 std::memcpy(
static_cast<UIntType*
>(swapped), values, 16ul);
131 bswap(
static_cast<UIntType*
>(swapped));
132 std::memcpy(values,
static_cast<UIntType*
>(swapped), 16ul);
134 static_cast<void>(values);
140template<Endianness EByteOrder>
143template<Endianness EByteOrder>
std::uint8_t bswap(std::uint8_t x)
Definition: Endianness.h:310
void networkToHost(T &value)
Definition: ByteSwap.h:147
void networkToHost128(T *values)
Definition: ByteSwap.h:152
void hostToNetwork128(T *values)
Definition: ByteSwap.h:162
Endianness
Definition: ByteSwap.h:53
void hostToNetwork(T &value)
Definition: ByteSwap.h:157
static void swap(T &value)
Definition: ByteSwap.h:105
static void swap(T *values)
Definition: ByteSwap.h:122
static void swap(T &value)
Definition: ByteSwap.h:66
static void swap(T *values)
Definition: ByteSwap.h:83
Definition: ByteSwap.h:60
Definition: ByteSwap.h:39
static constexpr std::size_t alignment()
Definition: ByteSwap.h:41
Definition: ByteSwap.h:28
typename std::conditional<(size==1ul), std::uint8_t, typename std::conditional<(size==2ul), std::uint16_t, typename std::conditional<(size<=4ul), std::uint32_t, std::uint64_t >::type >::type >::type type
Definition: ByteSwap.h:32