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