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