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