From e7c7150d6395c1e31f4e73e0e43dc6bb7e6dfacd Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 19 Feb 2021 14:43:59 -0500 Subject: [PATCH] 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 Reviewed-by: Rob Clark Reviewed-by: Jason Ekstrand Part-of: --- src/util/bitscan.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/bitscan.h b/src/util/bitscan.h index 895a1e7a372..1ea7b07359f 100644 --- a/src/util/bitscan.h +++ b/src/util/bitscan.h @@ -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