xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/SIInstrFormats.td (revision 5def4c47d4bd90b209b9b4a4ba9faec15846d8fd)
1//===-- SIInstrFormats.td - SI Instruction Encodings ----------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// SI Instruction format definitions.
10//
11//===----------------------------------------------------------------------===//
12
13class InstSI <dag outs, dag ins, string asm = "",
14              list<dag> pattern = []> :
15  AMDGPUInst<outs, ins, asm, pattern>, GCNPredicateControl {
16  // Low bits - basic encoding information.
17  field bit SALU = 0;
18  field bit VALU = 0;
19
20  // SALU instruction formats.
21  field bit SOP1 = 0;
22  field bit SOP2 = 0;
23  field bit SOPC = 0;
24  field bit SOPK = 0;
25  field bit SOPP = 0;
26
27  // VALU instruction formats.
28  field bit VOP1 = 0;
29  field bit VOP2 = 0;
30  field bit VOPC = 0;
31  field bit VOP3 = 0;
32  field bit VOP3P = 0;
33  field bit VINTRP = 0;
34  field bit SDWA = 0;
35  field bit DPP = 0;
36  field bit TRANS = 0;
37
38  // Memory instruction formats.
39  field bit MUBUF = 0;
40  field bit MTBUF = 0;
41  field bit SMRD = 0;
42  field bit MIMG = 0;
43  field bit EXP = 0;
44  field bit FLAT = 0;
45  field bit DS = 0;
46
47  // Pseudo instruction formats.
48  field bit VGPRSpill = 0;
49  field bit SGPRSpill = 0;
50
51  // High bits - other information.
52  field bit VM_CNT = 0;
53  field bit EXP_CNT = 0;
54  field bit LGKM_CNT = 0;
55
56  // Whether WQM _must_ be enabled for this instruction.
57  field bit WQM = 0;
58
59  // Whether WQM _must_ be disabled for this instruction.
60  field bit DisableWQM = 0;
61
62  field bit Gather4 = 0;
63
64  // Most sopk treat the immediate as a signed 16-bit, however some
65  // use it as unsigned.
66  field bit SOPKZext = 0;
67
68  // This is an s_store_dword* instruction that requires a cache flush
69  // on wave termination. It is necessary to distinguish from mayStore
70  // SMEM instructions like the cache flush ones.
71  field bit ScalarStore = 0;
72
73  // Whether the operands can be ignored when computing the
74  // instruction size.
75  field bit FixedSize = 0;
76
77  // This bit tells the assembler to use the 32-bit encoding in case it
78  // is unable to infer the encoding from the operands.
79  field bit VOPAsmPrefer32Bit = 0;
80
81  // This bit indicates that this is a VOP3 opcode which supports op_sel
82  // modifier (gfx9 only).
83  field bit VOP3_OPSEL = 0;
84
85  // Is it possible for this instruction to be atomic?
86  field bit maybeAtomic = 0;
87
88  // This bit indicates that this is a VI instruction which is renamed
89  // in GFX9. Required for correct mapping from pseudo to MC.
90  field bit renamedInGFX9 = 0;
91
92  // This bit indicates that this has a floating point result type, so
93  // the clamp modifier has floating point semantics.
94  field bit FPClamp = 0;
95
96  // This bit indicates that instruction may support integer clamping
97  // which depends on GPU features.
98  field bit IntClamp = 0;
99
100  // This field indicates that the clamp applies to the low component
101  // of a packed output register.
102  field bit ClampLo = 0;
103
104  // This field indicates that the clamp applies to the high component
105  // of a packed output register.
106  field bit ClampHi = 0;
107
108  // This bit indicates that this is a packed VOP3P instruction
109  field bit IsPacked = 0;
110
111  // This bit indicates that this is a D16 buffer instruction.
112  field bit D16Buf = 0;
113
114  // This field indicates that FLAT instruction accesses FLAT_GLBL segment.
115  // Must be 0 for non-FLAT instructions.
116  field bit IsFlatGlobal = 0;
117
118  // Reads the mode register, usually for FP environment.
119  field bit ReadsModeReg = 0;
120
121  // This bit indicates that this uses the floating point double precision
122  // rounding mode flags
123  field bit FPDPRounding = 0;
124
125  // Instruction is FP atomic.
126  field bit FPAtomic = 0;
127
128  // This bit indicates that this is one of MFMA instructions.
129  field bit IsMAI = 0;
130
131  // This bit indicates that this is one of DOT instructions.
132  field bit IsDOT = 0;
133
134  // This field indicates that FLAT instruction accesses FLAT_SCRATCH segment.
135  // Must be 0 for non-FLAT instructions.
136  field bit IsFlatScratch = 0;
137
138  // These need to be kept in sync with the enum in SIInstrFlags.
139  let TSFlags{0} = SALU;
140  let TSFlags{1} = VALU;
141
142  let TSFlags{2} = SOP1;
143  let TSFlags{3} = SOP2;
144  let TSFlags{4} = SOPC;
145  let TSFlags{5} = SOPK;
146  let TSFlags{6} = SOPP;
147
148  let TSFlags{7} = VOP1;
149  let TSFlags{8} = VOP2;
150  let TSFlags{9} = VOPC;
151  let TSFlags{10} = VOP3;
152  let TSFlags{12} = VOP3P;
153
154  let TSFlags{13} = VINTRP;
155  let TSFlags{14} = SDWA;
156  let TSFlags{15} = DPP;
157  let TSFlags{16} = TRANS;
158
159  let TSFlags{17} = MUBUF;
160  let TSFlags{18} = MTBUF;
161  let TSFlags{19} = SMRD;
162  let TSFlags{20} = MIMG;
163  let TSFlags{21} = EXP;
164  let TSFlags{22} = FLAT;
165  let TSFlags{23} = DS;
166
167  let TSFlags{24} = VGPRSpill;
168  let TSFlags{25} = SGPRSpill;
169
170  let TSFlags{32} = VM_CNT;
171  let TSFlags{33} = EXP_CNT;
172  let TSFlags{34} = LGKM_CNT;
173
174  let TSFlags{35} = WQM;
175  let TSFlags{36} = DisableWQM;
176  let TSFlags{37} = Gather4;
177
178  let TSFlags{38} = SOPKZext;
179  let TSFlags{39} = ScalarStore;
180  let TSFlags{40} = FixedSize;
181  let TSFlags{41} = VOPAsmPrefer32Bit;
182  let TSFlags{42} = VOP3_OPSEL;
183
184  let TSFlags{43} = maybeAtomic;
185  let TSFlags{44} = renamedInGFX9;
186
187  let TSFlags{45} = FPClamp;
188  let TSFlags{46} = IntClamp;
189  let TSFlags{47} = ClampLo;
190  let TSFlags{48} = ClampHi;
191
192  let TSFlags{49} = IsPacked;
193
194  let TSFlags{50} = D16Buf;
195
196  let TSFlags{51} = IsFlatGlobal;
197
198  let TSFlags{52} = FPDPRounding;
199
200  let TSFlags{53} = FPAtomic;
201
202  let TSFlags{54} = IsMAI;
203
204  let TSFlags{55} = IsDOT;
205
206  let TSFlags{56} = IsFlatScratch;
207
208  let SchedRW = [Write32Bit];
209
210  let AsmVariantName = AMDGPUAsmVariants.Default;
211
212  // Avoid changing source registers in a way that violates constant bus read limitations.
213  let hasExtraSrcRegAllocReq = !or(VOP1, VOP2, VOP3, VOPC, SDWA, VALU);
214}
215
216class PseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = "">
217  : InstSI<outs, ins, asm, pattern> {
218  let isPseudo = 1;
219  let isCodeGenOnly = 1;
220}
221
222class SPseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = "">
223  : PseudoInstSI<outs, ins, pattern, asm> {
224  let SALU = 1;
225}
226
227class VPseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = "">
228  : PseudoInstSI<outs, ins, pattern, asm> {
229  let VALU = 1;
230  let Uses = [EXEC];
231}
232
233class CFPseudoInstSI<dag outs, dag ins, list<dag> pattern = [],
234  bit UseExec = 0, bit DefExec = 0> :
235  SPseudoInstSI<outs, ins, pattern> {
236
237  let Uses = !if(UseExec, [EXEC], []);
238  let Defs = !if(DefExec, [EXEC, SCC], [SCC]);
239  let mayLoad = 0;
240  let mayStore = 0;
241  let hasSideEffects = 0;
242}
243
244class Enc32 {
245  field bits<32> Inst;
246  int Size = 4;
247}
248
249class Enc64 {
250  field bits<64> Inst;
251  int Size = 8;
252}
253
254class VOPDstOperand <RegisterClass rc> : RegisterOperand <rc, "printVOPDst">;
255
256class VINTRPe <bits<2> op> : Enc32 {
257  bits<8> vdst;
258  bits<8> vsrc;
259  bits<2> attrchan;
260  bits<6> attr;
261
262  let Inst{7-0} = vsrc;
263  let Inst{9-8} = attrchan;
264  let Inst{15-10} = attr;
265  let Inst{17-16} = op;
266  let Inst{25-18} = vdst;
267  let Inst{31-26} = 0x32; // encoding
268}
269
270class MIMGe : Enc64 {
271  bits<8> vdata;
272  bits<4> dmask;
273  bits<1> unorm;
274  bits<1> glc;
275  bits<1> r128;
276  bits<1> tfe;
277  bits<1> lwe;
278  bits<1> slc;
279  bit d16;
280  bits<7> srsrc;
281  bits<7> ssamp;
282
283  let Inst{11-8} = dmask;
284  let Inst{12} = unorm;
285  let Inst{13} = glc;
286  let Inst{15} = r128;
287  let Inst{16} = tfe;
288  let Inst{17} = lwe;
289  let Inst{25} = slc;
290  let Inst{31-26} = 0x3c;
291  let Inst{47-40} = vdata;
292  let Inst{52-48} = srsrc{6-2};
293  let Inst{57-53} = ssamp{6-2};
294  let Inst{63} = d16;
295}
296
297class MIMGe_gfx6789 <bits<8> op> : MIMGe {
298  bits<8> vaddr;
299  bits<1> da;
300
301  let Inst{0} = op{7};
302  let Inst{14} = da;
303  let Inst{24-18} = op{6-0};
304  let Inst{39-32} = vaddr;
305}
306
307class MIMGe_gfx10 <bits<8> op> : MIMGe {
308  bits<8> vaddr0;
309  bits<3> dim;
310  bits<2> nsa;
311  bits<1> dlc;
312  bits<1> a16;
313
314  let Inst{0} = op{7};
315  let Inst{2-1} = nsa;
316  let Inst{5-3} = dim;
317  let Inst{7} = dlc;
318  let Inst{24-18} = op{6-0};
319  let Inst{39-32} = vaddr0;
320  let Inst{62} = a16;
321}
322
323class EXPe : Enc64 {
324  bits<4> en;
325  bits<6> tgt;
326  bits<1> compr;
327  bits<1> done;
328  bits<1> vm;
329  bits<8> src0;
330  bits<8> src1;
331  bits<8> src2;
332  bits<8> src3;
333
334  let Inst{3-0} = en;
335  let Inst{9-4} = tgt;
336  let Inst{10} = compr;
337  let Inst{11} = done;
338  let Inst{12} = vm;
339  let Inst{31-26} = 0x3e;
340  let Inst{39-32} = src0;
341  let Inst{47-40} = src1;
342  let Inst{55-48} = src2;
343  let Inst{63-56} = src3;
344}
345
346let Uses = [EXEC] in {
347
348class VINTRPCommon <dag outs, dag ins, string asm, list<dag> pattern> :
349    InstSI <outs, ins, asm, pattern> {
350  let VINTRP = 1;
351  // VINTRP instructions read parameter values from LDS, but these parameter
352  // values are stored outside of the LDS memory that is allocated to the
353  // shader for general purpose use.
354  //
355  // While it may be possible for ds_read/ds_write instructions to access
356  // the parameter values in LDS, this would essentially be an out-of-bounds
357  // memory access which we consider to be undefined behavior.
358  //
359  // So even though these instructions read memory, this memory is outside the
360  // addressable memory space for the shader, and we consider these instructions
361  // to be readnone.
362  let mayLoad = 0;
363  let mayStore = 0;
364  let hasSideEffects = 0;
365  let VALU = 1;
366}
367
368} // End Uses = [EXEC]
369