util: faster logbase2

This commit is contained in:
Brian Paul 2011-06-02 08:43:07 -06:00
parent bab3b4a758
commit f62e1f41b4

View file

@ -477,10 +477,13 @@ float_to_byte_tex(float f)
static INLINE unsigned
util_logbase2(unsigned n)
{
unsigned log2 = 0;
while (n >>= 1)
++log2;
return log2;
unsigned pos = 0;
if (n >= 1<<16) { n >>= 16; pos += 16; }
if (n >= 1<< 8) { n >>= 8; pos += 8; }
if (n >= 1<< 4) { n >>= 4; pos += 4; }
if (n >= 1<< 2) { n >>= 2; pos += 2; }
if (n >= 1<< 1) { pos += 1; }
return pos;
}