From: Marek Olšák Date: Thu, 29 Mar 2012 22:21:11 +0000 (+0200) Subject: gallium/util: add util_bit_last - finds the last bit set in a word X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6694a68d890a9aa491b5c3e8a576318bb6124e21;p=mesa.git gallium/util: add util_bit_last - finds the last bit set in a word --- diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index f35c35ffe47..90b421ed841 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/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: *