[libc-commits] [libc] 9baa414 - [libc][NFC] Simplify `BigInt::mul` (#84468)
via libc-commits
libc-commits at lists.llvm.org
Fri Mar 8 05:16:12 PST 2024
Author: Guillaume Chatelet
Date: 2024-03-08T14:16:07+01:00
New Revision: 9baa4140f2b633a8d075f859690139ef2d79b78b
URL: https://github.com/llvm/llvm-project/commit/9baa4140f2b633a8d075f859690139ef2d79b78b
DIFF: https://github.com/llvm/llvm-project/commit/9baa4140f2b633a8d075f859690139ef2d79b78b.diff
LOG: [libc][NFC] Simplify `BigInt::mul` (#84468)
Added:
Modified:
libc/src/__support/UInt.h
Removed:
################################################################################
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