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