aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/radeon/SIInstrInfo.td
blob: 30c9c3377ad86c725d577ed944c688f9eff3f14c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
//===-- SIInstrInfo.td - SI Instruction Encodings ---------*- tablegen -*--===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//



class InstSI <dag outs, dag ins, string asm, list<dag> pattern> :
    AMDGPUInst<outs, ins, asm, pattern> {

  field bits<4> EncodingType = 0;
  field bits<1> NeedWait = 0;

  let TSFlags{3-0} = EncodingType;
  let TSFlags{4} = NeedWait;

}

class Enc32 <dag outs, dag ins, string asm, list<dag> pattern> :
    InstSI <outs, ins, asm, pattern> {

  field bits<32> Inst;
}

class Enc64 <dag outs, dag ins, string asm, list<dag> pattern> :
    InstSI <outs, ins, asm, pattern> {

  field bits<64> Inst;
}

class SIOperand <ValueType vt, dag opInfo>: Operand <vt> {
  let EncoderMethod = "encodeOperand";
  let MIOperandInfo = opInfo;
}

def IMM8bit : ImmLeaf <
  i32,
  [{return (int32_t)Imm >= 0 && (int32_t)Imm <= 0xff;}]
>;

def IMM12bit : ImmLeaf <
  i16,
  [{return (int16_t)Imm >= 0 && (int16_t)Imm <= 0xfff;}]
>;

class GPR4Align <RegisterClass rc> : Operand <vAny> {
  let EncoderMethod = "GPR4AlignEncode";
  let MIOperandInfo = (ops rc:$reg); 
}

class GPR2Align <RegisterClass rc, ValueType vt> : Operand <vt> {
  let EncoderMethod = "GPR2AlignEncode";
  let MIOperandInfo = (ops rc:$reg);
}

def i32Literal : Operand <i32> {
  let EncoderMethod = "i32LiteralEncode";
}

def SMRDmemrr : Operand<iPTR> {
  let MIOperandInfo = (ops SReg_64, SReg_32);
  let EncoderMethod = "GPR2AlignEncode";
}

def SMRDmemri : Operand<iPTR> {
  let MIOperandInfo = (ops SReg_64, i32imm);
  let EncoderMethod = "SMRDmemriEncode";
}

def ADDR_Reg     : ComplexPattern<i64, 2, "SelectADDRReg", [], []>;
def ADDR_Offset8 : ComplexPattern<i64, 2, "SelectADDR8BitOffset", [], []>;

def EXP : Enc64<
  (outs),
  (ins i32imm:$en, i32imm:$tgt, i32imm:$compr, i32imm:$done, i32imm:$vm,
       VReg_32:$src0, VReg_32:$src1, VReg_32:$src2, VReg_32:$src3),
  "EXP $en, $tgt, $compr, $done, $vm, $src0, $src1, $src2, $src3",
  [] > {

  bits<4> EN;
  bits<6> TGT;
  bits<1> COMPR;
  bits<1> DONE;
  bits<1> VM;
  bits<8> VSRC0;
  bits<8> VSRC1;
  bits<8> VSRC2;
  bits<8> VSRC3;

  let Inst{3-0} = EN;
  let Inst{9-4} = TGT;
  let Inst{10} = COMPR;
  let Inst{11} = DONE;
  let Inst{12} = VM;
  let Inst{31-26} = 0x3e;
  let Inst{39-32} = VSRC0;
  let Inst{47-40} = VSRC1;
  let Inst{55-48} = VSRC2;
  let Inst{63-56} = VSRC3;
  let EncodingType = 0; //SIInstrEncodingType::EXP

  let NeedWait = 1;
  let usesCustomInserter = 1;
}

class MIMG <bits<7> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc64 <outs, ins, asm, pattern> {

  bits<8> VDATA;
  bits<4> DMASK;
  bits<1> UNORM;
  bits<1> GLC;
  bits<1> DA;
  bits<1> R128;
  bits<1> TFE;
  bits<1> LWE;
  bits<1> SLC;
  bits<8> VADDR;
  bits<5> SRSRC;
  bits<5> SSAMP; 

