Skip to content

Commit 1269cab

Browse files
committed
Merge #19403: build: improve __builtin_clz* detection
9952242 build: improve builtin_clz* detection (fanquake) Pull request description: Fixes #19402. The way we currently test for `__builtin_clz*` support with `AC_CHECK_DECLS` does not work with Clang: ```bash configure:21492: clang++-10 -std=c++11 -c -g -O2 -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS conftest.cpp >&5 conftest.cpp:100:10: error: builtin functions must be directly called (void) __builtin_clz; ^ 1 error generated. ``` This also removes the `__builtin_clz()` check, as we don't actually use it anywhere, and it's trvial to re-add detection if we do start using it at some point. If this is controversial then I'll add a test for it as well. ACKs for top commit: sipa: ACK 9952242 laanwj: ACK 9952242 Tree-SHA512: 695abb1a694a01a25aaa483b4fffa7d598842f2ba4fe8630fbed9ce5450b915c33bf34bb16ad16a16b702dd7c91ebf49fe509a2498b9e28254fe0ec5177bbac0
2 parents 8edfc17 + 9952242 commit 1269cab

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

build_msvc/bitcoin_config.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,6 @@
137137
don't. */
138138
#define HAVE_DECL_STRNLEN 1
139139

140-
/* Define to 1 if you have the declaration of `__builtin_clz', and to 0 if you
141-
don't. */
142-
//#define HAVE_DECL___BUILTIN_CLZ 1
143-
144-
/* Define to 1 if you have the declaration of `__builtin_clzl', and to 0 if
145-
you don't. */
146-
//#define HAVE_DECL___BUILTIN_CLZL 1
147-
148-
/* Define to 1 if you have the declaration of `__builtin_clzll', and to 0 if
149-
you don't. */
150-
//#define HAVE_DECL___BUILTIN_CLZLL 1
151-
152140
/* Define to 1 if you have the <dlfcn.h> header file. */
153141
/* #undef HAVE_DLFCN_H */
154142

configure.ac

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,21 @@ AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,
850850
#include <byteswap.h>
851851
#endif])
852852

853-
AC_CHECK_DECLS([__builtin_clz, __builtin_clzl, __builtin_clzll])
853+
AC_MSG_CHECKING(for __builtin_clzl)
854+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
855+
(void) __builtin_clzl(0);
856+
]])],
857+
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_BUILTIN_CLZL, 1, [Define this symbol if you have __builtin_clzl])],
858+
[ AC_MSG_RESULT(no)]
859+
)
860+
861+
AC_MSG_CHECKING(for __builtin_clzll)
862+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ ]], [[
863+
(void) __builtin_clzll(0);
864+
]])],
865+
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_BUILTIN_CLZLL, 1, [Define this symbol if you have __builtin_clzll])],
866+
[ AC_MSG_RESULT(no)]
867+
)
854868

855869
dnl Check for malloc_info (for memory statistics information in getmemoryinfo)
856870
AC_MSG_CHECKING(for getmemoryinfo)

src/crypto/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ void static inline WriteBE64(unsigned char* ptr, uint64_t x)
8282
/** Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */
8383
uint64_t static inline CountBits(uint64_t x)
8484
{
85-
#if HAVE_DECL___BUILTIN_CLZL
85+
#if HAVE_BUILTIN_CLZL
8686
if (sizeof(unsigned long) >= sizeof(uint64_t)) {
8787
return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0;
8888
}
8989
#endif
90-
#if HAVE_DECL___BUILTIN_CLZLL
90+
#if HAVE_BUILTIN_CLZLL
9191
if (sizeof(unsigned long long) >= sizeof(uint64_t)) {
9292
return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0;
9393
}

0 commit comments

Comments
 (0)