util: add BITSET_*_COUNT macros

We currently have BITSET_*_RANGE macros which take a closed interval/range: a
start bit and an end bit. Occassionally that is what you want, but most of the
time callers actually want a start and a length. For example, register
allocators will often do operations at (variable start register, variable start
register + variable size - 1). It's more convenient to just take a start and a
size, while also making the size=0 case well-defined as a no-op set/clear and
false for test.

This patch adds BITSET_*_COUNT macros aliasing to the existing range macros, and
the rest of the series converts many call sites across the tree to use the new
macros.

Of the few call sites not converted, a whole bunch look like off-by-one bugs
which I did not want to "fix" here and risk breaking something else. Probably
worth checking your driver if you have RANGE calls leftover after this series.

Also, aco and dozen both open-coded RANGE helpers that should probably be
switched to the common code but that's neither here nor there.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Reviewed-by: Mel Henning <mhenning@darkrefraction.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38955>
This commit is contained in:
Alyssa Rosenzweig 2025-12-15 14:38:36 -05:00 committed by Marge Bot
parent 7d5afb0ee9
commit 593517a53a

View file

@ -275,6 +275,10 @@ __bitset_clear_range(BITSET_WORD *r, int start, int end)
#define BITSET_CLEAR_RANGE(x, b, e) \
__bitset_clear_range(x, b, e)
#define BITSET_CLEAR_COUNT(x, b, n) BITSET_CLEAR_RANGE(x, (b), (b) + (n) - 1)
#define BITSET_TEST_COUNT(x, b, n) BITSET_TEST_RANGE(x, (b), (b) + (n) - 1)
#define BITSET_SET_COUNT(x, b, n) BITSET_SET_RANGE(x, (b), (b) + (n) - 1)
static inline unsigned
__bitset_extract(const BITSET_WORD *r, unsigned start, unsigned count)
{