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