Fix the encoding of ORi and other DForm4 instructions. This brings us to
[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, bit ppc64, bit vmx, dag OL, string asmstr>
94   : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx, dag OL, string asmstr>
105   : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx, dag OL, string asmstr>
116   : DForm_base<opcode, ppc64, vmx, OL, asmstr>;
117
118 class DForm_2_r0<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
119   : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx, dag OL, string asmstr>
130   : DForm_1<opcode, ppc64, vmx, OL, asmstr>;
131
132 class DForm_4<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr> 
133   : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx, dag OL, string asmstr>
144   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
145   let A = 0;
146   let B = 0;
147   let C = 0;
148 }
149
150 class DForm_5<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
151   : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx, dag OL, string asmstr>
165   : DForm_5<opcode, ppc64, vmx, OL, asmstr> {
166   let L = ppc64;
167 }
168
169 class DForm_6<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr> 
170   : DForm_5<opcode, ppc64, vmx, OL, asmstr>;
171
172 class DForm_6_ext<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
173   : DForm_6<opcode, ppc64, vmx, OL, asmstr> {
174   let L = ppc64;
175 }
176
177 class DForm_8<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
178   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
179 }
180
181 class DForm_9<bits<6> opcode, bit ppc64, bit vmx, dag OL, string asmstr>
182   : DForm_1<opcode, ppc64, vmx, OL, asmstr> {
183 }
184
185 // 1.7.5 DS-Form
186 class DSForm_1<bits<6> opcode, bits<2> xo, bit ppc64, bit vmx,
187                dag OL, string asmstr> : I<opcode, ppc64, vmx, 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, bit ppc64, bit vmx, 
199                dag OL, string asmstr>
200   : DSForm_1<opcode, xo, ppc64, vmx, OL, asmstr>;
201
202 // 1.7.6 X-Form
203 class XForm_base_r3xo<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
204                       dag OL, string asmstr> 
205   : I<opcode, ppc64, vmx, OL, asmstr> {
206   bits<5> RST;
207   bits<5> A;
208   bits<5> B;
209
210   let Inst{6-10}  = RST;
211   let Inst{11-15} = A;
212   let Inst{16-20} = B;
213   let Inst{21-30} = xo;
214   let Inst{31}    = rc;
215 }
216
217
218 class XForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
219               dag OL, string asmstr> 
220   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
221
222 class XForm_5<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
223               dag OL, string asmstr>
224   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
225   let A = 0;
226   let B = 0;
227 }
228
229 class XForm_6<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
230               dag OL, string asmstr> 
231   : I<opcode, ppc64, vmx, OL, asmstr> {
232   bits<5> A;
233   bits<5> RST;
234   bits<5> B;
235
236   let Inst{6-10}  = RST;
237   let Inst{11-15} = A;
238   let Inst{16-20} = B;
239   let Inst{21-30} = xo;
240   let Inst{31}    = rc;
241 }
242
243 class XForm_8<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
244               dag OL, string asmstr> 
245   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
246
247 class XForm_10<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
248                dag OL, string asmstr> 
249   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
250 }
251
252 class XForm_11<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
253                dag OL, string asmstr> 
254   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
255   let B = 0;
256 }
257
258 class XForm_16<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
259                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
260   bits<3> BF;
261   bits<1> L; 
262   bits<5> RA;
263   bits<5> RB;
264   
265   let Inst{6-8}   = BF;
266   let Inst{9}     = 0;
267   let Inst{10}    = L;
268   let Inst{11-15} = RA;
269   let Inst{16-20} = RB;
270   let Inst{21-30} = xo;
271   let Inst{31}    = 0;
272 }
273
274 class XForm_16_ext<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
275                    dag OL, string asmstr>
276   : XForm_16<opcode, xo, ppc64, vmx, OL, asmstr> {
277   let L = ppc64;
278 }
279
280 class XForm_17<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
281                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
282   bits<3> BF;
283   bits<5> FRA;
284   bits<5> FRB;
285   
286   let Inst{6-8}   = BF;
287   let Inst{9-10}  = 0;
288   let Inst{11-15} = FRA;
289   let Inst{16-20} = FRB;
290   let Inst{21-30} = xo;
291   let Inst{31}    = 0;
292 }
293
294 class XForm_25<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
295                dag OL, string asmstr> 
296   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
297 }
298
299 class XForm_26<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
300                dag OL, string asmstr> 
301   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
302   let A = 0;
303 }
304
305 class XForm_28<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
306                dag OL, string asmstr> 
307   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
308 }
309
310 // 1.7.7 XL-Form
311 class XLForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
312                dag OL, string asmstr> 
313   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
314 }
315
316 class XLForm_2<bits<6> opcode, bits<10> xo, bit lk, bit ppc64, bit vmx, 
317                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
318   bits<5> BO;
319   bits<5> BI;
320   bits<2> BH;
321   
322   let Inst{6-10}  = BO;
323   let Inst{11-15} = BI;
324   let Inst{16-18} = 0;
325   let Inst{19-20} = BH;
326   let Inst{21-30} = xo;
327   let Inst{31}    = lk;
328 }
329
330 class XLForm_2_ext<bits<6> opcode, bits<10> xo, bits<5> bo, 
331                    bits<5> bi, bit lk, bit ppc64, bit vmx, 
332                    dag OL, string asmstr>
333   : XLForm_2<opcode, xo, lk, ppc64, vmx, OL, asmstr> {
334   let BO = bo;
335   let BI = bi;
336   let BH = 0;
337 }
338
339 // 1.7.8 XFX-Form
340 class XFXForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx, 
341                 dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
342   bits<5>  ST;
343   bits<10> SPR;
344
345   let Inst{6-10}  = ST;
346   let Inst{11-20} = SPR;
347   let Inst{21-30} = xo;
348   let Inst{31}    = 0;
349 }
350
351 class XFXForm_1_ext<bits<6> opcode, bits<10> xo, bits<10> spr, bit ppc64, 
352                     bit vmx, dag OL, string asmstr> 
353   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr> {
354   let SPR = spr;
355 }
356
357 class XFXForm_7<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
358                 dag OL, string asmstr>
359   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr>;
360
361 class XFXForm_7_ext<bits<6> opcode, bits<10> xo, bits<10> spr, 
362                     bit ppc64, bit vmx, dag OL, string asmstr> 
363   : XFXForm_7<opcode, xo, ppc64, vmx, OL, asmstr> {
364   let SPR = spr;
365 }
366
367 // 1.7.10 XS-Form
368 class XSForm_1<bits<6> opcode, bits<9> xo, bit rc, bit ppc64, bit vmx,
369                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
370   bits<5> RS;
371   bits<5> A;
372   bits<6> SH;
373
374   let Inst{6-10}  = RS;
375   let Inst{11-15} = A;
376   let Inst{16-20} = SH{1-5};
377   let Inst{21-29} = xo;
378   let Inst{30}    = SH{0};
379   let Inst{31}    = rc;
380 }
381
382 // 1.7.11 XO-Form
383 class XOForm_1<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
384                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
385   bits<5> RT;
386   bits<5> RA;
387   bits<5> RB;
388
389   let Inst{6-10}  = RT;
390   let Inst{11-15} = RA;
391   let Inst{16-20} = RB;
392   let Inst{21}    = oe;
393   let Inst{22-30} = xo;
394   let Inst{31}    = rc;  
395 }
396
397 class XOForm_1r<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
398                dag OL, string asmstr>
399   : XOForm_1<opcode, xo, oe, rc, ppc64, vmx, OL, asmstr> {
400   let Inst{11-15} = RB;
401   let Inst{16-20} = RA;
402 }
403
404 class XOForm_3<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
405                dag OL, string asmstr>
406   : XOForm_1<opcode, xo, oe, rc, ppc64, vmx, OL, asmstr> {
407   let RB = 0;
408 }
409
410 // 1.7.12 A-Form
411 class AForm_1<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, 
412               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
413   bits<5> FRT;
414   bits<5> FRA;
415   bits<5> FRB;
416   bits<5> FRC;
417
418   let Inst{6-10}  = FRT;
419   let Inst{11-15} = FRA;
420   let Inst{16-20} = FRB;
421   let Inst{21-25} = FRC;
422   let Inst{26-30} = xo;
423   let Inst{31}    = rc;
424 }
425
426 class AForm_2<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
427               string asmstr> 
428   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
429   let FRC = 0;
430 }
431
432 class AForm_3<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
433               string asmstr> 
434   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
435   let FRB = 0;
436 }
437
438 // 1.7.13 M-Form
439 class MForm_1<bits<6> opcode, bit rc, bit ppc64, bit vmx,
440               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
441   bits<5> RA;
442   bits<5> RS;
443   bits<5> RB;
444   bits<5> MB;
445   bits<5> ME;
446
447   let Inst{6-10}  = RS;
448   let Inst{11-15} = RA;
449   let Inst{16-20} = RB;
450   let Inst{21-25} = MB;
451   let Inst{26-30} = ME;
452   let Inst{31}    = rc;
453 }
454
455 class MForm_2<bits<6> opcode, bit rc, bit ppc64, bit vmx, 
456               dag OL, string asmstr>
457   : MForm_1<opcode, rc, ppc64, vmx, OL, asmstr> {
458 }
459
460 // 1.7.14 MD-Form
461 class MDForm_1<bits<6> opcode, bits<3> xo, bit rc, bit ppc64, bit vmx,
462                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
463   bits<5> RS;
464   bits<5> RA;
465   bits<6> SH;
466   bits<6> MBE;
467
468   let Inst{6-10}  = RS;
469   let Inst{11-15} = RA;
470   let Inst{16-20} = SH{1-5};
471   let Inst{21-26} = MBE;
472   let Inst{27-29} = xo;
473   let Inst{30}    = SH{0};
474   let Inst{31}    = rc;
475 }
476
477 //===----------------------------------------------------------------------===//
478
479 class Pseudo<dag OL, string asmstr> : I<0, 0, 0, OL, asmstr> {
480   let PPC64 = 0;
481   let VMX = 0;
482
483   let Inst{31-0} = 0;
484 }