projects
/
mesa.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
c060f29
)
gallium/u_math: add util_logbase2_ceil
author
Nicolai Hähnle
<nicolai.haehnle@amd.com>
Tue, 6 Sep 2016 12:41:51 +0000
(14:41 +0200)
committer
Nicolai Hähnle
<nicolai.haehnle@amd.com>
Tue, 27 Sep 2016 14:44:38 +0000
(16:44 +0200)
For finding the exponent of the next power of two.
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/util/u_math.h
patch
|
blob
|
history
diff --git
a/src/gallium/auxiliary/util/u_math.h
b/src/gallium/auxiliary/util/u_math.h
index a9232711bf1264efec54d2f7f32b47ee733c4435..2ab5f03a6628b79bc4801ad4b1f8d26c1a035aa7 100644
(file)
--- 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