]> Savannah Git Hosting - gnulib.git/commitdiff
Use __builtin_clz{,l,ll} with clang, also on Windows.
authorBruno Haible <bruno@clisp.org>
Wed, 5 Aug 2020 17:25:42 +0000 (19:25 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 5 Aug 2020 17:27:46 +0000 (19:27 +0200)
* lib/integer_length.c: With clang, use the GCC built-in, not
<intrin.h>.
* 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.

ChangeLog
lib/count-leading-zeros.h
lib/integer_length.c
lib/integer_length_l.c
lib/vasnprintf.c

index 17473e3e960e8c8c5ed436cfd1aa01ccfcfcfa9a..f766b912aff97c23e2786126faa8d076cd4772ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-08-05  Bruno Haible  <bruno@clisp.org>
+
+       Use __builtin_clz{,l,ll} with clang, also on Windows.
+       * lib/integer_length.c: With clang, use the GCC built-in, not
+       <intrin.h>.
+       * 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  <eggert@cs.ucla.edu>
 
        Update srclist.txt as per recent glibc changes
index 7e88c8cb9d04f08408c1db71150d9a49e1a3dc64..7cf605a5f649a23089a0cf84f4b6006b023a4546 100644 (file)
@@ -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
index 43d8f49d65dae259953167b803526d4bae3d7c0c..1896c6a3aa6ed0aa30fc1160550972b8e3101f5a 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "float+.h"
 
-#if defined _MSC_VER
+#if defined _MSC_VER && !(__clang_major__ >= 4)
 # include <intrin.h>
 #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
index 161f1afa127bf0ac535164cc826ae41de2ae6b46..907a6dbcbbf4a7e76802caf556f74264bc28bf6c 100644 (file)
@@ -41,7 +41,7 @@
 # define MSVC_BUILTIN _BitScanReverse
 #endif
 
-#if defined _MSC_VER
+#if defined _MSC_VER && !(__clang_major__ >= 4)
 # include <intrin.h>
 /* 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
index 0cdc6c095a44d0260c405bbc4bd46224038e5a09..7f75139560778244a5a33075bb4840ddf5de86c1 100644 (file)
@@ -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