diff options
author | Mike Blumenkrantz <michael.blumenkrantz@gmail.com> | 2021-02-19 14:43:59 -0500 |
---|---|---|
committer | Dylan Baker <dylan.c.baker@intel.com> | 2021-03-25 10:37:59 -0700 |
commit | 090239c2440450963b20278b24bfed3593f77ae1 (patch) | |
tree | 29469c4cff28d50a2f227375317cd0916cd7a332 /src | |
parent | 2ac46f95bd7929357dc0b599ffd5702480d716f9 (diff) |
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>
(cherry picked from commit e7c7150d6395c1e31f4e73e0e43dc6bb7e6dfacd)
Diffstat (limited to 'src')
-rw-r--r-- | src/util/bitscan.h | 10 |
1 files changed, 10 insertions, 0 deletions
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 |