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