mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-01-03 00:40:09 +01:00
mesa: Add a _mesa_fls() function to find the last bit set in a word.
ffs() finds the least significant bit set; _mesa_fls() finds the /most/ significant bit. v2: Make it an inline function in imports.h, per Brian's suggestion. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Brian Paul <brianp@vmware.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
parent
1a5d4f7cb2
commit
0fc163408e
1 changed files with 22 additions and 0 deletions
|
|
@ -520,6 +520,28 @@ extern unsigned int
|
|||
_mesa_bitcount_64(uint64_t n);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Find the last (most significant) bit set in a word.
|
||||
*
|
||||
* Essentially ffs() in the reverse direction.
|
||||
*/
|
||||
static inline unsigned int
|
||||
_mesa_fls(unsigned int n)
|
||||
{
|
||||
#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 304)
|
||||
return n == 0 ? 0 : 32 - __builtin_clz(n);
|
||||
#else
|
||||
unsigned int v = 1;
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
while (n >>= 1)
|
||||
v++;
|
||||
|
||||
return v;
|
||||
#endif
|
||||
}
|
||||
|
||||
extern GLhalfARB
|
||||
_mesa_float_to_half(float f);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue