Fix a minor bug (ORo didn't mark that it set CR0).
[oota-llvm.git] / lib / Target / PowerPC / PPCInstrFormats.td
1 //===- PowerPCInstrFormats.td - PowerPC Instruction Formats --*- tablegen -*-=//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 //
11 //===----------------------------------------------------------------------===//
12
13 // DOT - This is a marker that should be added to instructions that set the
14 // flags in CR0.
15 class DOT {
16   list<Register> Defs = [CR0];
17   bit RC = 1;
18 }
19
20
21 class Format<bits<5> val> {
22   bits<5> Value = val;
23 }
24
25 def Pseudo: Format<0>;
26 def Gpr : Format<1>;
27 def Gpr0 : Format<2>;
28 def Simm16 : Format<3>;
29 def PCRelimm24 : Format<5>;
30 def Imm24 : Format<6>;
31 def Imm5 : Format<7>;
32 def PCRelimm14 : Format<8>;
33 def Imm14 : Format<9>;
34 def Imm2 : Format<10>;
35 def Crf : Format<11>;
36 def Imm3 : Format<12>;
37 def Imm1 : Format<13>;
38 def Fpr : Format<14>;
39 def Imm4 : Format<15>;
40 def Imm8 : Format<16>;
41 def Disimm16 : Format<17>;
42 def Disimm14 : Format<18>;
43 def Spr : Format<19>;
44 def Sgr : Format<20>;
45 def Imm15 : Format<21>;
46 def Vpr : Format<22>;
47 def Imm6 : Format<23>;
48
49 //===----------------------------------------------------------------------===//
50 //
51 // PowerPC instruction formats
52
53 class I<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr> 
54   : Instruction {
55   field bits<32> Inst;
56
57   bit PPC64 = ppc64;
58   bit VMX = vmx;
59
60   let Name = "";
61   let Namespace = "PPC";
62   let Inst{0-5} = opcode;
63   let OperandList = OL;
64   let AsmString = asmstr;
65 }
66
67 // 1.7.1 I-Form
68 class IForm<bits<6> opcode, bit aa, bit lk, bit ppc64, bit vmx,
69             dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
70   bits<24> LI;
71
72   let Inst{6-29}  = LI;
73   let Inst{30}    = aa;
74   let Inst{31}    = lk;
75 }
76
77 // 1.7.2 B-Form
78 class BForm<bits<6> opcode, bit aa, bit lk, bit ppc64, bit vmx,
79             dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
80   bits<5>  BO;
81   bits<3>  CRNum;
82   bits<2>  BICode;
83   bits<14> BD;
84
85   let Inst{6-10}  = BO;
86   let Inst{11-13} = CRNum;
87   let Inst{14-15} = BICode;
88   let Inst{16-29} = BD;
89   let Inst{30}    = aa;
90   let Inst{31}    = lk;
91 }
92
93 class BForm_ext<bits<6> opcode, bit aa, bit lk, bits<5> bo, bits<2> bicode, 
94                 bit ppc64, bit vmx, dag OL, string asmstr>
95   : BForm<opcode, aa, lk, ppc64, vmx, OL, asmstr> {
96   let BO = bo;
97   let BICode = bicode;
98 }
99
100 // 1.7.4 D-Form
101 class DForm_base<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
102   : I<opcode, ppc64, vmx, OL, asmstr> {
103   bits<5>  A;
104   bits<5>  B;
105   bits<16> C;
106   
107   let Inst{6-10}  = A;
108   let Inst{11-15} = B;
109   let Inst{16-31} = C;
110 }
111
112 class DForm_1<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
113   : I<opcode, ppc64, vmx, OL, asmstr> {
114   bits<5>  A;
115   bits<16> C;
116   bits<5>  B;
117   
118   let Inst{6-10}  = A;
119   let Inst{11-15} = B;
120   let Inst{16-31} = C;
121 }
122
123 class DForm_2<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
124   : DForm_base<opcode, ppc64, vmx, OL, asmstr>;
125
126 class DForm_2_r0<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
127   : I<opcode, ppc64, vmx, OL, asmstr> {
128   bits<5>  A;
129   bits<16> B;
130   
131   let Inst{6-10}  = A;
132   let Inst{11-15} = 0;
133   let Inst{16-31} = B;
134 }
135
136 // Currently we make the use/def reg distinction in ISel, not tablegen
137 class DForm_3<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
138   : DForm_1<opcode, ppc64, vmx, OL, asmstr>;
139
140 class DForm_4<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr> 
141   : I<opcode, ppc64, vmx, OL, asmstr> {
142   bits<5>  B;
143   bits<5>  A;
144   bits<16> C;
145   
146   let Inst{6-10}  = A;
147   let Inst{11-15} = B;
148   let Inst{16-31} = C;
149 }
150               
151 class DForm_4_zero<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
152   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
153   let A = 0;
154   let B = 0;
155   let C = 0;
156 }
157
158 class DForm_5<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
159   : I<opcode, ppc64, vmx, OL, asmstr> {
160   bits<3>  BF;
161   bits<1>  L;
162   bits<5>  RA;
163   bits<16> I;
164
165   let Inst{6-8}   = BF;
166   let Inst{9}     = 0;
167   let Inst{10}    = L;
168   let Inst{11-15} = RA;
169   let Inst{16-31} = I;
170 }
171
172 class DForm_5_ext<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
173   : DForm_5<opcode, ppc64, vmx, OL, asmstr> {
174   let L = ppc64;
175 }
176
177 class DForm_6<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr> 
178   : DForm_5<opcode, ppc64, vmx, OL, asmstr>;
179
180 class DForm_6_ext<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
181   : DForm_6<opcode, ppc64, vmx, OL, asmstr> {
182   let L = ppc64;
183 }
184
185 class DForm_8<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
186   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
187 }
188
189 class DForm_9<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
190   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
191 }
192
193 // 1.7.5 DS-Form
194 class DSForm_1<bits<6> opcode, bits<2> xo, bit ppc64, bit vmx,
195                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
196   bits<5>  RST;
197   bits<14> DS;
198   bits<5>  RA;
199
200   let Inst{6-10}  = RST;
201   let Inst{11-15} = RA;
202   let Inst{16-29} = DS;
203   let Inst{30-31} = xo;
204 }
205
206 class DSForm_2<bits<6> opcode, bits<2> xo, bit ppc64, bit vmx, 
207                dag OL, string asmstr>
208   : DSForm_1<opcode, xo, ppc64, vmx, OL, asmstr>;
209
210 // 1.7.6 X-Form
211 class XForm_base_r3xo<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
212                       dag OL, string asmstr> 
213   : I<opcode, ppc64, vmx, OL, asmstr> {
214   bits<5> RST;
215   bits<5> A;
216   bits<5> B;
217
218   let Inst{6-10}  = RST;
219   let Inst{11-15} = A;
220   let Inst{16-20} = B;
221   let Inst{21-30} = xo;
222   let Inst{31}    = rc;
223 }
224
225 // This is the same as XForm_base_r3xo, but the first two operands are swapped
226 // when code is emitted.
227 class XForm_base_r3xo_swapped
228         <bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
229          dag OL, string asmstr> 
230   : I<opcode, ppc64, vmx, OL, asmstr> {
231   bits<5> A;
232   bits<5> RST;
233   bits<5> B;
234   bit RC = 0;
235
236   let Inst{6-10}  = RST;
237   let Inst{11-15} = A;
238   let Inst{16-20} = B;
239   let Inst{21-30} = xo;
240   let Inst{31}    = RC;
241 }
242
243
244 class XForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
245               dag OL, string asmstr> 
246   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
247
248 class XForm_5<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
249               dag OL, string asmstr>
250   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
251   let A = 0;
252   let B = 0;
253 }
254
255 class XForm_6<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
256               dag OL, string asmstr> 
257   : XForm_base_r3xo_swapped<opcode, xo, ppc64, vmx, OL, asmstr> {
258 }
259
260 class XForm_8<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
261               dag OL, string asmstr> 
262   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
263
264 class XForm_10<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
265                dag OL, string asmstr> 
266   : XForm_base_r3xo_swapped<opcode, xo, ppc64, vmx, OL, asmstr> {
267   let RC = rc;
268 }
269
270 class XForm_11<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
271                dag OL, string asmstr> 
272   : XForm_base_r3xo_swapped<opcode, xo, ppc64, vmx, OL, asmstr> {
273   let B = 0;
274   let RC = rc;
275 }
276
277 class XForm_16<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
278                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
279   bits<3> BF;
280   bits<1> L; 
281   bits<5> RA;
282   bits<5> RB;
283   
284   let Inst{6-8}   = BF;
285   let Inst{9}     = 0;
286   let Inst{10}    = L;
287   let Inst{11-15} = RA;
288   let Inst{16-20} = RB;
289   let Inst{21-30} = xo;
290   let Inst{31}    = 0;
291 }
292
293 class XForm_16_ext<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
294                    dag OL, string asmstr>
295   : XForm_16<opcode, xo, ppc64, vmx, OL, asmstr> {
296   let L = ppc64;
297 }
298
299 class XForm_17<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
300                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
301   bits<3> BF;
302   bits<5> FRA;
303   bits<5> FRB;
304   
305   let Inst{6-8}   = BF;
306   let Inst{9-10}  = 0;
307   let Inst{11-15} = FRA;
308   let Inst{16-20} = FRB;
309   let Inst{21-30} = xo;
310   let Inst{31}    = 0;
311 }
312
313 class XForm_25<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
314                dag OL, string asmstr> 
315   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
316 }
317
318 class XForm_26<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
319                dag OL, string asmstr> 
320   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
321   let A = 0;
322 }
323
324 class XForm_28<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
325                dag OL, string asmstr> 
326   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
327 }
328
329 // 1.7.7 XL-Form
330 class XLForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
331                dag OL, string asmstr> 
332   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
333 }
334
335 class XLForm_2<bits<6> opcode, bits<10> xo, bit lk, bit ppc64, bit vmx, 
336                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
337   bits<5> BO;
338   bits<5> BI;
339   bits<2> BH;
340   
341   let Inst{6-10}  = BO;
342   let Inst{11-15} = BI;
343   let Inst{16-18} = 0;
344   let Inst{19-20} = BH;
345   let Inst{21-30} = xo;
346   let Inst{31}    = lk;
347 }
348
349 class XLForm_2_ext<bits<6> opcode, bits<10> xo, bits<5> bo, 
350                    bits<5> bi, bit lk, bit ppc64, bit vmx, 
351                    dag OL, string asmstr>
352   : XLForm_2<opcode, xo, lk, ppc64, vmx, OL, asmstr> {
353   let BO = bo;
354   let BI = bi;
355   let BH = 0;
356 }
357
358 // 1.7.8 XFX-Form
359 class XFXForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx, 
360                 dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
361   bits<5>  ST;
362   bits<10> SPR;
363
364   let Inst{6-10}  = ST;
365   let Inst{11-20} = SPR;
366   let Inst{21-30} = xo;
367   let Inst{31}    = 0;
368 }
369
370 class XFXForm_1_ext<bits<6> opcode, bits<10> xo, bits<10> spr, bit ppc64, 
371                     bit vmx, dag OL, string asmstr> 
372   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr> {
373   let SPR = spr;
374 }
375
376 class XFXForm_7<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
377                 dag OL, string asmstr>
378   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr>;
379
380 class XFXForm_7_ext<bits<6> opcode, bits<10> xo, bits<10> spr, 
381                     bit ppc64, bit vmx, dag OL, string asmstr> 
382   : XFXForm_7<opcode, xo, ppc64, vmx, OL, asmstr> {
383   let SPR = spr;
384 }
385
386 // 1.7.10 XS-Form
387 class XSForm_1<bits<6> opcode, bits<9> xo, bit rc, bit ppc64, bit vmx,
388                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
389   bits<5> RS;
390   bits<5> A;
391   bits<6> SH;
392
393   let Inst{6-10}  = RS;
394   let Inst{11-15} = A;
395   let Inst{16-20} = SH{1-5};
396   let Inst{21-29} = xo;
397   let Inst{30}    = SH{0};
398   let Inst{31}    = rc;
399 }
400
401 // 1.7.11 XO-Form
402 class XOForm_1<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
403                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
404   bits<5> RT;
405   bits<5> RA;
406   bits<5> RB;
407
408   let Inst{6-10}  = RT;
409   let Inst{11-15} = RA;
410   let Inst{16-20} = RB;
411   let Inst{21}    = oe;
412   let Inst{22-30} = xo;
413   let Inst{31}    = rc;  
414 }
415
416 class XOForm_1r<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
417                dag OL, string asmstr>
418   : XOForm_1<opcode, xo, oe, rc, ppc64, vmx, OL, asmstr> {
419   let Inst{11-15} = RB;
420   let Inst{16-20} = RA;
421 }
422
423 class XOForm_3<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
424                dag OL, string asmstr>
425   : XOForm_1<opcode, xo, oe, rc, ppc64, vmx, OL, asmstr> {
426   let RB = 0;
427 }
428
429 // 1.7.12 A-Form
430 class AForm_1<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, 
431               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
432   bits<5> FRT;
433   bits<5> FRA;
434   bits<5> FRC;
435   bits<5> FRB;
436
437   let Inst{6-10}  = FRT;
438   let Inst{11-15} = FRA;
439   let Inst{16-20} = FRB;
440   let Inst{21-25} = FRC;
441   let Inst{26-30} = xo;
442   let Inst{31}    = rc;
443 }
444
445 class AForm_2<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
446               string asmstr> 
447   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
448   let FRC = 0;
449 }
450
451 class AForm_3<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
452               string asmstr> 
453   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
454   let FRB = 0;
455 }
456
457 // 1.7.13 M-Form
458 class MForm_1<bits<6> opcode, bit rc, bit ppc64, bit vmx,
459               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
460   bits<5> RA;
461   bits<5> RS;
462   bits<5> RB;
463   bits<5> MB;
464   bits<5> ME;
465
466   let Inst{6-10}  = RS;
467   let Inst{11-15} = RA;
468   let Inst{16-20} = RB;
469   let Inst{21-25} = MB;
470   let Inst{26-30} = ME;
471   let Inst{31}    = rc;
472 }
473
474 class MForm_2<bits<6> opcode, bit rc, bit ppc64, bit vmx, 
475               dag OL, string asmstr>
476   : MForm_1<opcode, rc, ppc64, vmx, OL, asmstr> {
477 }
478
479 // 1.7.14 MD-Form
480 class MDForm_1<bits<6> opcode, bits<3> xo, bit rc, bit ppc64, bit vmx,
481                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
482   bits<5> RS;
483   bits<5> RA;
484   bits<6> SH;
485   bits<6> MBE;
486
487   let Inst{6-10}  = RS;
488   let Inst{11-15} = RA;
489   let Inst{16-20} = SH{1-5};
490   let Inst{21-26} = MBE;
491   let Inst{27-29} = xo;
492   let Inst{30}    = SH{0};
493   let Inst{31}    = rc;
494 }
495
496 //===----------------------------------------------------------------------===//
497
498 class Pseudo<dag OL, string asmstr> : I<0, 0, 0, OL, asmstr> {
499   let PPC64 = 0;
500   let VMX = 0;
501
502   let Inst{31-0} = 0;
503 }