From 2d274dba8b83a009a92f9564056812831a54f273 Mon Sep 17 00:00:00 2001 From: Kp Date: Wed, 25 Dec 2013 23:36:50 +0000 Subject: [PATCH] Tighten SWAPINT --- common/include/byteswap.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/include/byteswap.h b/common/include/byteswap.h index 6236ae51c..5b06cfa10 100644 --- a/common/include/byteswap.h +++ b/common/include/byteswap.h @@ -40,7 +40,16 @@ static inline int16_t SWAPSHORT(const int16_t &i) { return SWAPSHORT(static_cast(i)); } -#define SWAPINT(x) (((x)<<24) | (((uint)(x)) >> 24) | (((x) &0x0000ff00) << 8) | (((x) & 0x00ff0000) >> 8)) + +static inline uint32_t SWAPINT(const uint32_t &x) +{ + return (x << 24) | (x >> 24) | ((x & 0xff00) << 8) | ((x >> 8) & 0xff00); +} + +static inline int32_t SWAPINT(const int32_t &i) +{ + return SWAPINT(static_cast(i)); +} #ifndef macintosh #define SWAPINT64(x) ((((x) & 0xff00000000000000LL) >> 56) | (((x) & 0x00ff000000000000LL) >> 40) | (((x) & 0x0000ff0000000000LL) >> 24) | (((x) & 0x000000ff00000000LL) >> 8) | (((x) & 0x00000000ff000000LL) << 8) | (((x) & 0x0000000000ff0000LL) << 24) | (((x) & 0x000000000000ff00LL) << 40) | (((x) & 0x00000000000000ffLL) << 56)) #else