  let Inst{11-8} = DMASK;
  let Inst{12} = UNORM;
  let Inst{13} = GLC;
  let Inst{14} = DA;
  let Inst{15} = R128;
  let Inst{16} = TFE;
  let Inst{17} = LWE;
  let Inst{24-18} = op;
  let Inst{25} = SLC;
  let Inst{31-26} = 0x3c;
  let Inst{39-32} = VADDR;
  let Inst{47-40} = VDATA;
  let Inst{52-48} = SRSRC;
  let Inst{57-53} = SSAMP;

  let EncodingType = 2; //SIInstrEncodingType::MIMG

  let NeedWait = 1;
  let usesCustomInserter = 1;
}

class MTBUF <bits<3> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc64<outs, ins, asm, pattern> {

  bits<8> VDATA;
  bits<12> OFFSET;
  bits<1> OFFEN;
  bits<1> IDXEN;
  bits<1> GLC;
  bits<1> ADDR64;
  bits<4> DFMT;
  bits<3> NFMT;
  bits<8> VADDR;
  bits<5> SRSRC;
  bits<1> SLC;
  bits<1> TFE;
  bits<8> SOFFSET;

  let Inst{11-0} = OFFSET;
  let Inst{12} = OFFEN;
  let Inst{13} = IDXEN;
  let Inst{14} = GLC;
  let Inst{15} = ADDR64;
  let Inst{18-16} = op;
  let Inst{22-19} = DFMT;
  let Inst{25-23} = NFMT;
  let Inst{31-26} = 0x3a; //encoding
  let Inst{39-32} = VADDR;
  let Inst{47-40} = VDATA;
  let Inst{52-48} = SRSRC;
  let Inst{54} = SLC;
  let Inst{55} = TFE;
  let Inst{63-56} = SOFFSET;
  let EncodingType = 3; //SIInstrEncodingType::MTBUF

  let NeedWait = 1;
  let usesCustomInserter = 1;
  let neverHasSideEffects = 1;
}

class MUBUF <bits<7> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc64<outs, ins, asm, pattern> {

  bits<8> VDATA;
  bits<12> OFFSET;
  bits<1> OFFEN;
  bits<1> IDXEN;
  bits<1> GLC;
  bits<1> ADDR64;
  bits<1> LDS;
  bits<8> VADDR;
  bits<5> SRSRC;
  bits<1> SLC;
  bits<1> TFE;
  bits<8> SOFFSET;

  let Inst{11-0} = OFFSET;
  let Inst{12} = OFFEN;
  let Inst{13} = IDXEN;
  let Inst{14} = GLC;
  let Inst{15} = ADDR64;
  let Inst{16} = LDS;
  let Inst{24-18} = op;
  let Inst{31-26} = 0x38; //encoding
  let Inst{39-32} = VADDR;
  let Inst{47-40} = VDATA;
  let Inst{52-48} = SRSRC;
  let Inst{54} = SLC;
  let Inst{55} = TFE;
  let Inst{63-56} = SOFFSET;
  let EncodingType = 4; //SIInstrEncodingType::MUBUF

  let NeedWait = 1;
  let usesCustomInserter = 1;
  let neverHasSideEffects = 1;
}

class SMRD <bits<5> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc32<outs, ins, asm, pattern> {

  bits<7> SDST;
  bits<15> PTR;
  bits<8> OFFSET = PTR{7-0};
  bits<1> IMM    = PTR{8};
  bits<6> SBASE  = PTR{14-9};
  
  let Inst{7-0} = OFFSET;
  let Inst{8} = IMM;
  let Inst{14-9} = SBASE;
  let Inst{21-15} = SDST;
  let Inst{26-22} = op;
  let Inst{31-27} = 0x18; //encoding
  let EncodingType = 5; //SIInstrEncodingType::SMRD

