[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: improve clang support (1)
From: |
Paul Eggert |
Subject: |
Re: improve clang support (1) |
Date: |
Wed, 5 Aug 2020 11:13:29 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 |
On 8/5/20 10:32 AM, Bruno Haible wrote:
clang has __builtin_clz, __builtin_clzl, __builtin_clzll, also on Windows.
At least in versions >= 4.0.0.
Should this sort of thing be using __has_builtin if available? Something like
the following untested patch for count-leading-zeros.h (this is inspired by how
verify.h does it):
diff --git a/lib/count-leading-zeros.h b/lib/count-leading-zeros.h
index 7cf605a5f..622c22be2 100644
--- a/lib/count-leading-zeros.h
+++ b/lib/count-leading-zeros.h
@@ -34,12 +34,22 @@ _GL_INLINE_HEADER_BEGIN
extern "C" {
#endif
+/* Whether __builtin_clz etc. work. */
+#if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
+# define _GL_HAS_BUILTIN_CLZ 1
+#elif defined __has_builtin
+# define _GL_HAS_BUILTIN_CLZ (__has_builtin (__builtin_clz) \
+ && __has_builtin (__builtin_clzl) \
+ && __has_builtin (__builtin_clzll))
+#else
+# define _GL_HAS_BUILTIN_CLZ 0
+#endif
+
/* Assuming the GCC builtin is BUILTIN and the MSC builtin is MSC_BUILTIN,
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) \
- || (__clang_major__ >= 4)
+#if _GL_HAS_BUILTIN_CLZ
# define COUNT_LEADING_ZEROS(BUILTIN, MSC_BUILTIN, TYPE) \
return x ? BUILTIN (x) : CHAR_BIT * sizeof x;
#elif _MSC_VER