mirror of
https://github.com/hedge-dev/XenonRecomp.git
synced 2025-06-06 18:31:03 +00:00
Address #17 (only)
This commit is contained in:
parent
2991a3b698
commit
68543c53c0
@ -2,24 +2,31 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
template<typename T>
|
||||
inline T ByteSwap(T value)
|
||||
#ifdef __clang__
|
||||
#define _byte_swap16(value) __builtin_bswap16(static_cast<uint16_t>(value))
|
||||
#define _byte_swap32(value) __builtin_bswap32(static_cast<uint32_t>(value))
|
||||
#define _byte_swap64(value) __builtin_bswap64(static_cast<uint64_t>(value))
|
||||
#elif defined(_MSC_VER)
|
||||
#define _byte_swap16(value) _byteswap_ushort(static_cast<uint16_t>(value))
|
||||
#define _byte_swap32(value) _byteswap_ulong(static_cast<uint32_t>(value))
|
||||
#define _byte_swap64(value) _byteswap_uint64(static_cast<uint64_t>(value))
|
||||
#endif
|
||||
|
||||
template<typename T> T ByteSwap(T value)
|
||||
{
|
||||
if constexpr (sizeof(T) == 1)
|
||||
return value;
|
||||
else if constexpr (sizeof(T) == 2)
|
||||
return static_cast<T>(__builtin_bswap16(static_cast<uint16_t>(value)));
|
||||
else if constexpr (sizeof(T) == 4)
|
||||
return static_cast<T>(__builtin_bswap32(static_cast<uint32_t>(value)));
|
||||
else if constexpr (sizeof(T) == 8)
|
||||
return static_cast<T>(__builtin_bswap64(static_cast<uint64_t>(value)));
|
||||
if constexpr (sizeof(T) == 2)
|
||||
return static_cast<T>(_byte_swap16(value));
|
||||
if constexpr (sizeof(T) == 4)
|
||||
return static_cast<T>(_byte_swap32(value));
|
||||
if constexpr (sizeof(T) == 8)
|
||||
return static_cast<T>(_byte_swap64(value));
|
||||
|
||||
assert(false && "Unexpected byte size.");
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void ByteSwapInplace(T& value)
|
||||
template<typename T> void ByteSwapInplace(T& value)
|
||||
{
|
||||
value = ByteSwap(value);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user