mesa: faster logbase2
With minor clean-ups by Brian Paul. Signed-off-by: Brian Paul <brianp@vmware.com>
This commit is contained in:

committed by
Brian Paul

parent
029ea39fb9
commit
bab3b4a758
@@ -81,31 +81,18 @@ _mesa_free_texmemory(void *m)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute floor(log_base_2(n)).
|
* Returns the floor form of binary logarithm for a 32-bit integer.
|
||||||
* If n < 0 return -1.
|
|
||||||
*/
|
*/
|
||||||
static int
|
static GLuint
|
||||||
logbase2( int n )
|
logbase2(GLuint n)
|
||||||
{
|
{
|
||||||
GLint i = 1;
|
GLuint pos = 0;
|
||||||
GLint log2 = 0;
|
if (n >= 1<<16) { n >>= 16; pos += 16; }
|
||||||
|
if (n >= 1<< 8) { n >>= 8; pos += 8; }
|
||||||
if (n < 0)
|
if (n >= 1<< 4) { n >>= 4; pos += 4; }
|
||||||
return -1;
|
if (n >= 1<< 2) { n >>= 2; pos += 2; }
|
||||||
|
if (n >= 1<< 1) { pos += 1; }
|
||||||
if (n == 0)
|
return pos;
|
||||||
return 0;
|
|
||||||
|
|
||||||
while ( n > i ) {
|
|
||||||
i *= 2;
|
|
||||||
log2++;
|
|
||||||
}
|
|
||||||
if (i != n) {
|
|
||||||
return log2 - 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return log2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user