From: Bruno Haible Date: Wed, 5 Aug 2020 17:25:42 +0000 (+0200) Subject: Use __builtin_clz{,l,ll} with clang, also on Windows. X-Git-Tag: v1.0~3818 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=878c98336e9d915a9150eb473d5825d6dde7880d;p=gnulib.git Use __builtin_clz{,l,ll} with clang, also on Windows. * lib/integer_length.c: With clang, use the GCC built-in, not . * lib/integer_length_l.c: Likewise. * lib/count-leading-zeros.h (COUNT_LEADING_ZEROS): Use the GCC built-in also on clang. * lib/vasnprintf.c (divide): Likewise. --- diff --git a/ChangeLog b/ChangeLog index 17473e3e96..f766b912af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2020-08-05 Bruno Haible + + Use __builtin_clz{,l,ll} with clang, also on Windows. + * lib/integer_length.c: With clang, use the GCC built-in, not + . + * lib/integer_length_l.c: Likewise. + * lib/count-leading-zeros.h (COUNT_LEADING_ZEROS): Use the GCC built-in + also on clang. + * lib/vasnprintf.c (divide): Likewise. + 2020-08-04 Paul Eggert Update srclist.txt as per recent glibc changes diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h index 7e88c8cb9d..7cf605a5f6 100644 --- a/lib/count-leading-zeros.h +++ b/lib/count-leading-zeros.h @@ -38,7 +38,8 @@ extern "C" { expand to code that computes the number of leading 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_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \ return x ? BUILTIN (x) : CHAR_BIT * sizeof x; #elif _MSC_VER diff --git a/lib/integer_length.c b/lib/integer_length.c index 43d8f49d65..1896c6a3aa 100644 --- a/lib/integer_length.c +++ b/lib/integer_length.c @@ -25,7 +25,7 @@ #include "float+.h" -#if defined _MSC_VER +#if defined _MSC_VER && !(__clang_major__ >= 4) # include #endif @@ -34,7 +34,7 @@ int integer_length (unsigned int x) { -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__clang_major__ >= 4) if (x == 0) return 0; else diff --git a/lib/integer_length_l.c b/lib/integer_length_l.c index 161f1afa12..907a6dbcbb 100644 --- a/lib/integer_length_l.c +++ b/lib/integer_length_l.c @@ -41,7 +41,7 @@ # define MSVC_BUILTIN _BitScanReverse #endif -#if defined _MSC_VER +#if defined _MSC_VER && !(__clang_major__ >= 4) # include /* Copied from integer_length.c. */ static inline int @@ -66,7 +66,7 @@ integer_length (unsigned int x) int FUNC (TYPE x) { -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__clang_major__ >= 4) if (x == 0) return 0; else diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 0cdc6c095a..7f75139560 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -633,7 +633,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q) mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ /* Determine s = GMP_LIMB_BITS - integer_length (msd). Code copied from gnulib's integer_length.c. */ -# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) +# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) \ + || (__clang_major__ >= 4) s = __builtin_clz (msd); # else # if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT