[mips] Added support for assembling sdbbp.
[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 def OPCODE6_CLO      : OPCODE6<0b010001>;
95 def OPCODE6_CLZ      : OPCODE6<0b010000>;
96 def OPCODE6_DCLO     : OPCODE6<0b010011>;
97 def OPCODE6_DCLZ     : OPCODE6<0b010010>;
98 def OPCODE6_LSA      : OPCODE6<0b000101>;
99 def OPCODE6_DLSA     : OPCODE6<0b010101>;
100 def OPCODE6_SDBBP    : OPCODE6<0b001110>;
101
102 class FIELD_FMT<bits<5> Val> {
103   bits<5> Value = Val;
104 }
105 def FIELD_FMT_S : FIELD_FMT<0b10000>;
106 def FIELD_FMT_D : FIELD_FMT<0b10001>;
107
108 class FIELD_CMP_COND<bits<5> Val> {
109   bits<5> Value = Val;
110 }
111 def FIELD_CMP_COND_F    : FIELD_CMP_COND<0b00000>;
112 def FIELD_CMP_COND_UN   : FIELD_CMP_COND<0b00001>;
113 def FIELD_CMP_COND_EQ   : FIELD_CMP_COND<0b00010>;
114 def FIELD_CMP_COND_UEQ  : FIELD_CMP_COND<0b00011>;
115 def FIELD_CMP_COND_OLT  : FIELD_CMP_COND<0b00100>;
116 def FIELD_CMP_COND_ULT  : FIELD_CMP_COND<0b00101>;
117 def FIELD_CMP_COND_OLE  : FIELD_CMP_COND<0b00110>;
118 def FIELD_CMP_COND_ULE  : FIELD_CMP_COND<0b00111>;
119 def FIELD_CMP_COND_SF   : FIELD_CMP_COND<0b01000>;
120 def FIELD_CMP_COND_NGLE : FIELD_CMP_COND<0b01001>;
121 def FIELD_CMP_COND_SEQ  : FIELD_CMP_COND<0b01010>;
122 def FIELD_CMP_COND_NGL  : FIELD_CMP_COND<0b01011>;
123 def FIELD_CMP_COND_LT   : FIELD_CMP_COND<0b01100>;
124 def FIELD_CMP_COND_NGE  : FIELD_CMP_COND<0b01101>;
125 def FIELD_CMP_COND_LE   : FIELD_CMP_COND<0b01110>;
126 def FIELD_CMP_COND_NGT  : FIELD_CMP_COND<0b01111>;
127
128 class FIELD_CMP_FORMAT<bits<5> Val> {
129   bits<5> Value = Val;
130 }
131 def FIELD_CMP_FORMAT_S : FIELD_CMP_FORMAT<0b10100>;
132 def FIELD_CMP_FORMAT_D : FIELD_CMP_FORMAT<0b10101>;
133
134 //===----------------------------------------------------------------------===//
135 //
136 // Disambiguators
137 //
138 //===----------------------------------------------------------------------===//
139 //
140 // Some encodings are ambiguous except by comparing field values.
141
142 class DecodeDisambiguates<string Name> {
143   string DecoderMethod = !strconcat("Decode", Name);
144 }
145
146 class DecodeDisambiguatedBy<string Name> : DecodeDisambiguates<Name> {
147   string DecoderNamespace = "Mips32r6_64r6_Ambiguous";
148 }
149
150 //===----------------------------------------------------------------------===//
151 //
152 // Encoding Formats
153 //
154 //===----------------------------------------------------------------------===//
155
156 class AUI_FM : MipsR6Inst {
157   bits<5> rs;
158   bits<5> rt;
159   bits<16> imm;
160
161   bits<32> Inst;
162
163   let Inst{31-26} = OPGROUP_AUI.Value;
164   let Inst{25-21} = rs;
165   let Inst{20-16} = rt;
166   let Inst{15-0} = imm;
167 }
168
169 class DAUI_FM : AUI_FM {
170   let Inst{31-26} = OPGROUP_DAUI.Value;
171 }
172
173 class BAL_FM : MipsR6Inst {
174   bits<16> offset;
175
176   bits<32> Inst;
177
178   let Inst{31-26} = OPGROUP_REGIMM.Value;
179   let Inst{25-21} = 0b00000;
180   let Inst{20-16} = OPCODE5_BGEZAL.Value;
181   let Inst{15-0} = offset;
182 }
183
184 class COP1_2R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst {
185   bits<5> fs;
186   bits<5> fd;
187
188   bits<32> Inst;
189
190   let Inst{31-26} = OPGROUP_COP1.Value;
191   let Inst{25-21} = Format.Value;
192   let Inst{20-16} = 0b00000;
193   let Inst{15-11} = fs;
194   let Inst{10-6}  = fd;
195   let Inst{5-0}   = funct;
196 }
197
198 class COP1_3R_FM<bits<6> funct, FIELD_FMT Format> : MipsR6Inst {
199   bits<5> ft;
200   bits<5> fs;
201   bits<5> fd;
202
203   bits<32> Inst;
204
205   let Inst{31-26} = OPGROUP_COP1.Value;
206   let Inst{25-21} = Format.Value;
207   let Inst{20-16} = ft;
208   let Inst{15-11} = fs;
209   let Inst{10-6} = fd;
210   let Inst{5-0} = funct;
211 }
212
213 class COP1_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst {
214   bits<5> ft;
215   bits<16> offset;
216
217   bits<32> Inst;
218
219   let Inst{31-26} = OPGROUP_COP1.Value;
220   let Inst{25-21} = Operation.Value;
221   let Inst{20-16} = ft;
222   let Inst{15-0} = offset;
223 }
224
225 class COP2_BCCZ_FM<OPCODE5 Operation> : MipsR6Inst {
226   bits<5> ct;
227   bits<16> offset;
228
229   bits<32> Inst;
230
231   let Inst{31-26} = OPGROUP_COP2.Value;
232   let Inst{25-21} = Operation.Value;
233   let Inst{20-16} = ct;
234   let Inst{15-0} = offset;
235 }
236
237 class PCREL16_FM<OPCODE5 Operation> : MipsR6Inst {
238   bits<5> rs;
239   bits<16> 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-16} = Operation.Value;
246   let Inst{15-0} = imm;
247 }
248
249 class PCREL19_FM<OPCODE2 Operation> : MipsR6Inst {
250   bits<5> rs;
251   bits<19> imm;
252
253   bits<32> Inst;
254
255   let Inst{31-26} = OPGROUP_PCREL.Value;
256   let Inst{25-21} = rs;
257   let Inst{20-19} = Operation.Value;
258   let Inst{18-0} = imm;
259 }
260
261 class PCREL18_FM<OPCODE3 Operation> : MipsR6Inst {
262   bits<5> rs;
263   bits<18> imm;
264
265   bits<32> Inst;
266
267   let Inst{31-26} = OPGROUP_PCREL.Value;
268   let Inst{25-21} = rs;
269   let Inst{20-18} = Operation.Value;
270   let Inst{17-0} = imm;
271 }
272
273 class SPECIAL3_2R_FM<OPCODE6 Operation> : MipsR6Inst {
274   bits<5> rd;
275   bits<5> rt;
276
277   bits<32> Inst;
278
279   let Inst{31-26} = OPGROUP_SPECIAL3.Value;
280   let Inst{25-21} = 0b00000;
281   let Inst{20-16} = rt;
282   let Inst{15-11} = rd;
283   let Inst{10-6}  = 0b00000;
284   let Inst{5-0}   = Operation.Value;
285 }
286
287 class SPECIAL3_MEM_FM<OPCODE6 Operation> : MipsR6Inst {
288   bits<21> addr;
289   bits<5> hint;
290   bits<5> base = addr{20-16};
291   bits<9> offset = addr{8-0};
292
293   bits<32> Inst;
294
295   let Inst{31-26} = OPGROUP_SPECIAL3.Value;
296   let Inst{25-21} = base;
297   let Inst{20-16} = hint;
298   let Inst{15-7}  = offset;
299   let Inst{6}     = 0;
300   let Inst{5-0}   = Operation.Value;
301 }
302
303 class SPECIAL_2R_FM<OPCODE6 Operation> : MipsR6Inst {
304   bits<5> rd;
305   bits<5> rs;
306
307   bits<32> Inst;
308
309   let Inst{31-26} = OPGROUP_SPECIAL.Value;
310   let Inst{25-21} = rs;
311   let Inst{20-16} = 0b00000;
312   let Inst{15-11} = rd;
313   let Inst{10-6}  = 0b00001;
314   let Inst{5-0}   = Operation.Value;
315 }
316
317 class SPECIAL_3R_FM<bits<5> mulop, bits<6> funct> : MipsR6Inst {
318   bits<5> rd;
319   bits<5> rs;
320   bits<5> rt;
321
322   bits<32> Inst;
323
324   let Inst{31-26} = OPGROUP_SPECIAL.Value;
325   let Inst{25-21} = rs;
326   let Inst{20-16} = rt;
327   let Inst{15-11} = rd;
328   let Inst{10-6}  = mulop;
329   let Inst{5-0}   = funct;
330 }
331
332 class SPECIAL_SDBBP_FM : MipsR6Inst {
333   bits<20> code_;
334
335   bits<32> Inst;
336
337   let Inst{31-26} = OPGROUP_SPECIAL.Value;
338   let Inst{25-6}  = code_;
339   let Inst{5-0}   = OPCODE6_SDBBP.Value;
340 }
341
342 // This class is ambiguous with other branches:
343 //   BEQC/BNEC require that rs > rt
344 class CMP_BRANCH_2R_OFF16_FM<OPGROUP funct> : MipsR6Inst {
345   bits<5> rs;
346   bits<5> rt;
347   bits<16> offset;
348
349   bits<32> Inst;
350
351   let Inst{31-26} = funct.Value;
352   let Inst{25-21} = rs;
353   let Inst{20-16} = rt;
354   let Inst{15-0} = offset;
355 }
356
357 // This class is ambiguous with other branches:
358 //   BLEZC/BGEZC/BEQZALC/BNEZALC/BGTZALC require that rs == 0 && rt != 0
359 // The '1R_RT' in the name means 1 register in the rt field.
360 class CMP_BRANCH_1R_RT_OFF16_FM<OPGROUP funct> : MipsR6Inst {
361   bits<5> rt;
362   bits<16> offset;
363
364   bits<32> Inst;
365
366   let Inst{31-26} = funct.Value;
367   let Inst{25-21} = 0b00000;
368   let Inst{20-16} = rt;
369   let Inst{15-0} = offset;
370 }
371
372 // This class is ambiguous with other branches:
373 //   BLTZC/BGTZC/BLTZALC/BGEZALC require that rs == rt && rt != 0
374 // The '1R_BOTH' in the name means 1 register in both the rs and rt fields.
375 class CMP_BRANCH_1R_BOTH_OFF16_FM<OPGROUP funct> : MipsR6Inst {
376   bits<5> rt;
377   bits<16> offset;
378
379   bits<32> Inst;
380
381   let Inst{31-26} = funct.Value;
382   let Inst{25-21} = rt;
383   let Inst{20-16} = rt;
384   let Inst{15-0} = offset;
385 }
386
387 class CMP_BRANCH_OFF21_FM<bits<6> funct> : MipsR6Inst {
388   bits<5> rs; // rs != 0
389   bits<21> offset;
390
391   bits<32> Inst;
392
393   let Inst{31-26} = funct;
394   let Inst{25-21} = rs;
395   let Inst{20-0} = offset;
396 }
397
398 class JMP_IDX_COMPACT_FM<bits<6> funct> : MipsR6Inst {
399   bits<5> rt;
400   bits<16> offset;
401
402   bits<32> Inst;
403
404   let Inst{31-26} = funct;
405   let Inst{25-21} = 0b000000;
406   let Inst{20-16} = rt;
407   let Inst{15-0} = offset;
408 }
409
410 class BRANCH_OFF26_FM<bits<6> funct> : MipsR6Inst {
411   bits<32> Inst;
412   bits<26> offset;
413
414   let Inst{31-26} = funct;
415   let Inst{25-0} = offset;
416 }
417
418 class SPECIAL3_ALIGN_FM<OPCODE6 Operation> : MipsR6Inst {
419   bits<5> rd;
420   bits<5> rs;
421   bits<5> rt;
422   bits<2> bp;
423
424   bits<32> Inst;
425
426   let Inst{31-26} = OPGROUP_SPECIAL3.Value;
427   let Inst{25-21} = rs;
428   let Inst{20-16} = rt;
429   let Inst{15-11} = rd;
430   let Inst{10-8}  = 0b010;
431   let Inst{7-6}   = bp;
432   let Inst{5-0}   = Operation.Value;
433 }
434
435 class SPECIAL3_DALIGN_FM<OPCODE6 Operation> : MipsR6Inst {
436   bits<5> rd;
437   bits<5> rs;
438   bits<5> rt;
439   bits<3> bp;
440
441   bits<32> Inst;
442
443   let Inst{31-26} = OPGROUP_SPECIAL3.Value;
444   let Inst{25-21} = rs;
445   let Inst{20-16} = rt;
446   let Inst{15-11} = rd;
447   let Inst{10-9}  = 0b01;
448   let Inst{8-6}   = bp;
449   let Inst{5-0}   = Operation.Value;
450 }
451
452 class SPECIAL3_LL_SC_FM<OPCODE6 Operation> : MipsR6Inst {
453   bits<5> rt;
454   bits<21> addr;
455   bits<5> base = addr{20-16};
456   bits<9> offset = addr{8-0};
457
458   bits<32> Inst;
459
460   let Inst{31-26} = OPGROUP_SPECIAL3.Value;
461   let Inst{25-21} = base;
462   let Inst{20-16} = rt;
463   let Inst{15-7} = offset;
464   let Inst{5-0} = Operation.Value;
465
466   string DecoderMethod = "DecodeSpecial3LlSc";
467 }
468
469 class SPECIAL_LSA_FM<OPCODE6 Operation> : MipsR6Inst {
470   bits<5> rd;
471   bits<5> rs;
472   bits<5> rt;
473   bits<2> imm2;
474
475   bits<32> Inst;
476
477   let Inst{31-26} = OPGROUP_SPECIAL.Value;
478   let Inst{25-21} = rs;
479   let Inst{20-16} = rt;
480   let Inst{15-11} = rd;
481   let Inst{10-8}  = 0b000;
482   let Inst{7-6}   = imm2;
483   let Inst{5-0}   = Operation.Value;
484 }
485
486 class REGIMM_FM<OPCODE5 Operation> : MipsR6Inst {
487   bits<5> rs;
488   bits<16> imm;
489
490   bits<32> Inst;
491
492   let Inst{31-26} = OPGROUP_REGIMM.Value;
493   let Inst{25-21} = rs;
494   let Inst{20-16} = Operation.Value;
495   let Inst{15-0} = imm;
496 }
497
498 class COP1_CMP_CONDN_FM<FIELD_CMP_FORMAT Format,
499                         FIELD_CMP_COND Cond> : MipsR6Inst {
500   bits<5> fd;
501   bits<5> fs;
502   bits<5> ft;
503
504   bits<32> Inst;
505
506   let Inst{31-26} = OPGROUP_COP1.Value;
507   let Inst{25-21} = Format.Value;
508   let Inst{20-16} = ft;
509   let Inst{15-11} = fs;
510   let Inst{10-6}  = fd;
511   let Inst{5}     = 0;
512   let Inst{4-0}   = Cond.Value;
513 }
514
515 class JR_HB_R6_FM<OPCODE6 Operation> : MipsR6Inst {
516   bits<5> rs;
517
518   bits<32> Inst;
519
520   let Inst{31-26} = OPGROUP_SPECIAL.Value;
521   let Inst{25-21} = rs;
522   let Inst{20-16} = 0;
523   let Inst{15-11} = 0;
524   let Inst{10} = 1;
525   let Inst{9-6} = 0;
526   let Inst{5-0} = Operation.Value;
527 }
528
529 class COP2LDST_FM<OPCODE5 Operation> : MipsR6Inst {
530   bits<5> rt;
531   bits<21> addr;
532   bits<5> base = addr{20-16};
533   bits<11> offset = addr{10-0};
534
535   bits<32> Inst;
536
537   let Inst{31-26} = OPGROUP_COP2LDST.Value;
538   let Inst{25-21} = Operation.Value;
539   let Inst{20-16} = rt;
540   let Inst{15-11} = base;
541   let Inst{10-0}  = offset;
542 }