Royce Mitchell III schrieb:
I managed to shave off another comparison in
favor of a shift:
What about using a 64k table?
static
BYTE HighestBits[65536] = {
0x00, 0x01, 0x02, 0x02, ... // and so on
};
// returns 0xFF when no bits set in dwValue
BYTE highest_bit(DWORD dwValue)
{
BYTE ret;
if (i > 0xffff) {
ret = HighestBits[(int) (dwValue >> 16)];
} else {
ret = HighestBits[(int) dwValue];
}
return ret - 1;
}
Regards,
Mark
There's a couple bugs in your code, but...
The table lookups are a little bit faster when they take full advantage
of available cpu caching. I'm not sure that they are good enough to
continue to fare well when put into our target environment ( at least
once per interrupt/thread schedule ). Besides, it's wasting a lot of
npool ram for a slight performance improvement.