Mesa (master): util: add BITSET_LAST_BIT() helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 3 10:55:58 UTC 2020


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

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Wed Apr 29 14:15:12 2020 +1000

util: add BITSET_LAST_BIT() helper

This is the reverse of BITSET_FFS()

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4910>

---

 src/util/bitset.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/util/bitset.h b/src/util/bitset.h
index 0fdfe205f39..012764afc42 100644
--- a/src/util/bitset.h
+++ b/src/util/bitset.h
@@ -95,7 +95,21 @@ __bitset_ffs(const BITSET_WORD *x, int n)
    return 0;
 }
 
+/* Get the last bit set in a bitset.
+ */
+static inline int
+__bitset_last_bit(const BITSET_WORD *x, int n)
+{
+   for (int i = n - 1; i >= 0; i--) {
+      if (x[i])
+         return util_last_bit(x[i]) + BITSET_WORDBITS * i;
+   }
+
+   return 0;
+}
+
 #define BITSET_FFS(x) __bitset_ffs(x, ARRAY_SIZE(x))
+#define BITSET_LAST_BIT(x, size) __bitset_last_bit(x, size)
 
 static inline unsigned
 __bitset_next_set(unsigned i, BITSET_WORD *tmp,



More information about the mesa-commit mailing list