  let NeedWait = 1;
  let usesCustomInserter = 1;
}

class SOP1 <bits<8> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc32<outs, ins, asm, pattern> {

  bits<7> SDST;
  bits<8> SSRC0;

  let Inst{7-0} = SSRC0;
  let Inst{15-8} = op;
  let Inst{22-16} = SDST;
  let Inst{31-23} = 0x17d; //encoding;
  let EncodingType = 6; //SIInstrEncodingType::SOP1
}

class SOP2 <bits<7> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc32 <outs, ins, asm, pattern> {
  
  bits<7> SDST;
  bits<8> SSRC0;
  bits<8> SSRC1;

  let Inst{7-0} = SSRC0;
  let Inst{15-8} = SSRC1;
  let Inst{22-16} = SDST;
  let Inst{29-23} = op;
  let Inst{31-30} = 0x2; // encoding
  let EncodingType = 7; // SIInstrEncodingType::SOP2  
}

class SOPC <bits<7> op, dag outs, dag ins, string asm, list<dag> pattern> :
  Enc32<outs, ins, asm, pattern> {

  bits<8> SSRC0;
  bits<8> SSRC1;

  let Inst{7-0} = SSRC0;
  let Inst{15-8} = SSRC1;
  let Inst{22-16} = op;
  let Inst{31-23} = 0x17e;
  let EncodingType = 8; // SIInstrEncodingType::SOPC
}

class SOPK <bits<5> op, dag outs, dag ins, string asm, list<dag> pattern> :
   Enc32 <outs, ins , asm, pattern> {

  bits <7> SDST;
  bits <16> SIMM16;
  
  let Inst{15-0} = SIMM16;
  let Inst{22-16} = SDST;
  let Inst{27-23} = op;
  let Inst{31-28} = 0xb; //encoding
  let EncodingType = 9; // SIInstrEncodingType::SOPK
}

class SOPP <bits<7> op, dag ins, string asm> : Enc32 <
  (outs),
  ins,
  asm,
  [] > {

  bits <16> SIMM16;

  let Inst{15-0} = SIMM16;
  let Inst{22-16} = op;
  let Inst{31-23} = 0x17f; // encoding
  let EncodingType = 10; // SIInstrEncodingType::SOPP
}
    

class VINTRP <bits <2> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc32 <outs, ins, asm, pattern> {

  bits<8> VDST;
  bits<8> VSRC;
  bits<2> ATTRCHAN;
  bits<6> ATTR;

  let Inst{7-0} = VSRC;
  let Inst{9-8} = ATTRCHAN;
  let Inst{15-10} = ATTR;
  let Inst{17-16} = op;
  let Inst{25-18} = VDST;
  let Inst{31-26} = 0x32; // encoding
  let EncodingType = 11; // SIInstrEncodingType::VINTRP

  let Uses = [M0];
}

class VOP1 <bits<8> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc32 <outs, ins, asm, pattern> {

  bits<8> VDST;
  bits<9> SRC0;
  
  let Inst{8-0} = SRC0;
  let Inst{16-9} = op;
  let Inst{24-17} = VDST;
  let Inst{31-25} = 0x3f; //encoding
  
  let EncodingType = 12; // SIInstrEncodingType::VOP1
  let PostEncoderMethod = "VOPPostEncode";
}

class VOP2 <bits<6> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc32 <outs, ins, asm, pattern> {

  bits<8> VDST;
  bits<9> SRC0;
  bits<8> VSRC1;
  
  let Inst{8-0} = SRC0;
  let Inst{16-9} = VSRC1;
  let Inst{24-17} = VDST;
  let Inst{30-25} = op;
  let Inst{31} = 0x0; //encoding
  
  let EncodingType = 13; // SIInstrEncodingType::VOP2
  let PostEncoderMethod = "VOPPostEncode";
}

class VOP3 <bits<9> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc64 <outs, ins, asm, pattern> {

