No way to leverage popcount instruction for this?
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.Are you saying you've got a better solution than the blog post that does a direct table lookup? Can you share it?
Do you have a better solution?