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