git: e6ff6154d203 - main - x86: use compiler intrinsics for bswap*

Mateusz Guzik mjg at FreeBSD.org
Mon Feb 1 05:02:50 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=e6ff6154d2034c13f3d0da73c1e00d69fdb36516

commit e6ff6154d2034c13f3d0da73c1e00d69fdb36516
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-02-01 03:00:13 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-02-01 04:53:23 +0000

    x86: use compiler intrinsics for bswap*
---
 sys/x86/include/endian.h | 62 +++---------------------------------------------
 1 file 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)


More information about the dev-commits-src-all mailing list