Mesa (master): util: document a limitation of util_fast_udiv32
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Oct 17 16:28:36 UTC 2018
Module: Mesa
Branch: master
Commit: 669dd229835122143ff49b0c921e69a3a31ed46b
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=669dd229835122143ff49b0c921e69a3a31ed46b
Author: Marek Olšák <marek.olsak at amd.com>
Date: Sat Sep 22 20:03:27 2018 -0400
util: document a limitation of util_fast_udiv32
trivial
---
src/util/fast_idiv_by_const.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/util/fast_idiv_by_const.h b/src/util/fast_idiv_by_const.h
index 92a3ccdf22..638b52a3ff 100644
--- a/src/util/fast_idiv_by_const.h
+++ b/src/util/fast_idiv_by_const.h
@@ -135,7 +135,13 @@ static inline uint32_t
util_fast_udiv32(uint32_t n, struct util_fast_udiv_info info)
{
n = n >> info.pre_shift;
- /* For non-power-of-two divisors, use a 32-bit ADD that clamps to UINT_MAX. */
+ /* If the divisor is not 1, you can instead use a 32-bit ADD that clamps
+ * to UINT_MAX. Dividing by 1 needs the full 64-bit ADD.
+ *
+ * If you have unsigned 64-bit MAD with 32-bit inputs, you can do:
+ * increment = increment ? multiplier : 0; // on the CPU
+ * (n * multiplier + increment) // on the GPU using unsigned 64-bit MAD
+ */
n = (((uint64_t)n + info.increment) * info.multiplier) >> 32;
n = n >> info.post_shift;
return n;
More information about the mesa-commit
mailing list