blob: b73a9b268e87f4715390522d48914d300e2c1e38 [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- AMDGPUInstPrinter.cpp - AMDGPU MC Inst -> ASM ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8// \file
9//===----------------------------------------------------------------------===//
10
11#include "AMDGPUInstPrinter.h"
12#include "MCTargetDesc/AMDGPUMCTargetDesc.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000013#include "SIDefines.h"
Christian Konigbf114b42013-02-21 15:17:22 +000014#include "llvm/MC/MCExpr.h"
Benjamin Kramerd78bb462013-05-23 17:10:37 +000015#include "llvm/MC/MCInst.h"
Matt Arsenault303011a2014-12-17 21:04:08 +000016#include "llvm/MC/MCInstrInfo.h"
Matt Arsenault4d7d3832014-04-15 22:32:49 +000017#include "llvm/MC/MCRegisterInfo.h"
18#include "llvm/Support/MathExtras.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000019
20using namespace llvm;
21
22void AMDGPUInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
Akira Hatanakab46d0232015-03-27 20:36:02 +000023 StringRef Annot, const MCSubtargetInfo &STI) {
Vincent Lejeunef97af792013-05-02 21:52:30 +000024 OS.flush();
Tom Stellard75aadc22012-12-11 21:25:42 +000025 printInstruction(MI, OS);
26
27 printAnnotation(OS, Annot);
28}
29
Matt Arsenault4d7d3832014-04-15 22:32:49 +000030void AMDGPUInstPrinter::printU8ImmOperand(const MCInst *MI, unsigned OpNo,
31 raw_ostream &O) {
32 O << formatHex(MI->getOperand(OpNo).getImm() & 0xff);
33}
34
35void AMDGPUInstPrinter::printU16ImmOperand(const MCInst *MI, unsigned OpNo,
36 raw_ostream &O) {
37 O << formatHex(MI->getOperand(OpNo).getImm() & 0xffff);
38}
39
40void AMDGPUInstPrinter::printU32ImmOperand(const MCInst *MI, unsigned OpNo,
41 raw_ostream &O) {
42 O << formatHex(MI->getOperand(OpNo).getImm() & 0xffffffff);
43}
44
Matt Arsenault61cc9082014-10-10 22:16:07 +000045void AMDGPUInstPrinter::printU8ImmDecOperand(const MCInst *MI, unsigned OpNo,
46 raw_ostream &O) {
47 O << formatDec(MI->getOperand(OpNo).getImm() & 0xff);
48}
49
50void AMDGPUInstPrinter::printU16ImmDecOperand(const MCInst *MI, unsigned OpNo,
51 raw_ostream &O) {
52 O << formatDec(MI->getOperand(OpNo).getImm() & 0xffff);
53}
54
Tom Stellard229d5e62014-08-05 14:48:12 +000055void AMDGPUInstPrinter::printOffen(const MCInst *MI, unsigned OpNo,
56 raw_ostream &O) {
57 if (MI->getOperand(OpNo).getImm())
58 O << " offen";
59}
60
61void AMDGPUInstPrinter::printIdxen(const MCInst *MI, unsigned OpNo,
62 raw_ostream &O) {
63 if (MI->getOperand(OpNo).getImm())
64 O << " idxen";
65}
66
67void AMDGPUInstPrinter::printAddr64(const MCInst *MI, unsigned OpNo,
68 raw_ostream &O) {
69 if (MI->getOperand(OpNo).getImm())
70 O << " addr64";
71}
72
73void AMDGPUInstPrinter::printMBUFOffset(const MCInst *MI, unsigned OpNo,
74 raw_ostream &O) {
75 if (MI->getOperand(OpNo).getImm()) {
76 O << " offset:";
Matt Arsenaultfb13b222014-12-03 03:12:13 +000077 printU16ImmDecOperand(MI, OpNo, O);
Tom Stellard229d5e62014-08-05 14:48:12 +000078 }
79}
80
Matt Arsenault61cc9082014-10-10 22:16:07 +000081void AMDGPUInstPrinter::printDSOffset(const MCInst *MI, unsigned OpNo,
82 raw_ostream &O) {
83 uint16_t Imm = MI->getOperand(OpNo).getImm();
84 if (Imm != 0) {
85 O << " offset:";
86 printU16ImmDecOperand(MI, OpNo, O);
87 }
88}
89
90void AMDGPUInstPrinter::printDSOffset0(const MCInst *MI, unsigned OpNo,
91 raw_ostream &O) {
Tom Stellard1f3416a2015-04-08 01:09:19 +000092 if (MI->getOperand(OpNo).getImm()) {
93 O << " offset0:";
94 printU8ImmDecOperand(MI, OpNo, O);
95 }
Matt Arsenault61cc9082014-10-10 22:16:07 +000096}
97
98void AMDGPUInstPrinter::printDSOffset1(const MCInst *MI, unsigned OpNo,
99 raw_ostream &O) {
Tom Stellard1f3416a2015-04-08 01:09:19 +0000100 if (MI->getOperand(OpNo).getImm()) {
101 O << " offset1:";
102 printU8ImmDecOperand(MI, OpNo, O);
103 }
Matt Arsenault61cc9082014-10-10 22:16:07 +0000104}
105
Tom Stellard065e3d42015-03-09 18:49:54 +0000106void AMDGPUInstPrinter::printGDS(const MCInst *MI, unsigned OpNo,
107 raw_ostream &O) {
108 if (MI->getOperand(OpNo).getImm())
109 O << " gds";
110}
111
Tom Stellard229d5e62014-08-05 14:48:12 +0000112void AMDGPUInstPrinter::printGLC(const MCInst *MI, unsigned OpNo,
113 raw_ostream &O) {
114 if (MI->getOperand(OpNo).getImm())
115 O << " glc";
116}
117
118void AMDGPUInstPrinter::printSLC(const MCInst *MI, unsigned OpNo,
119 raw_ostream &O) {
120 if (MI->getOperand(OpNo).getImm())
121 O << " slc";
122}
123
124void AMDGPUInstPrinter::printTFE(const MCInst *MI, unsigned OpNo,
125 raw_ostream &O) {
126 if (MI->getOperand(OpNo).getImm())
127 O << " tfe";
128}
129
Matt Arsenault72b31ee2013-11-12 02:35:51 +0000130void AMDGPUInstPrinter::printRegOperand(unsigned reg, raw_ostream &O) {
131 switch (reg) {
132 case AMDGPU::VCC:
133 O << "vcc";
134 return;
135 case AMDGPU::SCC:
136 O << "scc";
137 return;
138 case AMDGPU::EXEC:
139 O << "exec";
140 return;
141 case AMDGPU::M0:
142 O << "m0";
143 return;
Matt Arsenault3f981402014-09-15 15:41:53 +0000144 case AMDGPU::FLAT_SCR:
145 O << "flat_scratch";
146 return;
147 case AMDGPU::VCC_LO:
148 O << "vcc_lo";
149 return;
150 case AMDGPU::VCC_HI:
151 O << "vcc_hi";
152 return;
153 case AMDGPU::EXEC_LO:
154 O << "exec_lo";
155 return;
156 case AMDGPU::EXEC_HI:
157 O << "exec_hi";
158 return;
159 case AMDGPU::FLAT_SCR_LO:
160 O << "flat_scratch_lo";
161 return;
162 case AMDGPU::FLAT_SCR_HI:
163 O << "flat_scratch_hi";
164 return;
Matt Arsenault72b31ee2013-11-12 02:35:51 +0000165 default:
166 break;
167 }
168
Matt Arsenaultfcf86c52014-04-15 22:32:42 +0000169 char Type;
170 unsigned NumRegs;
Matt Arsenault72b31ee2013-11-12 02:35:51 +0000171
Matt Arsenaultfcf86c52014-04-15 22:32:42 +0000172 if (MRI.getRegClass(AMDGPU::VGPR_32RegClassID).contains(reg)) {
173 Type = 'v';
174 NumRegs = 1;
175 } else if (MRI.getRegClass(AMDGPU::SGPR_32RegClassID).contains(reg)) {
176 Type = 's';
177 NumRegs = 1;
178 } else if (MRI.getRegClass(AMDGPU::VReg_64RegClassID).contains(reg)) {
179 Type = 'v';
180 NumRegs = 2;
181 } else if (MRI.getRegClass(AMDGPU::SReg_64RegClassID).contains(reg)) {
182 Type = 's';
183 NumRegs = 2;
184 } else if (MRI.getRegClass(AMDGPU::VReg_128RegClassID).contains(reg)) {
185 Type = 'v';
186 NumRegs = 4;
187 } else if (MRI.getRegClass(AMDGPU::SReg_128RegClassID).contains(reg)) {
188 Type = 's';
189 NumRegs = 4;
190 } else if (MRI.getRegClass(AMDGPU::VReg_96RegClassID).contains(reg)) {
191 Type = 'v';
192 NumRegs = 3;
193 } else if (MRI.getRegClass(AMDGPU::VReg_256RegClassID).contains(reg)) {
194 Type = 'v';
195 NumRegs = 8;
196 } else if (MRI.getRegClass(AMDGPU::SReg_256RegClassID).contains(reg)) {
197 Type = 's';
198 NumRegs = 8;
199 } else if (MRI.getRegClass(AMDGPU::VReg_512RegClassID).contains(reg)) {
200 Type = 'v';
201 NumRegs = 16;
202 } else if (MRI.getRegClass(AMDGPU::SReg_512RegClassID).contains(reg)) {
203 Type = 's';
204 NumRegs = 16;
205 } else {
206 O << getRegisterName(reg);
Matt Arsenault72b31ee2013-11-12 02:35:51 +0000207 return;
208 }
209
Matt Arsenaultf4d871b2014-06-23 18:00:26 +0000210 // The low 8 bits of the encoding value is the register index, for both VGPRs
211 // and SGPRs.
212 unsigned RegIdx = MRI.getEncodingValue(reg) & ((1 << 8) - 1);
Matt Arsenaultfcf86c52014-04-15 22:32:42 +0000213 if (NumRegs == 1) {
214 O << Type << RegIdx;
Matt Arsenault72b31ee2013-11-12 02:35:51 +0000215 return;
216 }
217
Matt Arsenaultfcf86c52014-04-15 22:32:42 +0000218 O << Type << '[' << RegIdx << ':' << (RegIdx + NumRegs - 1) << ']';
Matt Arsenault72b31ee2013-11-12 02:35:51 +0000219}
220
Tom Stellardc0503922015-03-12 21:34:22 +0000221void AMDGPUInstPrinter::printVOPDst(const MCInst *MI, unsigned OpNo,
222 raw_ostream &O) {
223 if (MII.get(MI->getOpcode()).TSFlags & SIInstrFlags::VOP3)
224 O << "_e64 ";
225 else
226 O << "_e32 ";
227
228 printOperand(MI, OpNo, O);
229}
230
Matt Arsenault303011a2014-12-17 21:04:08 +0000231void AMDGPUInstPrinter::printImmediate32(uint32_t Imm, raw_ostream &O) {
Matt Arsenault4d7d3832014-04-15 22:32:49 +0000232 int32_t SImm = static_cast<int32_t>(Imm);
233 if (SImm >= -16 && SImm <= 64) {
234 O << SImm;
235 return;
236 }
237
Matt Arsenault02dc2652014-09-17 17:32:13 +0000238 if (Imm == FloatToBits(0.0f))
239 O << "0.0";
240 else if (Imm == FloatToBits(1.0f))
241 O << "1.0";
242 else if (Imm == FloatToBits(-1.0f))
243 O << "-1.0";
244 else if (Imm == FloatToBits(0.5f))
245 O << "0.5";
246 else if (Imm == FloatToBits(-0.5f))
247 O << "-0.5";
248 else if (Imm == FloatToBits(2.0f))
249 O << "2.0";
250 else if (Imm == FloatToBits(-2.0f))
251 O << "-2.0";
252 else if (Imm == FloatToBits(4.0f))
253 O << "4.0";
254 else if (Imm == FloatToBits(-4.0f))
255 O << "-4.0";
Matt Arsenault303011a2014-12-17 21:04:08 +0000256 else
Matt Arsenault02dc2652014-09-17 17:32:13 +0000257 O << formatHex(static_cast<uint64_t>(Imm));
Matt Arsenault303011a2014-12-17 21:04:08 +0000258}
259
260void AMDGPUInstPrinter::printImmediate64(uint64_t Imm, raw_ostream &O) {
261 int64_t SImm = static_cast<int64_t>(Imm);
262 if (SImm >= -16 && SImm <= 64) {
263 O << SImm;
264 return;
Matt Arsenault4d7d3832014-04-15 22:32:49 +0000265 }
Matt Arsenault303011a2014-12-17 21:04:08 +0000266
267 if (Imm == DoubleToBits(0.0))
268 O << "0.0";
269 else if (Imm == DoubleToBits(1.0))
270 O << "1.0";
271 else if (Imm == DoubleToBits(-1.0))
272 O << "-1.0";
273 else if (Imm == DoubleToBits(0.5))
274 O << "0.5";
275 else if (Imm == DoubleToBits(-0.5))
276 O << "-0.5";
277 else if (Imm == DoubleToBits(2.0))
278 O << "2.0";
279 else if (Imm == DoubleToBits(-2.0))
280 O << "-2.0";
281 else if (Imm == DoubleToBits(4.0))
282 O << "4.0";
283 else if (Imm == DoubleToBits(-4.0))
284 O << "-4.0";
285 else
286 llvm_unreachable("64-bit literal constants not supported");
Matt Arsenault4d7d3832014-04-15 22:32:49 +0000287}
288
Tom Stellard75aadc22012-12-11 21:25:42 +0000289void AMDGPUInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
290 raw_ostream &O) {
291
292 const MCOperand &Op = MI->getOperand(OpNo);
293 if (Op.isReg()) {
294 switch (Op.getReg()) {
295 // This is the default predicate state, so we don't need to print it.
Matt Arsenault72b31ee2013-11-12 02:35:51 +0000296 case AMDGPU::PRED_SEL_OFF:
297 break;
298
299 default:
300 printRegOperand(Op.getReg(), O);
301 break;
Tom Stellard75aadc22012-12-11 21:25:42 +0000302 }
303 } else if (Op.isImm()) {
Matt Arsenault303011a2014-12-17 21:04:08 +0000304 const MCInstrDesc &Desc = MII.get(MI->getOpcode());
305 int RCID = Desc.OpInfo[OpNo].RegClass;
306 if (RCID != -1) {
307 const MCRegisterClass &ImmRC = MRI.getRegClass(RCID);
308 if (ImmRC.getSize() == 4)
309 printImmediate32(Op.getImm(), O);
310 else if (ImmRC.getSize() == 8)
311 printImmediate64(Op.getImm(), O);
312 else
313 llvm_unreachable("Invalid register class size");
Matt Arsenault70120fa2015-02-21 21:29:00 +0000314 } else if (Desc.OpInfo[OpNo].OperandType == MCOI::OPERAND_IMMEDIATE) {
315 printImmediate32(Op.getImm(), O);
Matt Arsenault303011a2014-12-17 21:04:08 +0000316 } else {
317 // We hit this for the immediate instruction bits that don't yet have a
318 // custom printer.
319 // TODO: Eventually this should be unnecessary.
320 O << formatDec(Op.getImm());
321 }
Tom Stellard75aadc22012-12-11 21:25:42 +0000322 } else if (Op.isFPImm()) {
Matt Arsenault02dc2652014-09-17 17:32:13 +0000323 // We special case 0.0 because otherwise it will be printed as an integer.
324 if (Op.getFPImm() == 0.0)
325 O << "0.0";
Matt Arsenault303011a2014-12-17 21:04:08 +0000326 else {
327 const MCInstrDesc &Desc = MII.get(MI->getOpcode());
328 const MCRegisterClass &ImmRC = MRI.getRegClass(Desc.OpInfo[OpNo].RegClass);
329
330 if (ImmRC.getSize() == 4)
331 printImmediate32(FloatToBits(Op.getFPImm()), O);
332 else if (ImmRC.getSize() == 8)
333 printImmediate64(DoubleToBits(Op.getFPImm()), O);
334 else
335 llvm_unreachable("Invalid register class size");
336 }
Christian Konigbf114b42013-02-21 15:17:22 +0000337 } else if (Op.isExpr()) {
338 const MCExpr *Exp = Op.getExpr();
339 Exp->print(O);
Tom Stellard75aadc22012-12-11 21:25:42 +0000340 } else {
Matt Arsenault393366c2014-09-21 17:27:31 +0000341 llvm_unreachable("unknown operand type in printOperand");
Tom Stellard75aadc22012-12-11 21:25:42 +0000342 }
343}
344
Vincent Lejeune94af31f2014-05-10 19:18:33 +0000345void AMDGPUInstPrinter::printOperandAndMods(const MCInst *MI, unsigned OpNo,
346 raw_ostream &O) {
347 unsigned InputModifiers = MI->getOperand(OpNo).getImm();
Matt Arsenault9783e002014-09-29 15:50:26 +0000348 if (InputModifiers & SISrcMods::NEG)
Matt Arsenault3673eba2014-09-21 17:27:28 +0000349 O << '-';
Matt Arsenault9783e002014-09-29 15:50:26 +0000350 if (InputModifiers & SISrcMods::ABS)
Matt Arsenault3673eba2014-09-21 17:27:28 +0000351 O << '|';
Vincent Lejeune94af31f2014-05-10 19:18:33 +0000352 printOperand(MI, OpNo + 1, O);
Matt Arsenault9783e002014-09-29 15:50:26 +0000353 if (InputModifiers & SISrcMods::ABS)
Matt Arsenault3673eba2014-09-21 17:27:28 +0000354 O << '|';
Vincent Lejeune94af31f2014-05-10 19:18:33 +0000355}
356
Michel Danzere9bb18b2013-02-14 19:03:25 +0000357void AMDGPUInstPrinter::printInterpSlot(const MCInst *MI, unsigned OpNum,
358 raw_ostream &O) {
359 unsigned Imm = MI->getOperand(OpNum).getImm();
360
361 if (Imm == 2) {
362 O << "P0";
363 } else if (Imm == 1) {
364 O << "P20";
365 } else if (Imm == 0) {
366 O << "P10";
367 } else {
Matt Arsenault393366c2014-09-21 17:27:31 +0000368 llvm_unreachable("Invalid interpolation parameter slot");
Michel Danzere9bb18b2013-02-14 19:03:25 +0000369 }
370}
371
Tom Stellard75aadc22012-12-11 21:25:42 +0000372void AMDGPUInstPrinter::printMemOperand(const MCInst *MI, unsigned OpNo,
373 raw_ostream &O) {
374 printOperand(MI, OpNo, O);
375 O << ", ";
376 printOperand(MI, OpNo + 1, O);
377}
378
379void AMDGPUInstPrinter::printIfSet(const MCInst *MI, unsigned OpNo,
Vincent Lejeunef97af792013-05-02 21:52:30 +0000380 raw_ostream &O, StringRef Asm,
381 StringRef Default) {
Tom Stellard75aadc22012-12-11 21:25:42 +0000382 const MCOperand &Op = MI->getOperand(OpNo);
383 assert(Op.isImm());
384 if (Op.getImm() == 1) {
385 O << Asm;
Vincent Lejeunef97af792013-05-02 21:52:30 +0000386 } else {
387 O << Default;
Tom Stellard75aadc22012-12-11 21:25:42 +0000388 }
389}
390
391void AMDGPUInstPrinter::printAbs(const MCInst *MI, unsigned OpNo,
392 raw_ostream &O) {
393 printIfSet(MI, OpNo, O, "|");
394}
395
396void AMDGPUInstPrinter::printClamp(const MCInst *MI, unsigned OpNo,
397 raw_ostream &O) {
398 printIfSet(MI, OpNo, O, "_SAT");
399}
400
Matt Arsenault97069782014-09-30 19:49:48 +0000401void AMDGPUInstPrinter::printClampSI(const MCInst *MI, unsigned OpNo,
402 raw_ostream &O) {
403 if (MI->getOperand(OpNo).getImm())
404 O << " clamp";
405}
406
407void AMDGPUInstPrinter::printOModSI(const MCInst *MI, unsigned OpNo,
408 raw_ostream &O) {
409 int Imm = MI->getOperand(OpNo).getImm();
410 if (Imm == SIOutMods::MUL2)
411 O << " mul:2";
412 else if (Imm == SIOutMods::MUL4)
413 O << " mul:4";
414 else if (Imm == SIOutMods::DIV2)
415 O << " div:2";
416}
417
Tom Stellard75aadc22012-12-11 21:25:42 +0000418void AMDGPUInstPrinter::printLiteral(const MCInst *MI, unsigned OpNo,
419 raw_ostream &O) {
Matt Arsenault762ef012014-06-23 18:00:24 +0000420 int32_t Imm = MI->getOperand(OpNo).getImm();
421 O << Imm << '(' << BitsToFloat(Imm) << ')';
Tom Stellard75aadc22012-12-11 21:25:42 +0000422}
423
424void AMDGPUInstPrinter::printLast(const MCInst *MI, unsigned OpNo,
425 raw_ostream &O) {
Vincent Lejeune709e0162013-05-17 16:49:49 +0000426 printIfSet(MI, OpNo, O.indent(25 - O.GetNumBytesInBuffer()), "*", " ");
Tom Stellard75aadc22012-12-11 21:25:42 +0000427}
428
429void AMDGPUInstPrinter::printNeg(const MCInst *MI, unsigned OpNo,
430 raw_ostream &O) {
431 printIfSet(MI, OpNo, O, "-");
432}
433
434void AMDGPUInstPrinter::printOMOD(const MCInst *MI, unsigned OpNo,
435 raw_ostream &O) {
436 switch (MI->getOperand(OpNo).getImm()) {
437 default: break;
438 case 1:
439 O << " * 2.0";
440 break;
441 case 2:
442 O << " * 4.0";
443 break;
444 case 3:
445 O << " / 2.0";
446 break;
447 }
448}
449
450void AMDGPUInstPrinter::printRel(const MCInst *MI, unsigned OpNo,
451 raw_ostream &O) {
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000452 printIfSet(MI, OpNo, O, "+");
Tom Stellard75aadc22012-12-11 21:25:42 +0000453}
454
455void AMDGPUInstPrinter::printUpdateExecMask(const MCInst *MI, unsigned OpNo,
456 raw_ostream &O) {
457 printIfSet(MI, OpNo, O, "ExecMask,");
458}
459
460void AMDGPUInstPrinter::printUpdatePred(const MCInst *MI, unsigned OpNo,
461 raw_ostream &O) {
462 printIfSet(MI, OpNo, O, "Pred,");
463}
464
465void AMDGPUInstPrinter::printWrite(const MCInst *MI, unsigned OpNo,
466 raw_ostream &O) {
467 const MCOperand &Op = MI->getOperand(OpNo);
468 if (Op.getImm() == 0) {
469 O << " (MASKED)";
470 }
471}
472
Tom Stellard365366f2013-01-23 02:09:06 +0000473void AMDGPUInstPrinter::printSel(const MCInst *MI, unsigned OpNo,
474 raw_ostream &O) {
475 const char * chans = "XYZW";
476 int sel = MI->getOperand(OpNo).getImm();
477
478 int chan = sel & 3;
479 sel >>= 2;
480
481 if (sel >= 512) {
482 sel -= 512;
483 int cb = sel >> 12;
484 sel &= 4095;
Matt Arsenault3673eba2014-09-21 17:27:28 +0000485 O << cb << '[' << sel << ']';
Tom Stellard365366f2013-01-23 02:09:06 +0000486 } else if (sel >= 448) {
487 sel -= 448;
488 O << sel;
489 } else if (sel >= 0){
490 O << sel;
491 }
492
493 if (sel >= 0)
Matt Arsenault3673eba2014-09-21 17:27:28 +0000494 O << '.' << chans[chan];
Tom Stellard365366f2013-01-23 02:09:06 +0000495}
496
Vincent Lejeunef97af792013-05-02 21:52:30 +0000497void AMDGPUInstPrinter::printBankSwizzle(const MCInst *MI, unsigned OpNo,
498 raw_ostream &O) {
499 int BankSwizzle = MI->getOperand(OpNo).getImm();
500 switch (BankSwizzle) {
501 case 1:
Vincent Lejeunebb8a87212013-06-29 19:32:29 +0000502 O << "BS:VEC_021/SCL_122";
Vincent Lejeunef97af792013-05-02 21:52:30 +0000503 break;
504 case 2:
Vincent Lejeunebb8a87212013-06-29 19:32:29 +0000505 O << "BS:VEC_120/SCL_212";
Vincent Lejeunef97af792013-05-02 21:52:30 +0000506 break;
507 case 3:
Vincent Lejeunebb8a87212013-06-29 19:32:29 +0000508 O << "BS:VEC_102/SCL_221";
Vincent Lejeunef97af792013-05-02 21:52:30 +0000509 break;
510 case 4:
511 O << "BS:VEC_201";
512 break;
513 case 5:
514 O << "BS:VEC_210";
515 break;
516 default:
517 break;
518 }
519 return;
520}
521
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000522void AMDGPUInstPrinter::printRSel(const MCInst *MI, unsigned OpNo,
523 raw_ostream &O) {
524 unsigned Sel = MI->getOperand(OpNo).getImm();
525 switch (Sel) {
526 case 0:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000527 O << 'X';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000528 break;
529 case 1:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000530 O << 'Y';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000531 break;
532 case 2:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000533 O << 'Z';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000534 break;
535 case 3:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000536 O << 'W';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000537 break;
538 case 4:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000539 O << '0';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000540 break;
541 case 5:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000542 O << '1';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000543 break;
544 case 7:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000545 O << '_';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000546 break;
547 default:
548 break;
549 }
550}
551
552void AMDGPUInstPrinter::printCT(const MCInst *MI, unsigned OpNo,
553 raw_ostream &O) {
554 unsigned CT = MI->getOperand(OpNo).getImm();
555 switch (CT) {
556 case 0:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000557 O << 'U';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000558 break;
559 case 1:
Matt Arsenault3673eba2014-09-21 17:27:28 +0000560 O << 'N';
Vincent Lejeuned3eed662013-05-17 16:50:20 +0000561 break;
562 default:
563 break;
564 }
565}
566
Vincent Lejeuneb0422e22013-05-02 21:52:40 +0000567void AMDGPUInstPrinter::printKCache(const MCInst *MI, unsigned OpNo,
568 raw_ostream &O) {
569 int KCacheMode = MI->getOperand(OpNo).getImm();
570 if (KCacheMode > 0) {
571 int KCacheBank = MI->getOperand(OpNo - 2).getImm();
Matt Arsenault3673eba2014-09-21 17:27:28 +0000572 O << "CB" << KCacheBank << ':';
Vincent Lejeuneb0422e22013-05-02 21:52:40 +0000573 int KCacheAddr = MI->getOperand(OpNo + 2).getImm();
Matt Arsenault3673eba2014-09-21 17:27:28 +0000574 int LineSize = (KCacheMode == 1) ? 16 : 32;
575 O << KCacheAddr * 16 << '-' << KCacheAddr * 16 + LineSize;
Vincent Lejeuneb0422e22013-05-02 21:52:40 +0000576 }
577}
578
Michel Danzer6064f572014-01-27 07:20:44 +0000579void AMDGPUInstPrinter::printSendMsg(const MCInst *MI, unsigned OpNo,
580 raw_ostream &O) {
581 unsigned SImm16 = MI->getOperand(OpNo).getImm();
582 unsigned Msg = SImm16 & 0xF;
583 if (Msg == 2 || Msg == 3) {
584 unsigned Op = (SImm16 >> 4) & 0xF;
585 if (Msg == 3)
586 O << "Gs_done(";
587 else
588 O << "Gs(";
589 if (Op == 0) {
590 O << "nop";
591 } else {
592 unsigned Stream = (SImm16 >> 8) & 0x3;
593 if (Op == 1)
594 O << "cut";
595 else if (Op == 2)
596 O << "emit";
597 else if (Op == 3)
598 O << "emit-cut";
599 O << " stream " << Stream;
600 }
601 O << "), [m0] ";
602 } else if (Msg == 1)
603 O << "interrupt ";
604 else if (Msg == 15)
605 O << "system ";
606 else
607 O << "unknown(" << Msg << ") ";
608}
609
Vincent Lejeuned6cbede2013-10-13 17:56:28 +0000610void AMDGPUInstPrinter::printWaitFlag(const MCInst *MI, unsigned OpNo,
611 raw_ostream &O) {
612 // Note: Mask values are taken from SIInsertWaits.cpp and not from ISA docs
613 // SIInsertWaits.cpp bits usage does not match ISA docs description but it
614 // works so it might be a misprint in docs.
615 unsigned SImm16 = MI->getOperand(OpNo).getImm();
616 unsigned Vmcnt = SImm16 & 0xF;
617 unsigned Expcnt = (SImm16 >> 4) & 0xF;
618 unsigned Lgkmcnt = (SImm16 >> 8) & 0xF;
Matt Arsenault3a997592014-09-26 01:09:46 +0000619
620 bool NeedSpace = false;
621
622 if (Vmcnt != 0xF) {
623 O << "vmcnt(" << Vmcnt << ')';
624 NeedSpace = true;
625 }
626
627 if (Expcnt != 0x7) {
628 if (NeedSpace)
629 O << ' ';
630 O << "expcnt(" << Expcnt << ')';
631 NeedSpace = true;
632 }
633
634 if (Lgkmcnt != 0x7) {
635 if (NeedSpace)
636 O << ' ';
Matt Arsenault3673eba2014-09-21 17:27:28 +0000637 O << "lgkmcnt(" << Lgkmcnt << ')';
Matt Arsenault3a997592014-09-26 01:09:46 +0000638 }
Vincent Lejeuned6cbede2013-10-13 17:56:28 +0000639}
640
Tom Stellard75aadc22012-12-11 21:25:42 +0000641#include "AMDGPUGenAsmWriter.inc"