From 52f9bba889fd9b50a0543fd9fedc389592cdc7e5 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 8 Dec 2023 19:10:18 +0000 Subject: [PATCH] crypto: replace non-standard CLZ builtins with c++20's bit_width Also some header cleanups. --- src/crypto/common.h | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/crypto/common.h b/src/crypto/common.h index 6ae5d4cd241..18d986f429d 100644 --- a/src/crypto/common.h +++ b/src/crypto/common.h @@ -5,15 +5,12 @@ #ifndef BITCOIN_CRYPTO_COMMON_H #define BITCOIN_CRYPTO_COMMON_H -#if defined(HAVE_CONFIG_H) -#include -#endif - -#include -#include - #include +#include +#include +#include + uint16_t static inline ReadLE16(const unsigned char* ptr) { uint16_t x; @@ -89,22 +86,7 @@ void static inline WriteBE64(unsigned char* ptr, uint64_t x) /** Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */ uint64_t static inline CountBits(uint64_t x) { -#if HAVE_BUILTIN_CLZL - if (sizeof(unsigned long) >= sizeof(uint64_t)) { - return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0; - } -#endif -#if HAVE_BUILTIN_CLZLL - if (sizeof(unsigned long long) >= sizeof(uint64_t)) { - return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0; - } -#endif - int ret = 0; - while (x) { - x >>= 1; - ++ret; - } - return ret; + return std::bit_width(x); } #endif // BITCOIN_CRYPTO_COMMON_H