Mike Nordell wrote:
int highest_bit(unsigned int i)
{
int temp;
int ret = 0;
temp = i > 0xffff; i >>= 16*temp; ret = 16*temp;
temp = i > 0xff; i >>= 8*temp; ret += 8*temp;
temp = i > 0xf; i >>= 4*temp; ret += 4*temp;
temp = i > 0x3; i >>= 2*temp; ret += 2*temp;
ret += (i>>1);
return ret;
}
This is almost, but not quite, 50% slower in msvc6 w/ "compile for
speed". :(
Perhaps the reordering could help...