Skip to content

Commit 595de12

Browse files
authored
[APFloat] Replace partsCount array with single variable (NFC) (#91910)
We only ever use the last element of this array, so there shouldn't be a need to store the preceding elements as well.
1 parent ad1083d commit 595de12

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

llvm/lib/Support/APFloat.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ powerOf5(APFloatBase::integerPart *dst, unsigned int power) {
732732
APFloatBase::integerPart pow5s[maxPowerOfFiveParts * 2 + 5];
733733
pow5s[0] = 78125 * 5;
734734

735-
unsigned int partsCount[16] = { 1 };
735+
unsigned int partsCount = 1;
736736
APFloatBase::integerPart scratch[maxPowerOfFiveParts], *p1, *p2, *pow5;
737737
unsigned int result;
738738
assert(power <= maxExponent);
@@ -747,25 +747,20 @@ powerOf5(APFloatBase::integerPart *dst, unsigned int power) {
747747
pow5 = pow5s;
748748

749749
for (unsigned int n = 0; power; power >>= 1, n++) {
750-
unsigned int pc;
751-
752-
pc = partsCount[n];
753-
754750
/* Calculate pow(5,pow(2,n+3)) if we haven't yet. */
755-
if (pc == 0) {
756-
pc = partsCount[n - 1];
757-
APInt::tcFullMultiply(pow5, pow5 - pc, pow5 - pc, pc, pc);
758-
pc *= 2;
759-
if (pow5[pc - 1] == 0)
760-
pc--;
761-
partsCount[n] = pc;
751+
if (n != 0) {
752+
APInt::tcFullMultiply(pow5, pow5 - partsCount, pow5 - partsCount,
753+
partsCount, partsCount);
754+
partsCount *= 2;
755+
if (pow5[partsCount - 1] == 0)
756+
partsCount--;
762757
}
763758

764759
if (power & 1) {
765760
APFloatBase::integerPart *tmp;
766761

767-
APInt::tcFullMultiply(p2, p1, pow5, result, pc);
768-
result += pc;
762+
APInt::tcFullMultiply(p2, p1, pow5, result, partsCount);
763+
result += partsCount;
769764
if (p2[result - 1] == 0)
770765
result--;
771766

@@ -776,7 +771,7 @@ powerOf5(APFloatBase::integerPart *dst, unsigned int power) {
776771
p2 = tmp;
777772
}
778773

779-
pow5 += pc;
774+
pow5 += partsCount;
780775
}
781776

782777
if (p1 != dst)

0 commit comments

Comments
 (0)