diff options
author | Keith Whitwell <[email protected]> | 2011-09-21 11:22:43 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2011-09-22 08:26:36 -0600 |
commit | 553930424dec0cb1a83d2c928c260de6626b0d11 (patch) | |
tree | 41b630835131abe39a24710da91c6ea087eefbee /src/gallium/auxiliary/util | |
parent | ffb1996f614679553ef1d029306d0194b3161113 (diff) |
util: add u_bit_scan helper
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_math.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index 46d9322932a..c74c1da7675 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -424,6 +424,22 @@ unsigned ffs( unsigned u ) #endif +/* Destructively loop over all of the bits in a mask as in: + * + * while (mymask) { + * int i = u_bit_scan(&mymask); + * ... process element i + * } + * + */ +static INLINE int u_bit_scan(unsigned *mask) +{ + int i = ffs(*mask) - 1; + *mask &= ~(1 << i); + return i; +} + + /** * Return float bits. */ |