aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2021-02-01 03:00:13 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2021-02-04 18:01:13 +0000
commit1a2bc12c4b2563628f329e2e971d1619e0240429 (patch)
tree6c31ca15d0d1ecc50706762ce6ebe3b61140411d
parent6d3ce617f398d4066780555210270b97c30e7c0e (diff)
downloadsrc-1a2bc12c4b2563628f329e2e971d1619e0240429.tar.gz
src-1a2bc12c4b2563628f329e2e971d1619e0240429.zip
x86: use compiler intrinsics for bswap*
(cherry picked from commit e6ff6154d2034c13f3d0da73c1e00d69fdb36516)
-rw-r--r--sys/x86/include/endian.h62
1 files changed, 3 insertions, 59 deletions
diff --git a/sys/x86/include/endian.h b/sys/x86/include/endian.h
index 9c39f4fddf80..18d52fb8a6fa 100644
--- a/sys/x86/include/endian.h
+++ b/sys/x86/include/endian.h
@@ -65,65 +65,9 @@
#define BYTE_ORDER _BYTE_ORDER
#endif
-#define __bswap16_gen(x) (__uint16_t)((x) << 8 | (x) >> 8)
-#define __bswap32_gen(x) \
- (((__uint32_t)__bswap16((x) & 0xffff) << 16) | __bswap16((x) >> 16))
-#define __bswap64_gen(x) \
- (((__uint64_t)__bswap32((x) & 0xffffffff) << 32) | __bswap32((x) >> 32))
-
-#ifdef __GNUCLIKE_BUILTIN_CONSTANT_P
-#define __bswap16(x) \
- ((__uint16_t)(__builtin_constant_p(x) ? \
- __bswap16_gen((__uint16_t)(x)) : __bswap16_var(x)))
-#define __bswap32(x) \
- (__builtin_constant_p(x) ? \
- __bswap32_gen((__uint32_t)(x)) : __bswap32_var(x))
-#define __bswap64(x) \
- (__builtin_constant_p(x) ? \
- __bswap64_gen((__uint64_t)(x)) : __bswap64_var(x))
-#else
-/* XXX these are broken for use in static initializers. */
-#define __bswap16(x) __bswap16_var(x)
-#define __bswap32(x) __bswap32_var(x)
-#define __bswap64(x) __bswap64_var(x)
-#endif
-
-/* These are defined as functions to avoid multiple evaluation of x. */
-
-static __inline __uint16_t
-__bswap16_var(__uint16_t _x)
-{
-
- return (__bswap16_gen(_x));
-}
-
-static __inline __uint32_t
-__bswap32_var(__uint32_t _x)
-{
-
-#ifdef __GNUCLIKE_ASM
- __asm("bswap %0" : "+r" (_x));
- return (_x);
-#else
- return (__bswap32_gen(_x));
-#endif
-}
-
-static __inline __uint64_t
-__bswap64_var(__uint64_t _x)
-{
-
-#if defined(__amd64__) && defined(__GNUCLIKE_ASM)
- __asm("bswap %0" : "+r" (_x));
- return (_x);
-#else
- /*
- * It is important for the optimizations that the following is not
- * really generic, but expands to 2 __bswap32_var()'s.
- */
- return (__bswap64_gen(_x));
-#endif
-}
+#define __bswap16(x) __builtin_bswap16(x)
+#define __bswap32(x) __builtin_bswap32(x)
+#define __bswap64(x) __builtin_bswap64(x)
#define __htonl(x) __bswap32(x)
#define __htons(x) __bswap16(x)