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:
parent
618f46ee02
commit
e7c7150d63
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue