[clang] [llvm] [RFC][AMDGPU] Use `bf16` instead of `i16` for bfloat (PR #80908)
Shilei Tian via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 13 16:00:05 PST 2024
================
@@ -488,6 +488,49 @@ static bool printImmediateFloat16(uint32_t Imm, const MCSubtargetInfo &STI,
return true;
}
+static bool printImmediateBFloat16(uint32_t Imm, const MCSubtargetInfo &STI,
+ raw_ostream &O) {
+ if (Imm == 0x3F80)
+ O << "1.0";
+ else if (Imm == 0xBF80)
+ O << "-1.0";
+ else if (Imm == 0x3F00)
+ O << "0.5";
+ else if (Imm == 0xBF00)
+ O << "-0.5";
+ else if (Imm == 0x4000)
+ O << "2.0";
+ else if (Imm == 0xC000)
+ O << "-2.0";
+ else if (Imm == 0x4080)
+ O << "4.0";
+ else if (Imm == 0xC080)
+ O << "-4.0";
+ else if (Imm == 0x3E22 && STI.hasFeature(AMDGPU::FeatureInv2PiInlineImm))
+ O << "0.15915494";
+ else
+ return false;
+
+ return true;
+}
+
+void AMDGPUInstPrinter::printImmediateBF16(uint32_t Imm,
+ const MCSubtargetInfo &STI,
+ raw_ostream &O) {
+ int16_t SImm = static_cast<int16_t>(Imm);
+ if (isInlinableIntLiteral(SImm)) {
+ O << SImm;
+ return;
+ }
+
+ uint16_t HImm = static_cast<uint16_t>(Imm);
+ if (printImmediateBFloat16(HImm, STI, O))
+ return;
+
+ uint64_t Imm16 = static_cast<uint16_t>(Imm);
----------------
shiltian wrote:
Yeah, but it is to make the type promoted to `uint64_t` w/o any ambiguity.
https://github.com/llvm/llvm-project/pull/80908
More information about the llvm-commits
mailing list