diff options
author | Bruno Haible <bruno@clisp.org> | 2020-08-05 19:57:21 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-08-05 19:57:21 +0200 |
commit | 50bf1b6fe4fe406568884bce97ddcff935571a0a (patch) | |
tree | 4956a4820cf881c88360990ea95cfa44bde0a7e9 /lib | |
parent | 878c98336e9d915a9150eb473d5825d6dde7880d (diff) | |
download | gnulib-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.h | 3 | ||||
-rw-r--r-- | lib/ffs.c | 4 | ||||
-rw-r--r-- | lib/ffsl.h | 5 |
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 @@ -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 |