util: Add util_unsigned_logbase2.
authorJosé Fonseca <jfonseca@vmware.com>
Sat, 29 Aug 2009 08:15:10 +0000 (09:15 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sat, 29 Aug 2009 08:21:42 +0000 (09:21 +0100)
Cherry picked from Keith's commit f911c3b9897b90132c8621a72bfeb824eb3b01e5.

src/gallium/auxiliary/util/u_math.h

index 57410e78b02af71a8965c1307d8e6320ea89b502..b0807c13392359dfea266f1d4a474ec9e6cf03d6 100644 (file)
@@ -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.
  */