Mesa (master): mesa: faster logbase2
Brian Paul
brianp at kemper.freedesktop.org
Thu Jun 2 14:47:55 UTC 2011
Module: Mesa
Branch: master
Commit: bab3b4a75886acd040e81730d9d3dfb31d4f0d48
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=bab3b4a75886acd040e81730d9d3dfb31d4f0d48
Author: Benjamin Bellec <b.bellec at gmail.com>
Date: Thu Jun 2 08:31:16 2011 -0600
mesa: faster logbase2
With minor clean-ups by Brian Paul.
Signed-off-by: Brian Paul <brianp at vmware.com>
---
src/mesa/main/teximage.c | 33 ++++++++++-----------------------
1 files changed, 10 insertions(+), 23 deletions(-)
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 4ea9a48..3e42911 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -81,31 +81,18 @@ _mesa_free_texmemory(void *m)
/*
- * Compute floor(log_base_2(n)).
- * If n < 0 return -1.
+ * Returns the floor form of binary logarithm for a 32-bit integer.
*/
-static int
-logbase2( int n )
-{
- GLint i = 1;
- GLint log2 = 0;
-
- if (n < 0)
- return -1;
-
- if (n == 0)
- return 0;
-
- while ( n > i ) {
- i *= 2;
- log2++;
- }
- if (i != n) {
- return log2 - 1;
- }
- else {
- return log2;
- }
+static GLuint
+logbase2(GLuint n)
+{
+ GLuint 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;
}
More information about the mesa-commit
mailing list