xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Mips/Mips32r6InstrFormats.td (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1//=- Mips32r6InstrFormats.td - Mips32r6 Instruction Formats -*- tablegen -*-==//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file describes Mips32r6 instruction formats.
10//
11//===----------------------------------------------------------------------===//
12
13class R6MMR6Rel;
14
15def MipsR62MicroMipsR6 : InstrMapping {
16  let FilterClass = "R6MMR6Rel";
17  // Instructions with the same BaseOpcode and isNVStore values form a row.
18  let RowFields = ["BaseOpcode"];
19  // Instructions with the same predicate sense form a column.
20  let ColFields = ["Arch"];
21  // The key column is the unpredicated instructions.
22  let KeyCol = ["mipsr6"];
23  // Value columns are PredSense=true and PredSense=false
24  let ValueCols = [["mipsr6"], ["micromipsr6"]];
25}
26
27class MipsR6Arch<string opstr> {
28  string Arch = "mipsr6";
29  string BaseOpcode = opstr;
30}
31
32class MipsR6Inst : MipsInst<(outs), (ins), "", [], NoItinerary, FrmOther> {
33  let DecoderNamespace = "Mips32r6_64r6";
34  let EncodingPredicates = [HasStdEnc];
35}
36
37//===----------------------------------------------------------------------===//
38//
39// Field Values
40//
41//===----------------------------------------------------------------------===//
42
43class OPGROUP<bits<6> Val> {
44  bits<6> Value = Val;
45}
46def OPGROUP_COP0     : OPGROUP<0b010000>;
47def OPGROUP_COP1     : OPGROUP<0b010001>;
48def OPGROUP_COP2     : OPGROUP<0b010010>;
49def OPGROUP_ADDI     : OPGROUP<0b001000>;
50def OPGROUP_AUI      : OPGROUP<0b001111>;
51def OPGROUP_BLEZ     : OPGROUP<0b000110>;
52def OPGROUP_BGTZ     : OPGROUP<0b000111>;
53def OPGROUP_BLEZL    : OPGROUP<0b010110>;
54def OPGROUP_BGTZL    : OPGROUP<0b010111>;
55def OPGROUP_DADDI    : OPGROUP<0b011000>;
56def OPGROUP_DAUI     : OPGROUP<0b011101>;
57def OPGROUP_PCREL    : OPGROUP<0b111011>;
58def OPGROUP_REGIMM   : OPGROUP<0b000001>;
59def OPGROUP_SPECIAL  : OPGROUP<0b000000>;
60// The spec occasionally names this value LL, LLD, SC, or SCD.
61def OPGROUP_SPECIAL3 : OPGROUP<0b011111>;
62// The spec names this constant LWC2, LDC2, SWC2, and SDC2 in different places.
63def OPGROUP_COP2LDST : OPGROUP<0b010010>;
64
65class OPCODE2<bits<2> Val> {
66  bits<2> Value = Val;
67}
68def OPCODE2_ADDIUPC : OPCODE2<0b00>;
69def OPCODE2_LWPC    : OPCODE2<0b01>;
70def OPCODE2_LWUPC   : OPCODE2<0b10>;
71
72class OPCODE3<bits<3> Val> {
73  bits<3> Value = Val;
74}
75def OPCODE3_LDPC : OPCODE3<0b110>;
76
77class OPCODE5<bits<5> Val> {
78  bits<5> Value = Val;
79}
80def OPCODE5_ALUIPC : OPCODE5<0b11111>;
81def OPCODE5_AUIPC  : OPCODE5<0b11110>;
82def OPCODE5_DAHI : OPCODE5<0b00110>;
83def OPCODE5_DATI : OPCODE5<0b11110>;
84def OPCODE5_BC1EQZ : OPCODE5<0b01001>;
85def OPCODE5_BC1NEZ : OPCODE5<0b01101>;
86def OPCODE5_BC2EQZ : OPCODE5<0b01001>;
87def OPCODE5_BC2NEZ : OPCODE5<0b01101>;
88def OPCODE5_BGEZAL : OPCODE5<0b10001>;
89def OPCODE5_SIGRIE : OPCODE5<0b10111>;
90// The next four constants are unnamed in the spec. These names are taken from
91// the OPGROUP names they are used with.
92def OPCODE5_LDC2   : OPCODE5<0b01110>;
93def OPCODE5_LWC2   : OPCODE5<0b01010>;
94def OPCODE5_SDC2   : OPCODE5<0b01111>;
95def OPCODE5_SWC2   : OPCODE5<0b01011>;
96
97class OPCODE6<bits<6> Val> {
98  bits<6> Value = Val;
99}
100def OPCODE6_ALIGN    : OPCODE6<0b100000>;
101def OPCODE6_DALIGN   : OPCODE6<0b100100>;
102def OPCODE6_BITSWAP  : OPCODE6<0b100000>;
103def OPCODE6_DBITSWAP : OPCODE6<0b100100>;
104def OPCODE6_JALR     : OPCODE6<0b001001>;
105def OPCODE6_CACHE    : OPCODE6<0b100101>;
106def 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.
109def OPCODE6_LL       : OPCODE6<0b110110>;
110def OPCODE6_LLD      : OPCODE6<0b110111>;
111def OPCODE6_SC       : OPCODE6<0b100110>;
112def OPCODE6_SCD      : OPCODE6<0b100111>;
113def OPCODE6_CLO      : OPCODE6<0b010001>;
114def OPCODE6_CLZ      : OPCODE6<0b010000>;
115def OPCODE6_DCLO     : OPCODE6<0b010011>;
116def OPCODE6_DCLZ     : OPCODE6<0b010010>;
117def OPCODE6_LSA      : OPCODE6<0b000101>;
118def OPCODE6_DLSA     : OPCODE6<0b010101>;
119def OPCODE6_SDBBP    : OPCODE6<0b001110>;
120
121class FIELD_FMT<bits<5> Val> {
122  bits<5> Value = Val;
123}
124def FIELD_FMT_S : FIELD_FMT<0b10000>;
125def FIELD_FMT_D : FIELD_FMT<0b10001>;
126
127class FIELD_CMP_COND<bits<5> Val> {
128  bits<5> Value = Val;
129}
130// Note: The CMP_COND_FMT names differ from the C_COND_FMT names.
131def FIELD_CMP_COND_AF   : FIELD_CMP_COND<0b00000>;
132def FIELD_CMP_COND_UN   : FIELD_CMP_COND<0b00001>;
133def FIELD_CMP_COND_EQ   : FIELD_CMP_COND<0b00010>;
134def FIELD_CMP_COND_UEQ  : FIELD_CMP_COND<0b00011>;
135def FIELD_CMP_COND_LT   : FIELD_CMP_COND<0b00100>;
136def FIELD_CMP_COND_ULT  : FIELD_CMP_COND<0b00101>;
137def FIELD_CMP_COND_LE   : FIELD_CMP_COND<0b00110>;
138def FIELD_CMP_COND_ULE  : FIELD_CMP_COND<0b00111>;
139def FIELD_CMP_COND_SAF  : FIELD_CMP_COND<0b01000>;
140def FIELD_CMP_COND_SUN  : FIELD_CMP_COND<0b01001>;
141def FIELD_CMP_COND_SEQ  : FIELD_CMP_COND<0b01010>;
142def FIELD_CMP_COND_SUEQ : FIELD_CMP_COND<0b01011>;
143def FIELD_CMP_COND_SLT  : FIELD_CMP_COND<0b01100>;
144def FIELD_CMP_COND_SULT : FIELD_CMP_COND<0b01101>;
145def FIELD_CMP_COND_SLE  : FIELD_CMP_COND<0b01110>;
146def FIELD_CMP_COND_SULE : FIELD_CMP_COND<0b01111>;
147
148class FIELD_CMP_FORMAT<bits<5> Val> {
149  bits<5> Value = Val;
150}
151def FIELD_CMP_FORMAT_S : FIELD_CMP_FORMAT<0b10100>;
152def FIELD_CMP_FORMAT_D : FIELD_CMP_FORMAT<0b10101>;
153
154//===----------------------------------------------------------------------===//
155//
156// Disambiguators
157//
158//===----------------------------------------------------------------------===//
159//
160// Some encodings are ambiguous except by comparing field values.
161
162class DecodeDisambiguates<string Name> {
163  string DecoderMethod = !strconcat("Decode", Name);
164}
165
166class DecodeDisambiguatedBy<string Name> : DecodeDisambiguates<Name> {
167  string DecoderNamespace = "Mips32r6_64r6_Ambiguous";
168}
169
170//===----------------------------------------------------------------------===//
171//
172// Encoding Formats
173//
174//===----------------------------------------------------------------------===//
175
176class AUI_FM : MipsR6Inst {
177  bits<5> rs;
178  bits<5> rt;
179  bits<16> imm;
180
181  bits<32> Inst;
182
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;
187}
188
189class DAUI_FM : AUI_FM {
190  let Inst{31-26} = OPGROUP_DAUI.Value;
191}
192
193class BAL_FM : MipsR6Inst {
194  bits<16> offset;
195
196  bits<32> Inst;
197
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;
202}
203
204class COP0_EVP_DVP_FM<bits<1> sc> : MipsR6Inst {
205  bits<5> rt;
206
207  bits<32> Inst;
208
209  let Inst{31-26} = OPGROUP_COP0.Value;
210  let Inst{25-21} = 0b01011;
211  let Inst{20-16} = rt;
212  let Inst{15-11} = 0b00000;
213  let Inst{10-6}  = 0b00000;
214  let Inst{5}     = sc;
215  let Inst{4-3}   = 0b00;
216  let Inst{2-0}   = 0b100;
217}
218
219class COP1_2R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst {
220  bits<5> fs;
221  bits<5> fd;
222
223  bits<32> Inst;
224
225  let Inst{31-26} = OPGROUP_COP1.Value;
226  let Inst{25-21} = Format.Value;
227  let Inst{20-16} = 0b00000;
228  let Inst{15-11} = fs;
229  let Inst{10-6}  = fd;
230  let Inst{5-0}   = funct;
231}
232
233class COP1_3R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst {
234  bits<5> ft;
235  bits<5> fs;
236  bits<5> fd;
237
238  bits<32> Inst;
239
240  let Inst{31-26} = OPGROUP_COP1.Value;
241  let Inst{25-21} = Format.Value;
242  let Inst{20-16} = ft;
243  let Inst{15-11} = fs;
244  let Inst{10-6} = fd;
245  let Inst{5-0} = funct;
246}
247
248class COP1_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst {
249  bits<5> ft;
250  bits<16> offset;
251
252  bits<32> Inst;
253
254  let Inst{31-26} = OPGROUP_COP1.Value;
255  let Inst{25-21} = Operation.Value;
256  let Inst{20-16} = ft;
257  let Inst{15-0} = offset;
258}
259
260class COP2_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst {
261  bits<5> ct;
262  bits<16> offset;
263
264  bits<32> Inst;
265
266  let Inst{31-26} = OPGROUP_COP2.Value;
267  let Inst{25-21} = Operation.Value;
268  let Inst{20-16} = ct;
269  let Inst{15-0} = offset;
270}
271
272class PCREL16_FM<OPCODE5 Operation> : MipsR6Inst {
273  bits<5> rs;
274  bits<16> imm;
275
276  bits<32> Inst;
277
278  let Inst{31-26} = OPGROUP_PCREL.Value;
279  let Inst{25-21} = rs;
280  let Inst{20-16} = Operation.Value;
281  let Inst{15-0} = imm;
282}
283
284class PCREL19_FM<OPCODE2 Operation> : MipsR6Inst {
285  bits<5> rs;
286  bits<19> imm;
287
288  bits<32> Inst;
289
290  let Inst{31-26} = OPGROUP_PCREL.Value;
291  let Inst{25-21} = rs;
292  let Inst{20-19} = Operation.Value;
293  let Inst{18-0} = imm;
294}
295
296class PCREL18_FM<OPCODE3 Operation> : MipsR6Inst {
297  bits<5> rs;
298  bits<18> imm;
299
300  bits<32> Inst;
301
302  let Inst{31-26} = OPGROUP_PCREL.Value;
303  let Inst{25-21} = rs;
304  let Inst{20-18} = Operation.Value;
305  let Inst{17-0} = imm;
306}
307
308class SPECIAL3_2R_FM<OPCODE6 Operation> : MipsR6Inst {
309  bits<5> rd;
310  bits<5> rt;
311
312  bits<32> Inst;
313
314  let Inst{31-26} = OPGROUP_SPECIAL3.Value;
315  let Inst{25-21} = 0b00000;
316  let Inst{20-16} = rt;
317  let Inst{15-11} = rd;
318  let Inst{10-6}  = 0b00000;
319  let Inst{5-0}   = Operation.Value;
320}
321
322class SPECIAL3_MEM_FM<OPCODE6 Operation> : MipsR6Inst {
323  bits<21> addr;
324  bits<5> hint;
325  bits<5> base = addr{20-16};
326  bits<9> offset = addr{8-0};
327
328  bits<32> Inst;
329
330  let Inst{31-26} = OPGROUP_SPECIAL3.Value;
331  let Inst{25-21} = base;
332  let Inst{20-16} = hint;
333  let Inst{15-7}  = offset;
334  let Inst{6}     = 0;
335  let Inst{5-0}   = Operation.Value;
336}
337
338class SPECIAL_2R_FM<OPCODE6 Operation> : MipsR6Inst {
339  bits<5> rd;
340  bits<5> rs;
341
342  bits<32> Inst;
343
344  let Inst{31-26} = OPGROUP_SPECIAL.Value;
345  let Inst{25-21} = rs;
346  let Inst{20-16} = 0b00000;
347  let Inst{15-11} = rd;
348  let Inst{10-6}  = 0b00001;
349  let Inst{5-0}   = Operation.Value;
350}
351
352class SPECIAL_3R_FM<bits<5> mulop, bits<6> funct> : MipsR6Inst {
353  bits<5> rd;
354  bits<5> rs;
355  bits<5> rt;
356
357  bits<32> Inst;
358
359  let Inst{31-26} = OPGROUP_SPECIAL.Value;
360  let Inst{25-21} = rs;
361  let Inst{20-16} = rt;
362  let Inst{15-11} = rd;
363  let Inst{10-6}  = mulop;
364  let Inst{5-0}   = funct;
365}
366
367class SPECIAL_SDBBP_FM : MipsR6Inst {
368  bits<20> code_;
369
370  bits<32> Inst;
371
372  let Inst{31-26} = OPGROUP_SPECIAL.Value;
373  let Inst{25-6}  = code_;
374  let Inst{5-0}   = OPCODE6_SDBBP.Value;
375}
376
377// This class is ambiguous with other branches:
378//   BEQC/BNEC require that rs < rt && rs != 0
379class CMP_BRANCH_2R_OFF16_FM<OPGROUP funct> : MipsR6Inst {
380  bits<5> rs;
381  bits<5> rt;
382  bits<16> offset;
383
384  bits<32> Inst;
385
386  let Inst{31-26} = funct.Value;
387  let Inst{25-21} = rs;
388  let Inst{20-16} = rt;
389  let Inst{15-0} = offset;
390}
391
392// This class is ambiguous with other branches:
393//   BLEZC/BGEZC/BEQZALC/BNEZALC/BGTZALC require that rs == 0 && rt != 0
394// The '1R_RT' in the name means 1 register in the rt field.
395class CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP funct> : MipsR6Inst {
396  bits<5> rt;
397  bits<16> offset;
398
399  bits<32> Inst;
400
401  let Inst{31-26} = funct.Value;
402  let Inst{25-21} = 0b00000;
403  let Inst{20-16} = rt;
404  let Inst{15-0} = offset;
405}
406
407// This class is ambiguous with other branches:
408//   BLTZC/BGTZC/BLTZALC/BGEZALC require that rs == rt && rt != 0
409// The '1R_BOTH' in the name means 1 register in both the rs and rt fields.
410class CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP funct> : MipsR6Inst {
411  bits<5> rt;
412  bits<16> offset;
413
414  bits<32> Inst;
415
416  let Inst{31-26} = funct.Value;
417  let Inst{25-21} = rt;
418  let Inst{20-16} = rt;
419  let Inst{15-0} = offset;
420}
421
422class CMP_BRANCH_OFF21_FM<bits<6> funct> : MipsR6Inst {
423  bits<5> rs; // rs != 0
424  bits<21> offset;
425
426  bits<32> Inst;
427
428  let Inst{31-26} = funct;
429  let Inst{25-21} = rs;
430  let Inst{20-0} = offset;
431}
432
433class JMP_IDX_COMPACT_FM<bits<6> funct> : MipsR6Inst {
434  bits<5> rt;
435  bits<16> offset;
436
437  bits<32> Inst;
438
439  let Inst{31-26} = funct;
440  let Inst{25-21} = 0b00000;
441  let Inst{20-16} = rt;
442  let Inst{15-0} = offset;
443}
444
445class BRANCH_OFF26_FM<bits<6> funct> : MipsR6Inst {
446  bits<32> Inst;
447  bits<26> offset;
448
449  let Inst{31-26} = funct;
450  let Inst{25-0} = offset;
451}
452
453class SPECIAL3_ALIGN_FM<OPCODE6 Operation> : MipsR6Inst {
454  bits<5> rd;
455  bits<5> rs;
456  bits<5> rt;
457  bits<2> bp;
458
459  bits<32> Inst;
460
461  let Inst{31-26} = OPGROUP_SPECIAL3.Value;
462  let Inst{25-21} = rs;
463  let Inst{20-16} = rt;
464  let Inst{15-11} = rd;
465  let Inst{10-8}  = 0b010;
466  let Inst{7-6}   = bp;
467  let Inst{5-0}   = Operation.Value;
468}
469
470class SPECIAL3_DALIGN_FM<OPCODE6 Operation> : MipsR6Inst {
471  bits<5> rd;
472  bits<5> rs;
473  bits<5> rt;
474  bits<3> bp;
475
476  bits<32> Inst;
477
478  let Inst{31-26} = OPGROUP_SPECIAL3.Value;
479  let Inst{25-21} = rs;
480  let Inst{20-16} = rt;
481  let Inst{15-11} = rd;
482  let Inst{10-9}  = 0b01;
483  let Inst{8-6}   = bp;
484  let Inst{5-0}   = Operation.Value;
485}
486
487class SPECIAL3_LL_SC_FM<OPCODE6 Operation> : MipsR6Inst {
488  bits<5> rt;
489  bits<21> addr;
490  bits<5> base = addr{20-16};
491  bits<9> offset = addr{8-0};
492
493  bits<32> Inst;
494
495  let Inst{31-26} = OPGROUP_SPECIAL3.Value;
496  let Inst{25-21} = base;
497  let Inst{20-16} = rt;
498  let Inst{15-7} = offset;
499  let Inst{5-0} = Operation.Value;
500
501  string DecoderMethod = "DecodeSpecial3LlSc";
502}
503
504class SPECIAL_LSA_FM<OPCODE6 Operation> : MipsR6Inst {
505  bits<5> rd;
506  bits<5> rs;
507  bits<5> rt;
508  bits<2> imm2;
509
510  bits<32> Inst;
511
512  let Inst{31-26} = OPGROUP_SPECIAL.Value;
513  let Inst{25-21} = rs;
514  let Inst{20-16} = rt;
515  let Inst{15-11} = rd;
516  let Inst{10-8}  = 0b000;
517  let Inst{7-6}   = imm2;
518  let Inst{5-0}   = Operation.Value;
519}
520
521class REGIMM_FM<OPCODE5 Operation> : MipsR6Inst {
522  bits<5> rs;
523  bits<16> imm;
524
525  bits<32> Inst;
526
527  let Inst{31-26} = OPGROUP_REGIMM.Value;
528  let Inst{25-21} = rs;
529  let Inst{20-16} = Operation.Value;
530  let Inst{15-0} = imm;
531}
532
533class COP1_CMP_CONDN_FM<FIELD_CMP_FORMAT Format,
534                        FIELD_CMP_COND Cond> : MipsR6Inst {
535  bits<5> fd;
536  bits<5> fs;
537  bits<5> ft;
538
539  bits<32> Inst;
540
541  let Inst{31-26} = OPGROUP_COP1.Value;
542  let Inst{25-21} = Format.Value;
543  let Inst{20-16} = ft;
544  let Inst{15-11} = fs;
545  let Inst{10-6}  = fd;
546  let Inst{5}     = 0;
547  let Inst{4-0}   = Cond.Value;
548}
549
550class JR_HB_R6_FM<OPCODE6 Operation> : MipsR6Inst {
551  bits<5> rs;
552
553  bits<32> Inst;
554
555  let Inst{31-26} = OPGROUP_SPECIAL.Value;
556  let Inst{25-21} = rs;
557  let Inst{20-16} = 0;
558  let Inst{15-11} = 0;
559  let Inst{10} = 1;
560  let Inst{9-6} = 0;
561  let Inst{5-0} = Operation.Value;
562}
563
564class COP2LDST_FM<OPCODE5 Operation> : MipsR6Inst {
565  bits<5> rt;
566  bits<21> addr;
567  bits<5> base = addr{20-16};
568  bits<11> offset = addr{10-0};
569
570  bits<32> Inst;
571
572  let Inst{31-26} = OPGROUP_COP2LDST.Value;
573  let Inst{25-21} = Operation.Value;
574  let Inst{20-16} = rt;
575  let Inst{15-11} = base;
576  let Inst{10-0}  = offset;
577}
578
579class SPECIAL3_2R_SZ_CRC<bits<2> sz, bits<3> direction> : MipsR6Inst {
580  bits<5> rs;
581  bits<5> rt;
582
583  let Inst{31-26} = OPGROUP_SPECIAL3.Value;
584  let Inst{25-21} = rs;
585  let Inst{20-16} = rt;
586  let Inst{15-11} = 0b00000;
587  let Inst{10-8} = direction;
588  let Inst{7-6} = sz;
589  let Inst{5-0} = 0b001111;
590
591  string DecoderMethod = "DecodeCRC";
592}
593
594class SPECIAL3_GINV<bits<2> ginv> : MipsR6Inst {
595  bits<5> rs;
596  bits<2> type_;
597
598  let Inst{31-26} = OPGROUP_SPECIAL3.Value;
599  let Inst{25-21} = rs;
600  let Inst{20-10} = 0x0;
601  let Inst{9-8}   = type_;
602  let Inst{7-6}   = ginv;
603  let Inst{5-0}   = 0b111101;
604}
605
606class SIGRIE_FM : MipsR6Inst {
607  bits<16> code_;
608
609  let Inst{31-26} = OPGROUP_REGIMM.Value;
610  let Inst{25-21} = 0;
611  let Inst{20-16} = OPCODE5_SIGRIE.Value;
612  let Inst{15-0} = code_;
613}
614