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