From: Dave Airlie Date: Mon, 29 Apr 2019 03:17:41 +0000 (+1000) Subject: util/bitset: fix bitset range mask calculations. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=512a31a41299758f0f60d0452b8c9e8c02238189;p=mesa.git util/bitset: fix bitset range mask calculations. The MASK macro is used in the RANGE macro, and it should return the pre-bitset word mask for the (b) value. i.e. BITSET_MASK(0) should be undefined since it's meaningless. BITSET_MASK(31) should give 0x7fffffff BITSET_MASK(32) should give 0xffffffff BITSET_MASK(33) should give 0x00000001 BITSET_MASK(64) should give 0xffffffff However then BITSET_RANGE ends up broken for cases where it's (b) value is the 0,32,64 value as in that case the lower mask would be 0 not 0xffffffff. This fixes the unit tests that I've added, and my code that uses bitsets. Reviewed-by: Jason Ekstrand Fixes: bb38cadb1c5f2 "More GLSL code" Reviewed-by: Kristian H. Kristensen --- diff --git a/src/util/bitset.h b/src/util/bitset.h index e610d5f897e..7f116214b92 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -62,8 +62,8 @@ #define BITSET_SET(x, b) ((x)[BITSET_BITWORD(b)] |= BITSET_BIT(b)) #define BITSET_CLEAR(x, b) ((x)[BITSET_BITWORD(b)] &= ~BITSET_BIT(b)) -#define BITSET_MASK(b) ((b) == BITSET_WORDBITS ? ~0 : BITSET_BIT(b) - 1) -#define BITSET_RANGE(b, e) (BITSET_MASK((e) + 1) & ~BITSET_MASK(b)) +#define BITSET_MASK(b) (((b) % BITSET_WORDBITS == 0) ? ~0 : BITSET_BIT(b) - 1) +#define BITSET_RANGE(b, e) ((BITSET_MASK((e) + 1)) & ~(BITSET_BIT(b) - 1)) /* bit range operations */