bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

improve clang support (1)


From: Bruno Haible
Subject: improve clang support (1)
Date: Wed, 05 Aug 2020 19:32:13 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; )

clang has __builtin_clz, __builtin_clzl, __builtin_clzll, also on Windows.
At least in versions >= 4.0.0.


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.

diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h
index 7e88c8c..7cf605a 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 43d8f49..1896c6a 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 <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
diff --git a/lib/integer_length_l.c b/lib/integer_length_l.c
index 161f1af..907a6db 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 <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
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 0cdc6c0..7f75139 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]