diff options
author | marius <marius@FreeBSD.org> | 2006-10-30 21:50:11 +0000 |
---|---|---|
committer | marius <marius@FreeBSD.org> | 2006-10-30 21:50:11 +0000 |
commit | 02d450964f3b7fa286520f9baca6c25197cff69d (patch) | |
tree | bc210aea425a71a9b35c600bde2c9f97d74e8577 | |
parent | cc337af506b649c9163515bf759e46664b8811c8 (diff) | |
download | FreeBSD-src-02d450964f3b7fa286520f9baca6c25197cff69d.zip FreeBSD-src-02d450964f3b7fa286520f9baca6c25197cff69d.tar.gz |
In the replacement text of the __bswapN_const() macros encapsulate the
argument in parentheses so these macros are safe to use and invocations
with an expression as the argument like __bswap32_const(42 << 23 | 13)
work as expected. Additionally, mask all the individually shifted bytes
as appropriate so the bytes which exceed the width of the respective
__bswapN_const() macro in invocations like __bswap16_const(0xdead600d)
are ignored like it's the case with the corresponding __bswapN_var()
function.
MFC after: 3 days
-rw-r--r-- | sys/sparc64/include/endian.h | 20 | ||||
-rw-r--r-- | sys/sun4v/include/endian.h | 20 |
2 files changed, 24 insertions, 16 deletions
diff --git a/sys/sparc64/include/endian.h b/sys/sparc64/include/endian.h index a643dd3..1744784 100644 --- a/sys/sparc64/include/endian.h +++ b/sys/sparc64/include/endian.h @@ -69,14 +69,18 @@ #define __is_constant(x) 0 #endif -#define __bswap16_const(x) ((x >> 8) | ((x << 8) & 0xff00)) -#define __bswap32_const(x) ((x >> 24) | ((x >> 8) & 0xff00) | \ - ((x << 8) & 0xff0000) | ((x << 24) & 0xff000000)) -#define __bswap64_const(x) ((x >> 56) | ((x >> 40) & 0xff00) | \ - ((x >> 24) & 0xff0000) | ((x >> 8) & 0xff000000) | \ - ((x << 8) & ((__uint64_t)0xff << 32)) | \ - ((x << 24) & ((__uint64_t)0xff << 40)) | \ - ((x << 40) & ((__uint64_t)0xff << 48)) | ((x << 56))) +#define __bswap16_const(x) ((((x) >> 8) & 0xff) | \ + (((x) << 8) & 0xff00)) +#define __bswap32_const(x) ((((x) >> 24) & 0xff) | \ + (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | \ + (((x) << 24) & 0xff000000)) +#define __bswap64_const(x) ((((x) >> 56) & 0xff) | \ + (((x) >> 40) & 0xff00) | (((x) >> 24) & 0xff0000) | \ + (((x) >> 8) & 0xff000000) | \ + (((x) << 8) & ((__uint64_t)0xff << 32)) | \ + (((x) << 24) & ((__uint64_t)0xff << 40)) | \ + (((x) << 40) & ((__uint64_t)0xff << 48)) | \ + (((x) << 56) & ((__uint64_t)0xff << 56))) static __inline __uint16_t __bswap16_var(__uint16_t _x) diff --git a/sys/sun4v/include/endian.h b/sys/sun4v/include/endian.h index a643dd3..1744784 100644 --- a/sys/sun4v/include/endian.h +++ b/sys/sun4v/include/endian.h @@ -69,14 +69,18 @@ #define __is_constant(x) 0 #endif -#define __bswap16_const(x) ((x >> 8) | ((x << 8) & 0xff00)) -#define __bswap32_const(x) ((x >> 24) | ((x >> 8) & 0xff00) | \ - ((x << 8) & 0xff0000) | ((x << 24) & 0xff000000)) -#define __bswap64_const(x) ((x >> 56) | ((x >> 40) & 0xff00) | \ - ((x >> 24) & 0xff0000) | ((x >> 8) & 0xff000000) | \ - ((x << 8) & ((__uint64_t)0xff << 32)) | \ - ((x << 24) & ((__uint64_t)0xff << 40)) | \ - ((x << 40) & ((__uint64_t)0xff << 48)) | ((x << 56))) +#define __bswap16_const(x) ((((x) >> 8) & 0xff) | \ + (((x) << 8) & 0xff00)) +#define __bswap32_const(x) ((((x) >> 24) & 0xff) | \ + (((x) >> 8) & 0xff00) | (((x) << 8) & 0xff0000) | \ + (((x) << 24) & 0xff000000)) +#define __bswap64_const(x) ((((x) >> 56) & 0xff) | \ + (((x) >> 40) & 0xff00) | (((x) >> 24) & 0xff0000) | \ + (((x) >> 8) & 0xff000000) | \ + (((x) << 8) & ((__uint64_t)0xff << 32)) | \ + (((x) << 24) & ((__uint64_t)0xff << 40)) | \ + (((x) << 40) & ((__uint64_t)0xff << 48)) | \ + (((x) << 56) & ((__uint64_t)0xff << 56))) static __inline __uint16_t __bswap16_var(__uint16_t _x) |