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