[llvm] 25b6d04 - [RISCV] Use binary search for RISCVLoadFPImm::getLoadFPImm.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 10 00:03:08 PST 2023
Author: Craig Topper
Date: 2023-03-10T00:02:35-08:00
New Revision: 25b6d04ad58f4f3b2e9728fe060a433e0e415c92
URL: https://github.com/llvm/llvm-project/commit/25b6d04ad58f4f3b2e9728fe060a433e0e415c92
DIFF: https://github.com/llvm/llvm-project/commit/25b6d04ad58f4f3b2e9728fe060a433e0e415c92.diff
LOG: [RISCV] Use binary search for RISCVLoadFPImm::getLoadFPImm.
The table is sorted so we can use a binary search instead of a
linear scan.
Added:
Modified:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
index cad0cb240b11..9ac8d05d3574 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
@@ -234,8 +234,9 @@ int RISCVLoadFPImm::getLoadFPImm(uint8_t Sign, uint8_t Exp, uint8_t Mantissa) {
return 0;
if (Sign == 0b0) {
- auto EMI = llvm::find(LoadFPImmArr, std::make_pair(Exp, Mantissa));
- if (EMI != std::end(LoadFPImmArr))
+ auto EMI = llvm::lower_bound(LoadFPImmArr, std::make_pair(Exp, Mantissa));
+ if (EMI != std::end(LoadFPImmArr) && EMI->first == Exp &&
+ EMI->second == Mantissa)
return std::distance(std::begin(LoadFPImmArr), EMI) + 1;
}
More information about the llvm-commits
mailing list