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