1 //===-- MipsInstrFormats.td - Mips Instruction Formats -----*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 //===----------------------------------------------------------------------===//
10 // Describe MIPS instructions format
12 // CPU INSTRUCTION FORMATS
14 // opcode - operation code.
16 // rt - dst reg (on a 2 regs instr) or src reg (on a 3 reg instr).
17 // rd - dst reg, only used on 3 regs instr.
18 // shamt - only used on shift instructions, contains the shift amount.
19 // funct - combined with opcode field give us an operation code.
21 //===----------------------------------------------------------------------===//
23 // Format specifies the encoding used by the instruction. This is part of the
24 // ad-hoc solution used to emit machine instruction encodings by our machine
26 class Format<bits<4> val> {
30 def Pseudo : Format<0>;
34 def FrmFR : Format<4>;
35 def FrmFI : Format<5>;
36 def FrmOther : Format<6>; // Instruction w/ a custom format
40 def Std2MicroMips : InstrMapping {
41 let FilterClass = "MMRel";
42 // Instructions with the same BaseOpcode and isNVStore values form a row.
43 let RowFields = ["BaseOpcode"];
44 // Instructions with the same predicate sense form a column.
45 let ColFields = ["Arch"];
46 // The key column is the unpredicated instructions.
48 // Value columns are PredSense=true and PredSense=false
49 let ValueCols = [["se"], ["micromips"]];
54 def Std2MicroMipsR6 : InstrMapping {
55 let FilterClass = "StdMMR6Rel";
56 // Instructions with the same BaseOpcode and isNVStore values form a row.
57 let RowFields = ["BaseOpcode"];
58 // Instructions with the same predicate sense form a column.
59 let ColFields = ["Arch"];
60 // The key column is the unpredicated instructions.
62 // Value columns are PredSense=true and PredSense=false
63 let ValueCols = [["se"], ["micromipsr6"]];
70 // Generic Mips Format
71 class MipsInst<dag outs, dag ins, string asmstr, list<dag> pattern,
72 InstrItinClass itin, Format f>: Instruction, PredicateControl
77 let Namespace = "Mips";
83 // Top 6 bits are the 'opcode' field
84 let Inst{31-26} = Opcode;
86 let OutOperandList = outs;
87 let InOperandList = ins;
89 let AsmString = asmstr;
90 let Pattern = pattern;
94 // Attributes specific to Mips instructions...
96 bits<4> FormBits = Form.Value;
97 bit isCTI = 0; // Any form of Control Transfer Instruction.
98 // Required for MIPSR6
99 bit hasForbiddenSlot = 0; // Instruction has a forbidden slot.
100 bit hasFCCRegOperand = 0; // Instruction uses $fcc<X> register and is
101 // present in MIPS-I to MIPS-III.
103 // TSFlags layout should be kept in sync with MCTargetDesc/MipsBaseInfo.h.
104 let TSFlags{3-0} = FormBits;
105 let TSFlags{4} = isCTI;
106 let TSFlags{5} = hasForbiddenSlot;
107 let TSFlags{6} = hasFCCRegOperand;
109 let DecoderNamespace = "Mips";
111 field bits<32> SoftFail = 0;
114 // Mips32/64 Instruction Format
115 class InstSE<dag outs, dag ins, string asmstr, list<dag> pattern,
116 InstrItinClass itin, Format f, string opstr = ""> :
117 MipsInst<outs, ins, asmstr, pattern, itin, f> {
118 let EncodingPredicates = [NotInMips16Mode];
119 string BaseOpcode = opstr;
123 // Mips Pseudo Instructions Format
124 class MipsPseudo<dag outs, dag ins, list<dag> pattern,
125 InstrItinClass itin = IIPseudo> :
126 MipsInst<outs, ins, "", pattern, itin, Pseudo> {
127 let isCodeGenOnly = 1;
131 // Mips32/64 Pseudo Instruction Format
132 class PseudoSE<dag outs, dag ins, list<dag> pattern,
133 InstrItinClass itin = IIPseudo> :
134 MipsPseudo<outs, ins, pattern, itin> {
135 let EncodingPredicates = [NotInMips16Mode];
138 // Pseudo-instructions for alternate assembly syntax (never used by codegen).
139 // These are aliases that require C++ handling to convert to the target
140 // instruction, while InstAliases can be handled directly by tblgen.
141 class MipsAsmPseudoInst<dag outs, dag ins, string asmstr>:
142 MipsInst<outs, ins, asmstr, [], IIPseudo, Pseudo> {
144 let hasNoSchedulingInfo = 1;
147 //===----------------------------------------------------------------------===//
148 // Format R instruction class in Mips : <|opcode|rs|rt|rd|shamt|funct|>
149 //===----------------------------------------------------------------------===//
151 class FR<bits<6> op, bits<6> _funct, dag outs, dag ins, string asmstr,
152 list<dag> pattern, InstrItinClass itin>:
153 InstSE<outs, ins, asmstr, pattern, itin, FrmR>
164 let Inst{25-21} = rs;
165 let Inst{20-16} = rt;
166 let Inst{15-11} = rd;
167 let Inst{10-6} = shamt;
168 let Inst{5-0} = funct;
171 //===----------------------------------------------------------------------===//
172 // Format I instruction class in Mips : <|opcode|rs|rt|immediate|>
173 //===----------------------------------------------------------------------===//
175 class FI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
176 InstrItinClass itin>: InstSE<outs, ins, asmstr, pattern, itin, FrmI>
184 let Inst{25-21} = rs;
185 let Inst{20-16} = rt;
186 let Inst{15-0} = imm16;
189 class BranchBase<bits<6> op, dag outs, dag ins, string asmstr,
190 list<dag> pattern, InstrItinClass itin>:
191 InstSE<outs, ins, asmstr, pattern, itin, FrmI>
199 let Inst{25-21} = rs;
200 let Inst{20-16} = rt;
201 let Inst{15-0} = imm16;
204 //===----------------------------------------------------------------------===//
205 // Format J instruction class in Mips : <|opcode|address|>
206 //===----------------------------------------------------------------------===//
208 class FJ<bits<6> op> : StdArch
214 let Inst{31-26} = op;
215 let Inst{25-0} = target;
218 //===----------------------------------------------------------------------===//
219 // MFC instruction class in Mips : <|op|mf|rt|rd|gst|0000|sel|>
220 //===----------------------------------------------------------------------===//
221 class MFC3OP_FM<bits<6> op, bits<5> mfmt, bits<3> guest> : StdArch {
228 let Inst{31-26} = op;
229 let Inst{25-21} = mfmt;
230 let Inst{20-16} = rt;
231 let Inst{15-11} = rd;
232 let Inst{10-8} = guest;
237 class MFC2OP_FM<bits<6> op, bits<5> mfmt> : StdArch {
243 let Inst{31-26} = op;
244 let Inst{25-21} = mfmt;
245 let Inst{20-16} = rt;
246 let Inst{15-0} = imm16;
249 class ADD_FM<bits<6> op, bits<6> funct> : StdArch {
256 let Inst{31-26} = op;
257 let Inst{25-21} = rs;
258 let Inst{20-16} = rt;
259 let Inst{15-11} = rd;
261 let Inst{5-0} = funct;
264 class ADDI_FM<bits<6> op> : StdArch {
271 let Inst{31-26} = op;
272 let Inst{25-21} = rs;
273 let Inst{20-16} = rt;
274 let Inst{15-0} = imm16;
277 class SRA_FM<bits<6> funct, bit rotate> : StdArch {
286 let Inst{21} = rotate;
287 let Inst{20-16} = rt;
288 let Inst{15-11} = rd;
289 let Inst{10-6} = shamt;
290 let Inst{5-0} = funct;
293 class SRLV_FM<bits<6> funct, bit rotate> : StdArch {
301 let Inst{25-21} = rs;
302 let Inst{20-16} = rt;
303 let Inst{15-11} = rd;
305 let Inst{6} = rotate;
306 let Inst{5-0} = funct;
309 class BEQ_FM<bits<6> op> : StdArch {
316 let Inst{31-26} = op;
317 let Inst{25-21} = rs;
318 let Inst{20-16} = rt;
319 let Inst{15-0} = offset;
322 class BGEZ_FM<bits<6> op, bits<5> funct> : StdArch {
328 let Inst{31-26} = op;
329 let Inst{25-21} = rs;
330 let Inst{20-16} = funct;
331 let Inst{15-0} = offset;
334 class BBIT_FM<bits<6> op> : StdArch {
341 let Inst{31-26} = op;
342 let Inst{25-21} = rs;
344 let Inst{15-0} = offset;
347 class SLTI_FM<bits<6> op> : StdArch {
354 let Inst{31-26} = op;
355 let Inst{25-21} = rs;
356 let Inst{20-16} = rt;
357 let Inst{15-0} = imm16;
360 class MFLO_FM<bits<6> funct> : StdArch {
367 let Inst{15-11} = rd;
369 let Inst{5-0} = funct;
372 class MTLO_FM<bits<6> funct> : StdArch {
378 let Inst{25-21} = rs;
380 let Inst{5-0} = funct;
383 class SEB_FM<bits<5> funct, bits<6> funct2> : StdArch {
389 let Inst{31-26} = 0x1f;
391 let Inst{20-16} = rt;
392 let Inst{15-11} = rd;
393 let Inst{10-6} = funct;
394 let Inst{5-0} = funct2;
397 class CLO_FM<bits<6> funct> : StdArch {
404 let Inst{31-26} = 0x1c;
405 let Inst{25-21} = rs;
406 let Inst{20-16} = rt;
407 let Inst{15-11} = rd;
409 let Inst{5-0} = funct;
413 class LUI_FM : StdArch {
419 let Inst{31-26} = 0xf;
421 let Inst{20-16} = rt;
422 let Inst{15-0} = imm16;
432 let Inst{25-21} = rs;
434 let Inst{15-11} = rd;
439 class BGEZAL_FM<bits<5> funct> : StdArch {
446 let Inst{25-21} = rs;
447 let Inst{20-16} = funct;
448 let Inst{15-0} = offset;
451 class SYNC_FM : StdArch {
457 let Inst{10-6} = stype;
461 class SYNCI_FM : StdArch {
462 // Produced by the mem_simm16 address as reg << 16 | imm (see getMemEncoding).
464 bits<5> rs = addr{20-16};
465 bits<16> offset = addr{15-0};
469 let Inst{31-26} = 0b000001;
470 let Inst{25-21} = rs;
471 let Inst{20-16} = 0b11111;
472 let Inst{15-0} = offset;
475 class MULT_FM<bits<6> op, bits<6> funct> : StdArch {
481 let Inst{31-26} = op;
482 let Inst{25-21} = rs;
483 let Inst{20-16} = rt;
485 let Inst{5-0} = funct;
488 class EXT_FM<bits<6> funct> : StdArch {
496 let Inst{31-26} = 0x1f;
497 let Inst{25-21} = rs;
498 let Inst{20-16} = rt;
499 let Inst{15-11} = size;
500 let Inst{10-6} = pos;
501 let Inst{5-0} = funct;
504 class RDHWR_FM : StdArch {
511 let Inst{31-26} = 0x1f;
513 let Inst{20-16} = rt;
514 let Inst{15-11} = rd;
515 let Inst{10-9} = 0b00;
517 let Inst{5-0} = 0x3b;
520 class TEQ_FM<bits<6> funct> : StdArch {
528 let Inst{25-21} = rs;
529 let Inst{20-16} = rt;
530 let Inst{15-6} = code_;
531 let Inst{5-0} = funct;
534 class TEQI_FM<bits<5> funct> : StdArch {
541 let Inst{25-21} = rs;
542 let Inst{20-16} = funct;
543 let Inst{15-0} = imm16;
546 class WAIT_FM : StdArch {
549 let Inst{31-26} = 0x10;
552 let Inst{5-0} = 0x20;
555 class EXTS_FM<bits<6> funct> : StdArch {
563 let Inst{31-26} = 0x1c;
564 let Inst{25-21} = rs;
565 let Inst{20-16} = rt;
566 let Inst{15-11} = lenm1;
567 let Inst{10-6} = pos;
568 let Inst{5-0} = funct;
571 class MTMR_FM<bits<6> funct> : StdArch {
576 let Inst{31-26} = 0x1c;
577 let Inst{25-21} = rs;
579 let Inst{5-0} = funct;
582 class POP_FM<bits<6> funct> : StdArch {
588 let Inst{31-26} = 0x1c;
589 let Inst{25-21} = rs;
591 let Inst{15-11} = rd;
593 let Inst{5-0} = funct;
596 class SEQ_FM<bits<6> funct> : StdArch {
603 let Inst{31-26} = 0x1c;
604 let Inst{25-21} = rs;
605 let Inst{20-16} = rt;
606 let Inst{15-11} = rd;
608 let Inst{5-0} = funct;
611 class SEQI_FM<bits<6> funct> : StdArch {
618 let Inst{31-26} = 0x1c;
619 let Inst{25-21} = rs;
620 let Inst{20-16} = rt;
621 let Inst{15-6} = imm10;
622 let Inst{5-0} = funct;
625 class SAA_FM<bits<6> funct> : StdArch {
631 let Inst{31-26} = 0x1c;
632 let Inst{25-21} = rs;
633 let Inst{20-16} = rt;
635 let Inst{5-0} = funct;
638 //===----------------------------------------------------------------------===//
639 // System calls format <op|code_|funct>
640 //===----------------------------------------------------------------------===//
642 class SYS_FM<bits<6> funct> : StdArch
646 let Inst{31-26} = 0x0;
647 let Inst{25-6} = code_;
648 let Inst{5-0} = funct;
651 //===----------------------------------------------------------------------===//
652 // Break instruction format <op|code_1|funct>
653 //===----------------------------------------------------------------------===//
655 class BRK_FM<bits<6> funct> : StdArch
660 let Inst{31-26} = 0x0;
661 let Inst{25-16} = code_1;
662 let Inst{15-6} = code_2;
663 let Inst{5-0} = funct;
666 //===----------------------------------------------------------------------===//
667 // Exception return format <Cop0|1|0|funct>
668 //===----------------------------------------------------------------------===//
670 class ER_FM<bits<6> funct, bit LLBit> : StdArch
673 let Inst{31-26} = 0x10;
677 let Inst{5-0} = funct;
680 //===----------------------------------------------------------------------===//
681 // Enable/disable interrupt instruction format <Cop0|MFMC0|rt|12|0|sc|0|0>
682 //===----------------------------------------------------------------------===//
684 class EI_FM<bits<1> sc> : StdArch
688 let Inst{31-26} = 0x10;
689 let Inst{25-21} = 0xb;
690 let Inst{20-16} = rt;
691 let Inst{15-11} = 0xc;
697 //===----------------------------------------------------------------------===//
699 // FLOATING POINT INSTRUCTION FORMATS
701 // opcode - operation code.
703 // ft - dst reg (on a 2 regs instr) or src reg (on a 3 reg instr).
704 // fd - dst reg, only used on 3 regs instr.
705 // fmt - double or single precision.
706 // funct - combined with opcode field give us an operation code.
708 //===----------------------------------------------------------------------===//
710 //===----------------------------------------------------------------------===//
711 // Format FI instruction class in Mips : <|opcode|base|ft|immediate|>
712 //===----------------------------------------------------------------------===//
714 class FFI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern>:
715 InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmFI>
723 let Inst{25-21} = base;
724 let Inst{20-16} = ft;
725 let Inst{15-0} = imm16;
728 class ADDS_FM<bits<6> funct, bits<5> fmt> : StdArch {
735 let Inst{31-26} = 0x11;
736 let Inst{25-21} = fmt;
737 let Inst{20-16} = ft;
738 let Inst{15-11} = fs;
740 let Inst{5-0} = funct;
743 class ABSS_FM<bits<6> funct, bits<5> fmt> : StdArch {
749 let Inst{31-26} = 0x11;
750 let Inst{25-21} = fmt;
752 let Inst{15-11} = fs;
754 let Inst{5-0} = funct;
757 class MFC1_FM<bits<5> funct> : StdArch {
763 let Inst{31-26} = 0x11;
764 let Inst{25-21} = funct;
765 let Inst{20-16} = rt;
766 let Inst{15-11} = fs;
770 class LW_FM<bits<6> op> : StdArch {
776 let Inst{31-26} = op;
777 let Inst{25-21} = addr{20-16};
778 let Inst{20-16} = rt;
779 let Inst{15-0} = addr{15-0};
782 class MADDS_FM<bits<3> funct, bits<3> fmt> : StdArch {
790 let Inst{31-26} = 0x13;
791 let Inst{25-21} = fr;
792 let Inst{20-16} = ft;
793 let Inst{15-11} = fs;
795 let Inst{5-3} = funct;
799 class LWXC1_FM<bits<6> funct> : StdArch {
806 let Inst{31-26} = 0x13;
807 let Inst{25-21} = base;
808 let Inst{20-16} = index;
811 let Inst{5-0} = funct;
814 class SWXC1_FM<bits<6> funct> : StdArch {
821 let Inst{31-26} = 0x13;
822 let Inst{25-21} = base;
823 let Inst{20-16} = index;
824 let Inst{15-11} = fs;
826 let Inst{5-0} = funct;
829 class BC1F_FM<bit nd, bit tf> : StdArch {
835 let Inst{31-26} = 0x11;
836 let Inst{25-21} = 0x8;
837 let Inst{20-18} = fcc;
840 let Inst{15-0} = offset;
843 class CEQS_FM<bits<5> fmt> : StdArch {
851 let Inst{31-26} = 0x11;
852 let Inst{25-21} = fmt;
853 let Inst{20-16} = ft;
854 let Inst{15-11} = fs;
855 let Inst{10-8} = fcc;
857 let Inst{3-0} = cond;
860 class C_COND_FM<bits<5> fmt, bits<4> c> : CEQS_FM<fmt> {
864 class CMov_I_F_FM<bits<6> funct, bits<5> fmt> : StdArch {
871 let Inst{31-26} = 0x11;
872 let Inst{25-21} = fmt;
873 let Inst{20-16} = rt;
874 let Inst{15-11} = fs;
876 let Inst{5-0} = funct;
879 class CMov_F_I_FM<bit tf> : StdArch {
887 let Inst{25-21} = rs;
888 let Inst{20-18} = fcc;
891 let Inst{15-11} = rd;
896 class CMov_F_F_FM<bits<5> fmt, bit tf> : StdArch {
903 let Inst{31-26} = 0x11;
904 let Inst{25-21} = fmt;
905 let Inst{20-18} = fcc;
908 let Inst{15-11} = fs;
910 let Inst{5-0} = 0x11;
913 class BARRIER_FM<bits<5> op> : StdArch {
916 let Inst{31-26} = 0; // SPECIAL
918 let Inst{20-16} = 0; // rt = 0
919 let Inst{15-11} = 0; // rd = 0
920 let Inst{10-6} = op; // Operation
921 let Inst{5-0} = 0; // SLL
924 class SDBBP_FM : StdArch {
929 let Inst{31-26} = 0b011100; // SPECIAL2
930 let Inst{25-6} = code_;
931 let Inst{5-0} = 0b111111; // SDBBP
934 class JR_HB_FM<bits<6> op> : StdArch{
939 let Inst{31-26} = 0; // SPECIAL
940 let Inst{25-21} = rs;
947 class JALR_HB_FM<bits<6> op> : StdArch {
953 let Inst{31-26} = 0; // SPECIAL
954 let Inst{25-21} = rs;
956 let Inst{15-11} = rd;
962 class COP0_TLB_FM<bits<6> op> : StdArch {
965 let Inst{31-26} = 0x10; // COP0
966 let Inst{25} = 1; // CO
968 let Inst{5-0} = op; // Operation
971 class CACHEOP_FM<bits<6> op> : StdArch {
974 bits<5> base = addr{20-16};
975 bits<16> offset = addr{15-0};
979 let Inst{31-26} = op;
980 let Inst{25-21} = base;
981 let Inst{20-16} = hint;
982 let Inst{15-0} = offset;
985 class HYPCALL_FM<bits<6> op> : StdArch {
990 let Inst{31-26} = 0b010000;
992 let Inst{20-11} = code_;