[PATCH v1 27/35] Assume __has_builtin(__builtin_bswap{16,32,64})

Alejandro Colomar alx@kernel.org
Sun Nov 9 21:53:55 GMT 2025


We already assume that GCC is at least GCC 5,
and we also assume that Clang is at least Clang 4.

Clang added support for __builtin_bswap{32,64}() in Clang 2.2:

llvm.git ef93b9d01107 (2007-12-02; "Implement __builtin_bswap32 and __builtin_bswap64.")

	$ git describe --contains ef93b9d01107
	llvmorg-2.2.0~1426

Also, Clang added support for __builtin_bswap16() in Clang 3.2:

llvm.git a801f4a81dc2 (2012-10-06; "Expose __builtin_bswap16.")

	$ git describe --contains a801f4a81dc2
	llvmorg-3.2.0-rc1~1^2~2032

Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 bits/byteswap.h | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/bits/byteswap.h b/bits/byteswap.h
index c0841a3574..e2bddb7f06 100644
--- a/bits/byteswap.h
+++ b/bits/byteswap.h
@@ -33,11 +33,7 @@
 static __inline __uint16_t
 __bswap_16 (__uint16_t __bsx)
 {
-#if __GNUC_PREREQ (4, 8)
   return __builtin_bswap16 (__bsx);
-#else
-  return __bswap_constant_16 (__bsx);
-#endif
 }
 
 /* Swap bytes in 32-bit value.  */
@@ -48,11 +44,7 @@ __bswap_16 (__uint16_t __bsx)
 static __inline __uint32_t
 __bswap_32 (__uint32_t __bsx)
 {
-#if __GNUC_PREREQ (4, 3)
   return __builtin_bswap32 (__bsx);
-#else
-  return __bswap_constant_32 (__bsx);
-#endif
 }
 
 /* Swap bytes in 64-bit value.  */
@@ -69,11 +61,7 @@ __bswap_32 (__uint32_t __bsx)
 __extension__ static __inline __uint64_t
 __bswap_64 (__uint64_t __bsx)
 {
-#if __GNUC_PREREQ (4, 3)
   return __builtin_bswap64 (__bsx);
-#else
-  return __bswap_constant_64 (__bsx);
-#endif
 }
 
 #endif /* _BITS_BYTESWAP_H */
-- 
2.51.0



More information about the Libc-alpha mailing list