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 J instruction class in Mips : <|opcode|address|>
173 //===----------------------------------------------------------------------===//
175 class FJ<bits<6> op> : StdArch
181 let Inst{31-26} = op;
182 let Inst{25-0} = target;
185 //===----------------------------------------------------------------------===//
186 // MFC instruction class in Mips : <|op|mf|rt|rd|gst|0000|sel|>
187 //===----------------------------------------------------------------------===//
188 class MFC3OP_FM<bits<6> op, bits<5> mfmt, bits<3> guest> : StdArch {
195 let Inst{31-26} = op;
196 let Inst{25-21} = mfmt;
197 let Inst{20-16} = rt;
198 let Inst{15-11} = rd;
199 let Inst{10-8} = guest;
204 class MFC2OP_FM<bits<6> op, bits<5> mfmt> : StdArch {
210 let Inst{31-26} = op;
211 let Inst{25-21} = mfmt;
212 let Inst{20-16} = rt;
213 let Inst{15-0} = imm16;
216 class ADD_FM<bits<6> op, bits<6> funct> : StdArch {
223 let Inst{31-26} = op;
224 let Inst{25-21} = rs;
225 let Inst{20-16} = rt;
226 let Inst{15-11} = rd;
228 let Inst{5-0} = funct;
231 class ADDI_FM<bits<6> op> : StdArch {
238 let Inst{31-26} = op;
239 let Inst{25-21} = rs;
240 let Inst{20-16} = rt;
241 let Inst{15-0} = imm16;
244 class SRA_FM<bits<6> funct, bit rotate> : StdArch {
253 let Inst{21} = rotate;
254 let Inst{20-16} = rt;
255 let Inst{15-11} = rd;
256 let Inst{10-6} = shamt;
257 let Inst{5-0} = funct;
260 class SRLV_FM<bits<6> funct, bit rotate> : StdArch {
268 let Inst{25-21} = rs;
269 let Inst{20-16} = rt;
270 let Inst{15-11} = rd;
272 let Inst{6} = rotate;
273 let Inst{5-0} = funct;
276 class BEQ_FM<bits<6> op> : StdArch {
283 let Inst{31-26} = op;
284 let Inst{25-21} = rs;
285 let Inst{20-16} = rt;
286 let Inst{15-0} = offset;
289 class BGEZ_FM<bits<6> op, bits<5> funct> : StdArch {
295 let Inst{31-26} = op;
296 let Inst{25-21} = rs;
297 let Inst{20-16} = funct;
298 let Inst{15-0} = offset;
301 class BBIT_FM<bits<6> op> : StdArch {
308 let Inst{31-26} = op;
309 let Inst{25-21} = rs;
311 let Inst{15-0} = offset;
314 class SLTI_FM<bits<6> op> : StdArch {
321 let Inst{31-26} = op;
322 let Inst{25-21} = rs;
323 let Inst{20-16} = rt;
324 let Inst{15-0} = imm16;
327 class MFLO_FM<bits<6> funct> : StdArch {
334 let Inst{15-11} = rd;
336 let Inst{5-0} = funct;
339 class MTLO_FM<bits<6> funct> : StdArch {
345 let Inst{25-21} = rs;
347 let Inst{5-0} = funct;
350 class SEB_FM<bits<5> funct, bits<6> funct2> : StdArch {
356 let Inst{31-26} = 0x1f;
358 let Inst{20-16} = rt;
359 let Inst{15-11} = rd;
360 let Inst{10-6} = funct;
361 let Inst{5-0} = funct2;
364 class CLO_FM<bits<6> funct> : StdArch {
371 let Inst{31-26} = 0x1c;
372 let Inst{25-21} = rs;
373 let Inst{20-16} = rt;
374 let Inst{15-11} = rd;
376 let Inst{5-0} = funct;
380 class LUI_FM : StdArch {
386 let Inst{31-26} = 0xf;
388 let Inst{20-16} = rt;
389 let Inst{15-0} = imm16;
399 let Inst{25-21} = rs;
401 let Inst{15-11} = rd;
406 class BGEZAL_FM<bits<5> funct> : StdArch {
413 let Inst{25-21} = rs;
414 let Inst{20-16} = funct;
415 let Inst{15-0} = offset;
418 class SYNC_FM : StdArch {
424 let Inst{10-6} = stype;
428 class SYNCI_FM : StdArch {
429 // Produced by the mem_simm16 address as reg << 16 | imm (see getMemEncoding).
431 bits<5> rs = addr{20-16};
432 bits<16> offset = addr{15-0};
436 let Inst{31-26} = 0b000001;
437 let Inst{25-21} = rs;
438 let Inst{20-16} = 0b11111;
439 let Inst{15-0} = offset;
442 class MULT_FM<bits<6> op, bits<6> funct> : StdArch {
448 let Inst{31-26} = op;
449 let Inst{25-21} = rs;
450 let Inst{20-16} = rt;
452 let Inst{5-0} = funct;
455 class EXT_FM<bits<6> funct> : StdArch {
463 let Inst{31-26} = 0x1f;
464 let Inst{25-21} = rs;
465 let Inst{20-16} = rt;
466 let Inst{15-11} = size;
467 let Inst{10-6} = pos;
468 let Inst{5-0} = funct;
471 class RDHWR_FM : StdArch {
478 let Inst{31-26} = 0x1f;
480 let Inst{20-16} = rt;
481 let Inst{15-11} = rd;
482 let Inst{10-9} = 0b00;
484 let Inst{5-0} = 0x3b;
487 class TEQ_FM<bits<6> funct> : StdArch {
495 let Inst{25-21} = rs;
496 let Inst{20-16} = rt;
497 let Inst{15-6} = code_;
498 let Inst{5-0} = funct;
501 class TEQI_FM<bits<5> funct> : StdArch {
508 let Inst{25-21} = rs;
509 let Inst{20-16} = funct;
510 let Inst{15-0} = imm16;
513 class WAIT_FM : StdArch {
516 let Inst{31-26} = 0x10;
519 let Inst{5-0} = 0x20;
522 class EXTS_FM<bits<6> funct> : StdArch {
530 let Inst{31-26} = 0x1c;
531 let Inst{25-21} = rs;
532 let Inst{20-16} = rt;
533 let Inst{15-11} = lenm1;
534 let Inst{10-6} = pos;
535 let Inst{5-0} = funct;
538 class MTMR_FM<bits<6> funct> : StdArch {
543 let Inst{31-26} = 0x1c;
544 let Inst{25-21} = rs;
546 let Inst{5-0} = funct;
549 class POP_FM<bits<6> funct> : StdArch {
555 let Inst{31-26} = 0x1c;
556 let Inst{25-21} = rs;
558 let Inst{15-11} = rd;
560 let Inst{5-0} = funct;
563 class SEQ_FM<bits<6> funct> : StdArch {
570 let Inst{31-26} = 0x1c;
571 let Inst{25-21} = rs;
572 let Inst{20-16} = rt;
573 let Inst{15-11} = rd;
575 let Inst{5-0} = funct;
578 class SEQI_FM<bits<6> funct> : StdArch {
585 let Inst{31-26} = 0x1c;
586 let Inst{25-21} = rs;
587 let Inst{20-16} = rt;
588 let Inst{15-6} = imm10;
589 let Inst{5-0} = funct;
592 class SAA_FM<bits<6> funct> : StdArch {
598 let Inst{31-26} = 0x1c;
599 let Inst{25-21} = rs;
600 let Inst{20-16} = rt;
602 let Inst{5-0} = funct;
605 //===----------------------------------------------------------------------===//
606 // System calls format <op|code_|funct>
607 //===----------------------------------------------------------------------===//
609 class SYS_FM<bits<6> funct> : StdArch
613 let Inst{31-26} = 0x0;
614 let Inst{25-6} = code_;
615 let Inst{5-0} = funct;
618 //===----------------------------------------------------------------------===//
619 // Break instruction format <op|code_1|funct>
620 //===----------------------------------------------------------------------===//
622 class BRK_FM<bits<6> funct> : StdArch
627 let Inst{31-26} = 0x0;
628 let Inst{25-16} = code_1;
629 let Inst{15-6} = code_2;
630 let Inst{5-0} = funct;
633 //===----------------------------------------------------------------------===//
634 // Exception return format <Cop0|1|0|funct>
635 //===----------------------------------------------------------------------===//
637 class ER_FM<bits<6> funct, bit LLBit> : StdArch
640 let Inst{31-26} = 0x10;
644 let Inst{5-0} = funct;
647 //===----------------------------------------------------------------------===//
648 // Enable/disable interrupt instruction format <Cop0|MFMC0|rt|12|0|sc|0|0>
649 //===----------------------------------------------------------------------===//
651 class EI_FM<bits<1> sc> : StdArch
655 let Inst{31-26} = 0x10;
656 let Inst{25-21} = 0xb;
657 let Inst{20-16} = rt;
658 let Inst{15-11} = 0xc;
664 //===----------------------------------------------------------------------===//
666 // FLOATING POINT INSTRUCTION FORMATS
668 // opcode - operation code.
670 // ft - dst reg (on a 2 regs instr) or src reg (on a 3 reg instr).
671 // fd - dst reg, only used on 3 regs instr.
672 // fmt - double or single precision.
673 // funct - combined with opcode field give us an operation code.
675 //===----------------------------------------------------------------------===//
677 //===----------------------------------------------------------------------===//
678 // Format FI instruction class in Mips : <|opcode|base|ft|immediate|>
679 //===----------------------------------------------------------------------===//
681 class ADDS_FM<bits<6> funct, bits<5> fmt> : StdArch {
688 let Inst{31-26} = 0x11;
689 let Inst{25-21} = fmt;
690 let Inst{20-16} = ft;
691 let Inst{15-11} = fs;
693 let Inst{5-0} = funct;
696 class ABSS_FM<bits<6> funct, bits<5> fmt> : StdArch {
702 let Inst{31-26} = 0x11;
703 let Inst{25-21} = fmt;
705 let Inst{15-11} = fs;
707 let Inst{5-0} = funct;
710 class MFC1_FM<bits<5> funct> : StdArch {
716 let Inst{31-26} = 0x11;
717 let Inst{25-21} = funct;
718 let Inst{20-16} = rt;
719 let Inst{15-11} = fs;
723 class LW_FM<bits<6> op> : StdArch {
729 let Inst{31-26} = op;
730 let Inst{25-21} = addr{20-16};
731 let Inst{20-16} = rt;
732 let Inst{15-0} = addr{15-0};
735 class MADDS_FM<bits<3> funct, bits<3> fmt> : StdArch {
743 let Inst{31-26} = 0x13;
744 let Inst{25-21} = fr;
745 let Inst{20-16} = ft;
746 let Inst{15-11} = fs;
748 let Inst{5-3} = funct;
752 class LWXC1_FM<bits<6> funct> : StdArch {
759 let Inst{31-26} = 0x13;
760 let Inst{25-21} = base;
761 let Inst{20-16} = index;
764 let Inst{5-0} = funct;
767 class SWXC1_FM<bits<6> funct> : StdArch {
774 let Inst{31-26} = 0x13;
775 let Inst{25-21} = base;
776 let Inst{20-16} = index;
777 let Inst{15-11} = fs;
779 let Inst{5-0} = funct;
782 class BC1F_FM<bit nd, bit tf> : StdArch {
788 let Inst{31-26} = 0x11;
789 let Inst{25-21} = 0x8;
790 let Inst{20-18} = fcc;
793 let Inst{15-0} = offset;
796 class CEQS_FM<bits<5> fmt> : StdArch {
804 let Inst{31-26} = 0x11;
805 let Inst{25-21} = fmt;
806 let Inst{20-16} = ft;
807 let Inst{15-11} = fs;
808 let Inst{10-8} = fcc;
810 let Inst{3-0} = cond;
813 class C_COND_FM<bits<5> fmt, bits<4> c> : CEQS_FM<fmt> {
817 class CMov_I_F_FM<bits<6> funct, bits<5> fmt> : StdArch {
824 let Inst{31-26} = 0x11;
825 let Inst{25-21} = fmt;
826 let Inst{20-16} = rt;
827 let Inst{15-11} = fs;
829 let Inst{5-0} = funct;
832 class CMov_F_I_FM<bit tf> : StdArch {
840 let Inst{25-21} = rs;
841 let Inst{20-18} = fcc;
844 let Inst{15-11} = rd;
849 class CMov_F_F_FM<bits<5> fmt, bit tf> : StdArch {
856 let Inst{31-26} = 0x11;
857 let Inst{25-21} = fmt;
858 let Inst{20-18} = fcc;
861 let Inst{15-11} = fs;
863 let Inst{5-0} = 0x11;
866 class BARRIER_FM<bits<5> op> : StdArch {
869 let Inst{31-26} = 0; // SPECIAL
871 let Inst{20-16} = 0; // rt = 0
872 let Inst{15-11} = 0; // rd = 0
873 let Inst{10-6} = op; // Operation
874 let Inst{5-0} = 0; // SLL
877 class SDBBP_FM : StdArch {
882 let Inst{31-26} = 0b011100; // SPECIAL2
883 let Inst{25-6} = code_;
884 let Inst{5-0} = 0b111111; // SDBBP
887 class JR_HB_FM<bits<6> op> : StdArch{
892 let Inst{31-26} = 0; // SPECIAL
893 let Inst{25-21} = rs;
900 class JALR_HB_FM<bits<6> op> : StdArch {
906 let Inst{31-26} = 0; // SPECIAL
907 let Inst{25-21} = rs;
909 let Inst{15-11} = rd;
915 class COP0_TLB_FM<bits<6> op> : StdArch {
918 let Inst{31-26} = 0x10; // COP0
919 let Inst{25} = 1; // CO
921 let Inst{5-0} = op; // Operation
924 class CACHEOP_FM<bits<6> op> : StdArch {
927 bits<5> base = addr{20-16};
928 bits<16> offset = addr{15-0};
932 let Inst{31-26} = op;
933 let Inst{25-21} = base;
934 let Inst{20-16} = hint;
935 let Inst{15-0} = offset;
938 class HYPCALL_FM<bits<6> op> : StdArch {
943 let Inst{31-26} = 0b010000;
945 let Inst{20-11} = code_;