summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2009-08-29 09:15:10 +0100
committerJosé Fonseca <[email protected]>2009-08-29 09:21:42 +0100
commitfdb3e75f7e796d88c8e3cd478e2830754116baf0 (patch)
tree650057f530b03a6a20c3cd6fdbd4080735b5cfa6 /src
parentc40eddd294abfe8af3619d08ccd7e9c8f1660fcb (diff)
util: Add util_unsigned_logbase2.
Cherry picked from Keith's commit f911c3b9897b90132c8621a72bfeb824eb3b01e5.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/auxiliary/util/u_math.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 57410e78b02..b0807c13392 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -375,6 +375,18 @@ unsigned ffs( unsigned u )
#endif
+/* Could also binary search for the highest bit.
+ */
+static INLINE unsigned
+util_unsigned_logbase2(unsigned n)
+{
+ unsigned log2 = 0;
+ while (n >>= 1)
+ ++log2;
+ return log2;
+}
+
+
/**
* Return float bits.
*/