Skip to content

Commit

Permalink
[RISCV] Make getFPImm return a float instead of a uint32_t. NFC
Browse files Browse the repository at this point in the history
The one caller bitcasted the uint32_t to float anyway.
  • Loading branch information
topperc committed Mar 8, 2023
1 parent e65cd4c commit 7fb0b1b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
Expand Up @@ -375,7 +375,7 @@ static inline int getLoadFPImm(uint8_t Sign, uint8_t Exp, uint8_t Mantissa) {
}

namespace RISCVLoadFPImm {
inline static uint32_t getFPImm(unsigned Imm) {
inline static float getFPImm(unsigned Imm) {
assert(Imm != 1 && Imm != 30 && Imm != 31 && "Unsupported immediate");
uint8_t Sign;
uint8_t Exp;
Expand All @@ -391,7 +391,8 @@ inline static uint32_t getFPImm(unsigned Imm) {
Mantissa = LoadFPImmArr[Imm - 1].second;
}

return Sign << 31 | Exp << 23 | Mantissa << 20;
uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 20;
return bit_cast<float>(I);
}

/// getLoadFP32Imm - Return a 5-bit binary encoding of the 32-bit
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
Expand Up @@ -165,7 +165,7 @@ void RISCVInstPrinter::printFPImmOperand(const MCInst *MI, unsigned OpNo,
else if (MO.getImm() == 31)
O << "nan";
else
O << bit_cast<float>(RISCVLoadFPImm::getFPImm(MO.getImm()));
O << RISCVLoadFPImm::getFPImm(MO.getImm());
}

void RISCVInstPrinter::printZeroOffsetMemOp(const MCInst *MI, unsigned OpNo,
Expand Down

0 comments on commit 7fb0b1b

Please sign in to comment.