c5ad77a958fa9127462738441d85c201a0948644
[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<5>  BI;
74   bits<14> BD;
75
76   let Inst{6-10}  = BO;
77   let Inst{11-15} = BI;
78   let Inst{16-29} = BD;
79   let Inst{30}    = aa;
80   let Inst{31}    = lk;
81 }
82
83 class BForm_ext<bits<6> opcode, bit aa, bit lk, bits<5> bo, bits<5> bi, 
84                 bit ppc64, bit vmx, dag OL, string asmstr>
85   : BForm<opcode, aa, lk, ppc64, vmx, OL, asmstr> {
86   let BO = bo;
87   let BI = bi;
88 }
89
90 // 1.7.4 D-Form
91 class DForm_base<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
92   : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx, dag OL, string asmstr>
103   : I<opcode, ppc64, vmx, OL, asmstr> {
104   bits<5>  A;
105   bits<16> C;
106   bits<5>  B;
107   
108   let Inst{6-10}  = A;
109   let Inst{11-15} = B;
110   let Inst{16-31} = C;
111 }
112
113 class DForm_2<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
114   : DForm_base<opcode, ppc64, vmx, OL, asmstr>;
115
116 class DForm_2_r0<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
117   : I<opcode, ppc64, vmx, OL, asmstr> {
118   bits<5>  A;
119   bits<16> B;
120   
121   let Inst{6-10}  = A;
122   let Inst{11-15} = 0;
123   let Inst{16-31} = B;
124 }
125
126 // Currently we make the use/def reg distinction in ISel, not tablegen
127 class DForm_3<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
128   : DForm_1<opcode, ppc64, vmx, OL, asmstr>;
129
130 class DForm_4<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr> 
131   : DForm_base<opcode, ppc64, vmx, OL, asmstr>;
132               
133 class DForm_4_zero<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
134   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
135   let A = 0;
136   let B = 0;
137   let C = 0;
138 }
139
140 class DForm_5<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
141   : I<opcode, ppc64, vmx, OL, asmstr> {
142   bits<3>  BF;
143   bits<1>  L;
144   bits<5>  RA;
145   bits<16> I;
146
147   let Inst{6-8}   = BF;
148   let Inst{9}     = 0;
149   let Inst{10}    = L;
150   let Inst{11-15} = RA;
151   let Inst{16-31} = I;
152 }
153
154 class DForm_5_ext<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
155   : DForm_5<opcode, ppc64, vmx, OL, asmstr> {
156   let L = ppc64;
157 }
158
159 class DForm_6<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr> 
160   : DForm_5<opcode, ppc64, vmx, OL, asmstr>;
161
162 class DForm_6_ext<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
163   : DForm_6<opcode, ppc64, vmx, OL, asmstr> {
164   let L = ppc64;
165 }
166
167 class DForm_8<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
168   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
169 }
170
171 class DForm_9<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
172   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
173 }
174
175 // 1.7.5 DS-Form
176 class DSForm_1<bits<6> opcode, bits<2> xo, bit ppc64, bit vmx,
177                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
178   bits<5>  RST;
179   bits<14> DS;
180   bits<5>  RA;
181
182   let Inst{6-10}  = RST;
183   let Inst{11-15} = RA;
184   let Inst{16-29} = DS;
185   let Inst{30-31} = xo;
186 }
187
188 class DSForm_2<bits<6> opcode, bits<2> xo, bit ppc64, bit vmx, 
189                dag OL, string asmstr>
190   : DSForm_1<opcode, xo, ppc64, vmx, OL, asmstr>;
191
192 // 1.7.6 X-Form
193 class XForm_base_r3xo<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
194                       dag OL, string asmstr> 
195   : I<opcode, ppc64, vmx, OL, asmstr> {
196   bits<5> RST;
197   bits<5> A;
198   bits<5> B;
199
200   let Inst{6-10}  = RST;
201   let Inst{11-15} = A;
202   let Inst{16-20} = B;
203   let Inst{21-30} = xo;
204   let Inst{31}    = rc;
205 }
206
207
208 class XForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
209               dag OL, string asmstr> 
210   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
211
212 class XForm_5<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
213               dag OL, string asmstr>
214   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
215   let A = 0;
216   let B = 0;
217 }
218
219 class XForm_6<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
220               dag OL, string asmstr> 
221   : I<opcode, ppc64, vmx, OL, asmstr> {
222   bits<5> A;
223   bits<5> RST;
224   bits<5> B;
225
226   let Inst{6-10}  = RST;
227   let Inst{11-15} = A;
228   let Inst{16-20} = B;
229   let Inst{21-30} = xo;
230   let Inst{31}    = rc;
231 }
232
233 class XForm_8<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
234               dag OL, string asmstr> 
235   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
236
237 class XForm_10<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
238                dag OL, string asmstr> 
239   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
240 }
241
242 class XForm_11<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
243                dag OL, string asmstr> 
244   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
245   let B = 0;
246 }
247
248 class XForm_16<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
249                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
250   bits<3> BF;
251   bits<1> L; 
252   bits<5> RA;
253   bits<5> RB;
254   
255   let Inst{6-8}   = BF;
256   let Inst{9}     = 0;
257   let Inst{10}    = L;
258   let Inst{11-15} = RA;
259   let Inst{16-20} = RB;
260   let Inst{21-30} = xo;
261   let Inst{31}    = 0;
262 }
263
264 class XForm_16_ext<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
265                    dag OL, string asmstr>
266   : XForm_16<opcode, xo, ppc64, vmx, OL, asmstr> {
267   let L = ppc64;
268 }
269
270 class XForm_17<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
271                dag OL, string asmstr> : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx,
285                dag OL, string asmstr> 
286   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
287 }
288
289 class XForm_26<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
290                dag OL, string asmstr> 
291   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
292   let A = 0;
293 }
294
295 class XForm_28<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
296                dag OL, string asmstr> 
297   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
298 }
299
300 // 1.7.7 XL-Form
301 class XLForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
302                dag OL, string asmstr> 
303   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
304 }
305
306 class XLForm_2<bits<6> opcode, bits<10> xo, bit lk, bit ppc64, bit vmx, 
307                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
308   bits<5> BO;
309   bits<5> BI;
310   bits<2> BH;
311   
312   let Inst{6-10}  = BO;
313   let Inst{11-15} = BI;
314   let Inst{16-18} = 0;
315   let Inst{19-20} = BH;
316   let Inst{21-30} = xo;
317   let Inst{31}    = lk;
318 }
319
320 class XLForm_2_ext<bits<6> opcode, bits<10> xo, bits<5> bo, 
321                    bits<5> bi, bit lk, bit ppc64, bit vmx, 
322                    dag OL, string asmstr>
323   : XLForm_2<opcode, xo, lk, ppc64, vmx, OL, asmstr> {
324   let BO = bo;
325   let BI = bi;
326   let BH = 0;
327 }
328
329 // 1.7.8 XFX-Form
330 class XFXForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx, 
331                 dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
332   bits<5>  ST;
333   bits<10> SPR;
334
335   let Inst{6-10}  = ST;
336   let Inst{11-20} = SPR;
337   let Inst{21-30} = xo;
338   let Inst{31}    = 0;
339 }
340
341 class XFXForm_1_ext<bits<6> opcode, bits<10> xo, bits<10> spr, bit ppc64, 
342                     bit vmx, dag OL, string asmstr> 
343   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr> {
344   let SPR = spr;
345 }
346
347 class XFXForm_7<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
348                 dag OL, string asmstr>
349   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr>;
350
351 class XFXForm_7_ext<bits<6> opcode, bits<10> xo, bits<10> spr, 
352                     bit ppc64, bit vmx, dag OL, string asmstr> 
353   : XFXForm_7<opcode, xo, ppc64, vmx, OL, asmstr> {
354   let SPR = spr;
355 }
356
357 // 1.7.10 XS-Form
358 class XSForm_1<bits<6> opcode, bits<9> xo, bit rc, bit ppc64, bit vmx,
359                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
360   bits<5> RS;
361   bits<5> A;
362   bits<6> SH;
363
364   let Inst{6-10}  = RS;
365   let Inst{11-15} = A;
366   let Inst{16-20} = SH{1-5};
367   let Inst{21-29} = xo;
368   let Inst{30}    = SH{0};
369   let Inst{31}    = rc;
370 }
371
372 // 1.7.11 XO-Form
373 class XOForm_1<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
374                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
375   bits<5> RT;
376   bits<5> RA;
377   bits<5> RB;
378
379   let Inst{6-10}  = RT;
380   let Inst{11-15} = RA;
381   let Inst{16-20} = RB;
382   let Inst{21}    = oe;
383   let Inst{22-30} = xo;
384   let Inst{31}    = rc;  
385 }
386
387 class XOForm_1r<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
388                dag OL, string asmstr>
389   : XOForm_1<opcode, xo, oe, rc, ppc64, vmx, OL, asmstr> {
390   let Inst{11-15} = RB;
391   let Inst{16-20} = RA;
392 }
393
394 class XOForm_3<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
395                dag OL, string asmstr>
396   : XOForm_1<opcode, xo, oe, rc, ppc64, vmx, OL, asmstr> {
397   let RB = 0;
398 }
399
400 // 1.7.12 A-Form
401 class AForm_1<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, 
402               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
403   bits<5> FRT;
404   bits<5> FRA;
405   bits<5> FRB;
406   bits<5> FRC;
407
408   let Inst{6-10}  = FRT;
409   let Inst{11-15} = FRA;
410   let Inst{16-20} = FRB;
411   let Inst{21-25} = FRC;
412   let Inst{26-30} = xo;
413   let Inst{31}    = rc;
414 }
415
416 class AForm_2<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
417               string asmstr> 
418   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
419   let FRC = 0;
420 }
421
422 class AForm_3<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
423               string asmstr> 
424   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
425   let FRB = 0;
426 }
427
428 // 1.7.13 M-Form
429 class MForm_1<bits<6> opcode, bit rc, bit ppc64, bit vmx,
430               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
431   bits<5> RA;
432   bits<5> RS;
433   bits<5> RB;
434   bits<5> MB;
435   bits<5> ME;
436
437   let Inst{6-10}  = RS;
438   let Inst{11-15} = RA;
439   let Inst{16-20} = RB;
440   let Inst{21-25} = MB;
441   let Inst{26-30} = ME;
442   let Inst{31}    = rc;
443 }
444
445 class MForm_2<bits<6> opcode, bit rc, bit ppc64, bit vmx, 
446               dag OL, string asmstr>
447   : MForm_1<opcode, rc, ppc64, vmx, OL, asmstr> {
448 }
449
450 // 1.7.14 MD-Form
451 class MDForm_1<bits<6> opcode, bits<3> xo, bit rc, bit ppc64, bit vmx,
452                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
453   bits<5> RS;
454   bits<5> RA;
455   bits<6> SH;
456   bits<6> MBE;
457
458   let Inst{6-10}  = RS;
459   let Inst{11-15} = RA;
460   let Inst{16-20} = SH{1-5};
461   let Inst{21-26} = MBE;
462   let Inst{27-29} = xo;
463   let Inst{30}    = SH{0};
464   let Inst{31}    = rc;
465 }
466
467 //===----------------------------------------------------------------------===//
468
469 class Pseudo<dag OL, string asmstr> : I<0, 0, 0, OL, asmstr> {
470   let PPC64 = 0;
471   let VMX = 0;
472
473   let Inst{31-0} = 0;
474 }