mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-19 05:05:45 +01:00
for byte swapping, now use a seperate header in which the compatibility code lives
This commit is contained in:
44
src/util/compat/bswap.h
Normal file
44
src/util/compat/bswap.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define bswap16 __builtin_bswap16
|
||||
#define bswap32 __builtin_bswap32
|
||||
#define bswap64 __builtin_bswap64
|
||||
#elif __has_include(<byteswap.h>)
|
||||
#include <byteswap.h>
|
||||
#define bswap16 bswap_16
|
||||
#define bswap32 bswap_32
|
||||
#define bswap64 bswap_64
|
||||
#else
|
||||
#define bswap16 bswap16_impl
|
||||
#define bswap32 bswap32_impl
|
||||
#define bswap64 bswap64_impl
|
||||
#define IMPL_BSWAP
|
||||
#endif
|
||||
|
||||
#if defined(IMPL_BSWAP) || !defined(NDEBUG)
|
||||
static inline uint16_t bswap16_impl(uint16_t x) {
|
||||
return (x << 8) | (x >> 8);
|
||||
}
|
||||
|
||||
static inline uint32_t bswap32_impl(uint32_t x) {
|
||||
return (x << 24) |
|
||||
((0x0000FF00U & x) << 8) |
|
||||
((0x00FF0000U & x) >> 8) |
|
||||
(x >> 24);
|
||||
}
|
||||
|
||||
static inline uint64_t bswap64_impl(uint64_t x) {
|
||||
return (x << 56) |
|
||||
((0x000000000000FF00ULL & x) << 40) |
|
||||
((0x0000000000FF0000ULL & x) << 24) |
|
||||
((0x00000000FF000000ULL & x) << 8) |
|
||||
((0x000000FF00000000ULL & x) >> 8) |
|
||||
((0x0000FF0000000000ULL & x) >> 24) |
|
||||
((0x00FF000000000000ULL & x) >> 40) |
|
||||
(x >> 56);
|
||||
}
|
||||
#endif
|
||||
#undef IMPL_BSWAP
|
||||
Reference in New Issue
Block a user