[virglrenderer-devel] [PATCH 3/6] u_math: bring over u_bit_scan_consecutive_range.

Dave Airlie airlied at gmail.com
Wed Jul 18 17:58:07 UTC 2018


From: Dave Airlie <airlied at redhat.com>

This just takes this fn over from mesa to use in virgl
---
 src/gallium/auxiliary/util/u_math.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index dbacff6..dd8e549 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -584,6 +584,31 @@ static inline int u_bit_scan(unsigned *mask)
    return i;
 }
 
+/* For looping over a bitmask when you want to loop over consecutive bits
+ * manually, for example:
+ *
+ * while (mask) {
+ *    int start, count, i;
+ *
+ *    u_bit_scan_consecutive_range(&mask, &start, &count);
+ *
+ *    for (i = 0; i < count; i++)
+ *       ... process element (start+i)
+ * }
+ */
+static inline void
+u_bit_scan_consecutive_range(unsigned *mask, int *start, int *count)
+{
+   if (*mask == 0xffffffff) {
+      *start = 0;
+      *count = 32;
+      *mask = 0;
+      return;
+   }
+   *start = ffs(*mask) - 1;
+   *count = ffs(~(*mask >> *start)) - 1;
+   *mask &= ~(((1u << *count) - 1) << *start);
+}
 
 /**
  * Return float bits.
-- 
2.14.3



More information about the virglrenderer-devel mailing list