diff options
Diffstat (limited to 'mesalib/src/gallium/auxiliary/util/u_math.h')
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_math.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_math.h b/mesalib/src/gallium/auxiliary/util/u_math.h index f35c35ffe..90b421ed8 100644 --- a/mesalib/src/gallium/auxiliary/util/u_math.h +++ b/mesalib/src/gallium/auxiliary/util/u_math.h @@ -477,6 +477,20 @@ unsigned ffs( unsigned u ) #endif /* FFS_DEFINED */ +/** + * Find last bit set in a word. The least significant bit is 1. + * Return 0 if no bits are set. + */ +static INLINE unsigned util_last_bit(unsigned u) +{ + unsigned r = 0; + while (u) { + r++; + u >>= 1; + } + return r; +} + /* Destructively loop over all of the bits in a mask as in: * |