util: improve BITFIELD_MASK and BITFIELD64_MASK on clang
gcc is able to optimize away either the modulo or the logical and. This makes no difference to gcc. clang is only able to optimize away the logical and. This allows clang to generate faster code for BITFIELD_MASK. As for BITFIELD64_MASK, this also makes no difference to clang except it fixes a compile error for BITFIELD64_MASK(64): error: shift count >= width of type [-Werror,-Wshift-count-overflow] Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9989 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25757>
This commit is contained in:
@@ -388,7 +388,7 @@ do { \
|
||||
#define BITFIELD_BIT(b) (1u << (b))
|
||||
/** Set all bits up to excluding bit b */
|
||||
#define BITFIELD_MASK(b) \
|
||||
((b) == 32 ? (~0u) : BITFIELD_BIT((b) % 32) - 1)
|
||||
((b) == 32 ? (~0u) : BITFIELD_BIT((b) & 31) - 1)
|
||||
/** Set count bits starting from bit b */
|
||||
#define BITFIELD_RANGE(b, count) \
|
||||
(BITFIELD_MASK((b) + (count)) & ~BITFIELD_MASK(b))
|
||||
@@ -397,7 +397,7 @@ do { \
|
||||
#define BITFIELD64_BIT(b) (1ull << (b))
|
||||
/** Set all bits up to excluding bit b */
|
||||
#define BITFIELD64_MASK(b) \
|
||||
((b) == 64 ? (~0ull) : BITFIELD64_BIT(b) - 1)
|
||||
((b) == 64 ? (~0ull) : BITFIELD64_BIT((b) & 63) - 1)
|
||||
/** Set count bits starting from bit b */
|
||||
#define BITFIELD64_RANGE(b, count) \
|
||||
(BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b))
|
||||
|
Reference in New Issue
Block a user