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