R600/SI: Use mad for fsub + fmul
[oota-llvm.git] / lib / Target / R600 / SIInstrInfo.td
1 //===-- SIInstrInfo.td - SI Instruction Infos -------------*- tablegen -*--===//
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 // Execpt for the NONE field, this must be kept in sync with the SISubtarget enum
11 // in AMDGPUMCInstLower.h
12 def SISubtarget {
13   int NONE = -1;
14   int SI = 0;
15 }
16
17 //===----------------------------------------------------------------------===//
18 // SI DAG Nodes
19 //===----------------------------------------------------------------------===//
20
21 def SIload_constant : SDNode<"AMDGPUISD::LOAD_CONSTANT",
22   SDTypeProfile<1, 2, [SDTCisVT<0, f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i32>]>,
23                       [SDNPMayLoad, SDNPMemOperand]
24 >;
25
26 def SItbuffer_store : SDNode<"AMDGPUISD::TBUFFER_STORE_FORMAT",
27   SDTypeProfile<0, 13,
28     [SDTCisVT<0, v4i32>,   // rsrc(SGPR)
29      SDTCisVT<1, iAny>,   // vdata(VGPR)
30      SDTCisVT<2, i32>,    // num_channels(imm)
31      SDTCisVT<3, i32>,    // vaddr(VGPR)
32      SDTCisVT<4, i32>,    // soffset(SGPR)
33      SDTCisVT<5, i32>,    // inst_offset(imm)
34      SDTCisVT<6, i32>,    // dfmt(imm)
35      SDTCisVT<7, i32>,    // nfmt(imm)
36      SDTCisVT<8, i32>,    // offen(imm)
37      SDTCisVT<9, i32>,    // idxen(imm)
38      SDTCisVT<10, i32>,   // glc(imm)
39      SDTCisVT<11, i32>,   // slc(imm)
40      SDTCisVT<12, i32>    // tfe(imm)
41     ]>,
42   [SDNPMayStore, SDNPMemOperand, SDNPHasChain]
43 >;
44
45 def SIload_input : SDNode<"AMDGPUISD::LOAD_INPUT",
46   SDTypeProfile<1, 3, [SDTCisVT<0, v4f32>, SDTCisVT<1, v4i32>, SDTCisVT<2, i16>,
47                        SDTCisVT<3, i32>]>
48 >;
49
50 class SDSample<string opcode> : SDNode <opcode,
51   SDTypeProfile<1, 4, [SDTCisVT<0, v4f32>, SDTCisVT<2, v32i8>,
52                        SDTCisVT<3, v4i32>, SDTCisVT<4, i32>]>
53 >;
54
55 def SIsample : SDSample<"AMDGPUISD::SAMPLE">;
56 def SIsampleb : SDSample<"AMDGPUISD::SAMPLEB">;
57 def SIsampled : SDSample<"AMDGPUISD::SAMPLED">;
58 def SIsamplel : SDSample<"AMDGPUISD::SAMPLEL">;
59
60 def SIconstdata_ptr : SDNode<
61   "AMDGPUISD::CONST_DATA_PTR", SDTypeProfile <1, 0, [SDTCisVT<0, i64>]>
62 >;
63
64 // Transformation function, extract the lower 32bit of a 64bit immediate
65 def LO32 : SDNodeXForm<imm, [{
66   return CurDAG->getTargetConstant(N->getZExtValue() & 0xffffffff, MVT::i32);
67 }]>;
68
69 def LO32f : SDNodeXForm<fpimm, [{
70   APInt V = N->getValueAPF().bitcastToAPInt().trunc(32);
71   return CurDAG->getTargetConstantFP(APFloat(APFloat::IEEEsingle, V), MVT::f32);
72 }]>;
73
74 // Transformation function, extract the upper 32bit of a 64bit immediate
75 def HI32 : SDNodeXForm<imm, [{
76   return CurDAG->getTargetConstant(N->getZExtValue() >> 32, MVT::i32);
77 }]>;
78
79 def HI32f : SDNodeXForm<fpimm, [{
80   APInt V = N->getValueAPF().bitcastToAPInt().lshr(32).trunc(32);
81   return CurDAG->getTargetConstantFP(APFloat(APFloat::IEEEsingle, V), MVT::f32);
82 }]>;
83
84 def IMM8bitDWORD : PatLeaf <(imm),
85   [{return (N->getZExtValue() & ~0x3FC) == 0;}]
86 >;
87
88 def as_dword_i32imm : SDNodeXForm<imm, [{
89   return CurDAG->getTargetConstant(N->getZExtValue() >> 2, MVT::i32);
90 }]>;
91
92 def as_i1imm : SDNodeXForm<imm, [{
93   return CurDAG->getTargetConstant(N->getZExtValue(), MVT::i1);
94 }]>;
95
96 def as_i8imm : SDNodeXForm<imm, [{
97   return CurDAG->getTargetConstant(N->getZExtValue(), MVT::i8);
98 }]>;
99
100 def as_i16imm : SDNodeXForm<imm, [{
101   return CurDAG->getTargetConstant(N->getSExtValue(), MVT::i16);
102 }]>;
103
104 def as_i32imm: SDNodeXForm<imm, [{
105   return CurDAG->getTargetConstant(N->getSExtValue(), MVT::i32);
106 }]>;
107
108 def IMM8bit : PatLeaf <(imm),
109   [{return isUInt<8>(N->getZExtValue());}]
110 >;
111
112 def IMM12bit : PatLeaf <(imm),
113   [{return isUInt<12>(N->getZExtValue());}]
114 >;
115
116 def IMM16bit : PatLeaf <(imm),
117   [{return isUInt<16>(N->getZExtValue());}]
118 >;
119
120 def IMM32bit : PatLeaf <(imm),
121   [{return isUInt<32>(N->getZExtValue());}]
122 >;
123
124 def mubuf_vaddr_offset : PatFrag<
125   (ops node:$ptr, node:$offset, node:$imm_offset),
126   (add (add node:$ptr, node:$offset), node:$imm_offset)
127 >;
128
129 class InlineImm <ValueType vt> : PatLeaf <(vt imm), [{
130   return isInlineImmediate(N);
131 }]>;
132
133 class SGPRImm <dag frag> : PatLeaf<frag, [{
134   if (TM.getSubtarget<AMDGPUSubtarget>().getGeneration() <
135       AMDGPUSubtarget::SOUTHERN_ISLANDS) {
136     return false;
137   }
138   const SIRegisterInfo *SIRI =
139                        static_cast<const SIRegisterInfo*>(TM.getSubtargetImpl()->getRegisterInfo());
140   for (SDNode::use_iterator U = N->use_begin(), E = SDNode::use_end();
141                                                 U != E; ++U) {
142     if (SIRI->isSGPRClass(getOperandRegClass(*U, U.getOperandNo()))) {
143       return true;
144     }
145   }
146   return false;
147 }]>;
148
149 //===----------------------------------------------------------------------===//
150 // Custom Operands
151 //===----------------------------------------------------------------------===//
152
153 def FRAMEri32 : Operand<iPTR> {
154   let MIOperandInfo = (ops i32:$ptr, i32imm:$index);
155 }
156
157 def sopp_brtarget : Operand<OtherVT> {
158   let EncoderMethod = "getSOPPBrEncoding";
159   let OperandType = "OPERAND_PCREL";
160 }
161
162 include "SIInstrFormats.td"
163
164 let OperandType = "OPERAND_IMMEDIATE" in {
165
166 def offen : Operand<i1> {
167   let PrintMethod = "printOffen";
168 }
169 def idxen : Operand<i1> {
170   let PrintMethod = "printIdxen";
171 }
172 def addr64 : Operand<i1> {
173   let PrintMethod = "printAddr64";
174 }
175 def mbuf_offset : Operand<i16> {
176   let PrintMethod = "printMBUFOffset";
177 }
178 def glc : Operand <i1> {
179   let PrintMethod = "printGLC";
180 }
181 def slc : Operand <i1> {
182   let PrintMethod = "printSLC";
183 }
184 def tfe : Operand <i1> {
185   let PrintMethod = "printTFE";
186 }
187
188 } // End OperandType = "OPERAND_IMMEDIATE"
189
190 //===----------------------------------------------------------------------===//
191 // Complex patterns
192 //===----------------------------------------------------------------------===//
193
194 def DS1Addr1Offset : ComplexPattern<i32, 2, "SelectDS1Addr1Offset">;
195 def DS64Bit4ByteAligned : ComplexPattern<i32, 3, "SelectDS64Bit4ByteAligned">;
196
197 def MUBUFAddr32 : ComplexPattern<i64, 9, "SelectMUBUFAddr32">;
198 def MUBUFAddr64 : ComplexPattern<i64, 3, "SelectMUBUFAddr64">;
199 def MUBUFScratch : ComplexPattern<i64, 4, "SelectMUBUFScratch">;
200 def MUBUFOffset : ComplexPattern<i64, 6, "SelectMUBUFOffset">;
201
202 def VOP3Mods0 : ComplexPattern<untyped, 4, "SelectVOP3Mods0">;
203 def VOP3Mods  : ComplexPattern<untyped, 2, "SelectVOP3Mods">;
204
205 //===----------------------------------------------------------------------===//
206 // SI assembler operands
207 //===----------------------------------------------------------------------===//
208
209 def SIOperand {
210   int ZERO = 0x80;
211   int VCC = 0x6A;
212 }
213
214 def SRCMODS {
215   int NONE = 0;
216 }
217
218 def DSTCLAMP {
219   int NONE = 0;
220 }
221
222 def DSTOMOD {
223   int NONE = 0;
224 }
225
226 //===----------------------------------------------------------------------===//
227 //
228 // SI Instruction multiclass helpers.
229 //
230 // Instructions with _32 take 32-bit operands.
231 // Instructions with _64 take 64-bit operands.
232 //
233 // VOP_* instructions can use either a 32-bit or 64-bit encoding.  The 32-bit
234 // encoding is the standard encoding, but instruction that make use of
235 // any of the instruction modifiers must use the 64-bit encoding.
236 //
237 // Instructions with _e32 use the 32-bit encoding.
238 // Instructions with _e64 use the 64-bit encoding.
239 //
240 //===----------------------------------------------------------------------===//
241
242 //===----------------------------------------------------------------------===//
243 // Scalar classes
244 //===----------------------------------------------------------------------===//
245
246 class SOP1_32 <bits<8> op, string opName, list<dag> pattern> : SOP1 <
247   op, (outs SReg_32:$dst), (ins SSrc_32:$src0),
248   opName#" $dst, $src0", pattern
249 >;
250
251 class SOP1_64 <bits<8> op, string opName, list<dag> pattern> : SOP1 <
252   op, (outs SReg_64:$dst), (ins SSrc_64:$src0),
253   opName#" $dst, $src0", pattern
254 >;
255
256 // 64-bit input, 32-bit output.
257 class SOP1_32_64 <bits<8> op, string opName, list<dag> pattern> : SOP1 <
258   op, (outs SReg_32:$dst), (ins SSrc_64:$src0),
259   opName#" $dst, $src0", pattern
260 >;
261
262 class SOP2_32 <bits<7> op, string opName, list<dag> pattern> : SOP2 <
263   op, (outs SReg_32:$dst), (ins SSrc_32:$src0, SSrc_32:$src1),
264   opName#" $dst, $src0, $src1", pattern
265 >;
266
267 class SOP2_64 <bits<7> op, string opName, list<dag> pattern> : SOP2 <
268   op, (outs SReg_64:$dst), (ins SSrc_64:$src0, SSrc_64:$src1),
269   opName#" $dst, $src0, $src1", pattern
270 >;
271
272 class SOP2_SHIFT_64 <bits<7> op, string opName, list<dag> pattern> : SOP2 <
273   op, (outs SReg_64:$dst), (ins SSrc_64:$src0, SSrc_32:$src1),
274   opName#" $dst, $src0, $src1", pattern
275 >;
276
277
278 class SOPC_Helper <bits<7> op, RegisterClass rc, ValueType vt,
279                     string opName, PatLeaf cond> : SOPC <
280   op, (outs SCCReg:$dst), (ins rc:$src0, rc:$src1),
281   opName#" $dst, $src0, $src1", []>;
282
283 class SOPC_32<bits<7> op, string opName, PatLeaf cond = COND_NULL>
284   : SOPC_Helper<op, SSrc_32, i32, opName, cond>;
285
286 class SOPC_64<bits<7> op, string opName, PatLeaf cond = COND_NULL>
287   : SOPC_Helper<op, SSrc_64, i64, opName, cond>;
288
289 class SOPK_32 <bits<5> op, string opName, list<dag> pattern> : SOPK <
290   op, (outs SReg_32:$dst), (ins i16imm:$src0),
291   opName#" $dst, $src0", pattern
292 >;
293
294 class SOPK_64 <bits<5> op, string opName, list<dag> pattern> : SOPK <
295   op, (outs SReg_64:$dst), (ins i16imm:$src0),
296   opName#" $dst, $src0", pattern
297 >;
298
299 multiclass SMRD_Helper <bits<5> op, string asm, RegisterClass baseClass,
300                         RegisterClass dstClass> {
301   def _IMM : SMRD <
302     op, 1, (outs dstClass:$dst),
303     (ins baseClass:$sbase, u32imm:$offset),
304     asm#" $dst, $sbase, $offset", []
305   >;
306
307   def _SGPR : SMRD <
308     op, 0, (outs dstClass:$dst),
309     (ins baseClass:$sbase, SReg_32:$soff),
310     asm#" $dst, $sbase, $soff", []
311   >;
312 }
313
314 //===----------------------------------------------------------------------===//
315 // Vector ALU classes
316 //===----------------------------------------------------------------------===//
317
318 // This must always be right before the operand being input modified.
319 def InputMods : OperandWithDefaultOps <i32, (ops (i32 0))> {
320   let PrintMethod = "printOperandAndMods";
321 }
322 def InputModsNoDefault : Operand <i32> {
323   let PrintMethod = "printOperandAndMods";
324 }
325
326 class getNumSrcArgs<ValueType Src1, ValueType Src2> {
327   int ret =
328     !if (!eq(Src1.Value, untyped.Value),      1,   // VOP1
329          !if (!eq(Src2.Value, untyped.Value), 2,   // VOP2
330                                               3)); // VOP3
331 }
332
333 // Returns the register class to use for the destination of VOP[123C]
334 // instructions for the given VT.
335 class getVALUDstForVT<ValueType VT> {
336   RegisterClass ret = !if(!eq(VT.Size, 32), VReg_32, VReg_64);
337 }
338
339 // Returns the register class to use for source 0 of VOP[12C]
340 // instructions for the given VT.
341 class getVOPSrc0ForVT<ValueType VT> {
342   RegisterClass ret = !if(!eq(VT.Size, 32), VSrc_32, VSrc_64);
343 }
344
345 // Returns the register class to use for source 1 of VOP[12C] for the
346 // given VT.
347 class getVOPSrc1ForVT<ValueType VT> {
348   RegisterClass ret = !if(!eq(VT.Size, 32), VReg_32, VReg_64);
349 }
350
351 // Returns the register classes for the source arguments of a VOP[12C]
352 // instruction for the given SrcVTs.
353 class getInRC32 <list<ValueType> SrcVT> {
354   list<RegisterClass> ret = [
355     getVOPSrc0ForVT<SrcVT[0]>.ret,
356     getVOPSrc1ForVT<SrcVT[1]>.ret
357   ];
358 }
359
360 // Returns the register class to use for sources of VOP3 instructions for the
361 // given VT.
362 class getVOP3SrcForVT<ValueType VT> {
363   RegisterClass ret = !if(!eq(VT.Size, 32), VSrc_32, VSrc_64);
364 }
365
366 // Returns the register classes for the source arguments of a VOP3
367 // instruction for the given SrcVTs.
368 class getInRC64 <list<ValueType> SrcVT> {
369   list<RegisterClass> ret = [
370     getVOP3SrcForVT<SrcVT[0]>.ret,
371     getVOP3SrcForVT<SrcVT[1]>.ret,
372     getVOP3SrcForVT<SrcVT[2]>.ret
373   ];
374 }
375
376 // Returns 1 if the source arguments have modifiers, 0 if they do not.
377 class hasModifiers<ValueType SrcVT> {
378   bit ret = !if(!eq(SrcVT.Value, f32.Value), 1,
379             !if(!eq(SrcVT.Value, f64.Value), 1, 0));
380 }
381
382 // Returns the input arguments for VOP[12C] instructions for the given SrcVT.
383 class getIns32 <RegisterClass Src0RC, RegisterClass Src1RC, int NumSrcArgs> {
384   dag ret = !if(!eq(NumSrcArgs, 1), (ins Src0RC:$src0),               // VOP1
385             !if(!eq(NumSrcArgs, 2), (ins Src0RC:$src0, Src1RC:$src1), // VOP2
386                                     (ins)));
387 }
388
389 // Returns the input arguments for VOP3 instructions for the given SrcVT.
390 class getIns64 <RegisterClass Src0RC, RegisterClass Src1RC,
391                 RegisterClass Src2RC, int NumSrcArgs,
392                 bit HasModifiers> {
393
394   dag ret =
395     !if (!eq(NumSrcArgs, 1),
396       !if (!eq(HasModifiers, 1),
397         // VOP1 with modifiers
398         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
399              i32imm:$clamp, i32imm:$omod)
400       /* else */,
401         // VOP1 without modifiers
402         (ins Src0RC:$src0)
403       /* endif */ ),
404     !if (!eq(NumSrcArgs, 2),
405       !if (!eq(HasModifiers, 1),
406         // VOP 2 with modifiers
407         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
408              InputModsNoDefault:$src1_modifiers, Src1RC:$src1,
409              i32imm:$clamp, i32imm:$omod)
410       /* else */,
411         // VOP2 without modifiers
412         (ins Src0RC:$src0, Src1RC:$src1)
413       /* endif */ )
414     /* NumSrcArgs == 3 */,
415       !if (!eq(HasModifiers, 1),
416         // VOP3 with modifiers
417         (ins InputModsNoDefault:$src0_modifiers, Src0RC:$src0,
418              InputModsNoDefault:$src1_modifiers, Src1RC:$src1,
419              InputModsNoDefault:$src2_modifiers, Src2RC:$src2,
420              i32imm:$clamp, i32imm:$omod)
421       /* else */,
422         // VOP3 without modifiers
423         (ins Src0RC:$src0, Src1RC:$src1, Src2RC:$src2)
424       /* endif */ )));
425 }
426
427 // Returns the assembly string for the inputs and outputs of a VOP[12C]
428 // instruction.  This does not add the _e32 suffix, so it can be reused
429 // by getAsm64.
430 class getAsm32 <int NumSrcArgs> {
431   string src1 = ", $src1";
432   string src2 = ", $src2";
433   string ret = " $dst, $src0"#
434                !if(!eq(NumSrcArgs, 1), "", src1)#
435                !if(!eq(NumSrcArgs, 3), src2, "");
436 }
437
438 // Returns the assembly string for the inputs and outputs of a VOP3
439 // instruction.
440 class getAsm64 <int NumSrcArgs, bit HasModifiers> {
441   string src0 = "$src0_modifiers,";
442   string src1 = !if(!eq(NumSrcArgs, 1), "", " $src1_modifiers,");
443   string src2 = !if(!eq(NumSrcArgs, 3), " $src2_modifiers,", "");
444   string ret =
445   !if(!eq(HasModifiers, 0),
446       getAsm32<NumSrcArgs>.ret,
447       " $dst, "#src0#src1#src2#" $clamp, $omod");
448 }
449
450
451 class VOPProfile <list<ValueType> _ArgVT> {
452
453   field list<ValueType> ArgVT = _ArgVT;
454
455   field ValueType DstVT = ArgVT[0];
456   field ValueType Src0VT = ArgVT[1];
457   field ValueType Src1VT = ArgVT[2];
458   field ValueType Src2VT = ArgVT[3];
459   field RegisterClass DstRC = getVALUDstForVT<DstVT>.ret;
460   field RegisterClass Src0RC32 = getVOPSrc0ForVT<Src0VT>.ret;
461   field RegisterClass Src1RC32 = getVOPSrc1ForVT<Src1VT>.ret;
462   field RegisterClass Src0RC64 = getVOP3SrcForVT<Src0VT>.ret;
463   field RegisterClass Src1RC64 = getVOP3SrcForVT<Src1VT>.ret;
464   field RegisterClass Src2RC64 = getVOP3SrcForVT<Src2VT>.ret;
465
466   field int NumSrcArgs = getNumSrcArgs<Src1VT, Src2VT>.ret;
467   field bit HasModifiers = hasModifiers<Src0VT>.ret;
468
469   field dag Outs = (outs DstRC:$dst);
470
471   field dag Ins32 = getIns32<Src0RC32, Src1RC32, NumSrcArgs>.ret;
472   field dag Ins64 = getIns64<Src0RC64, Src1RC64, Src2RC64, NumSrcArgs,
473                              HasModifiers>.ret;
474
475   field string Asm32 = "_e32"#getAsm32<NumSrcArgs>.ret;
476   field string Asm64 = getAsm64<NumSrcArgs, HasModifiers>.ret;
477 }
478
479 def VOP_F32_F32 : VOPProfile <[f32, f32, untyped, untyped]>;
480 def VOP_F32_F64 : VOPProfile <[f32, f64, untyped, untyped]>;
481 def VOP_F32_I32 : VOPProfile <[f32, i32, untyped, untyped]>;
482 def VOP_F64_F32 : VOPProfile <[f64, f32, untyped, untyped]>;
483 def VOP_F64_F64 : VOPProfile <[f64, f64, untyped, untyped]>;
484 def VOP_F64_I32 : VOPProfile <[f64, i32, untyped, untyped]>;
485 def VOP_I32_F32 : VOPProfile <[i32, f32, untyped, untyped]>;
486 def VOP_I32_F64 : VOPProfile <[i32, f64, untyped, untyped]>;
487 def VOP_I32_I32 : VOPProfile <[i32, i32, untyped, untyped]>;
488
489 def VOP_F32_F32_F32 : VOPProfile <[f32, f32, f32, untyped]>;
490 def VOP_F32_F32_I32 : VOPProfile <[f32, f32, i32, untyped]>;
491 def VOP_F64_F64_F64 : VOPProfile <[f64, f64, f64, untyped]>;
492 def VOP_F64_F64_I32 : VOPProfile <[f64, f64, i32, untyped]>;
493 def VOP_I32_F32_F32 : VOPProfile <[i32, f32, f32, untyped]>;
494 def VOP_I32_I32_I32 : VOPProfile <[i32, i32, i32, untyped]>;
495 def VOP_I32_I32_I32_VCC : VOPProfile <[i32, i32, i32, untyped]> {
496   let Src0RC32 = VReg_32;
497 }
498 def VOP_I64_I64_I32 : VOPProfile <[i64, i64, i32, untyped]>;
499 def VOP_I64_I64_I64 : VOPProfile <[i64, i64, i64, untyped]>;
500
501 def VOP_F32_F32_F32_F32 : VOPProfile <[f32, f32, f32, f32]>;
502 def VOP_F64_F64_F64_F64 : VOPProfile <[f64, f64, f64, f64]>;
503 def VOP_I32_I32_I32_I32 : VOPProfile <[i32, i32, i32, i32]>;
504 def VOP_I64_I32_I32_I64 : VOPProfile <[i64, i32, i32, i64]>;
505
506
507 class VOP <string opName> {
508   string OpName = opName;
509 }
510
511 class VOP2_REV <string revOp, bit isOrig> {
512   string RevOp = revOp;
513   bit IsOrig = isOrig;
514 }
515
516 class SIMCInstr <string pseudo, int subtarget> {
517   string PseudoInstr = pseudo;
518   int Subtarget = subtarget;
519 }
520
521 class VOP3DisableFields <bit HasSrc1, bit HasSrc2, bit HasModifiers> {
522
523   bits<2> src0_modifiers = !if(HasModifiers, ?, 0);
524   bits<2> src1_modifiers = !if(HasModifiers, !if(HasSrc1, ?, 0), 0);
525   bits<2> src2_modifiers = !if(HasModifiers, !if(HasSrc2, ? ,0) ,0);
526   bits<2> omod = !if(HasModifiers, ?, 0);
527   bits<1> clamp = !if(HasModifiers, ?, 0);
528   bits<9> src1 = !if(HasSrc1, ?, 0);
529   bits<9> src2 = !if(HasSrc2, ?, 0);
530 }
531
532 class VOP3_Pseudo <dag outs, dag ins, list<dag> pattern, string opName> :
533   VOP3Common <outs, ins, "", pattern>,
534   VOP <opName>,
535   SIMCInstr<opName, SISubtarget.NONE> {
536   let isPseudo = 1;
537 }
538
539 class VOP3_Real_si <bits<9> op, dag outs, dag ins, string asm, string opName> :
540   VOP3 <op, outs, ins, asm, []>,
541   SIMCInstr<opName, SISubtarget.SI>;
542
543 multiclass VOP3_m <bits<9> op, dag outs, dag ins, string asm, list<dag> pattern,
544                    string opName, int NumSrcArgs, bit HasMods = 1> {
545
546   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
547
548   def _si : VOP3_Real_si <op, outs, ins, asm, opName>,
549             VOP3DisableFields<!if(!eq(NumSrcArgs, 1), 0, 1),
550                               !if(!eq(NumSrcArgs, 2), 0, 1),
551                               HasMods>;
552
553 }
554
555 multiclass VOP3_1_m <bits<8> op, dag outs, dag ins, string asm,
556                      list<dag> pattern, string opName, bit HasMods = 1> {
557
558   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
559
560   def _si : VOP3_Real_si <
561               {1, 1, op{6}, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
562               outs, ins, asm, opName>,
563             VOP3DisableFields<0, 0, HasMods>;
564 }
565
566 multiclass VOP3_2_m <bits<9> op, dag outs, dag ins, string asm,
567                      list<dag> pattern, string opName, string revOp,
568                      bit HasMods = 1, bit UseFullOp = 0> {
569
570   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
571            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
572
573   def _si : VOP3_Real_si <op,
574               outs, ins, asm, opName>,
575             VOP2_REV<revOp#"_e64_si", !eq(revOp, opName)>,
576             VOP3DisableFields<1, 0, HasMods>;
577 }
578
579 multiclass VOP3b_2_m <bits<9> op, dag outs, dag ins, string asm,
580                       list<dag> pattern, string opName, string revOp,
581                       bit HasMods = 1, bit UseFullOp = 0> {
582   def "" : VOP3_Pseudo <outs, ins, pattern, opName>,
583            VOP2_REV<revOp#"_e64", !eq(revOp, opName)>;
584
585   // The VOP2 variant puts the carry out into VCC, the VOP3 variant
586   // can write it into any SGPR. We currently don't use the carry out,
587   // so for now hardcode it to VCC as well.
588   let sdst = SIOperand.VCC, Defs = [VCC] in {
589     def _si : VOP3b <op, outs, ins, asm, pattern>,
590               VOP3DisableFields<1, 0, HasMods>,
591               SIMCInstr<opName, SISubtarget.SI>,
592               VOP2_REV<revOp#"_e64_si", !eq(revOp, opName)>;
593   } // End sdst = SIOperand.VCC, Defs = [VCC]
594 }
595
596 multiclass VOP3_C_m <bits<8> op, dag outs, dag ins, string asm,
597                      list<dag> pattern, string opName,
598                      bit HasMods, bit defExec> {
599
600   def "" : VOP3_Pseudo <outs, ins, pattern, opName>;
601
602     def _si : VOP3_Real_si <
603                 {0, op{7}, op{6}, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
604                 outs, ins, asm, opName>,
605               VOP3DisableFields<1, 0, HasMods> {
606   let Defs = !if(defExec, [EXEC], []);
607   }
608 }
609
610 multiclass VOP1_Helper <bits<8> op, string opName, dag outs,
611                         dag ins32, string asm32, list<dag> pat32,
612                         dag ins64, string asm64, list<dag> pat64,
613                         bit HasMods> {
614
615   def _e32 : VOP1 <op, outs, ins32, opName#asm32, pat32>, VOP<opName>;
616
617   defm _e64 : VOP3_1_m <op, outs, ins64, opName#"_e64"#asm64, pat64, opName, HasMods>;
618 }
619
620 multiclass VOP1Inst <bits<8> op, string opName, VOPProfile P,
621                      SDPatternOperator node = null_frag> : VOP1_Helper <
622   op, opName, P.Outs,
623   P.Ins32, P.Asm32, [],
624   P.Ins64, P.Asm64,
625   !if(P.HasModifiers,
626       [(set P.DstVT:$dst, (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0,
627                                 i32:$src0_modifiers, i32:$clamp, i32:$omod))))],
628       [(set P.DstVT:$dst, (node P.Src0VT:$src0))]),
629   P.HasModifiers
630 >;
631
632 class VOP2_e32 <bits<6> op, string opName, dag outs, dag ins, string asm,
633                 list<dag> pattern, string revOp> :
634   VOP2 <op, outs, ins, opName#asm, pattern>,
635   VOP <opName>,
636   VOP2_REV<revOp#"_e32", !eq(revOp, opName)>;
637
638 multiclass VOP2_Helper <bits<6> op, string opName, dag outs,
639                         dag ins32, string asm32, list<dag> pat32,
640                         dag ins64, string asm64, list<dag> pat64,
641                         string revOp, bit HasMods> {
642   def _e32 : VOP2_e32 <op, opName, outs, ins32, asm32, pat32, revOp>;
643
644   defm _e64 : VOP3_2_m <
645     {1, 0, 0, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
646     outs, ins64, opName#"_e64"#asm64, pat64, opName, revOp, HasMods
647   >;
648 }
649
650 multiclass VOP2Inst <bits<6> op, string opName, VOPProfile P,
651                      SDPatternOperator node = null_frag,
652                      string revOp = opName> : VOP2_Helper <
653   op, opName, P.Outs,
654   P.Ins32, P.Asm32, [],
655   P.Ins64, P.Asm64,
656   !if(P.HasModifiers,
657       [(set P.DstVT:$dst,
658            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
659                                       i32:$clamp, i32:$omod)),
660                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
661       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
662   revOp, P.HasModifiers
663 >;
664
665 multiclass VOP2b_Helper <bits<6> op, string opName, dag outs,
666                          dag ins32, string asm32, list<dag> pat32,
667                          dag ins64, string asm64, list<dag> pat64,
668                          string revOp, bit HasMods> {
669
670   def _e32 : VOP2_e32 <op, opName, outs, ins32, asm32, pat32, revOp>;
671
672   defm _e64 : VOP3b_2_m <
673     {1, 0, 0, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
674     outs, ins64, opName#"_e64"#asm64, pat64, opName, revOp, HasMods
675   >;
676 }
677
678 multiclass VOP2bInst <bits<6> op, string opName, VOPProfile P,
679                       SDPatternOperator node = null_frag,
680                       string revOp = opName> : VOP2b_Helper <
681   op, opName, P.Outs,
682   P.Ins32, P.Asm32, [],
683   P.Ins64, P.Asm64,
684   !if(P.HasModifiers,
685       [(set P.DstVT:$dst,
686            (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
687                                       i32:$clamp, i32:$omod)),
688                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
689       [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))]),
690   revOp, P.HasModifiers
691 >;
692
693 multiclass VOPC_Helper <bits<8> op, string opName,
694                         dag ins32, string asm32, list<dag> pat32,
695                         dag out64, dag ins64, string asm64, list<dag> pat64,
696                         bit HasMods, bit DefExec> {
697   def _e32 : VOPC <op, ins32, opName#asm32, pat32>, VOP <opName> {
698     let Defs = !if(DefExec, [EXEC], []);
699   }
700
701   defm _e64 : VOP3_C_m <op, out64, ins64, opName#"_e64"#asm64, pat64, opName,
702                         HasMods, DefExec>;
703 }
704
705 multiclass VOPCInst <bits<8> op, string opName,
706                      VOPProfile P, PatLeaf cond = COND_NULL,
707                      bit DefExec = 0> : VOPC_Helper <
708   op, opName,
709   P.Ins32, P.Asm32, [],
710   (outs SReg_64:$dst), P.Ins64, P.Asm64,
711   !if(P.HasModifiers,
712       [(set i1:$dst,
713           (setcc (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
714                                       i32:$clamp, i32:$omod)),
715                  (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
716                  cond))],
717       [(set i1:$dst, (setcc P.Src0VT:$src0, P.Src1VT:$src1, cond))]),
718   P.HasModifiers, DefExec
719 >;
720
721 multiclass VOPC_F32 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
722   VOPCInst <op, opName, VOP_F32_F32_F32, cond>;
723
724 multiclass VOPC_F64 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
725   VOPCInst <op, opName, VOP_F64_F64_F64, cond>;
726
727 multiclass VOPC_I32 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
728   VOPCInst <op, opName, VOP_I32_I32_I32, cond>;
729
730 multiclass VOPC_I64 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
731   VOPCInst <op, opName, VOP_I64_I64_I64, cond>;
732
733
734 multiclass VOPCX <bits<8> op, string opName, VOPProfile P,
735                   PatLeaf cond = COND_NULL>
736   : VOPCInst <op, opName, P, cond, 1>;
737
738 multiclass VOPCX_F32 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
739   VOPCX <op, opName, VOP_F32_F32_F32, cond>;
740
741 multiclass VOPCX_F64 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
742   VOPCX <op, opName, VOP_F64_F64_F64, cond>;
743
744 multiclass VOPCX_I32 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
745   VOPCX <op, opName, VOP_I32_I32_I32, cond>;
746
747 multiclass VOPCX_I64 <bits<8> op, string opName, PatLeaf cond = COND_NULL> :
748   VOPCX <op, opName, VOP_I64_I64_I64, cond>;
749
750 multiclass VOP3_Helper <bits<9> op, string opName, dag outs, dag ins, string asm,
751                         list<dag> pat, int NumSrcArgs, bit HasMods> : VOP3_m <
752     op, outs, ins, opName#asm, pat, opName, NumSrcArgs, HasMods
753 >;
754
755 multiclass VOP3Inst <bits<9> op, string opName, VOPProfile P,
756                      SDPatternOperator node = null_frag> : VOP3_Helper <
757   op, opName, P.Outs, P.Ins64, P.Asm64,
758   !if(!eq(P.NumSrcArgs, 3),
759     !if(P.HasModifiers,
760         [(set P.DstVT:$dst,
761             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
762                                        i32:$clamp, i32:$omod)),
763                   (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
764                   (P.Src2VT (VOP3Mods P.Src2VT:$src2, i32:$src2_modifiers))))],
765         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1,
766                                   P.Src2VT:$src2))]),
767   !if(!eq(P.NumSrcArgs, 2),
768     !if(P.HasModifiers,
769         [(set P.DstVT:$dst,
770             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
771                                        i32:$clamp, i32:$omod)),
772                   (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers))))],
773         [(set P.DstVT:$dst, (node P.Src0VT:$src0, P.Src1VT:$src1))])
774   /* P.NumSrcArgs == 1 */,
775     !if(P.HasModifiers,
776         [(set P.DstVT:$dst,
777             (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers,
778                                        i32:$clamp, i32:$omod))))],
779         [(set P.DstVT:$dst, (node P.Src0VT:$src0))]))),
780   P.NumSrcArgs, P.HasModifiers
781 >;
782
783 multiclass VOP3b_Helper <bits<9> op, RegisterClass vrc, RegisterClass arc,
784                     string opName, list<dag> pattern> :
785   VOP3b_2_m <
786   op, (outs vrc:$dst0, SReg_64:$dst1),
787   (ins arc:$src0, arc:$src1, arc:$src2,
788    InstFlag:$abs, InstFlag:$clamp, InstFlag:$omod, InstFlag:$neg),
789   opName#" $dst0, $dst1, $src0, $src1, $src2, $abs, $clamp, $omod, $neg", pattern,
790   opName, opName, 1, 1
791 >;
792
793 multiclass VOP3b_64 <bits<9> op, string opName, list<dag> pattern> :
794   VOP3b_Helper <op, VReg_64, VSrc_64, opName, pattern>;
795
796 multiclass VOP3b_32 <bits<9> op, string opName, list<dag> pattern> :
797   VOP3b_Helper <op, VReg_32, VSrc_32, opName, pattern>;
798
799
800 class Vop3ModPat<Instruction Inst, VOPProfile P, SDPatternOperator node> : Pat<
801   (node (P.Src0VT (VOP3Mods0 P.Src0VT:$src0, i32:$src0_modifiers, i32:$clamp, i32:$omod)),
802         (P.Src1VT (VOP3Mods P.Src1VT:$src1, i32:$src1_modifiers)),
803         (P.Src2VT (VOP3Mods P.Src2VT:$src2, i32:$src2_modifiers))),
804   (Inst i32:$src0_modifiers, P.Src0VT:$src0,
805         i32:$src1_modifiers, P.Src1VT:$src1,
806         i32:$src2_modifiers, P.Src2VT:$src2,
807         i32:$clamp,
808         i32:$omod)>;
809
810 //===----------------------------------------------------------------------===//
811 // Vector I/O classes
812 //===----------------------------------------------------------------------===//
813
814 class DS_1A <bits<8> op, dag outs, dag ins, string asm, list<dag> pat> :
815     DS <op, outs, ins, asm, pat> {
816   bits<16> offset;
817
818   // Single load interpret the 2 i8imm operands as a single i16 offset.
819   let offset0 = offset{7-0};
820   let offset1 = offset{15-8};
821 }
822
823 class DS_Load_Helper <bits<8> op, string asm, RegisterClass regClass> : DS_1A <
824   op,
825   (outs regClass:$vdst),
826   (ins i1imm:$gds, VReg_32:$addr, u16imm:$offset),
827   asm#" $vdst, $addr, $offset, [M0]",
828   []> {
829   let data0 = 0;
830   let data1 = 0;
831   let mayLoad = 1;
832   let mayStore = 0;
833 }
834
835 class DS_Load2_Helper <bits<8> op, string asm, RegisterClass regClass> : DS <
836   op,
837   (outs regClass:$vdst),
838   (ins i1imm:$gds, VReg_32:$addr, u8imm:$offset0, u8imm:$offset1),
839   asm#" $vdst, $addr, $offset0, $offset1, [M0]",
840   []> {
841   let data0 = 0;
842   let data1 = 0;
843   let mayLoad = 1;
844   let mayStore = 0;
845 }
846
847 class DS_Store_Helper <bits<8> op, string asm, RegisterClass regClass> : DS_1A <
848   op,
849   (outs),
850   (ins i1imm:$gds, VReg_32:$addr, regClass:$data0, u16imm:$offset),
851   asm#" $addr, $data0, $offset [M0]",
852   []> {
853   let data1 = 0;
854   let mayStore = 1;
855   let mayLoad = 0;
856   let vdst = 0;
857 }
858
859 class DS_Store2_Helper <bits<8> op, string asm, RegisterClass regClass> : DS <
860   op,
861   (outs),
862   (ins i1imm:$gds, VReg_32:$addr, regClass:$data0, regClass:$data1,
863        u8imm:$offset0, u8imm:$offset1),
864   asm#" $addr, $data0, $data1, $offset0, $offset1 [M0]",
865   []> {
866   let mayStore = 1;
867   let mayLoad = 0;
868   let vdst = 0;
869 }
870
871 // 1 address, 1 data.
872 class DS_1A1D_RET <bits<8> op, string asm, RegisterClass rc> : DS_1A <
873   op,
874   (outs rc:$vdst),
875   (ins i1imm:$gds, VReg_32:$addr, rc:$data0, u16imm:$offset),
876   asm#" $vdst, $addr, $data0, $offset, [M0]",
877   []> {
878
879   let data1 = 0;
880   let mayStore = 1;
881   let mayLoad = 1;
882 }
883
884 // 1 address, 2 data.
885 class DS_1A2D_RET <bits<8> op, string asm, RegisterClass rc> : DS_1A <
886   op,
887   (outs rc:$vdst),
888   (ins i1imm:$gds, VReg_32:$addr, rc:$data0, rc:$data1, u16imm:$offset),
889   asm#" $vdst, $addr, $data0, $data1, $offset, [M0]",
890   []> {
891   let mayStore = 1;
892   let mayLoad = 1;
893 }
894
895 // 1 address, 2 data.
896 class DS_1A2D_NORET <bits<8> op, string asm, RegisterClass rc> : DS_1A <
897   op,
898   (outs),
899   (ins i1imm:$gds, VReg_32:$addr, rc:$data0, rc:$data1, u16imm:$offset),
900   asm#" $addr, $data0, $data1, $offset, [M0]",
901   []> {
902   let mayStore = 1;
903   let mayLoad = 1;
904 }
905
906 // 1 address, 1 data.
907 class DS_1A1D_NORET <bits<8> op, string asm, RegisterClass rc> : DS_1A <
908   op,
909   (outs),
910   (ins i1imm:$gds, VReg_32:$addr, rc:$data0, u16imm:$offset),
911   asm#" $addr, $data0, $offset, [M0]",
912   []> {
913
914   let data1 = 0;
915   let mayStore = 1;
916   let mayLoad = 1;
917 }
918
919 class MUBUFAddr64Table <bit is_addr64> {
920
921   bit IsAddr64 = is_addr64;
922 }
923
924 class MTBUF_Store_Helper <bits<3> op, string asm, RegisterClass regClass> : MTBUF <
925   op,
926   (outs),
927   (ins regClass:$vdata, u16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc,
928    i1imm:$addr64, i8imm:$dfmt, i8imm:$nfmt, VReg_32:$vaddr,
929    SReg_128:$srsrc, i1imm:$slc, i1imm:$tfe, SSrc_32:$soffset),
930   asm#" $vdata, $offset, $offen, $idxen, $glc, $addr64, $dfmt,"
931      #" $nfmt, $vaddr, $srsrc, $slc, $tfe, $soffset",
932   []> {
933   let mayStore = 1;
934   let mayLoad = 0;
935 }
936
937 multiclass MUBUF_Load_Helper <bits<7> op, string asm, RegisterClass regClass,
938                               ValueType load_vt = i32,
939                               SDPatternOperator ld = null_frag> {
940
941   let lds = 0, mayLoad = 1 in {
942
943     let addr64 = 0 in {
944
945       let offen = 0, idxen = 0, vaddr = 0 in {
946         def _OFFSET : MUBUF <op, (outs regClass:$vdata),
947                              (ins SReg_128:$srsrc,
948                              mbuf_offset:$offset, SSrc_32:$soffset, glc:$glc,
949                              slc:$slc, tfe:$tfe),
950                              asm#" $vdata, $srsrc, $soffset"#"$offset"#"$glc"#"$slc"#"$tfe",
951                              [(set load_vt:$vdata, (ld (MUBUFOffset v4i32:$srsrc,
952                                                        i32:$soffset, i16:$offset,
953                                                        i1:$glc, i1:$slc, i1:$tfe)))]>,
954                      MUBUFAddr64Table<0>;
955       }
956
957       let offen = 1, idxen = 0  in {
958         def _OFFEN  : MUBUF <op, (outs regClass:$vdata),
959                              (ins SReg_128:$srsrc, VReg_32:$vaddr,
960                              SSrc_32:$soffset, mbuf_offset:$offset, glc:$glc, slc:$slc,
961                              tfe:$tfe),
962                              asm#" $vdata, $vaddr, $srsrc, $soffset offen"#"$offset"#"$glc"#"$slc"#"$tfe", []>;
963       }
964
965       let offen = 0, idxen = 1 in {
966         def _IDXEN  : MUBUF <op, (outs regClass:$vdata),
967                              (ins SReg_128:$srsrc, VReg_32:$vaddr,
968                              mbuf_offset:$offset, SSrc_32:$soffset, glc:$glc,
969                              slc:$slc, tfe:$tfe),
970                              asm#" $vdata, $vaddr, $srsrc, $soffset idxen"#"$offset"#"$glc"#"$slc"#"$tfe", []>;
971       }
972
973       let offen = 1, idxen = 1 in {
974         def _BOTHEN : MUBUF <op, (outs regClass:$vdata),
975                              (ins SReg_128:$srsrc, VReg_64:$vaddr,
976                              SSrc_32:$soffset, glc:$glc, slc:$slc, tfe:$tfe),
977                              asm#" $vdata, $vaddr, $srsrc, $soffset, idxen offen"#"$glc"#"$slc"#"$tfe", []>;
978       }
979     }
980
981     let offen = 0, idxen = 0, addr64 = 1, glc = 0, slc = 0, tfe = 0, soffset = 128 /* ZERO */ in {
982       def _ADDR64 : MUBUF <op, (outs regClass:$vdata),
983                            (ins SReg_128:$srsrc, VReg_64:$vaddr, mbuf_offset:$offset),
984                            asm#" $vdata, $vaddr, $srsrc, 0 addr64"#"$offset",
985                            [(set load_vt:$vdata, (ld (MUBUFAddr64 v4i32:$srsrc,
986                                                   i64:$vaddr, i16:$offset)))]>, MUBUFAddr64Table<1>;
987     }
988   }
989 }
990
991 multiclass MUBUF_Store_Helper <bits<7> op, string name, RegisterClass vdataClass,
992                           ValueType store_vt, SDPatternOperator st> {
993
994   let addr64 = 0, lds = 0 in {
995
996     def "" : MUBUF <
997       op, (outs),
998       (ins vdataClass:$vdata, SReg_128:$srsrc, VReg_32:$vaddr, SSrc_32:$soffset,
999            mbuf_offset:$offset, offen:$offen, idxen:$idxen, glc:$glc, slc:$slc,
1000            tfe:$tfe),
1001       name#" $vdata, $vaddr, $srsrc, $soffset"#"$offen"#"$idxen"#"$offset"#
1002            "$glc"#"$slc"#"$tfe",
1003       []
1004     >;
1005
1006     let offen = 0, idxen = 0, vaddr = 0 in {
1007       def _OFFSET : MUBUF <
1008         op, (outs),
1009         (ins vdataClass:$vdata, SReg_128:$srsrc, mbuf_offset:$offset,
1010               SSrc_32:$soffset, glc:$glc, slc:$slc, tfe:$tfe),
1011         name#" $vdata, $srsrc, $soffset"#"$offset"#"$glc"#"$slc"#"$tfe",
1012         [(st store_vt:$vdata, (MUBUFOffset v4i32:$srsrc, i32:$soffset,
1013                                            i16:$offset, i1:$glc, i1:$slc,
1014                                            i1:$tfe))]
1015       >, MUBUFAddr64Table<0>;
1016     } // offen = 0, idxen = 0, vaddr = 0
1017
1018     let offen = 1, idxen = 0  in {
1019       def _OFFEN  : MUBUF <
1020         op, (outs),
1021         (ins vdataClass:$vdata, SReg_128:$srsrc, VReg_32:$vaddr, SSrc_32:$soffset,
1022              mbuf_offset:$offset, glc:$glc, slc:$slc, tfe:$tfe),
1023         name#" $vdata, $vaddr, $srsrc, $soffset offen"#"$offset"#
1024             "$glc"#"$slc"#"$tfe",
1025         []
1026       >;
1027     } // end offen = 1, idxen = 0
1028
1029   } // End addr64 = 0, lds = 0
1030
1031   def _ADDR64 : MUBUF <
1032     op, (outs),
1033     (ins vdataClass:$vdata, SReg_128:$srsrc, VReg_64:$vaddr, mbuf_offset:$offset),
1034     name#" $vdata, $vaddr, $srsrc, 0 addr64"#"$offset",
1035     [(st store_vt:$vdata,
1036      (MUBUFAddr64 v4i32:$srsrc, i64:$vaddr, i16:$offset))]>, MUBUFAddr64Table<1>
1037      {
1038
1039       let mayLoad = 0;
1040       let mayStore = 1;
1041
1042       // Encoding
1043       let offen = 0;
1044       let idxen = 0;
1045       let glc = 0;
1046       let addr64 = 1;
1047       let lds = 0;
1048       let slc = 0;
1049       let tfe = 0;
1050       let soffset = 128; // ZERO
1051    }
1052 }
1053
1054 class MTBUF_Load_Helper <bits<3> op, string asm, RegisterClass regClass> : MTBUF <
1055   op,
1056   (outs regClass:$dst),
1057   (ins u16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc, i1imm:$addr64,
1058        i8imm:$dfmt, i8imm:$nfmt, VReg_32:$vaddr, SReg_128:$srsrc,
1059        i1imm:$slc, i1imm:$tfe, SSrc_32:$soffset),
1060   asm#" $dst, $offset, $offen, $idxen, $glc, $addr64, $dfmt,"
1061      #" $nfmt, $vaddr, $srsrc, $slc, $tfe, $soffset",
1062   []> {
1063   let mayLoad = 1;
1064   let mayStore = 0;
1065 }
1066
1067 class MIMG_Mask <string op, int channels> {
1068   string Op = op;
1069   int Channels = channels;
1070 }
1071
1072 class MIMG_NoSampler_Helper <bits<7> op, string asm,
1073                              RegisterClass dst_rc,
1074                              RegisterClass src_rc> : MIMG <
1075   op,
1076   (outs dst_rc:$vdata),
1077   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
1078        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
1079        SReg_256:$srsrc),
1080   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
1081      #" $tfe, $lwe, $slc, $vaddr, $srsrc",
1082   []> {
1083   let SSAMP = 0;
1084   let mayLoad = 1;
1085   let mayStore = 0;
1086   let hasPostISelHook = 1;
1087 }
1088
1089 multiclass MIMG_NoSampler_Src_Helper <bits<7> op, string asm,
1090                                       RegisterClass dst_rc,
1091                                       int channels> {
1092   def _V1 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_32>,
1093             MIMG_Mask<asm#"_V1", channels>;
1094   def _V2 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_64>,
1095             MIMG_Mask<asm#"_V2", channels>;
1096   def _V4 : MIMG_NoSampler_Helper <op, asm, dst_rc, VReg_128>,
1097             MIMG_Mask<asm#"_V4", channels>;
1098 }
1099
1100 multiclass MIMG_NoSampler <bits<7> op, string asm> {
1101   defm _V1 : MIMG_NoSampler_Src_Helper <op, asm, VReg_32, 1>;
1102   defm _V2 : MIMG_NoSampler_Src_Helper <op, asm, VReg_64, 2>;
1103   defm _V3 : MIMG_NoSampler_Src_Helper <op, asm, VReg_96, 3>;
1104   defm _V4 : MIMG_NoSampler_Src_Helper <op, asm, VReg_128, 4>;
1105 }
1106
1107 class MIMG_Sampler_Helper <bits<7> op, string asm,
1108                            RegisterClass dst_rc,
1109                            RegisterClass src_rc> : MIMG <
1110   op,
1111   (outs dst_rc:$vdata),
1112   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
1113        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
1114        SReg_256:$srsrc, SReg_128:$ssamp),
1115   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
1116      #" $tfe, $lwe, $slc, $vaddr, $srsrc, $ssamp",
1117   []> {
1118   let mayLoad = 1;
1119   let mayStore = 0;
1120   let hasPostISelHook = 1;
1121 }
1122
1123 multiclass MIMG_Sampler_Src_Helper <bits<7> op, string asm,
1124                                     RegisterClass dst_rc,
1125                                     int channels> {
1126   def _V1 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_32>,
1127             MIMG_Mask<asm#"_V1", channels>;
1128   def _V2 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_64>,
1129             MIMG_Mask<asm#"_V2", channels>;
1130   def _V4 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_128>,
1131             MIMG_Mask<asm#"_V4", channels>;
1132   def _V8 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_256>,
1133             MIMG_Mask<asm#"_V8", channels>;
1134   def _V16 : MIMG_Sampler_Helper <op, asm, dst_rc, VReg_512>,
1135             MIMG_Mask<asm#"_V16", channels>;
1136 }
1137
1138 multiclass MIMG_Sampler <bits<7> op, string asm> {
1139   defm _V1 : MIMG_Sampler_Src_Helper<op, asm, VReg_32, 1>;
1140   defm _V2 : MIMG_Sampler_Src_Helper<op, asm, VReg_64, 2>;
1141   defm _V3 : MIMG_Sampler_Src_Helper<op, asm, VReg_96, 3>;
1142   defm _V4 : MIMG_Sampler_Src_Helper<op, asm, VReg_128, 4>;
1143 }
1144
1145 class MIMG_Gather_Helper <bits<7> op, string asm,
1146                           RegisterClass dst_rc,
1147                           RegisterClass src_rc> : MIMG <
1148   op,
1149   (outs dst_rc:$vdata),
1150   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
1151        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, src_rc:$vaddr,
1152        SReg_256:$srsrc, SReg_128:$ssamp),
1153   asm#" $vdata, $dmask, $unorm, $glc, $da, $r128,"
1154      #" $tfe, $lwe, $slc, $vaddr, $srsrc, $ssamp",
1155   []> {
1156   let mayLoad = 1;
1157   let mayStore = 0;
1158
1159   // DMASK was repurposed for GATHER4. 4 components are always
1160   // returned and DMASK works like a swizzle - it selects
1161   // the component to fetch. The only useful DMASK values are
1162   // 1=red, 2=green, 4=blue, 8=alpha. (e.g. 1 returns
1163   // (red,red,red,red) etc.) The ISA document doesn't mention
1164   // this.
1165   // Therefore, disable all code which updates DMASK by setting these two:
1166   let MIMG = 0;
1167   let hasPostISelHook = 0;
1168 }
1169
1170 multiclass MIMG_Gather_Src_Helper <bits<7> op, string asm,
1171                                     RegisterClass dst_rc,
1172                                     int channels> {
1173   def _V1 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_32>,
1174             MIMG_Mask<asm#"_V1", channels>;
1175   def _V2 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_64>,
1176             MIMG_Mask<asm#"_V2", channels>;
1177   def _V4 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_128>,
1178             MIMG_Mask<asm#"_V4", channels>;
1179   def _V8 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_256>,
1180             MIMG_Mask<asm#"_V8", channels>;
1181   def _V16 : MIMG_Gather_Helper <op, asm, dst_rc, VReg_512>,
1182             MIMG_Mask<asm#"_V16", channels>;
1183 }
1184
1185 multiclass MIMG_Gather <bits<7> op, string asm> {
1186   defm _V1 : MIMG_Gather_Src_Helper<op, asm, VReg_32, 1>;
1187   defm _V2 : MIMG_Gather_Src_Helper<op, asm, VReg_64, 2>;
1188   defm _V3 : MIMG_Gather_Src_Helper<op, asm, VReg_96, 3>;
1189   defm _V4 : MIMG_Gather_Src_Helper<op, asm, VReg_128, 4>;
1190 }
1191
1192 //===----------------------------------------------------------------------===//
1193 // Vector instruction mappings
1194 //===----------------------------------------------------------------------===//
1195
1196 // Maps an opcode in e32 form to its e64 equivalent
1197 def getVOPe64 : InstrMapping {
1198   let FilterClass = "VOP";
1199   let RowFields = ["OpName"];
1200   let ColFields = ["Size"];
1201   let KeyCol = ["4"];
1202   let ValueCols = [["8"]];
1203 }
1204
1205 // Maps an opcode in e64 form to its e32 equivalent
1206 def getVOPe32 : InstrMapping {
1207   let FilterClass = "VOP";
1208   let RowFields = ["OpName"];
1209   let ColFields = ["Size"];
1210   let KeyCol = ["8"];
1211   let ValueCols = [["4"]];
1212 }
1213
1214 // Maps an original opcode to its commuted version
1215 def getCommuteRev : InstrMapping {
1216   let FilterClass = "VOP2_REV";
1217   let RowFields = ["RevOp"];
1218   let ColFields = ["IsOrig"];
1219   let KeyCol = ["1"];
1220   let ValueCols = [["0"]];
1221 }
1222
1223 def getMaskedMIMGOp : InstrMapping {
1224   let FilterClass = "MIMG_Mask";
1225   let RowFields = ["Op"];
1226   let ColFields = ["Channels"];
1227   let KeyCol = ["4"];
1228   let ValueCols = [["1"], ["2"], ["3"] ];
1229 }
1230
1231 // Maps an commuted opcode to its original version
1232 def getCommuteOrig : InstrMapping {
1233   let FilterClass = "VOP2_REV";
1234   let RowFields = ["RevOp"];
1235   let ColFields = ["IsOrig"];
1236   let KeyCol = ["0"];
1237   let ValueCols = [["1"]];
1238 }
1239
1240 def isDS : InstrMapping {
1241   let FilterClass = "DS";
1242   let RowFields = ["Inst"];
1243   let ColFields = ["Size"];
1244   let KeyCol = ["8"];
1245   let ValueCols = [["8"]];
1246 }
1247
1248 def getMCOpcode : InstrMapping {
1249   let FilterClass = "SIMCInstr";
1250   let RowFields = ["PseudoInstr"];
1251   let ColFields = ["Subtarget"];
1252   let KeyCol = [!cast<string>(SISubtarget.NONE)];
1253   let ValueCols = [[!cast<string>(SISubtarget.SI)]];
1254 }
1255
1256 def getAddr64Inst : InstrMapping {
1257   let FilterClass = "MUBUFAddr64Table";
1258   let RowFields = ["NAME"];
1259   let ColFields = ["IsAddr64"];
1260   let KeyCol = ["0"];
1261   let ValueCols = [["1"]];
1262 }
1263
1264 include "SIInstructions.td"