[Mesa-dev] [PATCH 01/31] mesa: Provide _mesa_bit_scan{, 64} similar to gallium.
Mathias.Froehlich at gmx.net
Mathias.Froehlich at gmx.net
Tue Jun 7 05:29:36 UTC 2016
From: Mathias Fröhlich <mathias.froehlich at web.de>
The function is yet unused but will be used with the
next changes.
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
src/mesa/main/imports.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/mesa/main/imports.h b/src/mesa/main/imports.h
index d96d666..3ccfb80 100644
--- a/src/mesa/main/imports.h
+++ b/src/mesa/main/imports.h
@@ -400,6 +400,30 @@ _mesa_flsll(uint64_t n)
#endif
}
+/* Destructively loop over all of the bits in a mask as in:
+ *
+ * while (mymask) {
+ * int i = _mesa_bit_scan(&mymask);
+ * ... process element i
+ * }
+ *
+ */
+static inline int
+_mesa_bit_scan(unsigned *mask)
+{
+ const int i = ffs(*mask) - 1;
+ *mask ^= (1u << i);
+ return i;
+}
+
+static inline int
+_mesa_bit_scan64(uint64_t *mask)
+{
+ const int i = ffsll(*mask) - 1;
+ *mask ^= (1llu << i);
+ return i;
+}
+
static inline bool
_mesa_half_is_negative(GLhalfARB h)
{
--
2.5.5
More information about the mesa-dev
mailing list