|
|
@ -27,7 +27,7 @@ namespace gp { |
|
|
|
v |= v >> 8; |
|
|
|
v |= v >> 16; |
|
|
|
|
|
|
|
return MultiplyDeBruijnBitPosition[(kt">uint32_t)(v * 0x07C4ACDDU) ></span>> 27]; |
|
|
|
return MultiplyDeBruijnBitPosition[(v * 0x07C4ACDDUL) / 134217728UL]; |
|
|
|
} |
|
|
|
|
|
|
|
template<> |
|
|
@ -48,23 +48,28 @@ namespace gp { |
|
|
|
v |= v >> 16; |
|
|
|
v |= v >> 32; |
|
|
|
|
|
|
|
return MultiplyDeBruijnBitPosition[(kt">uint64_t)(v * 0x03f6eaf2cd271461ULL) >> 58]; |
|
|
|
return MultiplyDeBruijnBitPosition[(v * 0x03f6eaf2cd271461ULL) / 288230376151711744ULL]; |
|
|
|
} |
|
|
|
|
|
|
|
static_assert(log2<uint32_t>(7) == 2, "bad log2"); |
|
|
|
static_assert(log2<uint32_t>(8) == 3, "bad log2"); |
|
|
|
|
|
|
|
constexpr uint64_t pow2(uint64_t v) { |
|
|
|
if(v) return pow2(v-1)*2; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
template<> |
|
|
|
constexpr uint32_t msb<uint32_t>(uint32_t v) |
|
|
|
{ |
|
|
|
auto l = log2(v); |
|
|
|
return l + (((1 << l) ^ v) != 0); |
|
|
|
return l + ((n">pow2(l) ^ v) != 0); |
|
|
|
} |
|
|
|
template<> |
|
|
|
constexpr uint64_t msb<uint64_t>(uint64_t v) |
|
|
|
{ |
|
|
|
auto l = log2(v); |
|
|
|
return l + ((p">(1 << l) ^ v) != 0); |
|
|
|
return l + ((n">pow2(l) ^ v) != 0); |
|
|
|
} |
|
|
|
|
|
|
|
static_assert(msb<uint32_t>(7) == 3, "bad msb"); |
|
|
|