util/bitscan: add u_foreach_bit macros

this is a standardized (and very slightly improved for usability) version
of the macro that has been copied into every vulkan driver

includes fixup from Rob Clark <robclark@freedesktop.org>

Reviewed-by: Rob Clark <robclark@freedesktop.org>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9191>
This commit is contained in:
Mike Blumenkrantz 2021-02-19 14:43:59 -05:00 committed by Marge Bot
parent 618f46ee02
commit e7c7150d63
1 changed files with 10 additions and 0 deletions

View File

@ -104,6 +104,11 @@ u_bit_scan(unsigned *mask)
return i;
}
#define u_foreach_bit(b, dword) \
for (uint32_t __dword = (dword), b; \
((b) = ffs(__dword) - 1, __dword); \
__dword &= ~(1 << (b)))
static inline int
u_bit_scan64(uint64_t *mask)
{
@ -112,6 +117,11 @@ u_bit_scan64(uint64_t *mask)
return i;
}
#define u_foreach_bit64(b, dword) \
for (uint64_t __dword = (dword), b; \
((b) = ffsll(__dword) - 1, __dword); \
__dword &= ~(1ull << (b)))
/* Determine if an unsigned value is a power of two.
*
* \note