[llvm] [APFloat] Replace partsCount array with single variable (NFC) (PR #91910)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun May 12 20:06:03 PDT 2024
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/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.
>From 7cdab4b06ee35e52d0e1c2e722e35259e4ed92e6 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Mon, 13 May 2024 11:53:35 +0900
Subject: [PATCH] [APFloat] Replace partsCount array with single variable
(NFCI)
We only ever use the last element of this array, so there shouldn't
be a need to store the preceding elements as well.
---
llvm/lib/Support/APFloat.cpp | 25 ++++++++++---------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 64a7e0c7223f0..2a9b3903720be 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -732,7 +732,7 @@ powerOf5(APFloatBase::integerPart *dst, unsigned int power) {
APFloatBase::integerPart pow5s[maxPowerOfFiveParts * 2 + 5];
pow5s[0] = 78125 * 5;
- unsigned int partsCount[16] = { 1 };
+ unsigned int partsCount = 1;
APFloatBase::integerPart scratch[maxPowerOfFiveParts], *p1, *p2, *pow5;
unsigned int result;
assert(power <= maxExponent);
@@ -747,25 +747,20 @@ powerOf5(APFloatBase::integerPart *dst, unsigned int power) {
pow5 = pow5s;
for (unsigned int n = 0; power; power >>= 1, n++) {
- unsigned int pc;
-
- pc = partsCount[n];
-
/* Calculate pow(5,pow(2,n+3)) if we haven't yet. */
- if (pc == 0) {
- pc = partsCount[n - 1];
- APInt::tcFullMultiply(pow5, pow5 - pc, pow5 - pc, pc, pc);
- pc *= 2;
- if (pow5[pc - 1] == 0)
- pc--;
- partsCount[n] = pc;
+ if (n != 0) {
+ APInt::tcFullMultiply(pow5, pow5 - partsCount, pow5 - partsCount,
+ partsCount, partsCount);
+ partsCount *= 2;
+ if (pow5[partsCount - 1] == 0)
+ partsCount--;
}
if (power & 1) {
APFloatBase::integerPart *tmp;
- APInt::tcFullMultiply(p2, p1, pow5, result, pc);
- result += pc;
+ APInt::tcFullMultiply(p2, p1, pow5, result, partsCount);
+ result += partsCount;
if (p2[result - 1] == 0)
result--;
@@ -776,7 +771,7 @@ powerOf5(APFloatBase::integerPart *dst, unsigned int power) {
p2 = tmp;
}
- pow5 += pc;
+ pow5 += partsCount;
}
if (p1 != dst)
More information about the llvm-commits
mailing list