summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util/u_math.h
diff options
context:
space:
mode:
authorMarek Olšák <maraeo@gmail.com>2012-03-30 00:21:11 +0200
committerMarek Olšák <maraeo@gmail.com>2012-07-17 21:22:14 +0200
commit6694a68d890a9aa491b5c3e8a576318bb6124e21 (patch)
tree706c2010352f804a60334a71af22738d61b730b6 /src/gallium/auxiliary/util/u_math.h
parent018e3f75d69490598d61059ece56d379867f3995 (diff)
downloadexternal_mesa3d-6694a68d890a9aa491b5c3e8a576318bb6124e21.zip
external_mesa3d-6694a68d890a9aa491b5c3e8a576318bb6124e21.tar.gz
external_mesa3d-6694a68d890a9aa491b5c3e8a576318bb6124e21.tar.bz2
gallium/util: add util_bit_last - finds the last bit set in a word
Diffstat (limited to 'src/gallium/auxiliary/util/u_math.h')
-rw-r--r--src/gallium/auxiliary/util/u_math.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index f35c35f..90b421e 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -477,6 +477,20 @@ unsigned ffs( unsigned u )
#endif /* FFS_DEFINED */
+/**
+ * Find last bit set in a word. The least significant bit is 1.
+ * Return 0 if no bits are set.
+ */
+static INLINE unsigned util_last_bit(unsigned u)
+{
+ unsigned r = 0;
+ while (u) {
+ r++;
+ u >>= 1;
+ }
+ return r;
+}
+
/* Destructively loop over all of the bits in a mask as in:
*