2012-12-11 22:25:42 +01:00
|
|
|
//===-- AMDGPUInstPrinter.cpp - AMDGPU MC Inst -> ASM ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
// \file
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPUInstPrinter.h"
|
2015-01-14 12:23:27 +01:00
|
|
|
#include "SIDefines.h"
|
2016-09-30 19:01:40 +02:00
|
|
|
#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
|
2016-05-26 19:00:33 +02:00
|
|
|
#include "Utils/AMDGPUAsmUtils.h"
|
2016-09-30 19:01:40 +02:00
|
|
|
#include "Utils/AMDGPUBaseInfo.h"
|
2013-02-21 16:17:22 +01:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2013-05-23 19:10:37 +02:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2014-12-17 22:04:08 +01:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2014-04-16 00:32:49 +02:00
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2016-09-30 19:01:40 +02:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2014-04-16 00:32:49 +02:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2015-12-25 23:10:01 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-11 22:25:42 +01:00
|
|
|
|
2016-04-13 18:18:41 +02:00
|
|
|
#include <string>
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
using namespace llvm;
|
2016-09-30 19:01:40 +02:00
|
|
|
using namespace llvm::AMDGPU;
|
2012-12-11 22:25:42 +01:00
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
|
2015-03-27 21:36:02 +01:00
|
|
|
StringRef Annot, const MCSubtargetInfo &STI) {
|
2013-05-02 23:52:30 +02:00
|
|
|
OS.flush();
|
2016-09-27 16:42:48 +02:00
|
|
|
printInstruction(MI, STI, OS);
|
2012-12-11 22:25:42 +01:00
|
|
|
printAnnotation(OS, Annot);
|
|
|
|
}
|
|
|
|
|
2016-03-09 13:29:31 +01:00
|
|
|
void AMDGPUInstPrinter::printU4ImmOperand(const MCInst *MI, unsigned OpNo,
|
2016-10-12 20:00:51 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-09-27 16:42:48 +02:00
|
|
|
raw_ostream &O) {
|
2016-03-09 13:29:31 +01:00
|
|
|
O << formatHex(MI->getOperand(OpNo).getImm() & 0xf);
|
|
|
|
}
|
|
|
|
|
2014-04-16 00:32:49 +02:00
|
|
|
void AMDGPUInstPrinter::printU8ImmOperand(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
raw_ostream &O) {
|
2014-04-16 00:32:49 +02:00
|
|
|
O << formatHex(MI->getOperand(OpNo).getImm() & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2014-04-16 00:32:49 +02:00
|
|
|
raw_ostream &O) {
|
|
|
|
O << formatHex(MI->getOperand(OpNo).getImm() & 0xffff);
|
|
|
|
}
|
|
|
|
|
2016-03-09 13:29:31 +01:00
|
|
|
void AMDGPUInstPrinter::printU4ImmDecOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
O << formatDec(MI->getOperand(OpNo).getImm() & 0xf);
|
|
|
|
}
|
|
|
|
|
2014-10-11 00:16:07 +02:00
|
|
|
void AMDGPUInstPrinter::printU8ImmDecOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
O << formatDec(MI->getOperand(OpNo).getImm() & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printU16ImmDecOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
O << formatDec(MI->getOperand(OpNo).getImm() & 0xffff);
|
|
|
|
}
|
|
|
|
|
2016-09-27 16:42:48 +02:00
|
|
|
void AMDGPUInstPrinter::printU32ImmOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
|
|
|
O << formatHex(MI->getOperand(OpNo).getImm() & 0xffffffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printNamedBit(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O, StringRef BitName) {
|
2016-02-26 10:51:05 +01:00
|
|
|
if (MI->getOperand(OpNo).getImm()) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << ' ' << BitName;
|
2016-02-26 10:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:48:12 +02:00
|
|
|
void AMDGPUInstPrinter::printOffen(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "offen");
|
2014-08-05 16:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printIdxen(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "idxen");
|
2014-08-05 16:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printAddr64(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "addr64");
|
2014-08-05 16:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printMBUFOffset(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
if (MI->getOperand(OpNo).getImm()) {
|
|
|
|
O << " offset:";
|
2014-12-03 04:12:13 +01:00
|
|
|
printU16ImmDecOperand(MI, OpNo, O);
|
2014-08-05 16:48:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printOffset(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2014-10-11 00:16:07 +02:00
|
|
|
uint16_t Imm = MI->getOperand(OpNo).getImm();
|
|
|
|
if (Imm != 0) {
|
|
|
|
O << " offset:";
|
|
|
|
printU16ImmDecOperand(MI, OpNo, O);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printOffset0(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2015-04-08 03:09:19 +02:00
|
|
|
if (MI->getOperand(OpNo).getImm()) {
|
|
|
|
O << " offset0:";
|
|
|
|
printU8ImmDecOperand(MI, OpNo, O);
|
|
|
|
}
|
2014-10-11 00:16:07 +02:00
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printOffset1(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2015-04-08 03:09:19 +02:00
|
|
|
if (MI->getOperand(OpNo).getImm()) {
|
|
|
|
O << " offset1:";
|
|
|
|
printU8ImmDecOperand(MI, OpNo, O);
|
|
|
|
}
|
2014-10-11 00:16:07 +02:00
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printSMRDOffset(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-04-29 11:02:30 +02:00
|
|
|
raw_ostream &O) {
|
2016-09-27 16:42:48 +02:00
|
|
|
printU32ImmOperand(MI, OpNo, STI, O);
|
2016-04-29 11:02:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printSMRDLiteralOffset(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-04-29 11:02:30 +02:00
|
|
|
raw_ostream &O) {
|
2016-09-27 16:42:48 +02:00
|
|
|
printU32ImmOperand(MI, OpNo, STI, O);
|
2016-04-29 11:02:30 +02:00
|
|
|
}
|
|
|
|
|
2015-03-09 19:49:54 +01:00
|
|
|
void AMDGPUInstPrinter::printGDS(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "gds");
|
2015-03-09 19:49:54 +01:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:48:12 +02:00
|
|
|
void AMDGPUInstPrinter::printGLC(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "glc");
|
2014-08-05 16:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printSLC(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "slc");
|
2014-08-05 16:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printTFE(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "tfe");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printDMask(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
if (MI->getOperand(OpNo).getImm()) {
|
|
|
|
O << " dmask:";
|
2016-09-27 16:42:48 +02:00
|
|
|
printU16ImmOperand(MI, OpNo, STI, O);
|
2016-02-26 10:51:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printUNorm(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "unorm");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printDA(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "da");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printR128(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "r128");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printLWE(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-02-26 10:51:05 +01:00
|
|
|
printNamedBit(MI, OpNo, O, "lwe");
|
2014-08-05 16:48:12 +02:00
|
|
|
}
|
|
|
|
|
2016-09-27 16:42:48 +02:00
|
|
|
void AMDGPUInstPrinter::printRegOperand(unsigned RegNo, raw_ostream &O,
|
2015-04-08 03:09:26 +02:00
|
|
|
const MCRegisterInfo &MRI) {
|
2016-09-27 16:42:48 +02:00
|
|
|
switch (RegNo) {
|
2013-11-12 03:35:51 +01:00
|
|
|
case AMDGPU::VCC:
|
|
|
|
O << "vcc";
|
|
|
|
return;
|
|
|
|
case AMDGPU::SCC:
|
|
|
|
O << "scc";
|
|
|
|
return;
|
|
|
|
case AMDGPU::EXEC:
|
|
|
|
O << "exec";
|
|
|
|
return;
|
|
|
|
case AMDGPU::M0:
|
|
|
|
O << "m0";
|
|
|
|
return;
|
2014-09-15 17:41:53 +02:00
|
|
|
case AMDGPU::FLAT_SCR:
|
|
|
|
O << "flat_scratch";
|
|
|
|
return;
|
|
|
|
case AMDGPU::VCC_LO:
|
|
|
|
O << "vcc_lo";
|
|
|
|
return;
|
|
|
|
case AMDGPU::VCC_HI:
|
|
|
|
O << "vcc_hi";
|
|
|
|
return;
|
2016-04-13 18:18:41 +02:00
|
|
|
case AMDGPU::TBA_LO:
|
|
|
|
O << "tba_lo";
|
|
|
|
return;
|
|
|
|
case AMDGPU::TBA_HI:
|
|
|
|
O << "tba_hi";
|
|
|
|
return;
|
|
|
|
case AMDGPU::TMA_LO:
|
|
|
|
O << "tma_lo";
|
|
|
|
return;
|
|
|
|
case AMDGPU::TMA_HI:
|
|
|
|
O << "tma_hi";
|
|
|
|
return;
|
2014-09-15 17:41:53 +02:00
|
|
|
case AMDGPU::EXEC_LO:
|
|
|
|
O << "exec_lo";
|
|
|
|
return;
|
|
|
|
case AMDGPU::EXEC_HI:
|
|
|
|
O << "exec_hi";
|
|
|
|
return;
|
|
|
|
case AMDGPU::FLAT_SCR_LO:
|
|
|
|
O << "flat_scratch_lo";
|
|
|
|
return;
|
|
|
|
case AMDGPU::FLAT_SCR_HI:
|
|
|
|
O << "flat_scratch_hi";
|
|
|
|
return;
|
2013-11-12 03:35:51 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-07-06 00:06:56 +02:00
|
|
|
// The low 8 bits of the encoding value is the register index, for both VGPRs
|
|
|
|
// and SGPRs.
|
2016-09-27 16:42:48 +02:00
|
|
|
unsigned RegIdx = MRI.getEncodingValue(RegNo) & ((1 << 8) - 1);
|
2014-04-16 00:32:42 +02:00
|
|
|
|
2016-07-06 00:06:56 +02:00
|
|
|
unsigned NumRegs;
|
2016-09-27 16:42:48 +02:00
|
|
|
if (MRI.getRegClass(AMDGPU::VGPR_32RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 'v';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 1;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::SGPR_32RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 's';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 1;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::VReg_64RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O <<'v';
|
2016-04-13 18:18:41 +02:00
|
|
|
NumRegs = 2;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::SGPR_64RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 's';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 2;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::VReg_128RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 'v';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 4;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::SGPR_128RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 's';
|
2016-04-29 19:04:50 +02:00
|
|
|
NumRegs = 4;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::VReg_96RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 'v';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 3;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::VReg_256RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 'v';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 8;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::SReg_256RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 's';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 8;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::VReg_512RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 'v';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 16;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::SReg_512RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << 's';
|
2014-04-16 00:32:42 +02:00
|
|
|
NumRegs = 16;
|
2016-09-27 16:42:48 +02:00
|
|
|
} else if (MRI.getRegClass(AMDGPU::TTMP_64RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << "ttmp";
|
|
|
|
NumRegs = 2;
|
2016-09-27 16:42:48 +02:00
|
|
|
// Trap temps start at offset 112. TODO: Get this from tablegen.
|
|
|
|
RegIdx -= 112;
|
|
|
|
} else if (MRI.getRegClass(AMDGPU::TTMP_128RegClassID).contains(RegNo)) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << "ttmp";
|
|
|
|
NumRegs = 4;
|
2016-09-27 16:42:48 +02:00
|
|
|
// Trap temps start at offset 112. TODO: Get this from tablegen.
|
|
|
|
RegIdx -= 112;
|
2014-04-16 00:32:42 +02:00
|
|
|
} else {
|
2016-09-27 16:42:48 +02:00
|
|
|
O << getRegisterName(RegNo);
|
2013-11-12 03:35:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-16 00:32:42 +02:00
|
|
|
if (NumRegs == 1) {
|
2016-07-06 00:06:56 +02:00
|
|
|
O << RegIdx;
|
2013-11-12 03:35:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-06 00:06:56 +02:00
|
|
|
O << '[' << RegIdx << ':' << (RegIdx + NumRegs - 1) << ']';
|
2013-11-12 03:35:51 +01:00
|
|
|
}
|
|
|
|
|
2015-03-12 22:34:22 +01:00
|
|
|
void AMDGPUInstPrinter::printVOPDst(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2015-03-12 22:34:22 +01:00
|
|
|
if (MII.get(MI->getOpcode()).TSFlags & SIInstrFlags::VOP3)
|
|
|
|
O << "_e64 ";
|
2016-03-09 13:29:31 +01:00
|
|
|
else if (MII.get(MI->getOpcode()).TSFlags & SIInstrFlags::DPP)
|
|
|
|
O << "_dpp ";
|
2016-04-26 15:33:56 +02:00
|
|
|
else if (MII.get(MI->getOpcode()).TSFlags & SIInstrFlags::SDWA)
|
|
|
|
O << "_sdwa ";
|
2015-03-12 22:34:22 +01:00
|
|
|
else
|
|
|
|
O << "_e32 ";
|
|
|
|
|
2016-09-27 16:42:48 +02:00
|
|
|
printOperand(MI, OpNo, STI, O);
|
2015-03-12 22:34:22 +01:00
|
|
|
}
|
|
|
|
|
2014-12-17 22:04:08 +01:00
|
|
|
void AMDGPUInstPrinter::printImmediate32(uint32_t Imm, raw_ostream &O) {
|
2014-04-16 00:32:49 +02:00
|
|
|
int32_t SImm = static_cast<int32_t>(Imm);
|
|
|
|
if (SImm >= -16 && SImm <= 64) {
|
|
|
|
O << SImm;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-17 19:32:13 +02:00
|
|
|
if (Imm == FloatToBits(0.0f))
|
|
|
|
O << "0.0";
|
|
|
|
else if (Imm == FloatToBits(1.0f))
|
|
|
|
O << "1.0";
|
|
|
|
else if (Imm == FloatToBits(-1.0f))
|
|
|
|
O << "-1.0";
|
|
|
|
else if (Imm == FloatToBits(0.5f))
|
|
|
|
O << "0.5";
|
|
|
|
else if (Imm == FloatToBits(-0.5f))
|
|
|
|
O << "-0.5";
|
|
|
|
else if (Imm == FloatToBits(2.0f))
|
|
|
|
O << "2.0";
|
|
|
|
else if (Imm == FloatToBits(-2.0f))
|
|
|
|
O << "-2.0";
|
|
|
|
else if (Imm == FloatToBits(4.0f))
|
|
|
|
O << "4.0";
|
|
|
|
else if (Imm == FloatToBits(-4.0f))
|
|
|
|
O << "-4.0";
|
2014-12-17 22:04:08 +01:00
|
|
|
else
|
2014-09-17 19:32:13 +02:00
|
|
|
O << formatHex(static_cast<uint64_t>(Imm));
|
2014-12-17 22:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printImmediate64(uint64_t Imm, raw_ostream &O) {
|
|
|
|
int64_t SImm = static_cast<int64_t>(Imm);
|
|
|
|
if (SImm >= -16 && SImm <= 64) {
|
|
|
|
O << SImm;
|
|
|
|
return;
|
2014-04-16 00:32:49 +02:00
|
|
|
}
|
2014-12-17 22:04:08 +01:00
|
|
|
|
|
|
|
if (Imm == DoubleToBits(0.0))
|
|
|
|
O << "0.0";
|
|
|
|
else if (Imm == DoubleToBits(1.0))
|
|
|
|
O << "1.0";
|
|
|
|
else if (Imm == DoubleToBits(-1.0))
|
|
|
|
O << "-1.0";
|
|
|
|
else if (Imm == DoubleToBits(0.5))
|
|
|
|
O << "0.5";
|
|
|
|
else if (Imm == DoubleToBits(-0.5))
|
|
|
|
O << "-0.5";
|
|
|
|
else if (Imm == DoubleToBits(2.0))
|
|
|
|
O << "2.0";
|
|
|
|
else if (Imm == DoubleToBits(-2.0))
|
|
|
|
O << "-2.0";
|
|
|
|
else if (Imm == DoubleToBits(4.0))
|
|
|
|
O << "4.0";
|
|
|
|
else if (Imm == DoubleToBits(-4.0))
|
|
|
|
O << "-4.0";
|
2015-10-23 20:07:58 +02:00
|
|
|
else {
|
AMDGPU] Assembler: better support for immediate literals in assembler.
Summary:
Prevously assembler parsed all literals as either 32-bit integers or 32-bit floating-point values. Because of this we couldn't support f64 literals.
E.g. in instruction "v_fract_f64 v[0:1], 0.5", literal 0.5 was encoded as 32-bit literal 0x3f000000, which is incorrect and will be interpreted as 3.0517578125E-5 instead of 0.5. Correct encoding is inline constant 240 (optimal) or 32-bit literal 0x3FE00000 at least.
With this change the way immediate literals are parsed is changed. All literals are always parsed as 64-bit values either integer or floating-point. Then we convert parsed literals to correct form based on information about type of operand parsed (was literal floating or binary) and type of expected instruction operands (is this f32/64 or b32/64 instruction).
Here are rules how we convert literals:
- We parsed fp literal:
- Instruction expects 64-bit operand:
- If parsed literal is inlinable (e.g. v_fract_f64_e32 v[0:1], 0.5)
- then we do nothing this literal
- Else if literal is not-inlinable but instruction requires to inline it (e.g. this is e64 encoding, v_fract_f64_e64 v[0:1], 1.5)
- report error
- Else literal is not-inlinable but we can encode it as additional 32-bit literal constant
- If instruction expect fp operand type (f64)
- Check if low 32 bits of literal are zeroes (e.g. v_fract_f64 v[0:1], 1.5)
- If so then do nothing
- Else (e.g. v_fract_f64 v[0:1], 3.1415)
- report warning that low 32 bits will be set to zeroes and precision will be lost
- set low 32 bits of literal to zeroes
- Instruction expects integer operand type (e.g. s_mov_b64_e32 s[0:1], 1.5)
- report error as it is unclear how to encode this literal
- Instruction expects 32-bit operand:
- Convert parsed 64 bit fp literal to 32 bit fp. Allow lose of precision but not overflow or underflow
- Is this literal inlinable and are we required to inline literal (e.g. v_trunc_f32_e64 v0, 0.5)
- do nothing
- Else report error
- Do nothing. We can encode any other 32-bit fp literal (e.g. v_trunc_f32 v0, 10000000.0)
- Parsed binary literal:
- Is this literal inlinable (e.g. v_trunc_f32_e32 v0, 35)
- do nothing
- Else, are we required to inline this literal (e.g. v_trunc_f32_e64 v0, 35)
- report error
- Else, literal is not-inlinable and we are not required to inline it
- Are high 32 bit of literal zeroes or same as sign bit (32 bit)
- do nothing (e.g. v_trunc_f32 v0, 0xdeadbeef)
- Else
- report error (e.g. v_trunc_f32 v0, 0x123456789abcdef0)
For this change it is required that we know operand types of instruction (are they f32/64 or b32/64). I added several new register operands (they extend previous register operands) and set operand types to corresponding types:
'''
enum OperandType {
OPERAND_REG_IMM32_INT,
OPERAND_REG_IMM32_FP,
OPERAND_REG_INLINE_C_INT,
OPERAND_REG_INLINE_C_FP,
}
'''
This is not working yet:
- Several tests are failing
- Problems with predicate methods for inline immediates
- LLVM generated assembler parts try to select e64 encoding before e32.
More changes are required for several AsmOperands.
Reviewers: vpykhtin, tstellarAMD
Subscribers: arsenm, kzhuravl, artem.tamazov
Differential Revision: https://reviews.llvm.org/D22922
llvm-svn: 281050
2016-09-09 16:44:04 +02:00
|
|
|
assert(isUInt<32>(Imm) || Imm == 0x3fc45f306dc9c882);
|
2015-10-23 20:07:58 +02:00
|
|
|
|
|
|
|
// In rare situations, we will have a 32-bit literal in a 64-bit
|
|
|
|
// operand. This is technically allowed for the encoding of s_mov_b64.
|
|
|
|
O << formatHex(static_cast<uint64_t>(Imm));
|
|
|
|
}
|
2014-04-16 00:32:49 +02:00
|
|
|
}
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
void AMDGPUInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2012-12-11 22:25:42 +01:00
|
|
|
raw_ostream &O) {
|
|
|
|
|
2016-08-15 12:56:48 +02:00
|
|
|
if (OpNo >= MI->getNumOperands()) {
|
|
|
|
O << "/*Missing OP" << OpNo << "*/";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
if (Op.isReg()) {
|
|
|
|
switch (Op.getReg()) {
|
|
|
|
// This is the default predicate state, so we don't need to print it.
|
2013-11-12 03:35:51 +01:00
|
|
|
case AMDGPU::PRED_SEL_OFF:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-04-08 03:09:26 +02:00
|
|
|
printRegOperand(Op.getReg(), O, MRI);
|
2013-11-12 03:35:51 +01:00
|
|
|
break;
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
} else if (Op.isImm()) {
|
2014-12-17 22:04:08 +01:00
|
|
|
const MCInstrDesc &Desc = MII.get(MI->getOpcode());
|
|
|
|
int RCID = Desc.OpInfo[OpNo].RegClass;
|
|
|
|
if (RCID != -1) {
|
2016-10-19 19:40:36 +02:00
|
|
|
unsigned RCBits = AMDGPU::getRegBitWidth(MRI.getRegClass(RCID));
|
|
|
|
if (RCBits == 32)
|
2014-12-17 22:04:08 +01:00
|
|
|
printImmediate32(Op.getImm(), O);
|
2016-10-19 19:40:36 +02:00
|
|
|
else if (RCBits == 64)
|
2014-12-17 22:04:08 +01:00
|
|
|
printImmediate64(Op.getImm(), O);
|
|
|
|
else
|
|
|
|
llvm_unreachable("Invalid register class size");
|
2015-02-21 22:29:00 +01:00
|
|
|
} else if (Desc.OpInfo[OpNo].OperandType == MCOI::OPERAND_IMMEDIATE) {
|
|
|
|
printImmediate32(Op.getImm(), O);
|
2014-12-17 22:04:08 +01:00
|
|
|
} else {
|
|
|
|
// We hit this for the immediate instruction bits that don't yet have a
|
|
|
|
// custom printer.
|
|
|
|
// TODO: Eventually this should be unnecessary.
|
|
|
|
O << formatDec(Op.getImm());
|
|
|
|
}
|
2012-12-11 22:25:42 +01:00
|
|
|
} else if (Op.isFPImm()) {
|
2014-09-17 19:32:13 +02:00
|
|
|
// We special case 0.0 because otherwise it will be printed as an integer.
|
|
|
|
if (Op.getFPImm() == 0.0)
|
|
|
|
O << "0.0";
|
2014-12-17 22:04:08 +01:00
|
|
|
else {
|
|
|
|
const MCInstrDesc &Desc = MII.get(MI->getOpcode());
|
2016-10-19 19:40:36 +02:00
|
|
|
int RCID = Desc.OpInfo[OpNo].RegClass;
|
|
|
|
unsigned RCBits = AMDGPU::getRegBitWidth(MRI.getRegClass(RCID));
|
|
|
|
if (RCBits == 32)
|
2014-12-17 22:04:08 +01:00
|
|
|
printImmediate32(FloatToBits(Op.getFPImm()), O);
|
2016-10-19 19:40:36 +02:00
|
|
|
else if (RCBits == 64)
|
2014-12-17 22:04:08 +01:00
|
|
|
printImmediate64(DoubleToBits(Op.getFPImm()), O);
|
|
|
|
else
|
|
|
|
llvm_unreachable("Invalid register class size");
|
|
|
|
}
|
2013-02-21 16:17:22 +01:00
|
|
|
} else if (Op.isExpr()) {
|
|
|
|
const MCExpr *Exp = Op.getExpr();
|
2015-06-09 02:31:39 +02:00
|
|
|
Exp->print(O, &MAI);
|
2012-12-11 22:25:42 +01:00
|
|
|
} else {
|
2016-03-01 14:57:29 +01:00
|
|
|
O << "/*INV_OP*/";
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 11:57:59 +02:00
|
|
|
void AMDGPUInstPrinter::printOperandAndFPInputMods(const MCInst *MI,
|
2016-09-27 16:42:48 +02:00
|
|
|
unsigned OpNo,
|
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2014-05-10 21:18:33 +02:00
|
|
|
unsigned InputModifiers = MI->getOperand(OpNo).getImm();
|
2014-09-29 17:50:26 +02:00
|
|
|
if (InputModifiers & SISrcMods::NEG)
|
2014-09-21 19:27:28 +02:00
|
|
|
O << '-';
|
2014-09-29 17:50:26 +02:00
|
|
|
if (InputModifiers & SISrcMods::ABS)
|
2014-09-21 19:27:28 +02:00
|
|
|
O << '|';
|
2016-09-27 16:42:48 +02:00
|
|
|
printOperand(MI, OpNo + 1, STI, O);
|
2014-09-29 17:50:26 +02:00
|
|
|
if (InputModifiers & SISrcMods::ABS)
|
2014-09-21 19:27:28 +02:00
|
|
|
O << '|';
|
2014-05-10 21:18:33 +02:00
|
|
|
}
|
|
|
|
|
2016-06-10 11:57:59 +02:00
|
|
|
void AMDGPUInstPrinter::printOperandAndIntInputMods(const MCInst *MI,
|
2016-09-27 16:42:48 +02:00
|
|
|
unsigned OpNo,
|
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2016-06-10 11:57:59 +02:00
|
|
|
unsigned InputModifiers = MI->getOperand(OpNo).getImm();
|
|
|
|
if (InputModifiers & SISrcMods::SEXT)
|
|
|
|
O << "sext(";
|
2016-09-27 16:42:48 +02:00
|
|
|
printOperand(MI, OpNo + 1, STI, O);
|
2016-06-10 11:57:59 +02:00
|
|
|
if (InputModifiers & SISrcMods::SEXT)
|
|
|
|
O << ')';
|
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printDPPCtrl(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2016-03-09 13:29:31 +01:00
|
|
|
unsigned Imm = MI->getOperand(OpNo).getImm();
|
2016-03-09 15:58:23 +01:00
|
|
|
if (Imm <= 0x0ff) {
|
2016-03-18 16:35:51 +01:00
|
|
|
O << " quad_perm:[";
|
2016-07-06 00:06:56 +02:00
|
|
|
O << formatDec(Imm & 0x3) << ',';
|
|
|
|
O << formatDec((Imm & 0xc) >> 2) << ',';
|
|
|
|
O << formatDec((Imm & 0x30) >> 4) << ',';
|
|
|
|
O << formatDec((Imm & 0xc0) >> 6) << ']';
|
2016-03-09 13:29:31 +01:00
|
|
|
} else if ((Imm >= 0x101) && (Imm <= 0x10f)) {
|
|
|
|
O << " row_shl:";
|
|
|
|
printU4ImmDecOperand(MI, OpNo, O);
|
|
|
|
} else if ((Imm >= 0x111) && (Imm <= 0x11f)) {
|
|
|
|
O << " row_shr:";
|
|
|
|
printU4ImmDecOperand(MI, OpNo, O);
|
|
|
|
} else if ((Imm >= 0x121) && (Imm <= 0x12f)) {
|
|
|
|
O << " row_ror:";
|
|
|
|
printU4ImmDecOperand(MI, OpNo, O);
|
|
|
|
} else if (Imm == 0x130) {
|
|
|
|
O << " wave_shl:1";
|
|
|
|
} else if (Imm == 0x134) {
|
|
|
|
O << " wave_rol:1";
|
|
|
|
} else if (Imm == 0x138) {
|
|
|
|
O << " wave_shr:1";
|
|
|
|
} else if (Imm == 0x13c) {
|
|
|
|
O << " wave_ror:1";
|
|
|
|
} else if (Imm == 0x140) {
|
2016-03-18 16:35:51 +01:00
|
|
|
O << " row_mirror";
|
2016-03-09 13:29:31 +01:00
|
|
|
} else if (Imm == 0x141) {
|
2016-03-18 16:35:51 +01:00
|
|
|
O << " row_half_mirror";
|
2016-03-09 13:29:31 +01:00
|
|
|
} else if (Imm == 0x142) {
|
|
|
|
O << " row_bcast:15";
|
|
|
|
} else if (Imm == 0x143) {
|
|
|
|
O << " row_bcast:31";
|
|
|
|
} else {
|
|
|
|
llvm_unreachable("Invalid dpp_ctrl value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printRowMask(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2016-03-09 13:29:31 +01:00
|
|
|
O << " row_mask:";
|
2016-10-12 20:00:51 +02:00
|
|
|
printU4ImmOperand(MI, OpNo, STI, O);
|
2016-03-09 13:29:31 +01:00
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printBankMask(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2016-03-09 13:29:31 +01:00
|
|
|
O << " bank_mask:";
|
2016-10-12 20:00:51 +02:00
|
|
|
printU4ImmOperand(MI, OpNo, STI, O);
|
2016-03-09 13:29:31 +01:00
|
|
|
}
|
|
|
|
|
2016-04-29 11:02:30 +02:00
|
|
|
void AMDGPUInstPrinter::printBoundCtrl(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2016-03-09 13:29:31 +01:00
|
|
|
unsigned Imm = MI->getOperand(OpNo).getImm();
|
|
|
|
if (Imm) {
|
|
|
|
O << " bound_ctrl:0"; // XXX - this syntax is used in sp3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 15:33:56 +02:00
|
|
|
void AMDGPUInstPrinter::printSDWASel(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
2016-10-07 16:46:06 +02:00
|
|
|
using namespace llvm::AMDGPU::SDWA;
|
|
|
|
|
2016-04-26 15:33:56 +02:00
|
|
|
unsigned Imm = MI->getOperand(OpNo).getImm();
|
|
|
|
switch (Imm) {
|
2016-10-07 16:46:06 +02:00
|
|
|
case SdwaSel::BYTE_0: O << "BYTE_0"; break;
|
|
|
|
case SdwaSel::BYTE_1: O << "BYTE_1"; break;
|
|
|
|
case SdwaSel::BYTE_2: O << "BYTE_2"; break;
|
|
|
|
case SdwaSel::BYTE_3: O << "BYTE_3"; break;
|
|
|
|
case SdwaSel::WORD_0: O << "WORD_0"; break;
|
|
|
|
case SdwaSel::WORD_1: O << "WORD_1"; break;
|
|
|
|
case SdwaSel::DWORD: O << "DWORD"; break;
|
2016-04-26 15:33:56 +02:00
|
|
|
default: llvm_unreachable("Invalid SDWA data select operand");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printSDWADstSel(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-04-26 15:33:56 +02:00
|
|
|
raw_ostream &O) {
|
|
|
|
O << "dst_sel:";
|
|
|
|
printSDWASel(MI, OpNo, O);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printSDWASrc0Sel(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-04-26 15:33:56 +02:00
|
|
|
raw_ostream &O) {
|
|
|
|
O << "src0_sel:";
|
|
|
|
printSDWASel(MI, OpNo, O);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printSDWASrc1Sel(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-04-26 15:33:56 +02:00
|
|
|
raw_ostream &O) {
|
|
|
|
O << "src1_sel:";
|
|
|
|
printSDWASel(MI, OpNo, O);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printSDWADstUnused(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2016-04-26 15:33:56 +02:00
|
|
|
raw_ostream &O) {
|
2016-10-07 16:46:06 +02:00
|
|
|
using namespace llvm::AMDGPU::SDWA;
|
|
|
|
|
2016-04-26 15:33:56 +02:00
|
|
|
O << "dst_unused:";
|
|
|
|
unsigned Imm = MI->getOperand(OpNo).getImm();
|
|
|
|
switch (Imm) {
|
2016-10-07 16:46:06 +02:00
|
|
|
case DstUnused::UNUSED_PAD: O << "UNUSED_PAD"; break;
|
|
|
|
case DstUnused::UNUSED_SEXT: O << "UNUSED_SEXT"; break;
|
|
|
|
case DstUnused::UNUSED_PRESERVE: O << "UNUSED_PRESERVE"; break;
|
2016-04-26 15:33:56 +02:00
|
|
|
default: llvm_unreachable("Invalid SDWA dest_unused operand");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 16:42:48 +02:00
|
|
|
void AMDGPUInstPrinter::printInterpSlot(const MCInst *MI, unsigned OpNo,
|
|
|
|
const MCSubtargetInfo &STI,
|
2013-02-14 20:03:25 +01:00
|
|
|
raw_ostream &O) {
|
2016-09-27 16:42:48 +02:00
|
|
|
unsigned Imm = MI->getOperand(OpNo).getImm();
|
2013-02-14 20:03:25 +01:00
|
|
|
|
|
|
|
if (Imm == 2) {
|
|
|
|
O << "P0";
|
|
|
|
} else if (Imm == 1) {
|
|
|
|
O << "P20";
|
|
|
|
} else if (Imm == 0) {
|
|
|
|
O << "P10";
|
|
|
|
} else {
|
2014-09-21 19:27:31 +02:00
|
|
|
llvm_unreachable("Invalid interpolation parameter slot");
|
2013-02-14 20:03:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 20:00:51 +02:00
|
|
|
void AMDGPUInstPrinter::printVGPRIndexMode(const MCInst *MI, unsigned OpNo,
|
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
|
|
|
unsigned Val = MI->getOperand(OpNo).getImm();
|
|
|
|
if (Val == 0) {
|
|
|
|
O << " 0";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Val & VGPRIndexMode::DST_ENABLE)
|
|
|
|
O << " dst";
|
|
|
|
|
|
|
|
if (Val & VGPRIndexMode::SRC0_ENABLE)
|
|
|
|
O << " src0";
|
|
|
|
|
|
|
|
if (Val & VGPRIndexMode::SRC1_ENABLE)
|
|
|
|
O << " src1";
|
|
|
|
|
|
|
|
if (Val & VGPRIndexMode::SRC2_ENABLE)
|
|
|
|
O << " src2";
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
void AMDGPUInstPrinter::printMemOperand(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2012-12-11 22:25:42 +01:00
|
|
|
raw_ostream &O) {
|
2016-09-27 16:42:48 +02:00
|
|
|
printOperand(MI, OpNo, STI, O);
|
2012-12-11 22:25:42 +01:00
|
|
|
O << ", ";
|
2016-09-27 16:42:48 +02:00
|
|
|
printOperand(MI, OpNo + 1, STI, O);
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printIfSet(const MCInst *MI, unsigned OpNo,
|
2013-05-02 23:52:30 +02:00
|
|
|
raw_ostream &O, StringRef Asm,
|
|
|
|
StringRef Default) {
|
2012-12-11 22:25:42 +01:00
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
assert(Op.isImm());
|
|
|
|
if (Op.getImm() == 1) {
|
|
|
|
O << Asm;
|
2013-05-02 23:52:30 +02:00
|
|
|
} else {
|
|
|
|
O << Default;
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-06 00:06:56 +02:00
|
|
|
void AMDGPUInstPrinter::printIfSet(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O, char Asm) {
|
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
assert(Op.isImm());
|
|
|
|
if (Op.getImm() == 1)
|
|
|
|
O << Asm;
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
void AMDGPUInstPrinter::printAbs(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-07-06 00:06:56 +02:00
|
|
|
printIfSet(MI, OpNo, O, '|');
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printClamp(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2012-12-11 22:25:42 +01:00
|
|
|
printIfSet(MI, OpNo, O, "_SAT");
|
|
|
|
}
|
|
|
|
|
2014-09-30 21:49:48 +02:00
|
|
|
void AMDGPUInstPrinter::printClampSI(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2014-09-30 21:49:48 +02:00
|
|
|
raw_ostream &O) {
|
|
|
|
if (MI->getOperand(OpNo).getImm())
|
|
|
|
O << " clamp";
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printOModSI(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &O) {
|
2014-09-30 21:49:48 +02:00
|
|
|
int Imm = MI->getOperand(OpNo).getImm();
|
|
|
|
if (Imm == SIOutMods::MUL2)
|
|
|
|
O << " mul:2";
|
|
|
|
else if (Imm == SIOutMods::MUL4)
|
|
|
|
O << " mul:4";
|
|
|
|
else if (Imm == SIOutMods::DIV2)
|
|
|
|
O << " div:2";
|
|
|
|
}
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
void AMDGPUInstPrinter::printLiteral(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2012-12-11 22:25:42 +01:00
|
|
|
raw_ostream &O) {
|
2016-05-13 22:39:24 +02:00
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
assert(Op.isImm() || Op.isExpr());
|
|
|
|
if (Op.isImm()) {
|
|
|
|
int64_t Imm = Op.getImm();
|
|
|
|
O << Imm << '(' << BitsToFloat(Imm) << ')';
|
|
|
|
}
|
|
|
|
if (Op.isExpr()) {
|
|
|
|
Op.getExpr()->print(O << '@', &MAI);
|
|
|
|
}
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printLast(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2015-06-12 14:42:13 +02:00
|
|
|
printIfSet(MI, OpNo, O, "*", " ");
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printNeg(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-07-06 00:06:56 +02:00
|
|
|
printIfSet(MI, OpNo, O, '-');
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printOMOD(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2012-12-11 22:25:42 +01:00
|
|
|
switch (MI->getOperand(OpNo).getImm()) {
|
|
|
|
default: break;
|
|
|
|
case 1:
|
|
|
|
O << " * 2.0";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
O << " * 4.0";
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
O << " / 2.0";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printRel(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-07-06 00:06:56 +02:00
|
|
|
printIfSet(MI, OpNo, O, '+');
|
2012-12-11 22:25:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printUpdateExecMask(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2012-12-11 22:25:42 +01:00
|
|
|
raw_ostream &O) {
|
|
|
|
printIfSet(MI, OpNo, O, "ExecMask,");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printUpdatePred(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2012-12-11 22:25:42 +01:00
|
|
|
raw_ostream &O) {
|
|
|
|
printIfSet(MI, OpNo, O, "Pred,");
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printWrite(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2012-12-11 22:25:42 +01:00
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
if (Op.getImm() == 0) {
|
|
|
|
O << " (MASKED)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 03:09:06 +01:00
|
|
|
void AMDGPUInstPrinter::printSel(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
raw_ostream &O) {
|
2013-01-23 03:09:06 +01:00
|
|
|
const char * chans = "XYZW";
|
|
|
|
int sel = MI->getOperand(OpNo).getImm();
|
|
|
|
|
|
|
|
int chan = sel & 3;
|
|
|
|
sel >>= 2;
|
|
|
|
|
|
|
|
if (sel >= 512) {
|
|
|
|
sel -= 512;
|
|
|
|
int cb = sel >> 12;
|
|
|
|
sel &= 4095;
|
2014-09-21 19:27:28 +02:00
|
|
|
O << cb << '[' << sel << ']';
|
2013-01-23 03:09:06 +01:00
|
|
|
} else if (sel >= 448) {
|
|
|
|
sel -= 448;
|
|
|
|
O << sel;
|
|
|
|
} else if (sel >= 0){
|
|
|
|
O << sel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sel >= 0)
|
2014-09-21 19:27:28 +02:00
|
|
|
O << '.' << chans[chan];
|
2013-01-23 03:09:06 +01:00
|
|
|
}
|
|
|
|
|
2013-05-02 23:52:30 +02:00
|
|
|
void AMDGPUInstPrinter::printBankSwizzle(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2013-05-02 23:52:30 +02:00
|
|
|
raw_ostream &O) {
|
|
|
|
int BankSwizzle = MI->getOperand(OpNo).getImm();
|
|
|
|
switch (BankSwizzle) {
|
|
|
|
case 1:
|
2013-06-29 21:32:29 +02:00
|
|
|
O << "BS:VEC_021/SCL_122";
|
2013-05-02 23:52:30 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2013-06-29 21:32:29 +02:00
|
|
|
O << "BS:VEC_120/SCL_212";
|
2013-05-02 23:52:30 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2013-06-29 21:32:29 +02:00
|
|
|
O << "BS:VEC_102/SCL_221";
|
2013-05-02 23:52:30 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
O << "BS:VEC_201";
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
O << "BS:VEC_210";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-17 18:50:20 +02:00
|
|
|
void AMDGPUInstPrinter::printRSel(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2013-05-17 18:50:20 +02:00
|
|
|
unsigned Sel = MI->getOperand(OpNo).getImm();
|
|
|
|
switch (Sel) {
|
|
|
|
case 0:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << 'X';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << 'Y';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << 'Z';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << 'W';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << '0';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
case 5:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << '1';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
case 7:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << '_';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMDGPUInstPrinter::printCT(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2013-05-17 18:50:20 +02:00
|
|
|
unsigned CT = MI->getOperand(OpNo).getImm();
|
|
|
|
switch (CT) {
|
|
|
|
case 0:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << 'U';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-09-21 19:27:28 +02:00
|
|
|
O << 'N';
|
2013-05-17 18:50:20 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 23:52:40 +02:00
|
|
|
void AMDGPUInstPrinter::printKCache(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2013-05-02 23:52:40 +02:00
|
|
|
int KCacheMode = MI->getOperand(OpNo).getImm();
|
|
|
|
if (KCacheMode > 0) {
|
|
|
|
int KCacheBank = MI->getOperand(OpNo - 2).getImm();
|
2014-09-21 19:27:28 +02:00
|
|
|
O << "CB" << KCacheBank << ':';
|
2013-05-02 23:52:40 +02:00
|
|
|
int KCacheAddr = MI->getOperand(OpNo + 2).getImm();
|
2014-09-21 19:27:28 +02:00
|
|
|
int LineSize = (KCacheMode == 1) ? 16 : 32;
|
|
|
|
O << KCacheAddr * 16 << '-' << KCacheAddr * 16 + LineSize;
|
2013-05-02 23:52:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 08:20:44 +01:00
|
|
|
void AMDGPUInstPrinter::printSendMsg(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2014-01-27 08:20:44 +01:00
|
|
|
raw_ostream &O) {
|
2016-05-06 19:48:48 +02:00
|
|
|
using namespace llvm::AMDGPU::SendMsg;
|
|
|
|
|
|
|
|
const unsigned SImm16 = MI->getOperand(OpNo).getImm();
|
|
|
|
const unsigned Id = SImm16 & ID_MASK_;
|
|
|
|
do {
|
|
|
|
if (Id == ID_INTERRUPT) {
|
|
|
|
if ((SImm16 & ~ID_MASK_) != 0) // Unused/unknown bits must be 0.
|
|
|
|
break;
|
|
|
|
O << "sendmsg(" << IdSymbolic[Id] << ')';
|
|
|
|
return;
|
2014-01-27 08:20:44 +01:00
|
|
|
}
|
2016-05-06 19:48:48 +02:00
|
|
|
if (Id == ID_GS || Id == ID_GS_DONE) {
|
|
|
|
if ((SImm16 & ~(ID_MASK_|OP_GS_MASK_|STREAM_ID_MASK_)) != 0) // Unused/unknown bits must be 0.
|
|
|
|
break;
|
|
|
|
const unsigned OpGs = (SImm16 & OP_GS_MASK_) >> OP_SHIFT_;
|
|
|
|
const unsigned StreamId = (SImm16 & STREAM_ID_MASK_) >> STREAM_ID_SHIFT_;
|
|
|
|
if (OpGs == OP_GS_NOP && Id != ID_GS_DONE) // NOP to be used for GS_DONE only.
|
|
|
|
break;
|
|
|
|
if (OpGs == OP_GS_NOP && StreamId != 0) // NOP does not use/define stream id bits.
|
|
|
|
break;
|
|
|
|
O << "sendmsg(" << IdSymbolic[Id] << ", " << OpGsSymbolic[OpGs];
|
|
|
|
if (OpGs != OP_GS_NOP) { O << ", " << StreamId; }
|
|
|
|
O << ')';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (Id == ID_SYSMSG) {
|
|
|
|
if ((SImm16 & ~(ID_MASK_|OP_SYS_MASK_)) != 0) // Unused/unknown bits must be 0.
|
|
|
|
break;
|
|
|
|
const unsigned OpSys = (SImm16 & OP_SYS_MASK_) >> OP_SHIFT_;
|
|
|
|
if (! (OP_SYS_FIRST_ <= OpSys && OpSys < OP_SYS_LAST_)) // Unused/unknown.
|
|
|
|
break;
|
|
|
|
O << "sendmsg(" << IdSymbolic[Id] << ", " << OpSysSymbolic[OpSys] << ')';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
O << SImm16; // Unknown simm16 code.
|
2014-01-27 08:20:44 +01:00
|
|
|
}
|
|
|
|
|
2013-10-13 19:56:28 +02:00
|
|
|
void AMDGPUInstPrinter::printWaitFlag(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI,
|
2013-10-13 19:56:28 +02:00
|
|
|
raw_ostream &O) {
|
2016-09-30 19:01:40 +02:00
|
|
|
IsaVersion IV = getIsaVersion(STI.getFeatureBits());
|
|
|
|
|
2013-10-13 19:56:28 +02:00
|
|
|
unsigned SImm16 = MI->getOperand(OpNo).getImm();
|
2016-10-11 20:58:22 +02:00
|
|
|
unsigned Vmcnt, Expcnt, Lgkmcnt;
|
|
|
|
decodeWaitcnt(IV, SImm16, Vmcnt, Expcnt, Lgkmcnt);
|
2014-09-26 03:09:46 +02:00
|
|
|
|
|
|
|
bool NeedSpace = false;
|
|
|
|
|
2016-10-11 20:58:22 +02:00
|
|
|
if (Vmcnt != getVmcntBitMask(IV)) {
|
2014-09-26 03:09:46 +02:00
|
|
|
O << "vmcnt(" << Vmcnt << ')';
|
|
|
|
NeedSpace = true;
|
|
|
|
}
|
|
|
|
|
2016-10-11 20:58:22 +02:00
|
|
|
if (Expcnt != getExpcntBitMask(IV)) {
|
2014-09-26 03:09:46 +02:00
|
|
|
if (NeedSpace)
|
|
|
|
O << ' ';
|
|
|
|
O << "expcnt(" << Expcnt << ')';
|
|
|
|
NeedSpace = true;
|
|
|
|
}
|
|
|
|
|
2016-10-11 20:58:22 +02:00
|
|
|
if (Lgkmcnt != getLgkmcntBitMask(IV)) {
|
2014-09-26 03:09:46 +02:00
|
|
|
if (NeedSpace)
|
|
|
|
O << ' ';
|
2014-09-21 19:27:28 +02:00
|
|
|
O << "lgkmcnt(" << Lgkmcnt << ')';
|
2014-09-26 03:09:46 +02:00
|
|
|
}
|
2013-10-13 19:56:28 +02:00
|
|
|
}
|
|
|
|
|
2016-04-25 16:13:51 +02:00
|
|
|
void AMDGPUInstPrinter::printHwreg(const MCInst *MI, unsigned OpNo,
|
2016-09-27 16:42:48 +02:00
|
|
|
const MCSubtargetInfo &STI, raw_ostream &O) {
|
2016-05-26 19:00:33 +02:00
|
|
|
using namespace llvm::AMDGPU::Hwreg;
|
|
|
|
|
2016-04-25 16:13:51 +02:00
|
|
|
unsigned SImm16 = MI->getOperand(OpNo).getImm();
|
2016-05-26 19:00:33 +02:00
|
|
|
const unsigned Id = (SImm16 & ID_MASK_) >> ID_SHIFT_;
|
|
|
|
const unsigned Offset = (SImm16 & OFFSET_MASK_) >> OFFSET_SHIFT_;
|
|
|
|
const unsigned Width = ((SImm16 & WIDTH_M1_MASK_) >> WIDTH_M1_SHIFT_) + 1;
|
2016-04-25 16:13:51 +02:00
|
|
|
|
2016-04-27 17:17:03 +02:00
|
|
|
O << "hwreg(";
|
2016-05-26 19:00:33 +02:00
|
|
|
if (ID_SYMBOLIC_FIRST_ <= Id && Id < ID_SYMBOLIC_LAST_) {
|
|
|
|
O << IdSymbolic[Id];
|
|
|
|
} else {
|
|
|
|
O << Id;
|
|
|
|
}
|
|
|
|
if (Width != WIDTH_M1_DEFAULT_ + 1 || Offset != OFFSET_DEFAULT_) {
|
2016-04-27 17:17:03 +02:00
|
|
|
O << ", " << Offset << ", " << Width;
|
2016-04-25 16:13:51 +02:00
|
|
|
}
|
2016-04-27 17:17:03 +02:00
|
|
|
O << ')';
|
2016-04-25 16:13:51 +02:00
|
|
|
}
|
|
|
|
|
2012-12-11 22:25:42 +01:00
|
|
|
#include "AMDGPUGenAsmWriter.inc"
|