[libc-commits] [libc] [libc][NFC] Simplify `BigInt::mul` (PR #84468)
Guillaume Chatelet via libc-commits
libc-commits at lists.llvm.org
Fri Mar 8 04:08:06 PST 2024
https://github.com/gchatelet created https://github.com/llvm/llvm-project/pull/84468
None
>From 55db80bc24647524e84eb606489c8ad34d7a9d0d Mon Sep 17 00:00:00 2001
From: Guillaume Chatelet <gchatelet at google.com>
Date: Fri, 8 Mar 2024 12:07:46 +0000
Subject: [PATCH] [libc][NFC] Simplify `BigInt::mul`
---
libc/src/__support/UInt.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/libc/src/__support/UInt.h b/libc/src/__support/UInt.h
index cf0c5a669ae8dd..fadccf545006dd 100644
--- a/libc/src/__support/UInt.h
+++ b/libc/src/__support/UInt.h
@@ -262,15 +262,13 @@ struct BigInt {
// Returns the carry value produced by the multiplication operation.
LIBC_INLINE constexpr WordType mul(WordType x) {
BigInt<2 * WORD_SIZE, Signed, WordType> partial_sum(0);
- WordType carry = 0;
for (size_t i = 0; i < WORD_COUNT; ++i) {
NumberPair<WordType> prod = full_mul(val[i], x);
BigInt<2 * WORD_SIZE, Signed, WordType> tmp({prod.lo, prod.hi});
- carry += partial_sum.add(tmp);
+ const WordType carry = partial_sum.add(tmp);
val[i] = partial_sum.val[0];
partial_sum.val[0] = partial_sum.val[1];
partial_sum.val[1] = carry;
- carry = 0;
}
return partial_sum.val[1];
}
More information about the libc-commits
mailing list