1 //=- Mips32r6InstrFormats.td - Mips32r6 Instruction Formats -*- tablegen -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes Mips32r6 instruction formats.
12 //===----------------------------------------------------------------------===//
16 def MipsR62MicroMipsR6 : InstrMapping {
17 let FilterClass = "R6MMR6Rel";
18 // Instructions with the same BaseOpcode and isNVStore values form a row.
19 let RowFields = ["BaseOpcode"];
20 // Instructions with the same predicate sense form a column.
21 let ColFields = ["Arch"];
22 // The key column is the unpredicated instructions.
23 let KeyCol = ["mipsr6"];
24 // Value columns are PredSense=true and PredSense=false
25 let ValueCols = [["mipsr6"], ["micromipsr6"]];
28 class MipsR6Arch<string opstr> {
29 string Arch = "mipsr6";
30 string BaseOpcode = opstr;
33 class MipsR6Inst : MipsInst<(outs), (ins), "", [], NoItinerary, FrmOther>,
35 let DecoderNamespace = "Mips32r6_64r6";
36 let EncodingPredicates = [HasStdEnc];
39 //===----------------------------------------------------------------------===//
43 //===----------------------------------------------------------------------===//
45 class OPGROUP<bits<6> Val> {
48 def OPGROUP_COP1 : OPGROUP<0b010001>;
49 def OPGROUP_COP2 : OPGROUP<0b010010>;
50 def OPGROUP_ADDI : OPGROUP<0b001000>;
51 def OPGROUP_AUI : OPGROUP<0b001111>;
52 def OPGROUP_BLEZ : OPGROUP<0b000110>;
53 def OPGROUP_BGTZ : OPGROUP<0b000111>;
54 def OPGROUP_BLEZL : OPGROUP<0b010110>;
55 def OPGROUP_BGTZL : OPGROUP<0b010111>;
56 def OPGROUP_DADDI : OPGROUP<0b011000>;
57 def OPGROUP_DAUI : OPGROUP<0b011101>;
58 def OPGROUP_PCREL : OPGROUP<0b111011>;
59 def OPGROUP_REGIMM : OPGROUP<0b000001>;
60 def OPGROUP_SPECIAL : OPGROUP<0b000000>;
61 // The spec occasionally names this value LL, LLD, SC, or SCD.
62 def OPGROUP_SPECIAL3 : OPGROUP<0b011111>;
63 // The spec names this constant LWC2, LDC2, SWC2, and SDC2 in different places.
64 def OPGROUP_COP2LDST : OPGROUP<0b010010>;
66 class OPCODE2<bits<2> Val> {
69 def OPCODE2_ADDIUPC : OPCODE2<0b00>;
70 def OPCODE2_LWPC : OPCODE2<0b01>;
71 def OPCODE2_LWUPC : OPCODE2<0b10>;
73 class OPCODE3<bits<3> Val> {
76 def OPCODE3_LDPC : OPCODE3<0b110>;
78 class OPCODE5<bits<5> Val> {
81 def OPCODE5_ALUIPC : OPCODE5<0b11111>;
82 def OPCODE5_AUIPC : OPCODE5<0b11110>;
83 def OPCODE5_DAHI : OPCODE5<0b00110>;
84 def OPCODE5_DATI : OPCODE5<0b11110>;
85 def OPCODE5_BC1EQZ : OPCODE5<0b01001>;
86 def OPCODE5_BC1NEZ : OPCODE5<0b01101>;
87 def OPCODE5_BC2EQZ : OPCODE5<0b01001>;
88 def OPCODE5_BC2NEZ : OPCODE5<0b01101>;
89 def OPCODE5_BGEZAL : OPCODE5<0b10001>;
90 // The next four constants are unnamed in the spec. These names are taken from
91 // the OPGROUP names they are used with.
92 def OPCODE5_LDC2 : OPCODE5<0b01110>;
93 def OPCODE5_LWC2 : OPCODE5<0b01010>;
94 def OPCODE5_SDC2 : OPCODE5<0b01111>;
95 def OPCODE5_SWC2 : OPCODE5<0b01011>;
97 class OPCODE6<bits<6> Val> {
100 def OPCODE6_ALIGN : OPCODE6<0b100000>;
101 def OPCODE6_DALIGN : OPCODE6<0b100100>;
102 def OPCODE6_BITSWAP : OPCODE6<0b100000>;
103 def OPCODE6_DBITSWAP : OPCODE6<0b100100>;
104 def OPCODE6_JALR : OPCODE6<0b001001>;
105 def OPCODE6_CACHE : OPCODE6<0b100101>;
106 def OPCODE6_PREF : OPCODE6<0b110101>;
107 // The next four constants are unnamed in the spec. These names are taken from
108 // the OPGROUP names they are used with.
109 def OPCODE6_LL : OPCODE6<0b110110>;
110 def OPCODE6_LLD : OPCODE6<0b110111>;
111 def OPCODE6_SC : OPCODE6<0b100110>;
112 def OPCODE6_SCD : OPCODE6<0b100111>;
113 def OPCODE6_CLO : OPCODE6<0b010001>;
114 def OPCODE6_CLZ : OPCODE6<0b010000>;
115 def OPCODE6_DCLO : OPCODE6<0b010011>;
116 def OPCODE6_DCLZ : OPCODE6<0b010010>;
117 def OPCODE6_LSA : OPCODE6<0b000101>;
118 def OPCODE6_DLSA : OPCODE6<0b010101>;
119 def OPCODE6_SDBBP : OPCODE6<0b001110>;
121 class FIELD_FMT<bits<5> Val> {
124 def FIELD_FMT_S : FIELD_FMT<0b10000>;
125 def FIELD_FMT_D : FIELD_FMT<0b10001>;
127 class FIELD_CMP_COND<bits<5> Val> {
130 // Note: The CMP_COND_FMT names differ from the C_COND_FMT names.
131 def FIELD_CMP_COND_AF : FIELD_CMP_COND<0b00000>;
132 def FIELD_CMP_COND_UN : FIELD_CMP_COND<0b00001>;
133 def FIELD_CMP_COND_EQ : FIELD_CMP_COND<0b00010>;
134 def FIELD_CMP_COND_UEQ : FIELD_CMP_COND<0b00011>;
135 def FIELD_CMP_COND_LT : FIELD_CMP_COND<0b00100>;
136 def FIELD_CMP_COND_ULT : FIELD_CMP_COND<0b00101>;
137 def FIELD_CMP_COND_LE : FIELD_CMP_COND<0b00110>;
138 def FIELD_CMP_COND_ULE : FIELD_CMP_COND<0b00111>;
139 def FIELD_CMP_COND_SAF : FIELD_CMP_COND<0b01000>;
140 def FIELD_CMP_COND_SUN : FIELD_CMP_COND<0b01001>;
141 def FIELD_CMP_COND_SEQ : FIELD_CMP_COND<0b01010>;
142 def FIELD_CMP_COND_SUEQ : FIELD_CMP_COND<0b01011>;
143 def FIELD_CMP_COND_SLT : FIELD_CMP_COND<0b01100>;
144 def FIELD_CMP_COND_SULT : FIELD_CMP_COND<0b01101>;
145 def FIELD_CMP_COND_SLE : FIELD_CMP_COND<0b01110>;
146 def FIELD_CMP_COND_SULE : FIELD_CMP_COND<0b01111>;
148 class FIELD_CMP_FORMAT<bits<5> Val> {
151 def FIELD_CMP_FORMAT_S : FIELD_CMP_FORMAT<0b10100>;
152 def FIELD_CMP_FORMAT_D : FIELD_CMP_FORMAT<0b10101>;
154 //===----------------------------------------------------------------------===//
158 //===----------------------------------------------------------------------===//
160 // Some encodings are ambiguous except by comparing field values.
162 class DecodeDisambiguates<string Name> {
163 string DecoderMethod = !strconcat("Decode", Name);
166 class DecodeDisambiguatedBy<string Name> : DecodeDisambiguates<Name> {
167 string DecoderNamespace = "Mips32r6_64r6_Ambiguous";
170 //===----------------------------------------------------------------------===//
174 //===----------------------------------------------------------------------===//
176 class AUI_FM : MipsR6Inst {
183 let Inst{31-26} = OPGROUP_AUI.Value;
184 let Inst{25-21} = rs;
185 let Inst{20-16} = rt;
186 let Inst{15-0} = imm;
189 class DAUI_FM : AUI_FM {
190 let Inst{31-26} = OPGROUP_DAUI.Value;
193 class BAL_FM : MipsR6Inst {
198 let Inst{31-26} = OPGROUP_REGIMM.Value;
199 let Inst{25-21} = 0b00000;
200 let Inst{20-16} = OPCODE5_BGEZAL.Value;
201 let Inst{15-0} = offset;
204 class COP1_2R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst {
210 let Inst{31-26} = OPGROUP_COP1.Value;
211 let Inst{25-21} = Format.Value;
212 let Inst{20-16} = 0b00000;
213 let Inst{15-11} = fs;
215 let Inst{5-0} = funct;
218 class COP1_3R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst {
225 let Inst{31-26} = OPGROUP_COP1.Value;
226 let Inst{25-21} = Format.Value;
227 let Inst{20-16} = ft;
228 let Inst{15-11} = fs;
230 let Inst{5-0} = funct;
233 class COP1_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst {
239 let Inst{31-26} = OPGROUP_COP1.Value;
240 let Inst{25-21} = Operation.Value;
241 let Inst{20-16} = ft;
242 let Inst{15-0} = offset;
245 class COP2_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst {
251 let Inst{31-26} = OPGROUP_COP2.Value;
252 let Inst{25-21} = Operation.Value;
253 let Inst{20-16} = ct;
254 let Inst{15-0} = offset;
257 class PCREL16_FM<OPCODE5 Operation> : MipsR6Inst {
263 let Inst{31-26} = OPGROUP_PCREL.Value;
264 let Inst{25-21} = rs;
265 let Inst{20-16} = Operation.Value;
266 let Inst{15-0} = imm;
269 class PCREL19_FM<OPCODE2 Operation> : MipsR6Inst {
275 let Inst{31-26} = OPGROUP_PCREL.Value;
276 let Inst{25-21} = rs;
277 let Inst{20-19} = Operation.Value;
278 let Inst{18-0} = imm;
281 class PCREL18_FM<OPCODE3 Operation> : MipsR6Inst {
287 let Inst{31-26} = OPGROUP_PCREL.Value;
288 let Inst{25-21} = rs;
289 let Inst{20-18} = Operation.Value;
290 let Inst{17-0} = imm;
293 class SPECIAL3_2R_FM<OPCODE6 Operation> : MipsR6Inst {
299 let Inst{31-26} = OPGROUP_SPECIAL3.Value;
300 let Inst{25-21} = 0b00000;
301 let Inst{20-16} = rt;
302 let Inst{15-11} = rd;
303 let Inst{10-6} = 0b00000;
304 let Inst{5-0} = Operation.Value;
307 class SPECIAL3_MEM_FM<OPCODE6 Operation> : MipsR6Inst {
310 bits<5> base = addr{20-16};
311 bits<9> offset = addr{8-0};
315 let Inst{31-26} = OPGROUP_SPECIAL3.Value;
316 let Inst{25-21} = base;
317 let Inst{20-16} = hint;
318 let Inst{15-7} = offset;
320 let Inst{5-0} = Operation.Value;
323 class SPECIAL_2R_FM<OPCODE6 Operation> : MipsR6Inst {
329 let Inst{31-26} = OPGROUP_SPECIAL.Value;
330 let Inst{25-21} = rs;
331 let Inst{20-16} = 0b00000;
332 let Inst{15-11} = rd;
333 let Inst{10-6} = 0b00001;
334 let Inst{5-0} = Operation.Value;
337 class SPECIAL_3R_FM<bits<5> mulop, bits<6> funct> : MipsR6Inst {
344 let Inst{31-26} = OPGROUP_SPECIAL.Value;
345 let Inst{25-21} = rs;
346 let Inst{20-16} = rt;
347 let Inst{15-11} = rd;
348 let Inst{10-6} = mulop;
349 let Inst{5-0} = funct;
352 class SPECIAL_SDBBP_FM : MipsR6Inst {
357 let Inst{31-26} = OPGROUP_SPECIAL.Value;
358 let Inst{25-6} = code_;
359 let Inst{5-0} = OPCODE6_SDBBP.Value;
362 // This class is ambiguous with other branches:
363 // BEQC/BNEC require that rs > rt
364 class CMP_BRANCH_2R_OFF16_FM<OPGROUP funct> : MipsR6Inst {
371 let Inst{31-26} = funct.Value;
372 let Inst{25-21} = rs;
373 let Inst{20-16} = rt;
374 let Inst{15-0} = offset;
377 // This class is ambiguous with other branches:
378 // BLEZC/BGEZC/BEQZALC/BNEZALC/BGTZALC require that rs == 0 && rt != 0
379 // The '1R_RT' in the name means 1 register in the rt field.
380 class CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP funct> : MipsR6Inst {
386 let Inst{31-26} = funct.Value;
387 let Inst{25-21} = 0b00000;
388 let Inst{20-16} = rt;
389 let Inst{15-0} = offset;
392 // This class is ambiguous with other branches:
393 // BLTZC/BGTZC/BLTZALC/BGEZALC require that rs == rt && rt != 0
394 // The '1R_BOTH' in the name means 1 register in both the rs and rt fields.
395 class CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP funct> : MipsR6Inst {
401 let Inst{31-26} = funct.Value;
402 let Inst{25-21} = rt;
403 let Inst{20-16} = rt;
404 let Inst{15-0} = offset;
407 class CMP_BRANCH_OFF21_FM<bits<6> funct> : MipsR6Inst {
408 bits<5> rs; // rs != 0
413 let Inst{31-26} = funct;
414 let Inst{25-21} = rs;
415 let Inst{20-0} = offset;
418 class JMP_IDX_COMPACT_FM<bits<6> funct> : MipsR6Inst {
424 let Inst{31-26} = funct;
425 let Inst{25-21} = 0b00000;
426 let Inst{20-16} = rt;
427 let Inst{15-0} = offset;
430 class BRANCH_OFF26_FM<bits<6> funct> : MipsR6Inst {
434 let Inst{31-26} = funct;
435 let Inst{25-0} = offset;
438 class SPECIAL3_ALIGN_FM<OPCODE6 Operation> : MipsR6Inst {
446 let Inst{31-26} = OPGROUP_SPECIAL3.Value;
447 let Inst{25-21} = rs;
448 let Inst{20-16} = rt;
449 let Inst{15-11} = rd;
450 let Inst{10-8} = 0b010;
452 let Inst{5-0} = Operation.Value;
455 class SPECIAL3_DALIGN_FM<OPCODE6 Operation> : MipsR6Inst {
463 let Inst{31-26} = OPGROUP_SPECIAL3.Value;
464 let Inst{25-21} = rs;
465 let Inst{20-16} = rt;
466 let Inst{15-11} = rd;
467 let Inst{10-9} = 0b01;
469 let Inst{5-0} = Operation.Value;
472 class SPECIAL3_LL_SC_FM<OPCODE6 Operation> : MipsR6Inst {
475 bits<5> base = addr{20-16};
476 bits<9> offset = addr{8-0};
480 let Inst{31-26} = OPGROUP_SPECIAL3.Value;
481 let Inst{25-21} = base;
482 let Inst{20-16} = rt;
483 let Inst{15-7} = offset;
484 let Inst{5-0} = Operation.Value;
486 string DecoderMethod = "DecodeSpecial3LlSc";
489 class SPECIAL_LSA_FM<OPCODE6 Operation> : MipsR6Inst {
497 let Inst{31-26} = OPGROUP_SPECIAL.Value;
498 let Inst{25-21} = rs;
499 let Inst{20-16} = rt;
500 let Inst{15-11} = rd;
501 let Inst{10-8} = 0b000;
502 let Inst{7-6} = imm2;
503 let Inst{5-0} = Operation.Value;
506 class REGIMM_FM<OPCODE5 Operation> : MipsR6Inst {
512 let Inst{31-26} = OPGROUP_REGIMM.Value;
513 let Inst{25-21} = rs;
514 let Inst{20-16} = Operation.Value;
515 let Inst{15-0} = imm;
518 class COP1_CMP_CONDN_FM<FIELD_CMP_FORMAT Format,
519 FIELD_CMP_COND Cond> : MipsR6Inst {
526 let Inst{31-26} = OPGROUP_COP1.Value;
527 let Inst{25-21} = Format.Value;
528 let Inst{20-16} = ft;
529 let Inst{15-11} = fs;
532 let Inst{4-0} = Cond.Value;
535 class JR_HB_R6_FM<OPCODE6 Operation> : MipsR6Inst {
540 let Inst{31-26} = OPGROUP_SPECIAL.Value;
541 let Inst{25-21} = rs;
546 let Inst{5-0} = Operation.Value;
549 class COP2LDST_FM<OPCODE5 Operation> : MipsR6Inst {
552 bits<5> base = addr{20-16};
553 bits<11> offset = addr{10-0};
557 let Inst{31-26} = OPGROUP_COP2LDST.Value;
558 let Inst{25-21} = Operation.Value;
559 let Inst{20-16} = rt;
560 let Inst{15-11} = base;
561 let Inst{10-0} = offset;