1//===-- SIInstrFormats.td - SI Instruction Encodings ----------------------===//
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//===----------------------------------------------------------------------===//
9//
10// SI Instruction format definitions.
11//
12//===----------------------------------------------------------------------===//
13
14class InstSI <dag outs, dag ins, string asm = "",
15              list<dag> pattern = []> :
16  AMDGPUInst<outs, ins, asm, pattern>, PredicateControl {
17
18  // Low bits - basic encoding information.
19  field bit SALU = 0;
20  field bit VALU = 0;
21
22  // SALU instruction formats.
23  field bit SOP1 = 0;
24  field bit SOP2 = 0;
25  field bit SOPC = 0;
26  field bit SOPK = 0;
27  field bit SOPP = 0;
28
29  // VALU instruction formats.
30  field bit VOP1 = 0;
31  field bit VOP2 = 0;
32  field bit VOPC = 0;
33  field bit VOP3 = 0;
34  field bit VINTRP = 0;
35  field bit SDWA = 0;
36  field bit DPP = 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  // These need to be kept in sync with the enum in SIInstrFlags.
82  let TSFlags{0} = SALU;
83  let TSFlags{1} = VALU;
84
85  let TSFlags{2} = SOP1;
86  let TSFlags{3} = SOP2;
87  let TSFlags{4} = SOPC;
88  let TSFlags{5} = SOPK;
89  let TSFlags{6} = SOPP;
90
91  let TSFlags{7} = VOP1;
92  let TSFlags{8} = VOP2;
93  let TSFlags{9} = VOPC;
94  let TSFlags{10} = VOP3;
95
96  let TSFlags{13} = VINTRP;
97  let TSFlags{14} = SDWA;
98  let TSFlags{15} = DPP;
99
100  let TSFlags{16} = MUBUF;
101  let TSFlags{17} = MTBUF;
102  let TSFlags{18} = SMRD;
103  let TSFlags{19} = MIMG;
104  let TSFlags{20} = EXP;
105  let TSFlags{21} = FLAT;
106  let TSFlags{22} = DS;
107
108  let TSFlags{23} = VGPRSpill;
109  let TSFlags{24} = SGPRSpill;
110
111  let TSFlags{32} = VM_CNT;
112  let TSFlags{33} = EXP_CNT;
113  let TSFlags{34} = LGKM_CNT;
114
115  let TSFlags{35} = WQM;
116  let TSFlags{36} = DisableWQM;
117  let TSFlags{37} = Gather4;
118
119  let TSFlags{38} = SOPKZext;
120  let TSFlags{39} = ScalarStore;
121  let TSFlags{40} = FixedSize;
122  let TSFlags{41} = VOPAsmPrefer32Bit;
123
124  let SchedRW = [Write32Bit];
125
126  field bits<1> DisableSIDecoder = 0;
127  field bits<1> DisableVIDecoder = 0;
128  field bits<1> DisableDecoder = 0;
129
130  let isAsmParserOnly = !if(!eq(DisableDecoder{0}, {0}), 0, 1);
131  let AsmVariantName = AMDGPUAsmVariants.Default;
132}
133
134class PseudoInstSI<dag outs, dag ins, list<dag> pattern = []>
135  : InstSI<outs, ins, "", pattern> {
136  let isPseudo = 1;
137  let isCodeGenOnly = 1;
138}
139
140class SPseudoInstSI<dag outs, dag ins, list<dag> pattern = []>
141  : PseudoInstSI<outs, ins, pattern> {
142  let SALU = 1;
143}
144
145class VPseudoInstSI<dag outs, dag ins, list<dag> pattern = []>
146  : PseudoInstSI<outs, ins, pattern> {
147  let VALU = 1;
148  let Uses = [EXEC];
149}
150
151class CFPseudoInstSI<dag outs, dag ins, list<dag> pattern = [],
152  bit UseExec = 0, bit DefExec = 0> :
153  SPseudoInstSI<outs, ins, pattern> {
154
155  let Uses = !if(UseExec, [EXEC], []);
156  let Defs = !if(DefExec, [EXEC, SCC], [SCC]);
157  let mayLoad = 0;
158  let mayStore = 0;
159  let hasSideEffects = 0;
160}
161
162class Enc32 {
163  field bits<32> Inst;
164  int Size = 4;
165}
166
167class Enc64 {
168  field bits<64> Inst;
169  int Size = 8;
170}
171
172class VOPDstOperand <RegisterClass rc> : RegisterOperand <rc, "printVOPDst">;
173
174class VINTRPe <bits<2> op> : Enc32 {
175  bits<8> vdst;
176  bits<8> vsrc;
177  bits<2> attrchan;
178  bits<6> attr;
179
180  let Inst{7-0} = vsrc;
181  let Inst{9-8} = attrchan;
182  let Inst{15-10} = attr;
183  let Inst{17-16} = op;
184  let Inst{25-18} = vdst;
185  let Inst{31-26} = 0x32; // encoding
186}
187
188class MIMGe <bits<7> op> : Enc64 {
189  bits<8> vdata;
190  bits<4> dmask;
191  bits<1> unorm;
192  bits<1> glc;
193  bits<1> da;
194  bits<1> r128;
195  bits<1> tfe;
196  bits<1> lwe;
197  bits<1> slc;
198  bits<8> vaddr;
199  bits<7> srsrc;
200  bits<7> ssamp;
201
202  let Inst{11-8} = dmask;
203  let Inst{12} = unorm;
204  let Inst{13} = glc;
205  let Inst{14} = da;
206  let Inst{15} = r128;
207  let Inst{16} = tfe;
208  let Inst{17} = lwe;
209  let Inst{24-18} = op;
210  let Inst{25} = slc;
211  let Inst{31-26} = 0x3c;
212  let Inst{39-32} = vaddr;
213  let Inst{47-40} = vdata;
214  let Inst{52-48} = srsrc{6-2};
215  let Inst{57-53} = ssamp{6-2};
216}
217
218class EXPe : Enc64 {
219  bits<4> en;
220  bits<6> tgt;
221  bits<1> compr;
222  bits<1> done;
223  bits<1> vm;
224  bits<8> vsrc0;
225  bits<8> vsrc1;
226  bits<8> vsrc2;
227  bits<8> vsrc3;
228
229  let Inst{3-0} = en;
230  let Inst{9-4} = tgt;
231  let Inst{10} = compr;
232  let Inst{11} = done;
233  let Inst{12} = vm;
234  let Inst{31-26} = 0x3e;
235  let Inst{39-32} = vsrc0;
236  let Inst{47-40} = vsrc1;
237  let Inst{55-48} = vsrc2;
238  let Inst{63-56} = vsrc3;
239}
240
241let Uses = [EXEC] in {
242
243class VINTRPCommon <dag outs, dag ins, string asm, list<dag> pattern> :
244    InstSI <outs, ins, asm, pattern> {
245  let VINTRP = 1;
246  // VINTRP instructions read parameter values from LDS, but these parameter
247  // values are stored outside of the LDS memory that is allocated to the
248  // shader for general purpose use.
249  //
250  // While it may be possible for ds_read/ds_write instructions to access
251  // the parameter values in LDS, this would essentially be an out-of-bounds
252  // memory access which we consider to be undefined behavior.
253  //
254  // So even though these instructions read memory, this memory is outside the
255  // addressable memory space for the shader, and we consider these instructions
256  // to be readnone.
257  let mayLoad = 0;
258  let mayStore = 0;
259  let hasSideEffects = 0;
260}
261
262class EXPCommon<dag outs, dag ins, string asm, list<dag> pattern> :
263  InstSI<outs, ins, asm, pattern> {
264  let EXP = 1;
265  let EXP_CNT = 1;
266  let mayLoad = 0; // Set to 1 if done bit is set.
267  let mayStore = 1;
268  let UseNamedOperandTable = 1;
269  let Uses = [EXEC];
270  let SchedRW = [WriteExport];
271}
272
273} // End Uses = [EXEC]
274
275class MIMG <dag outs, dag ins, string asm, list<dag> pattern> :
276    InstSI <outs, ins, asm, pattern> {
277
278  let VM_CNT = 1;
279  let EXP_CNT = 1;
280  let MIMG = 1;
281  let Uses = [EXEC];
282
283  let UseNamedOperandTable = 1;
284  let hasSideEffects = 0; // XXX ????
285}
286