diff options
author | Nicolai Hähnle <[email protected]> | 2016-09-06 14:41:51 +0200 |
---|---|---|
committer | Nicolai Hähnle <[email protected]> | 2016-09-27 16:44:38 +0200 |
commit | b3ebc229dcd5d1cc882443f9b851890b00cd9dbc (patch) | |
tree | d8deab5e2862cf3be8b07b7638e80aced706c09d /src/gallium/auxiliary | |
parent | c060f291c26ac22721a515c78c7a4779f389ff7e (diff) |
gallium/u_math: add util_logbase2_ceil
For finding the exponent of the next power of two.
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/util/u_math.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/util/u_math.h b/src/gallium/auxiliary/util/u_math.h index a9232711bf1..2ab5f03a662 100644 --- a/src/gallium/auxiliary/util/u_math.h +++ b/src/gallium/auxiliary/util/u_math.h @@ -429,6 +429,18 @@ util_logbase2(unsigned n) #endif } +/** + * Returns the ceiling of log n base 2, and 0 when n == 0. Equivalently, + * returns the smallest x such that n <= 2**x. + */ +static inline unsigned +util_logbase2_ceil(unsigned n) +{ + if (n <= 1) + return 0; + + return 1 + util_logbase2(n - 1); +} /** * Returns the smallest power of two >= x |