diff options
author | José Fonseca <[email protected]> | 2009-09-07 14:21:51 +0100 |
---|---|---|
committer | José Fonseca <[email protected]> | 2009-09-07 15:02:06 +0100 |
commit | 6b129a82223c674d3e11472aa8abe07fd741764a (patch) | |
tree | 3a977315162055d02478faaf3f7adcd0d67332a8 /src/gallium/auxiliary | |
parent | 8be72bb7646d430e66cb36e09c13c13bee030d53 (diff) |
util: Utility function to check if a number is a power of two.
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/util/u_math.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index 4c6c2bc00e1..b12c97dfb4d 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -341,6 +341,16 @@ util_is_inf_or_nan(float x) /** + * Test whether x is a power of two. + */ +static INLINE boolean +util_is_pot(unsigned x) +{ + return (x & (x - 1)) == 0; +} + + +/** * Find first bit set in word. Least significant bit is 1. * Return 0 if no bits set. */ |