1. fix places where immed is used in place of imm to be consistent with
[oota-llvm.git] / lib / Target / Mips / Mips16InstrFormats.td
1 //===- Mips16InstrFormats.td - Mips Instruction Formats ----*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //===----------------------------------------------------------------------===//
11 //  Describe MIPS instructions format
12 //
13 //  CPU INSTRUCTION FORMATS
14 //
15 //  funct or f      Function field
16 //
17 //  immediate       4-,5-,8- or 11-bit immediate, branch displacemen, or
18 //  or imm          address displacement
19 //
20 //  op              5-bit major operation code  
21 //
22 //  rx              3-bit source or destination register
23 //
24 //  ry              3-bit source or destination register
25 //
26 //  rz              3-bit source or destination register
27 //
28 //  sa              3- or 5-bit shift amount
29 //
30 //===----------------------------------------------------------------------===//
31
32 // Format specifies the encoding used by the instruction.  This is part of the
33 // ad-hoc solution used to emit machine instruction encodings by our machine
34 // code emitter.
35 //
36 class Format16<bits<5> val> {
37   bits<5> Value = val;
38 }
39
40 def Pseudo16          : Format16<0>;
41 def FrmI16            : Format16<1>;
42 def FrmRI16           : Format16<2>;
43 def FrmRR16           : Format16<3>;
44 def FrmRRI16          : Format16<4>;
45 def FrmRRR16          : Format16<5>;
46 def FrmRRI_A16        : Format16<6>;
47 def FrmSHIFT16        : Format16<7>;
48 def FrmI8_TYPE16      : Format16<8>;
49 def FrmI8_MOVR3216    : Format16<9>;
50 def FrmI8_MOV32R16    : Format16<10>;
51 def FrmI8_SVRS16      : Format16<11>;
52 def FrmJAL16          : Format16<12>;
53 def FrmJALX16         : Format16<13>;
54 def FrmEXT_I16        : Format16<14>;
55 def FrmASMACRO16      : Format16<15>;
56 def FrmEXT_RI16       : Format16<16>;
57 def FrmEXT_RRI16      : Format16<17>;
58 def FrmEXT_RRI_A16    : Format16<18>;
59 def FrmEXT_SHIFT16    : Format16<19>;
60 def FrmEXT_I816       : Format16<20>;
61 def FrmEXT_I8_SVRS16  : Format16<21>;
62 def FrmOther16        : Format16<22>; // Instruction w/ a custom format
63
64 // Base class for Mips 16 Format
65 // This class does not depend on the instruction size
66 //
67 class MipsInst16_Base<dag outs, dag ins, string asmstr, list<dag> pattern,
68                  InstrItinClass itin, Format16 f>: Instruction
69 {
70   Format16 Form = f;
71
72   let Namespace = "Mips";
73
74
75   let OutOperandList = outs;
76   let InOperandList  = ins;
77
78   let AsmString   = asmstr;
79   let Pattern     = pattern;
80   let Itinerary   = itin;
81
82   //
83   // Attributes specific to Mips instructions...
84   //
85   bits<5> FormBits = Form.Value;
86
87   // TSFlags layout should be kept in sync with MipsInstrInfo.h.
88   let TSFlags{4-0}   = FormBits;
89
90   let Predicates = [InMips16Mode];
91 }
92
93 //
94 // Generic Mips 16 Format
95 //
96 class MipsInst16<dag outs, dag ins, string asmstr, list<dag> pattern,
97                  InstrItinClass itin, Format16 f>:
98         MipsInst16_Base<outs, ins, asmstr, pattern, itin, f>
99 {
100   field bits<16> Inst;
101   bits<5> Opcode = 0;
102
103   // Top 6 bits are the 'opcode' field
104   let Inst{15-11} = Opcode;
105 }
106
107 //
108 // For 32 bit extended instruction forms.
109 //
110 class MipsInst16_32<dag outs, dag ins, string asmstr, list<dag> pattern,
111                     InstrItinClass itin, Format16 f>:
112         MipsInst16_Base<outs, ins, asmstr, pattern, itin, f>
113 {
114   field bits<32> Inst;
115
116 }
117
118 class MipsInst16_EXTEND<dag outs, dag ins, string asmstr, list<dag> pattern,
119                         InstrItinClass itin, Format16 f>:
120         MipsInst16_32<outs, ins, asmstr, pattern, itin, f>
121 {
122
123   let Inst{31-27} = 0b11110;
124
125 }
126
127
128
129 // Mips Pseudo Instructions Format
130 class MipsPseudo16<dag outs, dag ins, string asmstr, list<dag> pattern>:
131                    MipsInst16<outs, ins, asmstr, pattern, IIPseudo, Pseudo16> {
132   let isCodeGenOnly = 1;
133   let isPseudo = 1;
134 }
135
136
137 //===----------------------------------------------------------------------===//
138 // Format I instruction class in Mips : <|opcode|imm11|>
139 //===----------------------------------------------------------------------===//
140
141 class FI16<bits<5> op, dag outs, dag ins, string asmstr, list<dag> pattern,
142            InstrItinClass itin>: MipsInst16<outs, ins, asmstr, pattern, 
143                                             itin, FrmI16>
144 {
145   bits<11> imm11;
146
147   let Opcode = op;
148
149   let Inst{10-0}  = imm11;
150 }
151
152 //===----------------------------------------------------------------------===//
153 // Format RI instruction class in Mips : <|opcode|rx|imm8|>
154 //===----------------------------------------------------------------------===//
155
156 class FRI16<bits<5> op, dag outs, dag ins, string asmstr,
157             list<dag> pattern, InstrItinClass itin>:
158             MipsInst16<outs, ins, asmstr, pattern, itin, FrmRI16>
159 {
160   bits<3>  rx;
161   bits<8>   imm8;
162
163   let Opcode = op;
164
165   let Inst{10-8} = rx;
166   let Inst{7-0} = imm8;
167 }
168
169 //===----------------------------------------------------------------------===//
170 // Format RR instruction class in Mips : <|opcode|rx|ry|funct|>
171 //===----------------------------------------------------------------------===//
172
173 class FRR16<bits<5> _funct, dag outs, dag ins, string asmstr,
174             list<dag> pattern, InstrItinClass itin>:
175             MipsInst16<outs, ins, asmstr, pattern, itin, FrmRR16>
176 {
177   bits<3>  rx;
178   bits<3>  ry;
179   bits<5>  funct;
180
181   let Opcode = 0b11101;
182   let funct  = _funct;
183
184   let Inst{10-8} = rx;
185   let Inst{7-5} = ry;
186   let Inst{4-0}   = funct;
187 }
188
189
190 //
191 // J(AL)R(C) subformat
192 //
193 class FRR16_JALRC<dag outs, dag ins, string asmstr,
194             list<dag> pattern, InstrItinClass itin>:
195             MipsInst16<outs, ins, asmstr, pattern, itin, FrmRR16>
196 {
197   bits<3>  rx;
198   bits<1>  nd;
199   bits<1>  l;
200   bits<1>  ra;
201
202   let Opcode = 0b11101;
203
204   let Inst{10-8} = rx;
205   let Inst{7} = nd;
206   let Inst{6} = l;
207   let Inst{5} = ra;
208   let Inst{4-0} = 0;
209 }
210
211 //===----------------------------------------------------------------------===//
212 // Format RRI instruction class in Mips : <|opcode|rx|ry|imm5|>
213 //===----------------------------------------------------------------------===//
214
215 class FRRI16<bits<5> op, dag outs, dag ins, string asmstr,
216              list<dag> pattern, InstrItinClass itin>:
217              MipsInst16<outs, ins, asmstr, pattern, itin, FrmRRI16>
218 {
219   bits<3>  rx;
220   bits<3>  ry;
221   bits<5>  imm5;
222
223   let Opcode = op;
224
225
226   let Inst{10-8} = rx;
227   let Inst{7-5} = ry;
228   let Inst{4-0}   = imm5;
229 }
230
231 //===----------------------------------------------------------------------===//
232 // Format RRR instruction class in Mips : <|opcode|rx|ry|rz|f|>
233 //===----------------------------------------------------------------------===//
234
235 class FRRR16<bits<5> op, bits<2> _f, dag outs, dag ins, string asmstr,
236              list<dag> pattern, InstrItinClass itin>:
237              MipsInst16<outs, ins, asmstr, pattern, itin, FrmRRR16>
238 {
239   bits<3>  rx;
240   bits<3>  ry;
241   bits<3>  rz;
242   bits<2>  f;
243
244   let Opcode = op;
245   let f  = _f;
246
247   let Inst{10-8} = rx;
248   let Inst{7-5} = ry;
249   let Inst{4-2} = rz;
250   let Inst{1-0}   = f;
251 }
252
253 //===----------------------------------------------------------------------===//
254 // Format RRI-A instruction class in Mips : <|opcode|rx|ry|f|imm4|>
255 //===----------------------------------------------------------------------===//
256
257 class FRRI_A16<bits<5> op, bits<1> _f, dag outs, dag ins, string asmstr,
258                list<dag> pattern, InstrItinClass itin>:
259                MipsInst16<outs, ins, asmstr, pattern, itin, FrmRRI_A16>
260 {
261   bits<3>  rx;
262   bits<3>  ry;
263   bits<1>  f;
264   bits<4>  imm4;
265
266   let Opcode = op;
267   let  f = _f;
268
269   let Inst{10-8} = rx;
270   let Inst{7-5} = ry;
271   let Inst{4} = f;
272   let Inst{3-0}   = imm4;
273 }
274
275 //===----------------------------------------------------------------------===//
276 // Format Shift instruction class in Mips : <|opcode|rx|ry|sa|f|>
277 //===----------------------------------------------------------------------===//
278
279 class FSHIFT16<bits<5> op, bits<2> _f, dag outs, dag ins, string asmstr,
280                list<dag> pattern, InstrItinClass itin>:
281                MipsInst16<outs, ins, asmstr, pattern, itin, FrmSHIFT16>
282 {
283   bits<3>  rx;
284   bits<3>  ry;
285   bits<3>  sa;
286   bits<2>  f;
287
288   let Opcode = op;
289   let f  = _f;
290
291   let Inst{10-8} = rx;
292   let Inst{7-5} = ry;
293   let Inst{4-2} = sa;
294   let Inst{1-0}   = f;
295 }
296
297 //===----------------------------------------------------------------------===//
298 // Format i8 instruction class in Mips : <|opcode|funct|imm8>
299 //===----------------------------------------------------------------------===//
300
301 class FI816<bits<5> op, bits<3> _func, dag outs, dag ins, string asmstr,
302             list<dag> pattern, InstrItinClass itin>:
303             MipsInst16<outs, ins, asmstr, pattern, itin, FrmI8_TYPE16>
304 {
305   bits<3>  func;
306   bits<8>   imm8;
307   
308   let Opcode = op;
309   let func  = _func;
310
311   let Inst{10-8} = func;
312   let Inst{7-0} = imm8;
313 }
314
315 //===----------------------------------------------------------------------===//
316 // Format i8_MOVR32 instruction class in Mips : <|opcode|func|ry|r32>
317 //===----------------------------------------------------------------------===//
318
319 class FI8_MOVR3216<bits<5> op, bits<3> _func, dag outs, dag ins, string asmstr,
320                    list<dag> pattern, InstrItinClass itin>:
321                    MipsInst16<outs, ins, asmstr, pattern, itin, FrmI8_MOVR3216>
322 {
323
324   bits<3>  func;
325   bits<4> ry;
326   bits<4> r32;
327   
328   let Opcode = op;
329   let func  = _func;
330
331   let Inst{10-8} = func;
332   let Inst{7-4} = ry;
333   let Inst{3-0} = r32;
334   
335 }
336
337
338
339 //===----------------------------------------------------------------------===//
340 // Format i8_MOV32R instruction class in Mips : <|opcode|func|ry|r32>
341 //===----------------------------------------------------------------------===//
342
343 class FI8_MOV32R16<bits<5> op, bits<3> _func, dag outs, dag ins, string asmstr,
344                    list<dag> pattern, InstrItinClass itin>:
345                    MipsInst16<outs, ins, asmstr, pattern, itin, FrmI8_MOV32R16>
346 {
347
348   bits<3>  func;
349   bits<5> r32;
350   bits<3> rz;
351
352   
353   let Opcode = op;
354   let func  = _func;
355
356   let Inst{10-8} = func;
357   let Inst{7-5} = r32{2-0}; 
358   let Inst{4-3} = r32{4-3};
359   let Inst{2-0} = rz;
360   
361 }
362
363 //===----------------------------------------------------------------------===//
364 // Format i8_SVRS instruction class in Mips : 
365 //    <|opcode|svrs|s|ra|s0|s1|framesize>
366 //===----------------------------------------------------------------------===//
367
368 class FI8_SVRS16<bits<5> op, bits<3> _SVRS, dag outs, dag ins, string asmstr,
369                  list<dag> pattern, InstrItinClass itin>:
370                  MipsInst16<outs, ins, asmstr, pattern, itin, FrmI8_SVRS16>
371 {
372   bits<3>  SVRS;
373   bits<1> s;
374   bits<1> ra;
375   bits<1> s0;
376   bits<1> s1;
377   bits<4> framesize;
378   
379   let Opcode = op;
380   let SVRS = _SVRS;
381
382   let Inst{10-8} = SVRS;
383   let Inst{7} = s;
384   let Inst{6} = ra;
385   let Inst{5} = s0;
386   let Inst{4} = s1;
387   let Inst{3-0} = framesize;
388     
389 }
390
391 //===----------------------------------------------------------------------===//
392 // Format JAL instruction class in Mips16 : 
393 //    <|opcode|svrs|s|ra|s0|s1|framesize>
394 //===----------------------------------------------------------------------===//
395
396 class FJAL16<bits<5> op, bits<1> _X, dag outs, dag ins, string asmstr,
397              list<dag> pattern, InstrItinClass itin>:
398              MipsInst16_32<outs, ins, asmstr, pattern, itin, FrmJAL16>
399 {
400   bits<1> X;
401   bits<26> imm26;
402
403   
404   let X = _X;
405
406   let Inst{31-27} = 0b00011;
407   let Inst{26} = X;
408   let Inst{25-21} = imm26{20-16};
409   let Inst{20-16} = imm26{25-21};
410   let Inst{15-0}  = imm26{15-0};
411     
412 }
413
414
415 //===----------------------------------------------------------------------===//
416 // Format EXT-I instruction class in Mips16 : 
417 //     <|EXTEND|imm10:5|imm15:11|op|0|0|0|0|0|0|imm4:0>
418 //===----------------------------------------------------------------------===//
419
420 class FEXT_I16<bits<5> _eop, dag outs, dag ins, string asmstr,
421                list<dag> pattern, InstrItinClass itin>:
422                MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, FrmEXT_I16>
423 {
424   bits<16> imm16;
425   bits<5> eop;
426   
427   let eop = _eop;
428
429   let Inst{26-21} = imm16{10-5};
430   let Inst{20-16} = imm16{15-11};
431   let Inst{15-11} = eop;
432   let Inst{10-5} = 0;
433   let Inst{4-0} = imm16{4-0};
434     
435 }
436
437
438
439
440
441
442 //===----------------------------------------------------------------------===//
443 // Format ASMACRO instruction class in Mips16 : 
444 //    <EXTEND|select|p4|p3|RRR|p2|p1|p0>
445 //===----------------------------------------------------------------------===//
446
447 class FASMACRO16<bits<5> op, dag outs, dag ins, string asmstr,
448                  list<dag> pattern, InstrItinClass itin>:
449                  MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, 
450                                    FrmASMACRO16>
451 {
452   bits<3> select;
453   bits<3> p4;
454   bits<5> p3;
455   bits<5> RRR;
456   bits<3> p2;
457   bits<3> p1;
458   bits<5> p0;
459   
460
461   let Inst{26-24} = select;
462   let Inst{23-21} = p4;
463   let Inst{20-16} = p3;
464   let Inst{15-11} = RRR;
465   let Inst{10-8} = p2;
466   let Inst{7-5} = p1;
467   let Inst{4-0} = p0; 
468     
469 }
470
471
472 //===----------------------------------------------------------------------===//
473 // Format EXT-RI instruction class in Mips16 : 
474 //    <|EXTEND|imm10:5|imm15:11|op|rx|0|0|0|imm4:0>
475 //===----------------------------------------------------------------------===//
476
477 class FEXT_RI16<bits<5> _op, dag outs, dag ins, string asmstr,
478                 list<dag> pattern, InstrItinClass itin>:
479                 MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, 
480                                   FrmEXT_RI16>
481 {
482   bits<16> imm16;
483   bits<5> op;
484   bits<3> rx;
485   
486   let op = _op;
487
488   let Inst{26-21} = imm16{10-5};
489   let Inst{20-16} = imm16{15-11};
490   let Inst{15-11} = op;
491   let Inst{10-8} = rx;
492   let Inst{7-5} = 0;
493   let Inst{4-0} = imm16{4-0};
494     
495 }
496
497 //===----------------------------------------------------------------------===//
498 // Format EXT-RRI instruction class in Mips16 :
499 //     <|EXTEND|imm10:5|imm15:11|op|rx|ry|imm4:0>
500 //===----------------------------------------------------------------------===//
501
502 class FEXT_RRI16<bits<5> _op, dag outs, dag ins, string asmstr,
503                  list<dag> pattern, InstrItinClass itin>:
504                  MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, 
505                                    FrmEXT_RRI16>
506 {
507   bits<16> imm16;
508   bits<3> rx;
509   bits<3> ry;
510
511
512   let Inst{26-21} = imm16{10-5};
513   let Inst{20-16} = imm16{15-11};
514   let Inst{15-11} = _op;
515   let Inst{10-8} = rx;
516   let Inst{7-5} = ry;
517   let Inst{4-0} = imm16{4-0};
518     
519 }
520
521 //===----------------------------------------------------------------------===//
522 // Format EXT-RRI-A instruction class in Mips16 : 
523 //    <|EXTEND|imm10:4|imm14:11|RRI-A|rx|ry|f|imm3:0>
524 //===----------------------------------------------------------------------===//
525
526 class FEXT_RRI_A16<bits<1> _f, dag outs, dag ins, string asmstr,
527                    list<dag> pattern, InstrItinClass itin>:
528                    MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, 
529                                      FrmEXT_RRI_A16>
530 {
531   bits<15> imm15;
532   bits<3> rx;
533   bits<3> ry;
534   bits<1> f;
535   
536   let f = _f;
537
538   let Inst{26-20} = imm15{10-4};
539   let Inst{19-16} = imm15{14-11};
540   let Inst{15-11} = 0b01000;
541   let Inst{10-8} = rx;
542   let Inst{7-5} = ry;
543   let Inst{4} = f;
544   let Inst{3-0} = imm15{3-0};
545     
546 }
547
548 //===----------------------------------------------------------------------===//
549 // Format EXT-SHIFT instruction class in Mips16 : 
550 //    <|EXTEND|sa 4:0|s5|0|SHIFT|rx|ry|0|f>
551 //===----------------------------------------------------------------------===//
552
553 class FEXT_SHIFT16<bits<5> op, bits<2> _f, dag outs, dag ins, string asmstr,
554                    list<dag> pattern, InstrItinClass itin>:
555                    MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, 
556                                      FrmEXT_SHIFT16>
557 {
558   bits<6> sa6;
559   bits<3> rx;
560   bits<3> ry;
561   bits<2> f;
562   
563   let f = _f;
564
565   let Inst{26-22} = sa6{4-0};
566   let Inst{21} = sa6{5};
567   let Inst{20-16} = 0;
568   let Inst{15-11} = 0b00110;
569   let Inst{10-8} = rx;
570   let Inst{7-5} = ry;
571   let Inst{4-2} = 0;
572   let Inst{1-0} = f; 
573     
574 }
575
576 //===----------------------------------------------------------------------===//
577 // Format EXT-I8 instruction class in Mips16 : 
578 //    <|EXTEND|imm10:5|imm15:11|I8|funct|0|imm4:0>
579 //===----------------------------------------------------------------------===//
580
581 class FEXT_I816<bits<3> _funct, dag outs, dag ins, string asmstr,
582                 list<dag> pattern, InstrItinClass itin>:
583                 MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, 
584                                   FrmEXT_I816>
585 {
586   bits<16> imm16;
587   bits<5> I8;
588   bits<3> funct;
589   
590   let funct = _funct;
591
592   let Inst{26-21} = imm16{10-5};
593   let Inst{20-16} = imm16{15-11};
594   let Inst{15-11} = I8;
595   let Inst{10-8} = funct;
596   let Inst{7-5} = 0;
597   let Inst{4-0} = imm16{4-0};
598     
599 }
600
601 //===----------------------------------------------------------------------===//
602 // Format EXT-I8_SVRS instruction class in Mips16 : 
603 //    <|EXTEND|xsregs|framesize7:4|aregs|I8|SVRS|s|ra|s0|s1|framesize3:0>
604 //===----------------------------------------------------------------------===//
605
606 class FEXT_I8_SVRS16<dag outs, dag ins, string asmstr,
607                      list<dag> pattern, InstrItinClass itin>:
608                      MipsInst16_EXTEND<outs, ins, asmstr, pattern, itin, 
609                                        FrmI8_SVRS16>
610 {
611   bits<3> xsregs;
612   bits<8> framesize;
613   bits<3> aregs;
614   bits<5> I8;
615   bits<3> SVRS;
616   bits<1> s;
617   bits<1> ra;
618   bits<1> s0;
619   bits<1> s1;
620   
621
622   let Inst{26-24} = xsregs;
623   let Inst{23-20} = framesize{7-4};
624   let Inst{19} = 0;
625   let Inst{18-16} = aregs;
626   let Inst{15-11} = I8;
627   let Inst{10-8} = SVRS;
628   let Inst{7} = s;
629   let Inst{6} = ra;
630   let Inst{5} = s0;
631   let Inst{4} = s1;
632   let Inst{3-0} = framesize{3-0};
633   
634     
635 }
636
637
638