mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 17:35:45 +01:00
we are using GNU extensions, using __builtin_bswap* is fine.
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../types.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 u16 bswap16_impl(u16 x) {
|
||||
return (x << 8) | (x >> 8);
|
||||
}
|
||||
|
||||
static inline u32 bswap32_impl(u32 x) {
|
||||
return (x << 24) |
|
||||
((0x0000FF00U & x) << 8) |
|
||||
((0x00FF0000U & x) >> 8) |
|
||||
(x >> 24);
|
||||
}
|
||||
|
||||
static inline u64 bswap64_impl(u64 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
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
#include "../atrb.h"
|
||||
#include "../types.h"
|
||||
#include "bswap.h"
|
||||
|
||||
/* little endian */
|
||||
atrb_const static inline u16 le16ton(u16); // converts little-endian (LE) encoding to native for a 16 bit integer. (NOOP if native is LE)
|
||||
@@ -31,19 +30,19 @@ u64 le64ton(u64 x) { return x; }
|
||||
u16 ntole16(u16 x) { return x; }
|
||||
u32 ntole32(u32 x) { return x; }
|
||||
u64 ntole64(u64 x) { return x; }
|
||||
u16 be16ton(u16 x) { return bswap16(x); }
|
||||
u32 be32ton(u32 x) { return bswap32(x); }
|
||||
u64 be64ton(u64 x) { return bswap64(x); }
|
||||
u16 ntobe16(u16 x) { return bswap16(x); }
|
||||
u32 ntobe32(u32 x) { return bswap32(x); }
|
||||
u64 ntobe64(u64 x) { return bswap64(x); }
|
||||
u16 be16ton(u16 x) { return __builtin_bswap16(x); }
|
||||
u32 be32ton(u32 x) { return __builtin_bswap32(x); }
|
||||
u64 be64ton(u64 x) { return __builtin_bswap64(x); }
|
||||
u16 ntobe16(u16 x) { return __builtin_bswap16(x); }
|
||||
u32 ntobe32(u32 x) { return __builtin_bswap32(x); }
|
||||
u64 ntobe64(u64 x) { return __builtin_bswap64(x); }
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
u16 le16ton(u16 x) { bswap_16(x); }
|
||||
u32 le32ton(u32 x) { bswap_32(x); }
|
||||
u64 le64ton(u64 x) { bswap_64(x); }
|
||||
u16 ntole16(u16 x) { bswap_16(x); }
|
||||
u32 ntole32(u32 x) { bswap_32(x); }
|
||||
u64 ntole64(u64 x) { bswap_64(x); }
|
||||
u16 le16ton(u16 x) { __builtin_bswap16(x); }
|
||||
u32 le32ton(u32 x) { __builtin_bswap32(x); }
|
||||
u64 le64ton(u64 x) { __builtin_bswap64(x); }
|
||||
u16 ntole16(u16 x) { __builtin_bswap16(x); }
|
||||
u32 ntole32(u32 x) { __builtin_bswap32(x); }
|
||||
u64 ntole64(u64 x) { __builtin_bswap64(x); }
|
||||
u16 be16ton(u16 x) { return x; }
|
||||
u32 be32ton(u32 x) { return x; }
|
||||
u64 be64ton(u64 x) { return x; }
|
||||
|
||||
Reference in New Issue
Block a user