asmap bucketing ported from Komodo

This commit is contained in:
miodragpop
2020-09-30 14:28:55 +02:00
parent 9a3e68a832
commit 56d9c00749
19 changed files with 1562 additions and 119 deletions

View File

@@ -87,6 +87,27 @@ void static inline WriteBE64(unsigned char* ptr, uint64_t x)
memcpy(ptr, (char*)&v, 8);
}
/** 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_DECL___BUILTIN_CLZL
if (sizeof(unsigned long) >= sizeof(uint64_t)) {
return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0;
}
#endif
#if HAVE_DECL___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;
}
int inline init_and_check_sodium()
{
if (sodium_init() == -1) {
@@ -124,5 +145,4 @@ int inline init_and_check_sodium()
return 0;
}
#endif // BITCOIN_CRYPTO_COMMON_H