[Mesa-dev] [PATCH 1/9] gallium/util: add u_bit_consecutive for generating a consecutive range of bits

Nicolai Hähnle nhaehnle at gmail.com
Fri Apr 22 22:41:23 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

There are some undefined behavior subtleties, so having a function to match
the u_bit_scan_consecutive_range makes sense.
---
 src/gallium/auxiliary/util/u_math.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h
index 10f158b..be6b5a3 100644
--- a/src/gallium/auxiliary/util/u_math.h
+++ b/src/gallium/auxiliary/util/u_math.h
@@ -543,6 +543,18 @@ u_bit_scan_consecutive_range64(uint64_t *mask, int *start, int *count)
    *mask &= ~(((1llu << *count) - 1) << *start);
 }
 
+/* Returns a bitfield in which the first count bits starting at start are
+ * set.
+ */
+static inline unsigned
+u_bit_consecutive(unsigned start, unsigned count)
+{
+   assert(start + count <= 32);
+   if (count == 32)
+      return ~0;
+   return ((1u << count) - 1) << start;
+}
+
 /**
  * Return float bits.
  */
-- 
2.5.0



More information about the mesa-dev mailing list