4 ms·
If you insist, you could calculate the log2 as something like x |= x >> 1; x |= x >> 2; x |= x >> 4; x |= x >> 8; x |= x >> 16; ret
by pbsd 5y ago
If you insist, you could calculate the log2 as something like
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
return popcount(x-1);
but there isn't really much of an advantage to it. lzcnt/bsr are better.