summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2015-08-28 20:53:08 +0200
committerMarek Olšák <marek.olsak@amd.com>2015-09-01 21:51:13 +0200
commitfc292b5821ca2d21cf5ebc83994138b87085d878 (patch)
tree025a83ee541f601109361ffd816f56d14b2ac6cc /src/gallium/auxiliary
parentd38a5601068ae1d923efece8f28757777f4474e4 (diff)
downloadexternal_mesa3d-fc292b5821ca2d21cf5ebc83994138b87085d878.zip
external_mesa3d-fc292b5821ca2d21cf5ebc83994138b87085d878.tar.gz
external_mesa3d-fc292b5821ca2d21cf5ebc83994138b87085d878.tar.bz2
gallium/util: add u_bit_scan_consecutive_range
Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Acked-by: Christian König <christian.koenig@amd.com>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/util/u_math.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 56bd185..7175d1d 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -483,6 +483,26 @@ u_bit_scan64(uint64_t *mask)
}
#endif
+/* 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)
+{
+ *start = ffs(*mask) - 1;
+ *count = ffs(~(*mask >> *start)) - 1;
+ *mask &= ~(((1 << *count) - 1) << *start);
+}
+
/**
* Return float bits.
*/