summaryrefslogtreecommitdiffstats
path: root/sys/sun4v
diff options
context:
space:
mode:
authormarius <marius@FreeBSD.org>2006-10-30 21:50:11 +0000
committermarius <marius@FreeBSD.org>2006-10-30 21:50:11 +0000
commit02d450964f3b7fa286520f9baca6c25197cff69d (patch)
treebc210aea425a71a9b35c600bde2c9f97d74e8577 /sys/sun4v
parentcc337af506b649c9163515bf759e46664b8811c8 (diff)
downloadFreeBSD-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
Diffstat (limited to 'sys/sun4v')
-rw-r--r--sys/sun4v/include/endian.h20
1 files changed, 12 insertions, 8 deletions
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)
OpenPOWER on IntegriCloud