Skip to content

Commit c9992c9

Browse files
committed
[RISCV] Remove one bit of mantissa in RISCVLoadFPImm related code.
We only need 2 bits of mantissa. The third bit was always 0.
1 parent b7021a3 commit c9992c9

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,21 @@ bool RISCVRVC::uncompress(MCInst &OutInst, const MCInst &MI,
216216

217217
// We expect an 5-bit binary encoding of a floating-point constant here.
218218
static constexpr std::pair<uint8_t, uint8_t> LoadFPImmArr[] = {
219-
{0b00000001, 0b000}, {0b01101111, 0b000}, {0b01110000, 0b000},
220-
{0b01110111, 0b000}, {0b01111000, 0b000}, {0b01111011, 0b000},
221-
{0b01111100, 0b000}, {0b01111101, 0b000}, {0b01111101, 0b010},
222-
{0b01111101, 0b100}, {0b01111101, 0b110}, {0b01111110, 0b000},
223-
{0b01111110, 0b010}, {0b01111110, 0b100}, {0b01111110, 0b110},
224-
{0b01111111, 0b000}, {0b01111111, 0b010}, {0b01111111, 0b100},
225-
{0b01111111, 0b110}, {0b10000000, 0b000}, {0b10000000, 0b010},
226-
{0b10000000, 0b100}, {0b10000001, 0b000}, {0b10000010, 0b000},
227-
{0b10000011, 0b000}, {0b10000110, 0b000}, {0b10000111, 0b000},
228-
{0b10001110, 0b000}, {0b10001111, 0b000}, {0b11111111, 0b000},
229-
{0b11111111, 0b100},
219+
{0b00000001, 0b00}, {0b01101111, 0b00}, {0b01110000, 0b00},
220+
{0b01110111, 0b00}, {0b01111000, 0b00}, {0b01111011, 0b00},
221+
{0b01111100, 0b00}, {0b01111101, 0b00}, {0b01111101, 0b01},
222+
{0b01111101, 0b10}, {0b01111101, 0b11}, {0b01111110, 0b00},
223+
{0b01111110, 0b01}, {0b01111110, 0b10}, {0b01111110, 0b11},
224+
{0b01111111, 0b00}, {0b01111111, 0b01}, {0b01111111, 0b10},
225+
{0b01111111, 0b11}, {0b10000000, 0b00}, {0b10000000, 0b01},
226+
{0b10000000, 0b10}, {0b10000001, 0b00}, {0b10000010, 0b00},
227+
{0b10000011, 0b00}, {0b10000110, 0b00}, {0b10000111, 0b00},
228+
{0b10001110, 0b00}, {0b10001111, 0b00}, {0b11111111, 0b00},
229+
{0b11111111, 0b10},
230230
};
231231

232232
int RISCVLoadFPImm::getLoadFPImm(uint8_t Sign, uint8_t Exp, uint8_t Mantissa) {
233-
if (Sign == 0b1 && Exp == 0b01111111 && Mantissa == 0b000)
233+
if (Sign == 0b1 && Exp == 0b01111111 && Mantissa == 0b00)
234234
return 0;
235235

236236
if (Sign == 0b0) {
@@ -252,14 +252,14 @@ float RISCVLoadFPImm::getFPImm(unsigned Imm) {
252252
if (Imm == 0) {
253253
Sign = 0b1;
254254
Exp = 0b01111111;
255-
Mantissa = 0b000;
255+
Mantissa = 0b00;
256256
} else {
257257
Sign = 0b0;
258258
Exp = LoadFPImmArr[Imm - 1].first;
259259
Mantissa = LoadFPImmArr[Imm - 1].second;
260260
}
261261

262-
uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 20;
262+
uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 21;
263263
return bit_cast<float>(I);
264264
}
265265

llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,12 @@ float getFPImm(unsigned Imm);
354354
/// floating-point immediate value. If the value cannot be represented as a
355355
/// 5-bit binary encoding, then return -1.
356356
static inline int getLoadFP32Imm(const APInt &Imm) {
357-
if (Imm.extractBitsAsZExtValue(20, 0) != 0)
357+
if (Imm.extractBitsAsZExtValue(21, 0) != 0)
358358
return -1;
359359

360360
uint8_t Sign = Imm.extractBitsAsZExtValue(1, 31);
361361
uint8_t Exp = Imm.extractBitsAsZExtValue(8, 23);
362-
uint8_t Mantissa = Imm.extractBitsAsZExtValue(3, 20);
362+
uint8_t Mantissa = Imm.extractBitsAsZExtValue(2, 21);
363363
return getLoadFPImm(Sign, Exp, Mantissa);
364364
}
365365

@@ -371,11 +371,11 @@ static inline int getLoadFP32Imm(const APFloat &FPImm) {
371371
/// floating-point immediate value. If the value cannot be represented as a
372372
/// 5-bit binary encoding, then return -1.
373373
static inline int getLoadFP64Imm(const APInt &Imm) {
374-
if (Imm.extractBitsAsZExtValue(49, 0) != 0)
374+
if (Imm.extractBitsAsZExtValue(50, 0) != 0)
375375
return -1;
376376

377377
uint8_t Sign = Imm.extractBitsAsZExtValue(1, 63);
378-
uint8_t Mantissa = Imm.extractBitsAsZExtValue(3, 49);
378+
uint8_t Mantissa = Imm.extractBitsAsZExtValue(2, 50);
379379
uint8_t Exp;
380380
if (Imm.extractBitsAsZExtValue(11, 52) == 1)
381381
Exp = 0b00000001;
@@ -395,11 +395,11 @@ static inline int getLoadFP64Imm(const APFloat &FPImm) {
395395
/// floating-point immediate value. If the value cannot be represented as a
396396
/// 5-bit binary encoding, then return -1.
397397
static inline int getLoadFP16Imm(const APInt &Imm) {
398-
if (Imm.extractBitsAsZExtValue(7, 0) != 0)
398+
if (Imm.extractBitsAsZExtValue(8, 0) != 0)
399399
return -1;
400400

401401
uint8_t Sign = Imm.extractBitsAsZExtValue(1, 15);
402-
uint8_t Mantissa = Imm.extractBitsAsZExtValue(3, 7);
402+
uint8_t Mantissa = Imm.extractBitsAsZExtValue(2, 8);
403403
uint8_t Exp;
404404
if (Imm.extractBitsAsZExtValue(5, 10) == 1)
405405
Exp = 0b00000001;

0 commit comments

Comments
 (0)