Fix encoding of fsel, fixing olden/power, McCat/bisort and several others.
[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 // This is the same as XForm_base_r3xo, but the first two operands are swapped
218 // when code is emitted.
219 class XForm_base_r3xo_swapped
220         <bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
221          dag OL, string asmstr> 
222   : I<opcode, ppc64, vmx, OL, asmstr> {
223   bits<5> A;
224   bits<5> RST;
225   bits<5> B;
226
227   let Inst{6-10}  = RST;
228   let Inst{11-15} = A;
229   let Inst{16-20} = B;
230   let Inst{21-30} = xo;
231   let Inst{31}    = rc;
232 }
233
234
235 class XForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
236               dag OL, string asmstr> 
237   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
238
239 class XForm_5<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
240               dag OL, string asmstr>
241   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
242   let A = 0;
243   let B = 0;
244 }
245
246 class XForm_6<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
247               dag OL, string asmstr> 
248   : XForm_base_r3xo_swapped<opcode, xo, rc, ppc64, vmx, OL, asmstr>;
249
250 class XForm_8<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
251               dag OL, string asmstr> 
252   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr>;
253
254 class XForm_10<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
255                dag OL, string asmstr> 
256   : XForm_base_r3xo_swapped<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
257 }
258
259 class XForm_11<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
260                dag OL, string asmstr> 
261   : XForm_base_r3xo_swapped<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
262   let B = 0;
263 }
264
265 class XForm_16<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
266                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
267   bits<3> BF;
268   bits<1> L; 
269   bits<5> RA;
270   bits<5> RB;
271   
272   let Inst{6-8}   = BF;
273   let Inst{9}     = 0;
274   let Inst{10}    = L;
275   let Inst{11-15} = RA;
276   let Inst{16-20} = RB;
277   let Inst{21-30} = xo;
278   let Inst{31}    = 0;
279 }
280
281 class XForm_16_ext<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
282                    dag OL, string asmstr>
283   : XForm_16<opcode, xo, ppc64, vmx, OL, asmstr> {
284   let L = ppc64;
285 }
286
287 class XForm_17<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
288                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
289   bits<3> BF;
290   bits<5> FRA;
291   bits<5> FRB;
292   
293   let Inst{6-8}   = BF;
294   let Inst{9-10}  = 0;
295   let Inst{11-15} = FRA;
296   let Inst{16-20} = FRB;
297   let Inst{21-30} = xo;
298   let Inst{31}    = 0;
299 }
300
301 class XForm_25<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 XForm_26<bits<6> opcode, bits<10> xo, bit rc, bit ppc64, bit vmx,
307                dag OL, string asmstr> 
308   : XForm_base_r3xo<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
309   let A = 0;
310 }
311
312 class XForm_28<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
313                dag OL, string asmstr> 
314   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
315 }
316
317 // 1.7.7 XL-Form
318 class XLForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
319                dag OL, string asmstr> 
320   : XForm_base_r3xo<opcode, xo, 0, ppc64, vmx, OL, asmstr> {
321 }
322
323 class XLForm_2<bits<6> opcode, bits<10> xo, bit lk, bit ppc64, bit vmx, 
324                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
325   bits<5> BO;
326   bits<5> BI;
327   bits<2> BH;
328   
329   let Inst{6-10}  = BO;
330   let Inst{11-15} = BI;
331   let Inst{16-18} = 0;
332   let Inst{19-20} = BH;
333   let Inst{21-30} = xo;
334   let Inst{31}    = lk;
335 }
336
337 class XLForm_2_ext<bits<6> opcode, bits<10> xo, bits<5> bo, 
338                    bits<5> bi, bit lk, bit ppc64, bit vmx, 
339                    dag OL, string asmstr>
340   : XLForm_2<opcode, xo, lk, ppc64, vmx, OL, asmstr> {
341   let BO = bo;
342   let BI = bi;
343   let BH = 0;
344 }
345
346 // 1.7.8 XFX-Form
347 class XFXForm_1<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx, 
348                 dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
349   bits<5>  ST;
350   bits<10> SPR;
351
352   let Inst{6-10}  = ST;
353   let Inst{11-20} = SPR;
354   let Inst{21-30} = xo;
355   let Inst{31}    = 0;
356 }
357
358 class XFXForm_1_ext<bits<6> opcode, bits<10> xo, bits<10> spr, bit ppc64, 
359                     bit vmx, dag OL, string asmstr> 
360   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr> {
361   let SPR = spr;
362 }
363
364 class XFXForm_7<bits<6> opcode, bits<10> xo, bit ppc64, bit vmx,
365                 dag OL, string asmstr>
366   : XFXForm_1<opcode, xo, ppc64, vmx, OL, asmstr>;
367
368 class XFXForm_7_ext<bits<6> opcode, bits<10> xo, bits<10> spr, 
369                     bit ppc64, bit vmx, dag OL, string asmstr> 
370   : XFXForm_7<opcode, xo, ppc64, vmx, OL, asmstr> {
371   let SPR = spr;
372 }
373
374 // 1.7.10 XS-Form
375 class XSForm_1<bits<6> opcode, bits<9> xo, bit rc, bit ppc64, bit vmx,
376                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
377   bits<5> RS;
378   bits<5> A;
379   bits<6> SH;
380
381   let Inst{6-10}  = RS;
382   let Inst{11-15} = A;
383   let Inst{16-20} = SH{1-5};
384   let Inst{21-29} = xo;
385   let Inst{30}    = SH{0};
386   let Inst{31}    = rc;
387 }
388
389 // 1.7.11 XO-Form
390 class XOForm_1<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
391                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
392   bits<5> RT;
393   bits<5> RA;
394   bits<5> RB;
395
396   let Inst{6-10}  = RT;
397   let Inst{11-15} = RA;
398   let Inst{16-20} = RB;
399   let Inst{21}    = oe;
400   let Inst{22-30} = xo;
401   let Inst{31}    = rc;  
402 }
403
404 class XOForm_1r<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 Inst{11-15} = RB;
408   let Inst{16-20} = RA;
409 }
410
411 class XOForm_3<bits<6> opcode, bits<9> xo, bit oe, bit rc, bit ppc64, bit vmx,
412                dag OL, string asmstr>
413   : XOForm_1<opcode, xo, oe, rc, ppc64, vmx, OL, asmstr> {
414   let RB = 0;
415 }
416
417 // 1.7.12 A-Form
418 class AForm_1<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, 
419               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
420   bits<5> FRT;
421   bits<5> FRA;
422   bits<5> FRC;
423   bits<5> FRB;
424
425   let Inst{6-10}  = FRT;
426   let Inst{11-15} = FRA;
427   let Inst{16-20} = FRB;
428   let Inst{21-25} = FRC;
429   let Inst{26-30} = xo;
430   let Inst{31}    = rc;
431 }
432
433 class AForm_2<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
434               string asmstr> 
435   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
436   let FRC = 0;
437 }
438
439 class AForm_3<bits<6> opcode, bits<5> xo, bit rc, bit ppc64, bit vmx, dag OL,
440               string asmstr> 
441   : AForm_1<opcode, xo, rc, ppc64, vmx, OL, asmstr> {
442   let FRB = 0;
443 }
444
445 // 1.7.13 M-Form
446 class MForm_1<bits<6> opcode, bit rc, bit ppc64, bit vmx,
447               dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
448   bits<5> RA;
449   bits<5> RS;
450   bits<5> RB;
451   bits<5> MB;
452   bits<5> ME;
453
454   let Inst{6-10}  = RS;
455   let Inst{11-15} = RA;
456   let Inst{16-20} = RB;
457   let Inst{21-25} = MB;
458   let Inst{26-30} = ME;
459   let Inst{31}    = rc;
460 }
461
462 class MForm_2<bits<6> opcode, bit rc, bit ppc64, bit vmx, 
463               dag OL, string asmstr>
464   : MForm_1<opcode, rc, ppc64, vmx, OL, asmstr> {
465 }
466
467 // 1.7.14 MD-Form
468 class MDForm_1<bits<6> opcode, bits<3> xo, bit rc, bit ppc64, bit vmx,
469                dag OL, string asmstr> : I<opcode, ppc64, vmx, OL, asmstr> {
470   bits<5> RS;
471   bits<5> RA;
472   bits<6> SH;
473   bits<6> MBE;
474
475   let Inst{6-10}  = RS;
476   let Inst{11-15} = RA;
477   let Inst{16-20} = SH{1-5};
478   let Inst{21-26} = MBE;
479   let Inst{27-29} = xo;
480   let Inst{30}    = SH{0};
481   let Inst{31}    = rc;
482 }
483
484 //===----------------------------------------------------------------------===//
485
486 class Pseudo<dag OL, string asmstr> : I<0, 0, 0, OL, asmstr> {
487   let PPC64 = 0;
488   let VMX = 0;
489
490   let Inst{31-0} = 0;
491 }