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