[llvm] c9992c9 - [RISCV] Remove one bit of mantissa in RISCVLoadFPImm related code.
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 10 19:17:24 PST 2023
Author: Craig Topper
Date: 2023-03-10T19:14:44-08:00
New Revision: c9992c9ac0534c04644967838cb665f72426b60a
URL: https://github.com/llvm/llvm-project/commit/c9992c9ac0534c04644967838cb665f72426b60a
DIFF: https://github.com/llvm/llvm-project/commit/c9992c9ac0534c04644967838cb665f72426b60a.diff
LOG: [RISCV] Remove one bit of mantissa in RISCVLoadFPImm related code.
We only need 2 bits of mantissa. The third bit was always 0.
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 9ac8d05d3574..3a931c94fa94 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
@@ -216,21 +216,21 @@ bool RISCVRVC::uncompress(MCInst &OutInst, const MCInst &MI,
// 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},
+ {0b00000001, 0b00}, {0b01101111, 0b00}, {0b01110000, 0b00},
+ {0b01110111, 0b00}, {0b01111000, 0b00}, {0b01111011, 0b00},
+ {0b01111100, 0b00}, {0b01111101, 0b00}, {0b01111101, 0b01},
+ {0b01111101, 0b10}, {0b01111101, 0b11}, {0b01111110, 0b00},
+ {0b01111110, 0b01}, {0b01111110, 0b10}, {0b01111110, 0b11},
+ {0b01111111, 0b00}, {0b01111111, 0b01}, {0b01111111, 0b10},
+ {0b01111111, 0b11}, {0b10000000, 0b00}, {0b10000000, 0b01},
+ {0b10000000, 0b10}, {0b10000001, 0b00}, {0b10000010, 0b00},
+ {0b10000011, 0b00}, {0b10000110, 0b00}, {0b10000111, 0b00},
+ {0b10001110, 0b00}, {0b10001111, 0b00}, {0b11111111, 0b00},
+ {0b11111111, 0b10},
};
int RISCVLoadFPImm::getLoadFPImm(uint8_t Sign, uint8_t Exp, uint8_t Mantissa) {
- if (Sign == 0b1 && Exp == 0b01111111 && Mantissa == 0b000)
+ if (Sign == 0b1 && Exp == 0b01111111 && Mantissa == 0b00)
return 0;
if (Sign == 0b0) {
@@ -252,14 +252,14 @@ float RISCVLoadFPImm::getFPImm(unsigned Imm) {
if (Imm == 0) {
Sign = 0b1;
Exp = 0b01111111;
- Mantissa = 0b000;
+ Mantissa = 0b00;
} else {
Sign = 0b0;
Exp = LoadFPImmArr[Imm - 1].first;
Mantissa = LoadFPImmArr[Imm - 1].second;
}
- uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 20;
+ uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 21;
return bit_cast<float>(I);
}
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
index 430e0da3fd16..605054b65323 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -354,12 +354,12 @@ float getFPImm(unsigned Imm);
/// floating-point immediate value. If the value cannot be represented as a
/// 5-bit binary encoding, then return -1.
static inline int getLoadFP32Imm(const APInt &Imm) {
- if (Imm.extractBitsAsZExtValue(20, 0) != 0)
+ if (Imm.extractBitsAsZExtValue(21, 0) != 0)
return -1;
uint8_t Sign = Imm.extractBitsAsZExtValue(1, 31);
uint8_t Exp = Imm.extractBitsAsZExtValue(8, 23);
- uint8_t Mantissa = Imm.extractBitsAsZExtValue(3, 20);
+ uint8_t Mantissa = Imm.extractBitsAsZExtValue(2, 21);
return getLoadFPImm(Sign, Exp, Mantissa);
}
@@ -371,11 +371,11 @@ static inline int getLoadFP32Imm(const APFloat &FPImm) {
/// floating-point immediate value. If the value cannot be represented as a
/// 5-bit binary encoding, then return -1.
static inline int getLoadFP64Imm(const APInt &Imm) {
- if (Imm.extractBitsAsZExtValue(49, 0) != 0)
+ if (Imm.extractBitsAsZExtValue(50, 0) != 0)
return -1;
uint8_t Sign = Imm.extractBitsAsZExtValue(1, 63);
- uint8_t Mantissa = Imm.extractBitsAsZExtValue(3, 49);
+ uint8_t Mantissa = Imm.extractBitsAsZExtValue(2, 50);
uint8_t Exp;
if (Imm.extractBitsAsZExtValue(11, 52) == 1)
Exp = 0b00000001;
@@ -395,11 +395,11 @@ static inline int getLoadFP64Imm(const APFloat &FPImm) {
/// floating-point immediate value. If the value cannot be represented as a
/// 5-bit binary encoding, then return -1.
static inline int getLoadFP16Imm(const APInt &Imm) {
- if (Imm.extractBitsAsZExtValue(7, 0) != 0)
+ if (Imm.extractBitsAsZExtValue(8, 0) != 0)
return -1;
uint8_t Sign = Imm.extractBitsAsZExtValue(1, 15);
- uint8_t Mantissa = Imm.extractBitsAsZExtValue(3, 7);
+ uint8_t Mantissa = Imm.extractBitsAsZExtValue(2, 8);
uint8_t Exp;
if (Imm.extractBitsAsZExtValue(5, 10) == 1)
Exp = 0b00000001;
More information about the llvm-commits
mailing list