MCPcopy Create free account
hub / github.com/comaps/comaps / select1

Function select1

libs/base/bits.hpp:15–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13
14template <typename T>
15unsigned int select1(T x, unsigned int i)
16{
17 // TODO: Fast implementation of select1.
18 ASSERT(i > 0 && i <= sizeof(T) * 8, (i));
19 for (unsigned int j = 0; j < sizeof(T) * 8; x >>= 1, ++j)
20 if (x & 1)
21 if (--i == 0)
22 return j;
23 return static_cast<unsigned int>(SELECT1_ERROR);
24}
25
26constexpr uint8_t FloorLog(uint64_t x) noexcept
27{

Callers 1

UNIT_TESTFunction · 0.85

Calls 1

ASSERTFunction · 0.85

Tested by 1

UNIT_TESTFunction · 0.68