diff options
author | Nicolai Hähnle <[email protected]> | 2016-04-22 12:48:19 -0500 |
---|---|---|
committer | Nicolai Hähnle <[email protected]> | 2016-04-27 11:16:39 -0500 |
commit | 91fb4bb2e999accfca3394a5720516d03868c521 (patch) | |
tree | 939ce6b9dea2091e5e01edfc980cbba7e7454f0c /src/gallium | |
parent | 504df3a1d791d071259d23b4a99b9b46b1f601af (diff) |
gallium/util: add u_bit_consecutive for generating a consecutive range of bits
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 <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/util/u_math.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index 4e58e505572..ecb1d636fcc 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -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. */ |