]> Savannah Git Hosting - gnulib.git/commitdiff
Use __builtin_ctz{,l,ll} and __builtin_ffs{,l,ll} with clang everywhere.
authorBruno Haible <bruno@clisp.org>
Wed, 5 Aug 2020 17:57:21 +0000 (19:57 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 5 Aug 2020 17:57:21 +0000 (19:57 +0200)
* lib/count-trailing-zeros.h (COUNT_TRAILING_ZEROS): Use the GCC
built-in also on clang.
* lib/ffs.c: With clang, use the GCC built-in, not <intrin.h>.
* lib/ffsl.h: Likewise. Assume GCC_BUILTIN is defined.

ChangeLog
lib/count-trailing-zeros.h
lib/ffs.c
lib/ffsl.h

index f766b912aff97c23e2786126faa8d076cd4772ab..bd05d1f7c044c6f4c432bf1f2eec7564ee97d44c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-08-05  Bruno Haible  <bruno@clisp.org>
+
+       Use __builtin_ctz{,l,ll} and __builtin_ffs{,l,ll} with clang everywhere.
+       * lib/count-trailing-zeros.h (COUNT_TRAILING_ZEROS): Use the GCC
+       built-in also on clang.
+       * lib/ffs.c: With clang, use the GCC built-in, not <intrin.h>.
+       * lib/ffsl.h: Likewise. Assume GCC_BUILTIN is defined.
+
 2020-08-05  Bruno Haible  <bruno@clisp.org>
 
        Use __builtin_clz{,l,ll} with clang, also on Windows.
index 1eb5fb919f4454b43f1cc56031efaa953ebdabe3..727b21dcc564f490bd8713e2e42894620f0b2b81 100644 (file)
@@ -38,7 +38,8 @@ extern "C" {
    expand to code that computes the number of trailing zeros of the local
    variable 'x' of type TYPE (an unsigned integer type) and return it
    from the current function.  */
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \
+    || (__clang_major__ >= 4)
 # define COUNT_TRAILING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE)               \
   return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
 #elif _MSC_VER
index d8a65cac011a64c925d03724a7f561511f8135d8..c94b8aca532c275e11e690fb5a68277b9b75f925 100644 (file)
--- a/lib/ffs.c
+++ b/lib/ffs.c
 
 #include <limits.h>
 
-#if defined _MSC_VER
+#if defined _MSC_VER && !(__clang_major__ >= 4)
 # include <intrin.h>
 #endif
 
 int
 ffs (int i)
 {
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__clang_major__ >= 4)
   return __builtin_ffs (i);
 #elif defined _MSC_VER
   /* _BitScanForward
index fa5c0935a3e88dda5c5e05bec0bce04dfb9a5674..b449f19739217a63fc2d6571c1c89893d8fe6e96 100644 (file)
@@ -27,7 +27,7 @@
 #include <limits.h>
 #include <strings.h>
 
-#if defined _MSC_VER
+#if defined _MSC_VER && !(__clang_major__ >= 4)
 # include <intrin.h>
 /* Copied from ffs.c.  */
 static inline int
@@ -50,7 +50,8 @@ ffs (int i)
 int
 FUNC (TYPE i)
 {
-#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && defined GCC_BUILTIN
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \
+    || (__clang_major__ >= 4)
   return GCC_BUILTIN (i);
 #elif defined _MSC_VER && defined MSVC_BUILTIN
   /* _BitScanForward, _BitScanForward64