+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.
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
#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
#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
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