1475f7ad03b6782e6c988afbecdfb8b21241e90d
[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               list<dag> pattern> 
228   : XForm_base_r3xo_swapped<opcode, xo, OL, asmstr> {
229   let Pattern = pattern;
230 }
231
232 class XForm_8<bits<6> opcode, bits<10> xo, dag OL, string asmstr> 
233   : XForm_base_r3xo<opcode, xo, OL, asmstr>;
234
235 class XForm_10<bits<6> opcode, bits<10> xo, dag OL, string asmstr> 
236   : XForm_base_r3xo_swapped<opcode, xo, OL, asmstr> {
237 }
238
239 class XForm_11<bits<6> opcode, bits<10> xo, dag OL, string asmstr,
240                list<dag> pattern> 
241   : XForm_base_r3xo_swapped<opcode, xo, OL, asmstr> {
242   let B = 0;
243   let Pattern = pattern;
244 }
245
246 class XForm_16<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
247          : I<opcode, OL, asmstr> {
248   bits<3> BF;
249   bits<1> L; 
250   bits<5> RA;
251   bits<5> RB;
252   
253   let Inst{6-8}   = BF;
254   let Inst{9}     = 0;
255   let Inst{10}    = L;
256   let Inst{11-15} = RA;
257   let Inst{16-20} = RB;
258   let Inst{21-30} = xo;
259   let Inst{31}    = 0;
260 }
261
262 class XForm_16_ext<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
263   : XForm_16<opcode, xo, OL, asmstr> {
264   let L = PPC64;
265 }
266
267 class XForm_17<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
268          : I<opcode, OL, asmstr> {
269   bits<3> BF;
270   bits<5> FRA;
271   bits<5> FRB;
272   
273   let Inst{6-8}   = BF;
274   let Inst{9-10}  = 0;
275   let Inst{11-15} = FRA;
276   let Inst{16-20} = FRB;
277   let Inst{21-30} = xo;
278   let Inst{31}    = 0;
279 }
280
281 class XForm_25<bits<6> opcode, bits<10> xo, dag OL, string asmstr> 
282   : XForm_base_r3xo<opcode, xo, OL, asmstr> {
283 }
284
285 class XForm_26<bits<6> opcode, bits<10> xo, dag OL, string asmstr> 
286   : XForm_base_r3xo<opcode, xo, OL, asmstr> {
287   let A = 0;
288 }
289
290 class XForm_28<bits<6> opcode, bits<10> xo, dag OL, string asmstr> 
291   : XForm_base_r3xo<opcode, xo, OL, asmstr> {
292 }
293
294 // 1.7.7 XL-Form
295 class XLForm_1<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
296          : I<opcode, OL, asmstr> {
297   bits<3> CRD;
298   bits<2> CRDb;
299   bits<3> CRA;
300   bits<2> CRAb;
301   bits<3> CRB;
302   bits<2> CRBb;
303   
304   let Inst{6-8}   = CRD;
305   let Inst{9-10}  = CRDb;
306   let Inst{11-13} = CRA;
307   let Inst{14-15} = CRAb;
308   let Inst{16-18} = CRB;
309   let Inst{19-20} = CRBb;
310   let Inst{21-30} = xo;
311   let Inst{31}    = 0;
312 }
313
314 class XLForm_2<bits<6> opcode, bits<10> xo, bit lk, 
315                dag OL, string asmstr> : I<opcode, OL, asmstr> {
316   bits<5> BO;
317   bits<5> BI;
318   bits<2> BH;
319   
320   let Inst{6-10}  = BO;
321   let Inst{11-15} = BI;
322   let Inst{16-18} = 0;
323   let Inst{19-20} = BH;
324   let Inst{21-30} = xo;
325   let Inst{31}    = lk;
326 }
327
328 class XLForm_2_ext<bits<6> opcode, bits<10> xo, bits<5> bo, 
329                    bits<5> bi, bit lk, dag OL, string asmstr>
330   : XLForm_2<opcode, xo, lk, OL, asmstr> {
331   let BO = bo;
332   let BI = bi;
333   let BH = 0;
334 }
335
336 class XLForm_3<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
337          : I<opcode, OL, asmstr> {
338   bits<3> BF;
339   bits<3> BFA;
340   
341   let Inst{6-8}   = BF;
342   let Inst{9-10}  = 0;
343   let Inst{11-13} = BFA;
344   let Inst{14-15} = 0;
345   let Inst{16-20} = 0;
346   let Inst{21-30} = xo;
347   let Inst{31}    = 0;
348 }
349
350 // 1.7.8 XFX-Form
351 class XFXForm_1<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
352          : I<opcode, OL, asmstr> {
353   bits<5>  RT;
354   bits<10> SPR;
355
356   let Inst{6-10}  = RT;
357   let Inst{11-20} = SPR;
358   let Inst{21-30} = xo;
359   let Inst{31}    = 0;
360 }
361
362 class XFXForm_1_ext<bits<6> opcode, bits<10> xo, bits<10> spr, 
363                    dag OL, string asmstr> 
364   : XFXForm_1<opcode, xo, OL, asmstr> {
365   let SPR = spr;
366 }
367
368 class XFXForm_3<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
369          : I<opcode, OL, asmstr> {
370   bits<5>  RT;
371    
372   let Inst{6-10}  = RT;
373   let Inst{11-20} = 0;
374   let Inst{21-30} = xo;
375   let Inst{31}    = 0;
376 }
377
378 class XFXForm_5<bits<6> opcode, bits<10> xo, dag OL, string asmstr> 
379   : I<opcode, OL, asmstr> {
380   bits<8>  FXM;
381   bits<5>  ST;
382    
383   let Inst{6-10}  = ST;
384   let Inst{11}    = 0;
385   let Inst{12-19} = FXM;
386   let Inst{20}    = 0;
387   let Inst{21-30} = xo;
388   let Inst{31}    = 0;
389 }
390
391 class XFXForm_5a<bits<6> opcode, bits<10> xo, dag OL, string asmstr> 
392   : I<opcode, OL, asmstr> {
393   bits<5>  ST;
394   bits<8>  FXM;
395    
396   let Inst{6-10}  = ST;
397   let Inst{11}    = 1;
398   let Inst{12-19} = FXM;
399   let Inst{20}    = 0;
400   let Inst{21-30} = xo;
401   let Inst{31}    = 0;
402 }
403
404
405 class XFXForm_7<bits<6> opcode, bits<10> xo, dag OL, string asmstr>
406   : XFXForm_1<opcode, xo, OL, asmstr>;
407
408 class XFXForm_7_ext<bits<6> opcode, bits<10> xo, bits<10> spr, 
409                     dag OL, string asmstr> 
410   : XFXForm_7<opcode, xo, OL, asmstr> {
411   let SPR = spr;
412 }
413
414 // 1.7.10 XS-Form
415 class XSForm_1<bits<6> opcode, bits<9> xo, dag OL, string asmstr>
416          : I<opcode, OL, asmstr> {
417   bits<5> RS;
418   bits<5> A;
419   bits<6> SH;
420
421   bit RC = 0;    // set by isDOT
422
423   let Inst{6-10}  = RS;
424   let Inst{11-15} = A;
425   let Inst{16-20} = SH{1-5};
426   let Inst{21-29} = xo;
427   let Inst{30}    = SH{0};
428   let Inst{31}    = RC;
429 }
430
431 // 1.7.11 XO-Form
432 class XOForm_1<bits<6> opcode, bits<9> xo, bit oe, dag OL, string asmstr,
433                list<dag> pattern>
434          : I<opcode, OL, asmstr> {
435   bits<5> RT;
436   bits<5> RA;
437   bits<5> RB;
438
439   let Pattern = pattern;
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_3<bits<6> opcode, bits<9> xo, bit oe, 
452                dag OL, string asmstr, list<dag> pattern>
453   : XOForm_1<opcode, xo, oe, OL, asmstr, pattern> {
454   let RB = 0;
455 }
456
457 // 1.7.12 A-Form
458 class AForm_1<bits<6> opcode, bits<5> xo, dag OL, string asmstr>
459          : I<opcode, OL, asmstr> {
460   bits<5> FRT;
461   bits<5> FRA;
462   bits<5> FRC;
463   bits<5> FRB;
464
465   bit RC = 0;    // set by isDOT
466
467   let Inst{6-10}  = FRT;
468   let Inst{11-15} = FRA;
469   let Inst{16-20} = FRB;
470   let Inst{21-25} = FRC;
471   let Inst{26-30} = xo;
472   let Inst{31}    = RC;
473 }
474
475 class AForm_2<bits<6> opcode, bits<5> xo, dag OL, string asmstr> 
476   : AForm_1<opcode, xo, OL, asmstr> {
477   let FRC = 0;
478 }
479
480 class AForm_3<bits<6> opcode, bits<5> xo, dag OL, string asmstr> 
481   : AForm_1<opcode, xo, OL, asmstr> {
482   let FRB = 0;
483 }
484
485 // 1.7.13 M-Form
486 class MForm_1<bits<6> opcode, dag OL, string asmstr> : I<opcode, OL, asmstr> {
487   bits<5> RA;
488   bits<5> RS;
489   bits<5> RB;
490   bits<5> MB;
491   bits<5> ME;
492
493   bit RC = 0;    // set by isDOT
494
495   let Inst{6-10}  = RS;
496   let Inst{11-15} = RA;
497   let Inst{16-20} = RB;
498   let Inst{21-25} = MB;
499   let Inst{26-30} = ME;
500   let Inst{31}    = RC;
501 }
502
503 class MForm_2<bits<6> opcode, dag OL, string asmstr>
504   : MForm_1<opcode, OL, asmstr> {
505 }
506
507 // 1.7.14 MD-Form
508 class MDForm_1<bits<6> opcode, bits<3> xo, dag OL, string asmstr>
509          : I<opcode, OL, asmstr> {
510   bits<5> RS;
511   bits<5> RA;
512   bits<6> SH;
513   bits<6> MBE;
514
515   bit RC = 0;    // set by isDOT
516
517   let Inst{6-10}  = RS;
518   let Inst{11-15} = RA;
519   let Inst{16-20} = SH{1-5};
520   let Inst{21-26} = MBE;
521   let Inst{27-29} = xo;
522   let Inst{30}    = SH{0};
523   let Inst{31}    = RC;
524 }
525
526 //===----------------------------------------------------------------------===//
527
528 class Pseudo<dag OL, string asmstr> : I<0, OL, asmstr> {
529   let PPC64 = 0;
530   let VMX = 0;
531
532   let Inst{31-0} = 0;
533 }