1//===----------------------------------------------------------------------===//
2// MicroMIPS Base Classes
3//===----------------------------------------------------------------------===//
4
5//
6// Base class for MicroMips instructions.
7// This class does not depend on the instruction size.
8//
9class MicroMipsInstBase<dag outs, dag ins, string asmstr, list<dag> pattern,
10                        InstrItinClass itin, Format f> : Instruction
11{
12  let Namespace = "Mips";
13  let DecoderNamespace = "MicroMips";
14
15  let OutOperandList = outs;
16  let InOperandList  = ins;
17
18  let AsmString   = asmstr;
19  let Pattern     = pattern;
20  let Itinerary   = itin;
21
22  let Predicates = [InMicroMips];
23
24  Format Form = f;
25}
26
27//
28// Base class for MicroMIPS 16-bit instructions.
29//
30class MicroMipsInst16<dag outs, dag ins, string asmstr, list<dag> pattern,
31               InstrItinClass itin, Format f> :
32  MicroMipsInstBase<outs, ins, asmstr, pattern, itin, f>
33{
34  let Size = 2;
35  field bits<16> Inst;
36  field bits<16> SoftFail = 0;
37  bits<6> Opcode = 0x0;
38}
39
40//===----------------------------------------------------------------------===//
41// MicroMIPS 16-bit Instruction Formats
42//===----------------------------------------------------------------------===//
43
44class ARITH_FM_MM16<bit funct> {
45  bits<3> rd;
46  bits<3> rt;
47  bits<3> rs;
48
49  bits<16> Inst;
50
51  let Inst{15-10} = 0x01;
52  let Inst{9-7}   = rd;
53  let Inst{6-4}   = rt;
54  let Inst{3-1}   = rs;
55  let Inst{0}     = funct;
56}
57
58class LOGIC_FM_MM16<bits<4> funct> {
59  bits<3> rt;
60  bits<3> rs;
61
62  bits<16> Inst;
63
64  let Inst{15-10} = 0x11;
65  let Inst{9-6}   = funct;
66  let Inst{5-3}   = rt;
67  let Inst{2-0}   = rs;
68}
69
70class SHIFT_FM_MM16<bits<1> funct> {
71  bits<3> rd;
72  bits<3> rt;
73  bits<3> shamt;
74
75  bits<16> Inst;
76
77  let Inst{15-10} = 0x09;
78  let Inst{9-7}   = rd;
79  let Inst{6-4}   = rt;
80  let Inst{3-1}   = shamt;
81  let Inst{0}     = funct;
82}
83
84class ADDIUR2_FM_MM16 {
85  bits<3> rd;
86  bits<3> rs;
87  bits<3> imm;
88
89  bits<16> Inst;
90
91  let Inst{15-10} = 0x1b;
92  let Inst{9-7}   = rd;
93  let Inst{6-4}   = rs;
94  let Inst{3-1}   = imm;
95  let Inst{0}     = 0;
96}
97
98class ADDIUS5_FM_MM16 {
99  bits<5> rd;
100  bits<4> imm;
101
102  bits<16> Inst;
103
104  let Inst{15-10} = 0x13;
105  let Inst{9-5}   = rd;
106  let Inst{4-1}   = imm;
107  let Inst{0}     = 0;
108}
109
110class ADDIUSP_FM_MM16 {
111  bits<9> imm;
112
113  bits<16> Inst;
114
115  let Inst{15-10} = 0x13;
116  let Inst{9-1}   = imm;
117  let Inst{0}     = 1;
118}
119
120class MOVE_FM_MM16<bits<6> funct> {
121  bits<5> rs;
122  bits<5> rd;
123
124  bits<16> Inst;
125
126  let Inst{15-10} = funct;
127  let Inst{9-5}   = rd;
128  let Inst{4-0}   = rs;
129}
130
131class LI_FM_MM16 {
132  bits<3> rd;
133  bits<7> imm;
134
135  bits<16> Inst;
136
137  let Inst{15-10} = 0x3b;
138  let Inst{9-7}   = rd;
139  let Inst{6-0}   = imm;
140}
141
142class JALR_FM_MM16<bits<5> op> {
143  bits<5> rs;
144
145  bits<16> Inst;
146
147  let Inst{15-10} = 0x11;
148  let Inst{9-5}   = op;
149  let Inst{4-0}   = rs;
150}
151
152class MFHILO_FM_MM16<bits<5> funct> {
153  bits<5> rd;
154
155  bits<16> Inst;
156
157  let Inst{15-10} = 0x11;
158  let Inst{9-5}   = funct;
159  let Inst{4-0}   = rd;
160}
161
162class JRADDIUSP_FM_MM16<bits<5> op> {
163  bits<5> rs;
164  bits<5> imm;
165
166  bits<16> Inst;
167
168  let Inst{15-10} = 0x11;
169  let Inst{9-5}   = op;
170  let Inst{4-0}   = imm;
171}
172
173class ADDIUR1SP_FM_MM16 {
174  bits<3> rd;
175  bits<6> imm;
176
177  bits<16> Inst;
178
179  let Inst{15-10} = 0x1b;
180  let Inst{9-7}   = rd;
181  let Inst{6-1}   = imm;
182  let Inst{0}     = 1;
183}
184
185//===----------------------------------------------------------------------===//
186// MicroMIPS 32-bit Instruction Formats
187//===----------------------------------------------------------------------===//
188
189class MMArch {
190  string Arch = "micromips";
191  list<dag> Pattern = [];
192}
193
194class ADD_FM_MM<bits<6> op, bits<10> funct> : MMArch {
195  bits<5> rt;
196  bits<5> rs;
197  bits<5> rd;
198
199  bits<32> Inst;
200
201  let Inst{31-26} = op;
202  let Inst{25-21} = rt;
203  let Inst{20-16} = rs;
204  let Inst{15-11} = rd;
205  let Inst{10}    = 0;
206  let Inst{9-0}   = funct;
207}
208
209class ADDI_FM_MM<bits<6> op> : MMArch {
210  bits<5>  rs;
211  bits<5>  rt;
212  bits<16> imm16;
213
214  bits<32> Inst;
215
216  let Inst{31-26} = op;
217  let Inst{25-21} = rt;
218  let Inst{20-16} = rs;
219  let Inst{15-0}  = imm16;
220}
221
222class SLTI_FM_MM<bits<6> op> : MMArch {
223  bits<5> rt;
224  bits<5> rs;
225  bits<16> imm16;
226
227  bits<32> Inst;
228
229  let Inst{31-26} = op;
230  let Inst{25-21} = rt;
231  let Inst{20-16} = rs;
232  let Inst{15-0}  = imm16;
233}
234
235class LUI_FM_MM : MMArch {
236  bits<5> rt;
237  bits<16> imm16;
238
239  bits<32> Inst;
240
241  let Inst{31-26} = 0x10;
242  let Inst{25-21} = 0xd;
243  let Inst{20-16} = rt;
244  let Inst{15-0}  = imm16;
245}
246
247class MULT_FM_MM<bits<10> funct> : MMArch {
248  bits<5>  rs;
249  bits<5>  rt;
250
251  bits<32> Inst;
252
253  let Inst{31-26} = 0x00;
254  let Inst{25-21} = rt;
255  let Inst{20-16} = rs;
256  let Inst{15-6}  = funct;
257  let Inst{5-0}   = 0x3c;
258}
259
260class SRA_FM_MM<bits<10> funct, bit rotate> : MMArch {
261  bits<5> rd;
262  bits<5> rt;
263  bits<5> shamt;
264
265  bits<32> Inst;
266
267  let Inst{31-26} = 0;
268  let Inst{25-21} = rd;
269  let Inst{20-16} = rt;
270  let Inst{15-11} = shamt;
271  let Inst{10}    = rotate;
272  let Inst{9-0}   = funct;
273}
274
275class SRLV_FM_MM<bits<10> funct, bit rotate> : MMArch {
276  bits<5> rd;
277  bits<5> rt;
278  bits<5> rs;
279
280  bits<32> Inst;
281
282  let Inst{31-26} = 0;
283  let Inst{25-21} = rt;
284  let Inst{20-16} = rs;
285  let Inst{15-11} = rd;
286  let Inst{10}    = rotate;
287  let Inst{9-0}   = funct;
288}
289
290class LW_FM_MM<bits<6> op> : MMArch {
291  bits<5> rt;
292  bits<21> addr;
293
294  bits<32> Inst;
295
296  let Inst{31-26} = op;
297  let Inst{25-21} = rt;
298  let Inst{20-16} = addr{20-16};
299  let Inst{15-0}  = addr{15-0};
300}
301
302class LWL_FM_MM<bits<4> funct> {
303  bits<5> rt;
304  bits<21> addr;
305
306  bits<32> Inst;
307
308  let Inst{31-26} = 0x18;
309  let Inst{25-21} = rt;
310  let Inst{20-16} = addr{20-16};
311  let Inst{15-12} = funct;
312  let Inst{11-0}  = addr{11-0};
313}
314
315class CMov_F_I_FM_MM<bits<7> func> : MMArch {
316  bits<5> rd;
317  bits<5> rs;
318  bits<3> fcc;
319
320  bits<32> Inst;
321
322  let Inst{31-26} = 0x15;
323  let Inst{25-21} = rd;
324  let Inst{20-16} = rs;
325  let Inst{15-13} = fcc;
326  let Inst{12-6}  = func;
327  let Inst{5-0}   = 0x3b;
328}
329
330class MTLO_FM_MM<bits<10> funct> : MMArch {
331  bits<5> rs;
332
333  bits<32> Inst;
334
335  let Inst{31-26} = 0x00;
336  let Inst{25-21} = 0x00;
337  let Inst{20-16} = rs;
338  let Inst{15-6}  = funct;
339  let Inst{5-0}   = 0x3c;
340}
341
342class MFLO_FM_MM<bits<10> funct> : MMArch {
343  bits<5> rd;
344
345  bits<32> Inst;
346
347  let Inst{31-26} = 0x00;
348  let Inst{25-21} = 0x00;
349  let Inst{20-16} = rd;
350  let Inst{15-6}  = funct;
351  let Inst{5-0}   = 0x3c;
352}
353
354class CLO_FM_MM<bits<10> funct> : MMArch {
355  bits<5> rd;
356  bits<5> rs;
357
358  bits<32> Inst;
359
360  let Inst{31-26} = 0x00;
361  let Inst{25-21} = rd;
362  let Inst{20-16} = rs;
363  let Inst{15-6}  = funct;
364  let Inst{5-0}   = 0x3c;
365}
366
367class SEB_FM_MM<bits<10> funct> : MMArch {
368  bits<5> rd;
369  bits<5> rt;
370
371  bits<32> Inst;
372
373  let Inst{31-26} = 0x00;
374  let Inst{25-21} = rd;
375  let Inst{20-16} = rt;
376  let Inst{15-6}  = funct;
377  let Inst{5-0}   = 0x3c;
378}
379
380class EXT_FM_MM<bits<6> funct> : MMArch {
381  bits<5> rt;
382  bits<5> rs;
383  bits<5> pos;
384  bits<5> size;
385
386  bits<32> Inst;
387
388  let Inst{31-26} = 0x00;
389  let Inst{25-21} = rt;
390  let Inst{20-16} = rs;
391  let Inst{15-11} = size;
392  let Inst{10-6}  = pos;
393  let Inst{5-0}   = funct;
394}
395
396class J_FM_MM<bits<6> op> : MMArch {
397  bits<26> target;
398
399  bits<32> Inst;
400
401  let Inst{31-26} = op;
402  let Inst{25-0}  = target;
403}
404
405class JR_FM_MM<bits<8> funct> : MMArch {
406  bits<5> rs;
407
408  bits<32> Inst;
409
410  let Inst{31-21} = 0x00;
411  let Inst{20-16} = rs;
412  let Inst{15-14} = 0x0;
413  let Inst{13-6}  = funct;
414  let Inst{5-0}   = 0x3c;
415}
416
417class JALR_FM_MM<bits<10> funct> {
418  bits<5> rs;
419  bits<5> rd;
420
421  bits<32> Inst;
422
423  let Inst{31-26} = 0x00;
424  let Inst{25-21} = rd;
425  let Inst{20-16} = rs;
426  let Inst{15-6}  = funct;
427  let Inst{5-0}   = 0x3c;
428}
429
430class BEQ_FM_MM<bits<6> op> : MMArch {
431  bits<5>  rs;
432  bits<5>  rt;
433  bits<16> offset;
434
435  bits<32> Inst;
436
437  let Inst{31-26} = op;
438  let Inst{25-21} = rt;
439  let Inst{20-16} = rs;
440  let Inst{15-0}  = offset;
441}
442
443class BGEZ_FM_MM<bits<5> funct> : MMArch {
444  bits<5>  rs;
445  bits<16> offset;
446
447  bits<32> Inst;
448
449  let Inst{31-26} = 0x10;
450  let Inst{25-21} = funct;
451  let Inst{20-16} = rs;
452  let Inst{15-0}  = offset;
453}
454
455class BGEZAL_FM_MM<bits<5> funct> : MMArch {
456  bits<5>  rs;
457  bits<16> offset;
458
459  bits<32> Inst;
460
461  let Inst{31-26} = 0x10;
462  let Inst{25-21} = funct;
463  let Inst{20-16} = rs;
464  let Inst{15-0}  = offset;
465}
466
467class SYNC_FM_MM : MMArch {
468  bits<5> stype;
469
470  bits<32> Inst;
471
472  let Inst{31-26} = 0x00;
473  let Inst{25-21} = 0x0;
474  let Inst{20-16} = stype;
475  let Inst{15-6}  = 0x1ad;
476  let Inst{5-0}   = 0x3c;
477}
478
479class BRK_FM_MM : MMArch {
480  bits<10> code_1;
481  bits<10> code_2;
482  bits<32> Inst;
483  let Inst{31-26} = 0x0;
484  let Inst{25-16} = code_1;
485  let Inst{15-6}  = code_2;
486  let Inst{5-0}   = 0x07;
487}
488
489class SYS_FM_MM : MMArch {
490  bits<10> code_;
491  bits<32> Inst;
492  let Inst{31-26} = 0x0;
493  let Inst{25-16} = code_;
494  let Inst{15-6}  = 0x22d;
495  let Inst{5-0}   = 0x3c;
496}
497
498class WAIT_FM_MM {
499  bits<10> code_;
500  bits<32> Inst;
501
502  let Inst{31-26} = 0x00;
503  let Inst{25-16} = code_;
504  let Inst{15-6}  = 0x24d;
505  let Inst{5-0}   = 0x3c;
506}
507
508class ER_FM_MM<bits<10> funct> : MMArch {
509  bits<32> Inst;
510
511  let Inst{31-26} = 0x00;
512  let Inst{25-16} = 0x00;
513  let Inst{15-6}  = funct;
514  let Inst{5-0}   = 0x3c;
515}
516
517class EI_FM_MM<bits<10> funct> : MMArch {
518  bits<32> Inst;
519  bits<5> rt;
520
521  let Inst{31-26} = 0x00;
522  let Inst{25-21} = 0x00;
523  let Inst{20-16} = rt;
524  let Inst{15-6}  = funct;
525  let Inst{5-0}   = 0x3c;
526}
527
528class TEQ_FM_MM<bits<6> funct> : MMArch {
529  bits<5> rs;
530  bits<5> rt;
531  bits<4> code_;
532
533  bits<32> Inst;
534
535  let Inst{31-26} = 0x00;
536  let Inst{25-21} = rt;
537  let Inst{20-16} = rs;
538  let Inst{15-12} = code_;
539  let Inst{11-6}  = funct;
540  let Inst{5-0}   = 0x3c;
541}
542
543class TEQI_FM_MM<bits<5> funct> : MMArch {
544  bits<5> rs;
545  bits<16> imm16;
546
547  bits<32> Inst;
548
549  let Inst{31-26} = 0x10;
550  let Inst{25-21} = funct;
551  let Inst{20-16} = rs;
552  let Inst{15-0}  = imm16;
553}
554
555class LL_FM_MM<bits<4> funct> {
556  bits<5> rt;
557  bits<21> addr;
558
559  bits<32> Inst;
560
561  let Inst{31-26} = 0x18;
562  let Inst{25-21} = rt;
563  let Inst{20-16} = addr{20-16};
564  let Inst{15-12} = funct;
565  let Inst{11-0}  = addr{11-0};
566}
567
568class ADDS_FM_MM<bits<2> fmt, bits<8> funct> : MMArch {
569  bits<5> ft;
570  bits<5> fs;
571  bits<5> fd;
572
573  bits<32> Inst;
574
575  let Inst{31-26} = 0x15;
576  let Inst{25-21} = ft;
577  let Inst{20-16} = fs;
578  let Inst{15-11} = fd;
579  let Inst{10}    = 0;
580  let Inst{9-8}   = fmt;
581  let Inst{7-0}   = funct;
582
583  list<dag> Pattern = [];
584}
585
586class LWXC1_FM_MM<bits<9> funct> : MMArch {
587  bits<5> fd;
588  bits<5> base;
589  bits<5> index;
590
591  bits<32> Inst;
592
593  let Inst{31-26} = 0x15;
594  let Inst{25-21} = index;
595  let Inst{20-16} = base;
596  let Inst{15-11} = fd;
597  let Inst{10-9}  = 0x0;
598  let Inst{8-0}   = funct;
599}
600
601class SWXC1_FM_MM<bits<9> funct> : MMArch {
602  bits<5> fs;
603  bits<5> base;
604  bits<5> index;
605
606  bits<32> Inst;
607
608  let Inst{31-26} = 0x15;
609  let Inst{25-21} = index;
610  let Inst{20-16} = base;
611  let Inst{15-11} = fs;
612  let Inst{10-9}  = 0x0;
613  let Inst{8-0}   = funct;
614}
615
616class CEQS_FM_MM<bits<2> fmt> : MMArch {
617  bits<5> fs;
618  bits<5> ft;
619  bits<4> cond;
620
621  bits<32> Inst;
622
623  let Inst{31-26} = 0x15;
624  let Inst{25-21} = ft;
625  let Inst{20-16} = fs;
626  let Inst{15-13} = 0x0;  // cc
627  let Inst{12}    = 0;
628  let Inst{11-10} = fmt;
629  let Inst{9-6}   = cond;
630  let Inst{5-0}   = 0x3c;
631}
632
633class BC1F_FM_MM<bits<5> tf> : MMArch {
634  bits<16> offset;
635
636  bits<32> Inst;
637
638  let Inst{31-26} = 0x10;
639  let Inst{25-21} = tf;
640  let Inst{20-18} = 0x0; // cc
641  let Inst{17-16} = 0x0;
642  let Inst{15-0}  = offset;
643}
644
645class ROUND_W_FM_MM<bits<1> fmt, bits<8> funct> : MMArch {
646  bits<5> fd;
647  bits<5> fs;
648
649  bits<32> Inst;
650
651  let Inst{31-26} = 0x15;
652  let Inst{25-21} = fd;
653  let Inst{20-16} = fs;
654  let Inst{15}    = 0;
655  let Inst{14}    = fmt;
656  let Inst{13-6}  = funct;
657  let Inst{5-0}   = 0x3b;
658}
659
660class ABS_FM_MM<bits<2> fmt, bits<7> funct> : MMArch {
661  bits<5> fd;
662  bits<5> fs;
663
664  bits<32> Inst;
665
666  let Inst{31-26} = 0x15;
667  let Inst{25-21} = fd;
668  let Inst{20-16} = fs;
669  let Inst{15}    = 0;
670  let Inst{14-13} = fmt;
671  let Inst{12-6}  = funct;
672  let Inst{5-0}   = 0x3b;
673}
674
675class CMov_F_F_FM_MM<bits<9> func, bits<2> fmt> : MMArch {
676  bits<5> fd;
677  bits<5> fs;
678
679  bits<32> Inst;
680
681  let Inst{31-26} = 0x15;
682  let Inst{25-21} = fd;
683  let Inst{20-16} = fs;
684  let Inst{15-13} = 0x0; //cc
685  let Inst{12-11} = 0x0;
686  let Inst{10-9}  = fmt;
687  let Inst{8-0}   = func;
688}
689
690class CMov_I_F_FM_MM<bits<8> funct, bits<2> fmt> : MMArch {
691  bits<5> fd;
692  bits<5> fs;
693  bits<5> rt;
694
695  bits<32> Inst;
696
697  let Inst{31-26} = 0x15;
698  let Inst{25-21} = rt;
699  let Inst{20-16} = fs;
700  let Inst{15-11} = fd;
701  let Inst{9-8}   = fmt;
702  let Inst{7-0}   = funct;
703}
704
705class MFC1_FM_MM<bits<8> funct> : MMArch {
706  bits<5> rt;
707  bits<5> fs;
708
709  bits<32> Inst;
710
711  let Inst{31-26} = 0x15;
712  let Inst{25-21} = rt;
713  let Inst{20-16} = fs;
714  let Inst{15-14} = 0x0;
715  let Inst{13-6}  = funct;
716  let Inst{5-0}   = 0x3b;
717}
718
719class MADDS_FM_MM<bits<6> funct>: MMArch {
720  bits<5> ft;
721  bits<5> fs;
722  bits<5> fd;
723  bits<5> fr;
724
725  bits<32> Inst;
726
727  let Inst{31-26} = 0x15;
728  let Inst{25-21} = ft;
729  let Inst{20-16} = fs;
730  let Inst{15-11} = fd;
731  let Inst{10-6}  = fr;
732  let Inst{5-0}   = funct;
733}
734
735class COMPACT_BRANCH_FM_MM<bits<5> funct> {
736  bits<5>  rs;
737  bits<16> offset;
738
739  bits<32> Inst;
740
741  let Inst{31-26} = 0x10;
742  let Inst{25-21} = funct;
743  let Inst{20-16} = rs;
744  let Inst{15-0}  = offset;
745}
746
747class COP0_TLB_FM_MM<bits<10> op> : MMArch {
748  bits<32> Inst;
749
750  let Inst{31-26} = 0x0;
751  let Inst{25-16} = 0x0;
752  let Inst{15-6}  = op;
753  let Inst{5-0}   = 0x3c;
754}
755