MCPcopy Create free account
hub / github.com/ElementsProject/elements / CountBits

Function CountBits

src/crypto/common.h:90–108  ·  view source on GitHub ↗

Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */

Source from the content-addressed store, hash-verified

88
89/** Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */
90uint64_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

Callers 5

randrangeMethod · 0.50
BOOST_AUTO_TEST_CASEFunction · 0.50
FUZZ_TARGET_INITFunction · 0.50
InterpretFunction · 0.50
SanityCheckASMapFunction · 0.50

Calls

no outgoing calls

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.40
FUZZ_TARGET_INITFunction · 0.40