[llvm] d704c7a - [RISCV] Move some RISCVLoadFPImm out of line. NFC

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 9 23:22:53 PST 2023


Author: Craig Topper
Date: 2023-03-09T23:22:33-08:00
New Revision: d704c7a6b3656e0a049f3c547ad5e2cbe4539c60

URL: https://github.com/llvm/llvm-project/commit/d704c7a6b3656e0a049f3c547ad5e2cbe4539c60
DIFF: https://github.com/llvm/llvm-project/commit/d704c7a6b3656e0a049f3c547ad5e2cbe4539c60.diff

LOG: [RISCV] Move some RISCVLoadFPImm out of line. NFC

This moves the LoadFPImmArr array to the cpp file. Being in the header
meant it was duplicated in every translation unit that includes the
header.

Move the 2 functions that use the array out of line.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
index 90734c921c22..cad0cb240b11 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
@@ -214,4 +214,52 @@ bool RISCVRVC::uncompress(MCInst &OutInst, const MCInst &MI,
   return uncompressInst(OutInst, MI, STI);
 }
 
+// We expect an 5-bit binary encoding of a floating-point constant here.
+static constexpr std::pair<uint8_t, uint8_t> LoadFPImmArr[] = {
+    {0b00000001, 0b000}, {0b01101111, 0b000}, {0b01110000, 0b000},
+    {0b01110111, 0b000}, {0b01111000, 0b000}, {0b01111011, 0b000},
+    {0b01111100, 0b000}, {0b01111101, 0b000}, {0b01111101, 0b010},
+    {0b01111101, 0b100}, {0b01111101, 0b110}, {0b01111110, 0b000},
+    {0b01111110, 0b010}, {0b01111110, 0b100}, {0b01111110, 0b110},
+    {0b01111111, 0b000}, {0b01111111, 0b010}, {0b01111111, 0b100},
+    {0b01111111, 0b110}, {0b10000000, 0b000}, {0b10000000, 0b010},
+    {0b10000000, 0b100}, {0b10000001, 0b000}, {0b10000010, 0b000},
+    {0b10000011, 0b000}, {0b10000110, 0b000}, {0b10000111, 0b000},
+    {0b10001110, 0b000}, {0b10001111, 0b000}, {0b11111111, 0b000},
+    {0b11111111, 0b100},
+};
+
+int RISCVLoadFPImm::getLoadFPImm(uint8_t Sign, uint8_t Exp, uint8_t Mantissa) {
+  if (Sign == 0b1 && Exp == 0b01111111 && Mantissa == 0b000)
+    return 0;
+
+  if (Sign == 0b0) {
+    auto EMI = llvm::find(LoadFPImmArr, std::make_pair(Exp, Mantissa));
+    if (EMI != std::end(LoadFPImmArr))
+      return std::distance(std::begin(LoadFPImmArr), EMI) + 1;
+  }
+
+  return -1;
+}
+
+float RISCVLoadFPImm::getFPImm(unsigned Imm) {
+  assert(Imm != 1 && Imm != 30 && Imm != 31 && "Unsupported immediate");
+  uint8_t Sign;
+  uint8_t Exp;
+  uint8_t Mantissa;
+
+  if (Imm == 0) {
+    Sign = 0b1;
+    Exp = 0b01111111;
+    Mantissa = 0b000;
+  } else {
+    Sign = 0b0;
+    Exp = LoadFPImmArr[Imm - 1].first;
+    Mantissa = LoadFPImmArr[Imm - 1].second;
+  }
+
+  uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 20;
+  return bit_cast<float>(I);
+}
+
 } // namespace llvm

diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
index afefdd28ce1f..430e0da3fd16 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -346,54 +346,9 @@ inline static bool isValidRoundingMode(unsigned Mode) {
 // Floating-point Immediates
 //
 
-// We expect an 5-bit binary encoding of a floating-point constant here.
-static const std::pair<uint8_t, uint8_t> LoadFPImmArr[] = {
-    {0b00000001, 0b000}, {0b01101111, 0b000}, {0b01110000, 0b000},
-    {0b01110111, 0b000}, {0b01111000, 0b000}, {0b01111011, 0b000},
-    {0b01111100, 0b000}, {0b01111101, 0b000}, {0b01111101, 0b010},
-    {0b01111101, 0b100}, {0b01111101, 0b110}, {0b01111110, 0b000},
-    {0b01111110, 0b010}, {0b01111110, 0b100}, {0b01111110, 0b110},
-    {0b01111111, 0b000}, {0b01111111, 0b010}, {0b01111111, 0b100},
-    {0b01111111, 0b110}, {0b10000000, 0b000}, {0b10000000, 0b010},
-    {0b10000000, 0b100}, {0b10000001, 0b000}, {0b10000010, 0b000},
-    {0b10000011, 0b000}, {0b10000110, 0b000}, {0b10000111, 0b000},
-    {0b10001110, 0b000}, {0b10001111, 0b000}, {0b11111111, 0b000},
-    {0b11111111, 0b100},
-};
-
-static inline int getLoadFPImm(uint8_t Sign, uint8_t Exp, uint8_t Mantissa) {
-  if (Sign == 0b1 && Exp == 0b01111111 && Mantissa == 0b000)
-    return 0;
-
-  if (Sign == 0b0) {
-    auto EMI = llvm::find(LoadFPImmArr, std::make_pair(Exp, Mantissa));
-    if (EMI != std::end(LoadFPImmArr))
-      return std::distance(std::begin(LoadFPImmArr), EMI) + 1;
-  }
-
-  return -1;
-}
-
 namespace RISCVLoadFPImm {
-inline static float getFPImm(unsigned Imm) {
-  assert(Imm != 1 && Imm != 30 && Imm != 31 && "Unsupported immediate");
-  uint8_t Sign;
-  uint8_t Exp;
-  uint8_t Mantissa;
-
-  if (Imm == 0) {
-    Sign = 0b1;
-    Exp = 0b01111111;
-    Mantissa = 0b000;
-  } else {
-    Sign = 0b0;
-    Exp = LoadFPImmArr[Imm - 1].first;
-    Mantissa = LoadFPImmArr[Imm - 1].second;
-  }
-
-  uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 20;
-  return bit_cast<float>(I);
-}
+int getLoadFPImm(uint8_t Sign, uint8_t Exp, uint8_t Mantissa);
+float getFPImm(unsigned Imm);
 
 /// getLoadFP32Imm - Return a 5-bit binary encoding of the 32-bit
 /// floating-point immediate value. If the value cannot be represented as a


        


More information about the llvm-commits mailing list