  bits<8> VDST;
  bits<9> SRC0;
  bits<9> SRC1;
  bits<9> SRC2;
  bits<3> ABS; 
  bits<1> CLAMP;
  bits<2> OMOD;
  bits<3> NEG;

  let Inst{7-0} = VDST;
  let Inst{10-8} = ABS;
  let Inst{11} = CLAMP;
  let Inst{25-17} = op;
  let Inst{31-26} = 0x34; //encoding
  let Inst{40-32} = SRC0;
  let Inst{49-41} = SRC1;
  let Inst{58-50} = SRC2;
  let Inst{60-59} = OMOD;
  let Inst{63-61} = NEG;
  
  let EncodingType = 14; // SIInstrEncodingType::VOP3
  let PostEncoderMethod = "VOPPostEncode";
}

class VOPC <bits<8> op, dag outs, dag ins, string asm, list<dag> pattern> :
    Enc32 <outs, ins, asm, pattern> {

  bits<9> SRC0;
  bits<8> VSRC1;

  let Inst{8-0} = SRC0;
  let Inst{16-9} = VSRC1;
  let Inst{24-17} = op;
  let Inst{31-25} = 0x3e;
 
  let EncodingType = 15; //SIInstrEncodingType::VOPC
  let PostEncoderMethod = "VOPPostEncode";

  let Defs = [VCC];
}

class MIMG_Load_Helper <bits<7> op, string asm> : MIMG <
  op,
  (outs VReg_128:$vdata),
  (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
       i1imm:$tfe, i1imm:$lwe, i1imm:$slc, VReg_128:$vaddr,
       GPR4Align<SReg_256>:$srsrc, GPR4Align<SReg_128>:$ssamp),
  asm,
  []
>; 

class MUBUF_Load_Helper <bits<7> op, string asm, RegisterClass regClass> : MUBUF <
  op,
  (outs regClass:$dst),
  (ins i16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc, i1imm:$addr64,
       i1imm:$lds, VReg_32:$vaddr, GPR4Align<SReg_128>:$srsrc, i1imm:$slc,
       i1imm:$tfe, SReg_32:$soffset),
  asm,
  []> {
  let mayLoad = 1;
}

class MTBUF_Load_Helper <bits<3> op, string asm, RegisterClass regClass> : MTBUF <
  op,
  (outs regClass:$dst),
  (ins i16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc, i1imm:$addr64,
       i8imm:$dfmt, i8imm:$nfmt, VReg_32:$vaddr, GPR4Align<SReg_128>:$srsrc,
       i1imm:$slc, i1imm:$tfe, SReg_32:$soffset),
  asm,
  []> {
  let mayLoad = 1;
}

class MTBUF_Store_Helper <bits<3> op, string asm, RegisterClass regClass> : MTBUF <
  op,
  (outs),
  (ins regClass:$vdata, i16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc,
   i1imm:$addr64, i8imm:$dfmt, i8imm:$nfmt, VReg_32:$vaddr,
   GPR4Align<SReg_128>:$srsrc, i1imm:$slc, i1imm:$tfe, SReg_32:$soffset),
  asm,
  []> {
  let mayStore = 1;
}

/*XXX: We should be able to infer the imm bit based on the arg types */
multiclass SMRD_Helper <bits<5> op, string asm, RegisterClass dstClass,
			ValueType vt> {

  def _SGPR : SMRD <
              op,
              (outs dstClass:$dst),
              (ins SMRDmemrr:$src0),
              asm,
              [(set (vt dstClass:$dst), (constant_load ADDR_Reg:$src0))]
  > {
    let IMM = 0;
  }

  def _IMM : SMRD <
              op,
              (outs dstClass:$dst),
              (ins SMRDmemri:$src0),
              asm,
              [(set (vt dstClass:$dst), (constant_load ADDR_Offset8:$src0))]
  > {
    let IMM = 1;
  }
}

include "SIInstrFormats.td"
include "SIInstructions.td"