summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-08-05 19:57:21 +0200
committerBruno Haible <bruno@clisp.org>2020-08-05 19:57:21 +0200
commit50bf1b6fe4fe406568884bce97ddcff935571a0a (patch)
tree4956a4820cf881c88360990ea95cfa44bde0a7e9 /lib
parent878c98336e9d915a9150eb473d5825d6dde7880d (diff)
downloadgnulib-50bf1b6fe4fe406568884bce97ddcff935571a0a.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/count-trailing-zeros.h3
-rw-r--r--lib/ffs.c4
-rw-r--r--lib/ffsl.h5
3 files changed, 7 insertions, 5 deletions
diff --git a/lib/count-trailing-zeros.h b/lib/count-trailing-zeros.h
index 1eb5fb919f..727b21dcc5 100644
--- a/lib/count-trailing-zeros.h
+++ b/lib/count-trailing-zeros.h
@@ -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
diff --git a/lib/ffs.c b/lib/ffs.c
index d8a65cac01..c94b8aca53 100644
--- a/lib/ffs.c
+++ b/lib/ffs.c
@@ -23,14 +23,14 @@
#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
diff --git a/lib/ffsl.h b/lib/ffsl.h
index fa5c0935a3..b449f19739 100644
--- a/lib/ffsl.h
+++ b/lib/ffsl.h
@@ -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