MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / CLZ

Function CLZ

Bcore/src/main/cpp/base/bit_utils.h:46–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44
45template<typename T>
46constexpr int CLZ(T x) {
47 static_assert(std::is_integral<T>::value, "T must be integral");
48 static_assert(std::is_unsigned<T>::value, "T must be unsigned");
49 static_assert(std::numeric_limits<T>::radix == 2, "Unexpected radix!");
50 static_assert(sizeof(T) == sizeof(uint64_t) || sizeof(T) <= sizeof(uint32_t),
51 "Unsupported sizeof(T)");
52 DCHECK_NE(x, 0u);
53 constexpr bool is_64_bit = (sizeof(T) == sizeof(uint64_t));
54 constexpr size_t adjustment =
55 is_64_bit ? 0u : std::numeric_limits<uint32_t>::digits - std::numeric_limits<T>::digits;
56 return is_64_bit ? __builtin_clzll(x) : __builtin_clz(x) - adjustment;
57}
58
59// Similar to CLZ except that on zero input it returns bitwidth and supports signed integers.
60template<typename T>

Callers 7

UnsignedLeb128SizeFunction · 0.85
SignedLeb128SizeFunction · 0.85
JAVASTYLE_CLZFunction · 0.85
MostSignificantBitFunction · 0.85
RoundUpToPowerOfTwoFunction · 0.85
TruncToPowerOfTwoFunction · 0.85
HighestOneBitValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected