1 //===-- SIInstrFormats.td - SI Instruction Encodings ----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // SI Instruction format definitions.
11 //===----------------------------------------------------------------------===//
13 class InstSI <dag outs, dag ins, string asm = "",
14 list<dag> pattern = []> :
15 AMDGPUInst<outs, ins, asm, pattern>, PredicateControl {
16 // Low bits - basic encoding information.
20 // SALU instruction formats.
27 // VALU instruction formats.
38 // Memory instruction formats.
44 field bit VSAMPLE = 0;
49 // Combined SGPR/VGPR spill bit
52 // LDSDIR instruction format.
55 // VINTERP instruction format.
56 field bit VINTERP = 0;
58 // High bits - other information.
60 field bit EXP_CNT = 0;
61 field bit LGKM_CNT = 0;
63 // Whether WQM _must_ be enabled for this instruction.
66 // Whether WQM _must_ be disabled for this instruction.
67 field bit DisableWQM = 0;
69 field bit Gather4 = 0;
71 // This is an s_store_dword* instruction that requires a cache flush
72 // on wave termination. It is necessary to distinguish from mayStore
73 // SMEM instructions like the cache flush ones.
74 field bit ScalarStore = 0;
76 // Whether the operands can be ignored when computing the
78 field bit FixedSize = 0;
80 // This bit indicates that this is a VOP3 opcode which supports op_sel
82 field bit VOP3_OPSEL = 0;
84 // Is it possible for this instruction to be atomic?
85 field bit maybeAtomic = 1;
87 // This bit indicates that this is a VI instruction which is renamed
88 // in GFX9. Required for correct mapping from pseudo to MC.
89 field bit renamedInGFX9 = 0;
91 // This bit indicates that this has a floating point result type, so
92 // the clamp modifier has floating point semantics.
93 field bit FPClamp = 0;
95 // This bit indicates that instruction may support integer clamping
96 // which depends on GPU features.
97 field bit IntClamp = 0;
99 // This field indicates that the clamp applies to the low component
100 // of a packed output register.
101 field bit ClampLo = 0;
103 // This field indicates that the clamp applies to the high component
104 // of a packed output register.
105 field bit ClampHi = 0;
107 // This bit indicates that this is a packed VOP3P instruction
108 field bit IsPacked = 0;
110 // This bit indicates that this is a D16 buffer instruction.
111 field bit D16Buf = 0;
113 // This field indicates that FLAT instruction accesses FLAT_GLBL segment.
114 // Must be 0 for non-FLAT instructions.
115 field bit FlatGlobal = 0;
117 // Reads the mode register, usually for FP environment.
118 field bit ReadsModeReg = 0;
120 // This bit indicates that this uses the floating point double precision
121 // rounding mode flags
122 field bit FPDPRounding = 0;
124 // Instruction is FP atomic.
125 field bit FPAtomic = 0;
127 // This bit indicates that this is one of MFMA instructions.
130 // This bit indicates that this is one of DOT instructions.
133 // This field indicates that FLAT instruction accesses FLAT_SCRATCH segment.
134 // Must be 0 for non-FLAT instructions.
135 field bit FlatScratch = 0;
137 // Atomic without a return.
138 field bit IsAtomicNoRet = 0;
140 // Atomic with return.
141 field bit IsAtomicRet = 0;
143 // This bit indicates that this is one of WMMA instructions.
144 field bit IsWMMA = 0;
146 // This bit indicates that tied source will not be read.
147 field bit TiedSourceNotRead = 0;
149 // This bit indicates that the instruction is never-uniform/divergent
150 field bit IsNeverUniform = 0;
152 // ds_gws_* instructions.
155 // This bit indicates that this is one of SWMMAC instructions.
156 field bit IsSWMMAC = 0;
158 // These need to be kept in sync with the enum in SIInstrFlags.
159 let TSFlags{0} = SALU;
160 let TSFlags{1} = VALU;
162 let TSFlags{2} = SOP1;
163 let TSFlags{3} = SOP2;
164 let TSFlags{4} = SOPC;
165 let TSFlags{5} = SOPK;
166 let TSFlags{6} = SOPP;
168 let TSFlags{7} = VOP1;
169 let TSFlags{8} = VOP2;
170 let TSFlags{9} = VOPC;
171 let TSFlags{10} = VOP3;
172 let TSFlags{12} = VOP3P;
174 let TSFlags{13} = VINTRP;
175 let TSFlags{14} = SDWA;
176 let TSFlags{15} = DPP;
177 let TSFlags{16} = TRANS;
179 let TSFlags{17} = MUBUF;
180 let TSFlags{18} = MTBUF;
181 let TSFlags{19} = SMRD;
182 let TSFlags{20} = MIMG;
183 let TSFlags{21} = VIMAGE;
184 let TSFlags{22} = VSAMPLE;
185 let TSFlags{23} = EXP;
186 let TSFlags{24} = FLAT;
187 let TSFlags{25} = DS;
189 let TSFlags{26} = Spill;
191 // Reserved, must be 0
194 let TSFlags{28} = LDSDIR;
195 let TSFlags{29} = VINTERP;
197 let TSFlags{32} = VM_CNT;
198 let TSFlags{33} = EXP_CNT;
199 let TSFlags{34} = LGKM_CNT;
201 let TSFlags{35} = WQM;
202 let TSFlags{36} = DisableWQM;
203 let TSFlags{37} = Gather4;
205 // Reserved, must be 0.
208 let TSFlags{39} = ScalarStore;
209 let TSFlags{40} = FixedSize;
211 // Reserved, must be 0.
214 let TSFlags{42} = VOP3_OPSEL;
216 let TSFlags{43} = maybeAtomic;
217 let TSFlags{44} = renamedInGFX9;
219 let TSFlags{45} = FPClamp;
220 let TSFlags{46} = IntClamp;
221 let TSFlags{47} = ClampLo;
222 let TSFlags{48} = ClampHi;
224 let TSFlags{49} = IsPacked;
226 let TSFlags{50} = D16Buf;
228 let TSFlags{51} = FlatGlobal;
230 let TSFlags{52} = FPDPRounding;
232 let TSFlags{53} = FPAtomic;
234 let TSFlags{54} = IsMAI;
236 let TSFlags{55} = IsDOT;
238 let TSFlags{56} = FlatScratch;
240 let TSFlags{57} = IsAtomicNoRet;
242 let TSFlags{58} = IsAtomicRet;
244 let TSFlags{59} = IsWMMA;
246 let TSFlags{60} = TiedSourceNotRead;
248 let TSFlags{61} = IsNeverUniform;
250 let TSFlags{62} = GWS;
252 let TSFlags{63} = IsSWMMAC;
254 let SchedRW = [Write32Bit];
256 let AsmVariantName = AMDGPUAsmVariants.Default;
258 // Avoid changing source registers in a way that violates constant bus read limitations.
259 let hasExtraSrcRegAllocReq = !or(VOP1, VOP2, VOP3, VOPC, SDWA, VALU);
262 class PseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = "">
263 : InstSI<outs, ins, asm, pattern> {
265 let isCodeGenOnly = 1;
268 class SPseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = "">
269 : PseudoInstSI<outs, ins, pattern, asm> {
273 class VPseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = "">
274 : PseudoInstSI<outs, ins, pattern, asm> {
279 class CFPseudoInstSI<dag outs, dag ins, list<dag> pattern = [],
280 bit UseExec = 0, bit DefExec = 0> :
281 SPseudoInstSI<outs, ins, pattern> {
283 let Uses = !if(UseExec, [EXEC], []);
284 let Defs = !if(DefExec, [EXEC, SCC], [SCC]);
287 let hasSideEffects = 0;
312 class VOPDstOperand <RegisterClass rc> : RegisterOperand <rc, "printVOPDst">;
314 def VOPDstOperand_t16 : VOPDstOperand <VGPR_16> {
315 let EncoderMethod = "getMachineOpValueT16";
316 let DecoderMethod = "DecodeVGPR_16RegisterClass";
319 def VOPDstOperand_t16Lo128 : VOPDstOperand <VGPR_16_Lo128> {
320 let EncoderMethod = "getMachineOpValueT16Lo128";
321 let DecoderMethod = "DecodeVGPR_16_Lo128RegisterClass";
324 class VINTRPe <bits<2> op> : Enc32 {
330 let Inst{7-0} = vsrc;
331 let Inst{9-8} = attrchan;
332 let Inst{15-10} = attr;
333 let Inst{17-16} = op;
334 let Inst{25-18} = vdst;
335 let Inst{31-26} = 0x32; // encoding
338 class MIMGe_gfxpre11 : Enc64 {
350 let Inst{11-8} = dmask;
351 let Inst{12} = unorm;
352 let Inst{13} = cpol{CPolBit.GLC};
355 let Inst{25} = cpol{CPolBit.SLC};
356 let Inst{31-26} = 0x3c;
357 let Inst{47-40} = vdata{7-0};
358 let Inst{52-48} = srsrc{6-2};
359 let Inst{57-53} = ssamp{6-2};
363 class MIMGe_gfx6789 <bits<8> op> : MIMGe_gfxpre11 {
368 let Inst{7} = cpol{CPolBit.SCC};
371 let Inst{24-18} = op{6-0};
372 let Inst{39-32} = vaddr;
375 class MIMGe_gfx90a <bits<8> op> : MIMGe_gfxpre11 {
380 let Inst{7} = cpol{CPolBit.SCC};
382 let Inst{16} = vdata{9}; // ACC bit
383 let Inst{24-18} = op{6-0};
384 let Inst{39-32} = vaddr;
387 class MIMGe_gfx10 <bits<8> op> : MIMGe_gfxpre11 {
396 let Inst{7} = cpol{CPolBit.DLC};
398 let Inst{24-18} = op{6-0};
399 let Inst{39-32} = vaddr0;
403 class MIMGe_gfx11 <bits<8> op> : Enc64 {
422 let Inst{11-8} = dmask;
423 let Inst{12} = cpol{CPolBit.SLC};
424 let Inst{13} = cpol{CPolBit.DLC};
425 let Inst{14} = cpol{CPolBit.GLC};
429 let Inst{25-18} = op;
430 let Inst{31-26} = 0x3c;
431 let Inst{39-32} = vaddr0;
432 let Inst{47-40} = vdata;
433 let Inst{52-48} = srsrc{6-2};
436 let Inst{62-58} = ssamp{6-2};
439 class VIMAGE_VSAMPLE_Common <bits<8> op> : Enc96 {
458 let Inst{21-14} = op;
459 let Inst{25-22} = dmask;
460 let Inst{39-32} = vdata;
461 let Inst{49-41} = rsrc;
462 let Inst{51-50} = cpol{4-3}; // scope
463 let Inst{54-52} = cpol{2-0}; // th
464 let Inst{71-64} = vaddr0;
465 let Inst{79-72} = vaddr1;
466 let Inst{87-80} = vaddr2;
467 let Inst{95-88} = vaddr3;
470 class VSAMPLEe <bits<8> op> : VIMAGE_VSAMPLE_Common<op> {
476 let Inst{13} = unorm;
477 let Inst{31-26} = 0x39;
479 let Inst{63-55} = samp;
482 class VIMAGEe <bits<8> op> : VIMAGE_VSAMPLE_Common<op> {
485 let Inst{31-26} = 0x34;
487 let Inst{63-56} = vaddr4;
502 let Inst{31-26} = 0x3e;
503 let Inst{39-32} = src0;
504 let Inst{47-40} = src1;
505 let Inst{55-48} = src2;
506 let Inst{63-56} = src3;
509 // Pre-GFX11 encoding has compr and vm bits.
510 class EXPe_ComprVM : EXPe {
514 let Inst{10} = compr;
518 // GFX11+ encoding has row bit.
519 class EXPe_Row : EXPe {
525 let Uses = [EXEC] in {
527 class VINTRPCommon <dag outs, dag ins, string asm, list<dag> pattern> :
528 InstSI <outs, ins, asm, pattern> {
530 // VINTRP instructions read parameter values from LDS, but these parameter
531 // values are stored outside of the LDS memory that is allocated to the
532 // shader for general purpose use.
534 // While it may be possible for ds_read/ds_write instructions to access
535 // the parameter values in LDS, this would essentially be an out-of-bounds
536 // memory access which we consider to be undefined behavior.
538 // So even though these instructions read memory, this memory is outside the
539 // addressable memory space for the shader, and we consider these instructions
543 let hasSideEffects = 0;
547 } // End Uses = [EXEC]