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