aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Strobl <marius@FreeBSD.org>2006-10-30 21:50:11 +0000
committerMarius Strobl <marius@FreeBSD.org>2006-10-30 21:50:11 +0000
commita1610d83b898cbd85caa57976bf6c972526c9d23 (patch)
treebc210aea425a71a9b35c600bde2c9f97d74e8577
parentd49da17b5ef030492f9807cc441093383d3223d0 (diff)
downloadsrc-a1610d83b898cbd85caa57976bf6c972526c9d23.tar.gz
src-a1610d83b898cbd85caa57976bf6c972526c9d23.zip
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
Notes
Notes: svn path=/head/; revision=163808
-rw-r--r--sys/sparc64/include/endian.h20
-rw-r--r--sys/sun4v/include/endian.h20
2 files changed, 24 insertions, 16 deletions
diff --git a/sys/sparc64/include/endian.h b/sys/sparc64/include/endian.h
index a643dd3537c8..17447844ac44 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 a643dd3537c8..17447844ac44 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)