Mesa (master): util: faster logbase2

Brian Paul brianp at kemper.freedesktop.org
Thu Jun 2 14:47:55 UTC 2011


Module: Mesa
Branch: master
Commit: f62e1f41b4d6047e72222aebbb0b55a508269b0c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f62e1f41b4d6047e72222aebbb0b55a508269b0c

Author: Brian Paul <brianp at vmware.com>
Date:   Thu Jun  2 08:43:07 2011 -0600

util: faster logbase2

---

 src/gallium/auxiliary/util/u_math.h |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 2ecade5..65a99fc 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -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;
 }
 
 




More information about the mesa-commit mailing list