Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */
| 88 | |
| 89 | /** Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */ |
| 90 | uint64_t static inline CountBits(uint64_t x) |
| 91 | { |
| 92 | #if HAVE_BUILTIN_CLZL |
| 93 | if (sizeof(unsigned long) >= sizeof(uint64_t)) { |
| 94 | return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0; |
| 95 | } |
| 96 | #endif |
| 97 | #if HAVE_BUILTIN_CLZLL |
| 98 | if (sizeof(unsigned long long) >= sizeof(uint64_t)) { |
| 99 | return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0; |
| 100 | } |
| 101 | #endif |
| 102 | int ret = 0; |
| 103 | while (x) { |
| 104 | x >>= 1; |
| 105 | ++ret; |
| 106 | } |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | #endif // BITCOIN_CRYPTO_COMMON_H |
no outgoing calls