Module: Mesa
Branch: main
Commit: 9f7e57ce98aa9609d90336b015e15924b9012e68
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=9f7e57ce98aa9609d90336b015e15924b9012e68

Author: Tatsuyuki Ishi <ishitatsuy...@gmail.com>
Date:   Mon Dec 13 16:10:45 2021 +0900

fast_urem_by_const: #ifdef DEBUG an assertion.

util_fast_urem32 is used in the hot path of hashmap lookups and this
asserts causes noticeable overhead. The correctness of this code should
be well exercised both from testing and mathematical proofs, so gate
this assertion behind #ifdef DEBUG.

Reviewed-by: Alyssa Rosenzweig <aly...@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14168>

---

 src/util/fast_urem_by_const.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/util/fast_urem_by_const.h b/src/util/fast_urem_by_const.h
index beb253d2291..ab0f9d1aee0 100644
--- a/src/util/fast_urem_by_const.h
+++ b/src/util/fast_urem_by_const.h
@@ -68,7 +68,9 @@ util_fast_urem32(uint32_t n, uint32_t d, uint64_t magic)
 {
    uint64_t lowbits = magic * n;
    uint32_t result = _mul32by64_hi(d, lowbits);
+#ifdef DEBUG
    assert(result == n % d);
+#endif
    return result;
 }
 

Reply via email to