Skip to content

Commit d8f1e5d

Browse files
authored
[APInt] Remove accumulator initialization from tcMultiply and tcFullMultiply. NFCI (#88202)
The tcMultiplyPart routine has a flag that says whether to add to the accumulator or overwrite it. By using the overwrite mode on the first iteration we don't need to initialize the accumulator to zero. Note, the initialization in tcFullMultiply was only initializing the first rhsParts of dst. tcMultiplyPart always overwrites the rhsParts+1 part that just contains the last carry. The first write to each part of dst past rhsParts is a carry write so that's how the upper part of dst is initialized.
1 parent 9f6d08f commit d8f1e5d

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

llvm/lib/Support/APInt.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,11 +2585,13 @@ int APInt::tcMultiply(WordType *dst, const WordType *lhs,
25852585
assert(dst != lhs && dst != rhs);
25862586

25872587
int overflow = 0;
2588-
tcSet(dst, 0, parts);
25892588

2590-
for (unsigned i = 0; i < parts; i++)
2591-
overflow |= tcMultiplyPart(&dst[i], lhs, rhs[i], 0, parts,
2592-
parts - i, true);
2589+
for (unsigned i = 0; i < parts; i++) {
2590+
// Don't accumulate on the first iteration so we don't need to initalize
2591+
// dst to 0.
2592+
overflow |=
2593+
tcMultiplyPart(&dst[i], lhs, rhs[i], 0, parts, parts - i, i != 0);
2594+
}
25932595

25942596
return overflow;
25952597
}
@@ -2605,10 +2607,11 @@ void APInt::tcFullMultiply(WordType *dst, const WordType *lhs,
26052607

26062608
assert(dst != lhs && dst != rhs);
26072609

2608-
tcSet(dst, 0, rhsParts);
2609-
2610-
for (unsigned i = 0; i < lhsParts; i++)
2611-
tcMultiplyPart(&dst[i], rhs, lhs[i], 0, rhsParts, rhsParts + 1, true);
2610+
for (unsigned i = 0; i < lhsParts; i++) {
2611+
// Don't accumulate on the first iteration so we don't need to initalize
2612+
// dst to 0.
2613+
tcMultiplyPart(&dst[i], rhs, lhs[i], 0, rhsParts, rhsParts + 1, i != 0);
2614+
}
26122615
}
26132616

26142617
// If RHS is zero LHS and REMAINDER are left unchanged, return one.

0 commit comments

Comments
 (0)