10#ifndef M5_UTILITY_STL_BYTESWAP_HPP
11#define M5_UTILITY_STL_BYTESWAP_HPP
22 typename std::enable_if<
sizeof(U) == 2 && std::is_unsigned<U>::value, std::nullptr_t>::type =
nullptr>
23inline constexpr U bswap_fixed(U x)
noexcept
25 return static_cast<U
>((
static_cast<uint16_t
>(x >> 8) & 0x00FFu) | (
static_cast<uint16_t
>(x << 8) & 0xFF00u));
29 typename std::enable_if<
sizeof(U) == 4 && std::is_unsigned<U>::value, std::nullptr_t>::type =
nullptr>
30inline constexpr U bswap_fixed(U x)
noexcept
32 return static_cast<U
>(((
static_cast<uint32_t
>(x) >> 24)) | ((
static_cast<uint32_t
>(x) >> 8) & 0x0000FF00u) |
33 ((
static_cast<uint32_t
>(x) << 8) & 0x00FF0000u) | ((
static_cast<uint32_t
>(x) << 24)));
37 typename std::enable_if<
sizeof(U) == 8 && std::is_unsigned<U>::value, std::nullptr_t>::type =
nullptr>
38inline constexpr U bswap_fixed(U x)
noexcept
40 return static_cast<U
>(
41 ((
static_cast<uint64_t
>(x) >> 56)) | ((
static_cast<uint64_t
>(x) >> 40) & 0x000000000000FF00ull) |
42 ((
static_cast<uint64_t
>(x) >> 24) & 0x0000000000FF0000ull) |
43 ((
static_cast<uint64_t
>(x) >> 8) & 0x00000000FF000000ull) |
44 ((
static_cast<uint64_t
>(x) << 8) & 0x000000FF00000000ull) |
45 ((
static_cast<uint64_t
>(x) << 24) & 0x0000FF0000000000ull) |
46 ((
static_cast<uint64_t
>(x) << 40) & 0x00FF000000000000ull) | ((
static_cast<uint64_t
>(x) << 56)));
49#if defined(__SIZEOF_INT128__)
51 typename std::enable_if<
sizeof(U) == 16 && std::is_unsigned<U>::value, std::nullptr_t>::type =
nullptr>
52inline constexpr U bswap_fixed(U x)
noexcept
54 return ((
static_cast<U
>(bswap_fixed<uint64_t>(
static_cast<uint64_t
>(x))) << 64) |
55 static_cast<U
>(bswap_fixed<uint64_t>(
static_cast<uint64_t
>(x >> 64))));
60 typename std::enable_if<
sizeof(U) == 1 && std::is_unsigned<U>::value, std::nullptr_t>::type =
nullptr>
61inline constexpr U bswap_fixed(U x)
noexcept
66template <
typename T,
typename std::enable_if<(std::is_
integral<T>::value || std::is_enum<T>::value),
67 std::
nullptr_t>::type =
nullptr>
68inline constexpr T byteswap_constexpr(T v)
noexcept
70 using U =
typename std::make_unsigned<T>::type;
71 return static_cast<T
>(bswap_fixed<U>(
static_cast<U
>(v)));
76template <
typename T,
typename std::enable_if<(std::is_
integral<T>::value || std::is_enum<T>::value),
77 std::
nullptr_t>::type =
nullptr>
80 return byteswap_constexpr(v);
84template <
typename T,
typename std::enable_if<!(std::is_
integral<T>::value || std::is_enum<T>::value),
85 std::
nullptr_t>::type =
nullptr>
86T byteswap(T) =
delete;
constexpr T byteswap(T v) noexcept
byteswap for integral type
Definition byteswap.hpp:78
Top level namespace of M5.
Definition bit_segment.hpp:17
STL compatibility functions and classes.