R600/SI: cleanup SIInstrInfo.td and SIInstrFormat.td
[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 //===----------------------------------------------------------------------===//
11 // SI DAG Nodes
12 //===----------------------------------------------------------------------===//
13
14 // SMRD takes a 64bit memory address and can only add an 32bit offset
15 def SIadd64bit32bit : SDNode<"ISD::ADD",
16   SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>, SDTCisVT<0, i64>, SDTCisVT<2, i32>]>
17 >;
18
19 // Transformation function, extract the lower 32bit of a 64bit immediate
20 def LO32 : SDNodeXForm<imm, [{
21   return CurDAG->getTargetConstant(N->getZExtValue() & 0xffffffff, MVT::i32);
22 }]>;
23
24 // Transformation function, extract the upper 32bit of a 64bit immediate
25 def HI32 : SDNodeXForm<imm, [{
26   return CurDAG->getTargetConstant(N->getZExtValue() >> 32, MVT::i32);
27 }]>;
28
29 def IMM8bitDWORD : ImmLeaf <
30   i32, [{
31     return (Imm & ~0x3FC) == 0;
32   }], SDNodeXForm<imm, [{
33     return CurDAG->getTargetConstant(
34       N->getZExtValue() >> 2, MVT::i32);
35   }]>
36 >;
37
38 def IMM12bit : ImmLeaf <
39   i16,
40   [{return isUInt<12>(Imm);}]
41 >;
42
43 class InlineImm <ValueType vt> : ImmLeaf <vt, [{
44   return -16 <= Imm && Imm <= 64;
45 }]>;
46
47
48 //===----------------------------------------------------------------------===//
49 // SI assembler operands
50 //===----------------------------------------------------------------------===//
51
52 class SIOperand <ValueType vt, dag opInfo>: Operand <vt> {
53   let EncoderMethod = "encodeOperand";
54   let MIOperandInfo = opInfo;
55 }
56
57 class GPR4Align <RegisterClass rc> : Operand <vAny> {
58   let EncoderMethod = "GPR4AlignEncode";
59   let MIOperandInfo = (ops rc:$reg); 
60 }
61
62 class GPR2Align <RegisterClass rc> : Operand <iPTR> {
63   let EncoderMethod = "GPR2AlignEncode";
64   let MIOperandInfo = (ops rc:$reg);
65 }
66
67 include "SIInstrFormats.td"
68
69 //===----------------------------------------------------------------------===//
70 //
71 // SI Instruction multiclass helpers.
72 //
73 // Instructions with _32 take 32-bit operands.
74 // Instructions with _64 take 64-bit operands.
75 //
76 // VOP_* instructions can use either a 32-bit or 64-bit encoding.  The 32-bit
77 // encoding is the standard encoding, but instruction that make use of
78 // any of the instruction modifiers must use the 64-bit encoding.
79 //
80 // Instructions with _e32 use the 32-bit encoding.
81 // Instructions with _e64 use the 64-bit encoding.
82 //
83 //===----------------------------------------------------------------------===//
84
85 //===----------------------------------------------------------------------===//
86 // Scalar classes
87 //===----------------------------------------------------------------------===//
88
89 class SOP1_32 <bits<8> op, string opName, list<dag> pattern>
90   : SOP1 <op, (outs SReg_32:$dst), (ins SSrc_32:$src0), opName, pattern>;
91
92 class SOP1_64 <bits<8> op, string opName, list<dag> pattern>
93   : SOP1 <op, (outs SReg_64:$dst), (ins SSrc_64:$src0), opName, pattern>;
94
95 class SOP2_32 <bits<7> op, string opName, list<dag> pattern>
96   : SOP2 <op, (outs SReg_32:$dst), (ins SSrc_32:$src0, SSrc_32:$src1), opName, pattern>;
97
98 class SOP2_64 <bits<7> op, string opName, list<dag> pattern>
99   : SOP2 <op, (outs SReg_64:$dst), (ins SSrc_64:$src0, SSrc_64:$src1), opName, pattern>;
100
101 class SOPC_32 <bits<7> op, string opName, list<dag> pattern>
102   : SOPC <op, (outs SCCReg:$dst), (ins SSrc_32:$src0, SSrc_32:$src1), opName, pattern>;
103
104 class SOPC_64 <bits<7> op, string opName, list<dag> pattern>
105   : SOPC <op, (outs SCCReg:$dst), (ins SSrc_64:$src0, SSrc_64:$src1), opName, pattern>;
106
107 class SOPK_32 <bits<5> op, string opName, list<dag> pattern>
108   : SOPK <op, (outs SReg_32:$dst), (ins i16imm:$src0), opName, pattern>;
109
110 class SOPK_64 <bits<5> op, string opName, list<dag> pattern>
111   : SOPK <op, (outs SReg_64:$dst), (ins i16imm:$src0), opName, pattern>;
112
113 multiclass SMRD_Helper <bits<5> op, string asm, RegisterClass dstClass> {
114   def _IMM : SMRD <
115     op, 1, (outs dstClass:$dst),
116     (ins GPR2Align<SReg_64>:$sbase, i32imm:$offset),
117     asm, []
118   >;
119
120   def _SGPR : SMRD <
121     op, 0, (outs dstClass:$dst),
122     (ins GPR2Align<SReg_64>:$sbase, SReg_32:$soff),
123     asm, []
124   >;
125 }
126
127 //===----------------------------------------------------------------------===//
128 // Vector ALU classes
129 //===----------------------------------------------------------------------===//
130
131 class VOP3_32 <bits<9> op, string opName, list<dag> pattern> : VOP3 <
132   op, (outs VReg_32:$dst),
133   (ins VSrc_32:$src0, VReg_32:$src1, VReg_32:$src2, i32imm:$src3,
134    i32imm:$src4, i32imm:$src5, i32imm:$src6),
135   opName, pattern
136 >;
137
138 class VOP3_64 <bits<9> op, string opName, list<dag> pattern> : VOP3 <
139   op, (outs VReg_64:$dst),
140   (ins VSrc_64:$src0, VReg_64:$src1, VReg_64:$src2,
141    i32imm:$src3, i32imm:$src4, i32imm:$src5, i32imm:$src6),
142   opName, pattern
143 >;
144
145 class VOP1_Helper <bits<8> op, RegisterClass vrc, RegisterClass arc,
146                    string opName, list<dag> pattern> : 
147   VOP1 <
148     op, (outs vrc:$dst), (ins arc:$src0), opName, pattern
149   >;
150
151 multiclass VOP1_32 <bits<8> op, string opName, list<dag> pattern> {
152   def _e32: VOP1_Helper <op, VReg_32, VSrc_32, opName, pattern>;
153   def _e64 : VOP3_32 <{1, 1, op{6}, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
154                       opName, []
155   >;
156 }
157
158 multiclass VOP1_64 <bits<8> op, string opName, list<dag> pattern> {
159
160   def _e32 : VOP1_Helper <op, VReg_64, VSrc_64, opName, pattern>;
161
162   def _e64 : VOP3_64 <
163     {1, 1, op{6}, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
164     opName, []
165   >;
166 }
167
168 class VOP2_Helper <bits<6> op, RegisterClass vrc, RegisterClass arc,
169                    string opName, list<dag> pattern> :
170   VOP2 <
171     op, (outs vrc:$dst), (ins arc:$src0, vrc:$src1), opName, pattern
172   >;
173
174 multiclass VOP2_32 <bits<6> op, string opName, list<dag> pattern> {
175
176   def _e32 : VOP2_Helper <op, VReg_32, VSrc_32, opName, pattern>;
177
178   def _e64 : VOP3_32 <{1, 0, 0, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
179                       opName, []
180   >;
181 }
182
183 multiclass VOP2_64 <bits<6> op, string opName, list<dag> pattern> {
184   def _e32: VOP2_Helper <op, VReg_64, VSrc_64, opName, pattern>;
185
186   def _e64 : VOP3_64 <
187     {1, 0, 0, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
188     opName, []
189   >;
190 }
191
192 multiclass VOPC_Helper <bits<8> op, RegisterClass vrc, RegisterClass arc,
193                         string opName, list<dag> pattern> {
194
195   def _e32 : VOPC <op, (ins arc:$src0, vrc:$src1), opName, pattern>;
196   def _e64 : VOP3 <
197     {0, op{7}, op{6}, op{5}, op{4}, op{3}, op{2}, op{1}, op{0}},
198     (outs SReg_64:$dst),
199     (ins arc:$src0, vrc:$src1,
200          InstFlag:$abs, InstFlag:$clamp,
201          InstFlag:$omod, InstFlag:$neg),
202     opName, pattern
203   > {
204     let SRC2 = 0x80;
205   }
206 }
207
208 multiclass VOPC_32 <bits<8> op, string opName, list<dag> pattern>
209   : VOPC_Helper <op, VReg_32, VSrc_32, opName, pattern>;
210
211 multiclass VOPC_64 <bits<8> op, string opName, list<dag> pattern>
212   : VOPC_Helper <op, VReg_64, VSrc_64, opName, pattern>;
213
214 //===----------------------------------------------------------------------===//
215 // Vector I/O classes
216 //===----------------------------------------------------------------------===//
217
218 class MTBUF_Store_Helper <bits<3> op, string asm, RegisterClass regClass> : MTBUF <
219   op,
220   (outs),
221   (ins regClass:$vdata, i16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc,
222    i1imm:$addr64, i8imm:$dfmt, i8imm:$nfmt, VReg_32:$vaddr,
223    GPR4Align<SReg_128>:$srsrc, i1imm:$slc, i1imm:$tfe, SSrc_32:$soffset),
224   asm,
225   []> {
226   let mayStore = 1;
227   let mayLoad = 0;
228 }
229
230 class MUBUF_Load_Helper <bits<7> op, string asm, RegisterClass regClass> : MUBUF <
231   op,
232   (outs regClass:$dst),
233   (ins i16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc, i1imm:$addr64,
234        i1imm:$lds, VReg_32:$vaddr, GPR4Align<SReg_128>:$srsrc, i1imm:$slc,
235        i1imm:$tfe, SSrc_32:$soffset),
236   asm,
237   []> {
238   let mayLoad = 1;
239   let mayStore = 0;
240 }
241
242 class MTBUF_Load_Helper <bits<3> op, string asm, RegisterClass regClass> : MTBUF <
243   op,
244   (outs regClass:$dst),
245   (ins i16imm:$offset, i1imm:$offen, i1imm:$idxen, i1imm:$glc, i1imm:$addr64,
246        i8imm:$dfmt, i8imm:$nfmt, VReg_32:$vaddr, GPR4Align<SReg_128>:$srsrc,
247        i1imm:$slc, i1imm:$tfe, SSrc_32:$soffset),
248   asm,
249   []> {
250   let mayLoad = 1;
251   let mayStore = 0;
252 }
253
254 class MIMG_Load_Helper <bits<7> op, string asm> : MIMG <
255   op,
256   (outs VReg_128:$vdata),
257   (ins i32imm:$dmask, i1imm:$unorm, i1imm:$glc, i1imm:$da, i1imm:$r128,
258        i1imm:$tfe, i1imm:$lwe, i1imm:$slc, VReg_32:$vaddr,
259        GPR4Align<SReg_256>:$srsrc, GPR4Align<SReg_128>:$ssamp),
260   asm,
261   []> {
262   let mayLoad = 1;
263   let mayStore = 0;
264 }
265
266 include "SIInstructions.td"