gallium/util: add u_bit_consecutive for generating a consecutive range of bits
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 22 Apr 2016 17:48:19 +0000 (12:48 -0500)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 27 Apr 2016 16:16:39 +0000 (11:16 -0500)
There are some undefined behavior subtleties, so having a function to match
the u_bit_scan_consecutive_range makes sense.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/util/u_math.h

index 4e58e505572e6d9280d3993d4225c373b6ab7cbf..ecb1d636fcc79b738ce6e5fa401d09be14e6d668 100644 (file)
@@ -545,6 +545,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.
  */