Fix formatting in AArch64 backend.
[oota-llvm.git] / lib / Target / AArch64 / AArch64InstrFormats.td
1 //===- AArch64InstrFormats.td - AArch64 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 //===----------------------------------------------------------------------===//
11 //
12 // A64 Instruction Format Definitions.
13 //
14
15 // A64 is currently the only instruction set supported by the AArch64
16 // architecture.
17 class A64Inst<dag outs, dag ins, string asmstr, list<dag> patterns,
18               InstrItinClass itin>
19     : Instruction {
20   // All A64 instructions are 32-bit. This field will be filled in
21   // graually going down the hierarchy.
22   field bits<32> Inst;
23
24   field bits<32> Unpredictable = 0;
25   // SoftFail is the generic name for this field, but we alias it so
26   // as to make it more obvious what it means in ARM-land.
27   field bits<32> SoftFail = Unpredictable;
28
29   // LLVM-level model of the AArch64/A64 distinction.
30   let Namespace = "AArch64";
31   let DecoderNamespace = "A64";
32   let Size = 4;
33
34   // Set the templated fields
35   let OutOperandList = outs;
36   let InOperandList = ins;
37   let AsmString = asmstr;
38   let Pattern = patterns;
39   let Itinerary = itin;
40 }
41
42 class PseudoInst<dag outs, dag ins, list<dag> patterns> : Instruction {
43   let Namespace = "AArch64";
44
45   let OutOperandList = outs;
46   let InOperandList= ins;
47   let Pattern = patterns;
48   let isCodeGenOnly = 1;
49   let isPseudo = 1;
50 }
51
52 // Represents a pseudo-instruction that represents a single A64 instruction for
53 // whatever reason, the eventual result will be a 32-bit real instruction.
54 class A64PseudoInst<dag outs, dag ins, list<dag> patterns>
55   : PseudoInst<outs, ins, patterns> {
56   let Size = 4;
57 }
58
59 // As above, this will be a single A64 instruction, but we can actually give the
60 // expansion in TableGen.
61 class A64PseudoExpand<dag outs, dag ins, list<dag> patterns, dag Result>
62   : A64PseudoInst<outs, ins, patterns>,
63     PseudoInstExpansion<Result>;
64
65
66 // First, some common cross-hierarchy register formats.
67
68 class A64InstRd<dag outs, dag ins, string asmstr,
69                 list<dag> patterns, InstrItinClass itin>
70   : A64Inst<outs, ins, asmstr, patterns, itin> {
71   bits<5> Rd;
72
73   let Inst{4-0} = Rd;
74 }
75
76 class A64InstRt<dag outs, dag ins, string asmstr,
77                 list<dag> patterns, InstrItinClass itin>
78   : A64Inst<outs, ins, asmstr, patterns, itin> {
79   bits<5> Rt;
80
81   let Inst{4-0} = Rt;
82 }
83
84
85 class A64InstRdn<dag outs, dag ins, string asmstr,
86                  list<dag> patterns, InstrItinClass itin>
87     : A64InstRd<outs, ins, asmstr, patterns, itin> {
88   // Inherit rdt
89   bits<5> Rn;
90
91   let Inst{9-5} = Rn;
92 }
93
94 class A64InstRtn<dag outs, dag ins, string asmstr,
95                 list<dag> patterns, InstrItinClass itin>
96     : A64InstRt<outs, ins, asmstr, patterns, itin> {
97   // Inherit rdt
98   bits<5> Rn;
99
100   let Inst{9-5} = Rn;
101 }
102
103 // Instructions taking Rt,Rt2,Rn
104 class A64InstRtt2n<dag outs, dag ins, string asmstr,
105                    list<dag> patterns, InstrItinClass itin>
106   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
107   bits<5> Rt2;
108
109   let Inst{14-10} = Rt2;
110 }
111
112 class A64InstRdnm<dag outs, dag ins, string asmstr,
113                   list<dag> patterns, InstrItinClass itin>
114   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
115   bits<5> Rm;
116
117   let Inst{20-16} = Rm;
118 }
119
120 //===----------------------------------------------------------------------===//
121 //
122 // Actual A64 Instruction Formats
123 //
124
125 // Format for Add-subtract (extended register) instructions.
126 class A64I_addsubext<bit sf, bit op, bit S, bits<2> opt, bits<3> option,
127                      dag outs, dag ins, string asmstr, list<dag> patterns,
128                      InstrItinClass itin>
129     : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
130     bits<3> Imm3;
131
132     let Inst{31} = sf;
133     let Inst{30} = op;
134     let Inst{29} = S;
135     let Inst{28-24} = 0b01011;
136     let Inst{23-22} = opt;
137     let Inst{21} = 0b1;
138     // Rm inherited in 20-16
139     let Inst{15-13} = option;
140     let Inst{12-10} = Imm3;
141     // Rn inherited in 9-5
142     // Rd inherited in 4-0
143 }
144
145 // Format for Add-subtract (immediate) instructions.
146 class A64I_addsubimm<bit sf, bit op, bit S, bits<2> shift,
147                      dag outs, dag ins, string asmstr,
148                      list<dag> patterns, InstrItinClass itin>
149   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
150   bits<12> Imm12;
151
152   let Inst{31} = sf;
153   let Inst{30} = op;
154   let Inst{29} = S;
155   let Inst{28-24} = 0b10001;
156   let Inst{23-22} = shift;
157   let Inst{21-10} = Imm12;
158 }
159
160 // Format for Add-subtract (shifted register) instructions.
161 class A64I_addsubshift<bit sf, bit op, bit S, bits<2> shift,
162                        dag outs, dag ins, string asmstr, list<dag> patterns,
163                        InstrItinClass itin>
164     : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
165     bits<6> Imm6;
166
167     let Inst{31} = sf;
168     let Inst{30} = op;
169     let Inst{29} = S;
170     let Inst{28-24} = 0b01011;
171     let Inst{23-22} = shift;
172     let Inst{21} = 0b0;
173     // Rm inherited in 20-16
174     let Inst{15-10} = Imm6;
175     // Rn inherited in 9-5
176     // Rd inherited in 4-0
177 }
178
179 // Format for Add-subtract (with carry) instructions.
180 class A64I_addsubcarry<bit sf, bit op, bit S, bits<6> opcode2,
181                        dag outs, dag ins, string asmstr, list<dag> patterns,
182                        InstrItinClass itin>
183     : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
184     let Inst{31} = sf;
185     let Inst{30} = op;
186     let Inst{29} = S;
187     let Inst{28-21} = 0b11010000;
188     // Rm inherited in 20-16
189     let Inst{15-10} = opcode2;
190     // Rn inherited in 9-5
191     // Rd inherited in 4-0
192 }
193
194
195 // Format for Bitfield instructions
196 class A64I_bitfield<bit sf, bits<2> opc, bit n,
197                     dag outs, dag ins, string asmstr,
198                     list<dag> patterns, InstrItinClass itin>
199   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
200   bits<6> ImmR;
201   bits<6> ImmS;
202
203   let Inst{31} = sf;
204   let Inst{30-29} = opc;
205   let Inst{28-23} = 0b100110;
206   let Inst{22} = n;
207   let Inst{21-16} = ImmR;
208   let Inst{15-10} = ImmS;
209   // Inherit Rn in 9-5
210   // Inherit Rd in 4-0
211 }
212
213 // Format for compare and branch (immediate) instructions.
214 class A64I_cmpbr<bit sf, bit op,
215                   dag outs, dag ins, string asmstr,
216                   list<dag> patterns, InstrItinClass itin>
217   : A64InstRt<outs, ins, asmstr, patterns, itin> {
218   bits<19> Label;
219
220   let Inst{31} = sf;
221   let Inst{30-25} = 0b011010;
222   let Inst{24} = op;
223   let Inst{23-5} = Label;
224   // Inherit Rt in 4-0
225 }
226
227 // Format for conditional branch (immediate) instructions.
228 class A64I_condbr<bit o1, bit o0,
229                   dag outs, dag ins, string asmstr,
230                   list<dag> patterns, InstrItinClass itin>
231   : A64Inst<outs, ins, asmstr, patterns, itin> {
232   bits<19> Label;
233   bits<4> Cond;
234
235   let Inst{31-25} = 0b0101010;
236   let Inst{24} = o1;
237   let Inst{23-5} = Label;
238   let Inst{4} = o0;
239   let Inst{3-0} = Cond;
240 }
241
242 // Format for conditional compare (immediate) instructions.
243 class A64I_condcmpimm<bit sf, bit op, bit o2, bit o3, bit s,
244                       dag outs, dag ins, string asmstr,
245                       list<dag> patterns, InstrItinClass itin>
246   : A64Inst<outs, ins, asmstr, patterns, itin> {
247   bits<5> Rn;
248   bits<5> UImm5;
249   bits<4> NZCVImm;
250   bits<4> Cond;
251
252   let Inst{31} = sf;
253   let Inst{30} = op;
254   let Inst{29} = s;
255   let Inst{28-21} = 0b11010010;
256   let Inst{20-16} = UImm5;
257   let Inst{15-12} = Cond;
258   let Inst{11} = 0b1;
259   let Inst{10} = o2;
260   let Inst{9-5} = Rn;
261   let Inst{4} = o3;
262   let Inst{3-0} = NZCVImm;
263 }
264
265 // Format for conditional compare (register) instructions.
266 class A64I_condcmpreg<bit sf, bit op, bit o2, bit o3, bit s,
267                       dag outs, dag ins, string asmstr,
268                       list<dag> patterns, InstrItinClass itin>
269   : A64Inst<outs, ins, asmstr, patterns, itin> {
270   bits<5> Rn;
271   bits<5> Rm;
272   bits<4> NZCVImm;
273   bits<4> Cond;
274
275
276   let Inst{31} = sf;
277   let Inst{30} = op;
278   let Inst{29} = s;
279   let Inst{28-21} = 0b11010010;
280   let Inst{20-16} = Rm;
281   let Inst{15-12} = Cond;
282   let Inst{11} = 0b0;
283   let Inst{10} = o2;
284   let Inst{9-5} = Rn;
285   let Inst{4} = o3;
286   let Inst{3-0} = NZCVImm;
287 }
288
289 // Format for conditional select instructions.
290 class A64I_condsel<bit sf, bit op, bit s, bits<2> op2,
291                    dag outs, dag ins, string asmstr,
292                    list<dag> patterns, InstrItinClass itin>
293   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
294   bits<4> Cond;
295
296   let Inst{31} = sf;
297   let Inst{30} = op;
298   let Inst{29} = s;
299   let Inst{28-21} = 0b11010100;
300   // Inherit Rm in 20-16
301   let Inst{15-12} = Cond;
302   let Inst{11-10} = op2;
303   // Inherit Rn in 9-5
304   // Inherit Rd in 4-0
305 }
306
307 // Format for data processing (1 source) instructions
308 class A64I_dp_1src<bit sf, bit S, bits<5> opcode2, bits<6> opcode,
309                 string asmstr, dag outs, dag ins,
310                 list<dag> patterns, InstrItinClass itin>
311   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
312   let Inst{31} = sf;
313   let Inst{30} = 0b1;
314   let Inst{29} = S;
315   let Inst{28-21} = 0b11010110;
316   let Inst{20-16} = opcode2;
317   let Inst{15-10} = opcode;
318 }
319
320 // Format for data processing (2 source) instructions
321 class A64I_dp_2src<bit sf, bits<6> opcode, bit S,
322                 string asmstr, dag outs, dag ins,
323                 list<dag> patterns, InstrItinClass itin>
324   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
325   let Inst{31} = sf;
326   let Inst{30} = 0b0;
327   let Inst{29} = S;
328   let Inst{28-21} = 0b11010110;
329   let Inst{15-10} = opcode;
330 }
331
332 // Format for data-processing (3 source) instructions
333
334 class A64I_dp3<bit sf, bits<6> opcode,
335                dag outs, dag ins, string asmstr,
336                list<dag> patterns, InstrItinClass itin>
337   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
338   bits<5> Ra;
339
340   let Inst{31} = sf;
341   let Inst{30-29} = opcode{5-4};
342   let Inst{28-24} = 0b11011;
343   let Inst{23-21} = opcode{3-1};
344   // Inherits Rm in 20-16
345   let Inst{15} = opcode{0};
346   let Inst{14-10} = Ra;
347   // Inherits Rn in 9-5
348   // Inherits Rd in 4-0
349 }
350
351 // Format for exception generation instructions
352 class A64I_exception<bits<3> opc, bits<3> op2, bits<2> ll,
353                      dag outs, dag ins, string asmstr,
354                      list<dag> patterns, InstrItinClass itin>
355   : A64Inst<outs, ins, asmstr, patterns, itin> {
356   bits<16> UImm16;
357
358   let Inst{31-24} = 0b11010100;
359   let Inst{23-21} = opc;
360   let Inst{20-5} = UImm16;
361   let Inst{4-2} = op2;
362   let Inst{1-0} = ll;
363 }
364
365 // Format for extract (immediate) instructions
366 class A64I_extract<bit sf, bits<3> op, bit n,
367                    dag outs, dag ins, string asmstr,
368                    list<dag> patterns, InstrItinClass itin>
369   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
370   bits<6> LSB;
371
372   let Inst{31} = sf;
373   let Inst{30-29} = op{2-1};
374   let Inst{28-23} = 0b100111;
375   let Inst{22} = n;
376   let Inst{21} = op{0};
377   // Inherits Rm in bits 20-16
378   let Inst{15-10} = LSB;
379   // Inherits Rn in 9-5
380   // Inherits Rd in 4-0
381 }
382
383 // Format for floating-point compare instructions.
384 class A64I_fpcmp<bit m, bit s, bits<2> type, bits<2> op, bits<5> opcode2,
385                 dag outs, dag ins, string asmstr,
386                 list<dag> patterns, InstrItinClass itin>
387   : A64Inst<outs, ins, asmstr, patterns, itin> {
388   bits<5> Rn;
389   bits<5> Rm;
390
391   let Inst{31} = m;
392   let Inst{30} = 0b0;
393   let Inst{29} = s;
394   let Inst{28-24} = 0b11110;
395   let Inst{23-22} = type;
396   let Inst{21} = 0b1;
397   let Inst{20-16} = Rm;
398   let Inst{15-14} = op;
399   let Inst{13-10} = 0b1000;
400   let Inst{9-5} = Rn;
401   let Inst{4-0} = opcode2;
402 }
403
404 // Format for floating-point conditional compare instructions.
405 class A64I_fpccmp<bit m, bit s, bits<2> type, bit op,
406                  dag outs, dag ins, string asmstr,
407                  list<dag> patterns, InstrItinClass itin>
408   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
409   bits<5> Rn;
410   bits<5> Rm;
411   bits<4> NZCVImm;
412   bits<4> Cond;
413
414   let Inst{31} = m;
415   let Inst{30} = 0b0;
416   let Inst{29} = s;
417   let Inst{28-24} = 0b11110;
418   let Inst{23-22} = type;
419   let Inst{21} = 0b1;
420   let Inst{20-16} = Rm;
421   let Inst{15-12} = Cond;
422   let Inst{11-10} = 0b01;
423   let Inst{9-5} = Rn;
424   let Inst{4} = op;
425   let Inst{3-0} = NZCVImm;
426 }
427
428 // Format for floating-point conditional select instructions.
429 class A64I_fpcondsel<bit m, bit s, bits<2> type,
430                      dag outs, dag ins, string asmstr,
431                      list<dag> patterns, InstrItinClass itin>
432   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
433   bits<4> Cond;
434
435   let Inst{31} = m;
436   let Inst{30} = 0b0;
437   let Inst{29} = s;
438   let Inst{28-24} = 0b11110;
439   let Inst{23-22} = type;
440   let Inst{21} = 0b1;
441   // Inherit Rm in 20-16
442   let Inst{15-12} = Cond;
443   let Inst{11-10} = 0b11;
444   // Inherit Rn in 9-5
445   // Inherit Rd in 4-0
446 }
447
448
449 // Format for floating-point data-processing (1 source) instructions.
450 class A64I_fpdp1<bit m, bit s, bits<2> type, bits<6> opcode,
451                  dag outs, dag ins, string asmstr,
452                  list<dag> patterns, InstrItinClass itin>
453   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
454   let Inst{31} = m;
455   let Inst{30} = 0b0;
456   let Inst{29} = s;
457   let Inst{28-24} = 0b11110;
458   let Inst{23-22} = type;
459   let Inst{21} = 0b1;
460   let Inst{20-15} = opcode;
461   let Inst{14-10} = 0b10000;
462   // Inherit Rn in 9-5
463   // Inherit Rd in 4-0
464 }
465
466 // Format for floating-point data-processing (2 sources) instructions.
467 class A64I_fpdp2<bit m, bit s, bits<2> type, bits<4> opcode,
468                  dag outs, dag ins, string asmstr,
469                  list<dag> patterns, InstrItinClass itin>
470   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
471   let Inst{31} = m;
472   let Inst{30} = 0b0;
473   let Inst{29} = s;
474   let Inst{28-24} = 0b11110;
475   let Inst{23-22} = type;
476   let Inst{21} = 0b1;
477   // Inherit Rm in 20-16
478   let Inst{15-12} = opcode;
479   let Inst{11-10} = 0b10;
480   // Inherit Rn in 9-5
481   // Inherit Rd in 4-0
482 }
483
484 // Format for floating-point data-processing (3 sources) instructions.
485 class A64I_fpdp3<bit m, bit s, bits<2> type, bit o1, bit o0,
486                  dag outs, dag ins, string asmstr,
487                  list<dag> patterns, InstrItinClass itin>
488   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
489   bits<5> Ra;
490
491   let Inst{31} = m;
492   let Inst{30} = 0b0;
493   let Inst{29} = s;
494   let Inst{28-24} = 0b11111;
495   let Inst{23-22} = type;
496   let Inst{21} = o1;
497   // Inherit Rm in 20-16
498   let Inst{15} = o0;
499   let Inst{14-10} = Ra;
500   // Inherit Rn in 9-5
501   // Inherit Rd in 4-0
502 }
503
504 // Format for floating-point <-> fixed-point conversion instructions.
505 class A64I_fpfixed<bit sf, bit s, bits<2> type, bits<2> mode, bits<3> opcode,
506                  dag outs, dag ins, string asmstr,
507                  list<dag> patterns, InstrItinClass itin>
508   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
509   bits<6> Scale;
510
511   let Inst{31} = sf;
512   let Inst{30} = 0b0;
513   let Inst{29} = s;
514   let Inst{28-24} = 0b11110;
515   let Inst{23-22} = type;
516   let Inst{21} = 0b0;
517   let Inst{20-19} = mode;
518   let Inst{18-16} = opcode;
519   let Inst{15-10} = Scale;
520   // Inherit Rn in 9-5
521   // Inherit Rd in 4-0
522 }
523
524 // Format for floating-point <-> integer conversion instructions.
525 class A64I_fpint<bit sf, bit s, bits<2> type, bits<2> rmode, bits<3> opcode,
526                  dag outs, dag ins, string asmstr,
527                  list<dag> patterns, InstrItinClass itin>
528   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
529   let Inst{31} = sf;
530   let Inst{30} = 0b0;
531   let Inst{29} = s;
532   let Inst{28-24} = 0b11110;
533   let Inst{23-22} = type;
534   let Inst{21} = 0b1;
535   let Inst{20-19} = rmode;
536   let Inst{18-16} = opcode;
537   let Inst{15-10} = 0b000000;
538   // Inherit Rn in 9-5
539   // Inherit Rd in 4-0
540 }
541
542
543 // Format for floating-point immediate instructions.
544 class A64I_fpimm<bit m, bit s, bits<2> type, bits<5> imm5,
545                  dag outs, dag ins, string asmstr,
546                  list<dag> patterns, InstrItinClass itin>
547   : A64InstRd<outs, ins, asmstr, patterns, itin> {
548   bits<8> Imm8;
549
550   let Inst{31} = m;
551   let Inst{30} = 0b0;
552   let Inst{29} = s;
553   let Inst{28-24} = 0b11110;
554   let Inst{23-22} = type;
555   let Inst{21} = 0b1;
556   let Inst{20-13} = Imm8;
557   let Inst{12-10} = 0b100;
558   let Inst{9-5} = imm5;
559   // Inherit Rd in 4-0
560 }
561
562 // Format for load-register (literal) instructions.
563 class A64I_LDRlit<bits<2> opc, bit v,
564                   dag outs, dag ins, string asmstr,
565                   list<dag> patterns, InstrItinClass itin>
566   : A64InstRt<outs, ins, asmstr, patterns, itin> {
567   bits<19> Imm19;
568
569   let Inst{31-30} = opc;
570   let Inst{29-27} = 0b011;
571   let Inst{26} = v;
572   let Inst{25-24} = 0b00;
573   let Inst{23-5} = Imm19;
574   // Inherit Rt in 4-0
575 }
576
577 // Format for load-store exclusive instructions.
578 class A64I_LDSTex_tn<bits<2> size, bit o2, bit L, bit o1, bit o0,
579                  dag outs, dag ins, string asmstr,
580                  list <dag> patterns, InstrItinClass itin>
581   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
582   let Inst{31-30} = size;
583   let Inst{29-24} = 0b001000;
584   let Inst{23} = o2;
585   let Inst{22} = L;
586   let Inst{21} = o1;
587   let Inst{15} = o0;
588 }
589
590 class A64I_LDSTex_tt2n<bits<2> size, bit o2, bit L, bit o1, bit o0,
591                      dag outs, dag ins, string asmstr,
592                      list <dag> patterns, InstrItinClass itin>:
593       A64I_LDSTex_tn<size, o2, L, o1, o0, outs, ins, asmstr, patterns, itin>{
594    bits<5> Rt2;
595    let Inst{14-10} = Rt2;
596 }
597
598 class A64I_LDSTex_stn<bits<2> size, bit o2, bit L, bit o1, bit o0,
599                      dag outs, dag ins, string asmstr,
600                      list <dag> patterns, InstrItinClass itin>:
601       A64I_LDSTex_tn<size, o2, L, o1, o0, outs, ins, asmstr, patterns, itin>{
602    bits<5> Rs;
603    let Inst{20-16} = Rs;
604 }
605
606 class A64I_LDSTex_stt2n<bits<2> size, bit o2, bit L, bit o1, bit o0,
607                      dag outs, dag ins, string asmstr,
608                      list <dag> patterns, InstrItinClass itin>:
609       A64I_LDSTex_stn<size, o2, L, o1, o0, outs, ins, asmstr, patterns, itin>{
610    bits<5> Rt2;
611    let Inst{14-10} = Rt2;
612 }
613
614 // Format for load-store register (immediate post-indexed) instructions
615 class A64I_LSpostind<bits<2> size, bit v, bits<2> opc,
616                      dag outs, dag ins, string asmstr,
617                      list<dag> patterns, InstrItinClass itin>
618   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
619   bits<9> SImm9;
620
621   let Inst{31-30} = size;
622   let Inst{29-27} = 0b111;
623   let Inst{26} = v;
624   let Inst{25-24} = 0b00;
625   let Inst{23-22} = opc;
626   let Inst{21} = 0b0;
627   let Inst{20-12} = SImm9;
628   let Inst{11-10} = 0b01;
629   // Inherit Rn in 9-5
630   // Inherit Rt in 4-0
631 }
632
633 // Format for load-store register (immediate pre-indexed) instructions
634 class A64I_LSpreind<bits<2> size, bit v, bits<2> opc,
635                     dag outs, dag ins, string asmstr,
636                     list<dag> patterns, InstrItinClass itin>
637   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
638   bits<9> SImm9;
639
640
641   let Inst{31-30} = size;
642   let Inst{29-27} = 0b111;
643   let Inst{26} = v;
644   let Inst{25-24} = 0b00;
645   let Inst{23-22} = opc;
646   let Inst{21} = 0b0;
647   let Inst{20-12} = SImm9;
648   let Inst{11-10} = 0b11;
649   // Inherit Rn in 9-5
650   // Inherit Rt in 4-0
651 }
652
653 // Format for load-store register (unprivileged) instructions
654 class A64I_LSunpriv<bits<2> size, bit v, bits<2> opc,
655                     dag outs, dag ins, string asmstr,
656                     list<dag> patterns, InstrItinClass itin>
657   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
658   bits<9> SImm9;
659
660
661   let Inst{31-30} = size;
662   let Inst{29-27} = 0b111;
663   let Inst{26} = v;
664   let Inst{25-24} = 0b00;
665   let Inst{23-22} = opc;
666   let Inst{21} = 0b0;
667   let Inst{20-12} = SImm9;
668   let Inst{11-10} = 0b10;
669   // Inherit Rn in 9-5
670   // Inherit Rt in 4-0
671 }
672
673 // Format for load-store (unscaled immediate) instructions.
674 class A64I_LSunalimm<bits<2> size, bit v, bits<2> opc,
675                      dag outs, dag ins, string asmstr,
676                      list<dag> patterns, InstrItinClass itin>
677   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
678   bits<9> SImm9;
679
680   let Inst{31-30} = size;
681   let Inst{29-27} = 0b111;
682   let Inst{26} = v;
683   let Inst{25-24} = 0b00;
684   let Inst{23-22} = opc;
685   let Inst{21} = 0b0;
686   let Inst{20-12} = SImm9;
687   let Inst{11-10} = 0b00;
688   // Inherit Rn in 9-5
689   // Inherit Rt in 4-0
690 }
691
692
693 // Format for load-store (unsigned immediate) instructions.
694 class A64I_LSunsigimm<bits<2> size, bit v, bits<2> opc,
695                       dag outs, dag ins, string asmstr,
696                       list<dag> patterns, InstrItinClass itin>
697   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
698   bits<12> UImm12;
699
700   let Inst{31-30} = size;
701   let Inst{29-27} = 0b111;
702   let Inst{26} = v;
703   let Inst{25-24} = 0b01;
704   let Inst{23-22} = opc;
705   let Inst{21-10} = UImm12;
706 }
707
708 // Format for load-store register (register offset) instructions.
709 class A64I_LSregoff<bits<2> size, bit v, bits<2> opc, bit optionlo,
710                     dag outs, dag ins, string asmstr,
711                     list<dag> patterns, InstrItinClass itin>
712   : A64InstRtn<outs, ins, asmstr, patterns, itin> {
713   bits<5> Rm;
714
715   // Complex operand selection needed for these instructions, so they
716   // need an "addr" field for encoding/decoding to be generated.
717   bits<3> Ext;
718   // OptionHi = Ext{2-1}
719   // S = Ext{0}
720
721   let Inst{31-30} = size;
722   let Inst{29-27} = 0b111;
723   let Inst{26} = v;
724   let Inst{25-24} = 0b00;
725   let Inst{23-22} = opc;
726   let Inst{21} = 0b1;
727   let Inst{20-16} = Rm;
728   let Inst{15-14} = Ext{2-1};
729   let Inst{13} = optionlo;
730   let Inst{12} = Ext{0};
731   let Inst{11-10} = 0b10;
732   // Inherits Rn in 9-5
733   // Inherits Rt in 4-0
734
735   let AddedComplexity = 50;
736 }
737
738 // Format for Load-store register pair (offset) instructions
739 class A64I_LSPoffset<bits<2> opc, bit v, bit l,
740                       dag outs, dag ins, string asmstr,
741                       list<dag> patterns, InstrItinClass itin>
742   : A64InstRtt2n<outs, ins, asmstr, patterns, itin> {
743   bits<7> SImm7;
744
745   let Inst{31-30} = opc;
746   let Inst{29-27} = 0b101;
747   let Inst{26} = v;
748   let Inst{25-23} = 0b010;
749   let Inst{22} = l;
750   let Inst{21-15} = SImm7;
751   // Inherit Rt2 in 14-10
752   // Inherit Rn in 9-5
753   // Inherit Rt in 4-0
754 }
755
756 // Format for Load-store register pair (post-indexed) instructions
757 class A64I_LSPpostind<bits<2> opc, bit v, bit l,
758                       dag outs, dag ins, string asmstr,
759                       list<dag> patterns, InstrItinClass itin>
760   : A64InstRtt2n<outs, ins, asmstr, patterns, itin> {
761   bits<7> SImm7;
762
763   let Inst{31-30} = opc;
764   let Inst{29-27} = 0b101;
765   let Inst{26} = v;
766   let Inst{25-23} = 0b001;
767   let Inst{22} = l;
768   let Inst{21-15} = SImm7;
769   // Inherit Rt2 in 14-10
770   // Inherit Rn in 9-5
771   // Inherit Rt in 4-0
772 }
773
774 // Format for Load-store register pair (pre-indexed) instructions
775 class A64I_LSPpreind<bits<2> opc, bit v, bit l,
776                       dag outs, dag ins, string asmstr,
777                       list<dag> patterns, InstrItinClass itin>
778   : A64InstRtt2n<outs, ins, asmstr, patterns, itin> {
779   bits<7> SImm7;
780
781   let Inst{31-30} = opc;
782   let Inst{29-27} = 0b101;
783   let Inst{26} = v;
784   let Inst{25-23} = 0b011;
785   let Inst{22} = l;
786   let Inst{21-15} = SImm7;
787   // Inherit Rt2 in 14-10
788   // Inherit Rn in 9-5
789   // Inherit Rt in 4-0
790 }
791
792 // Format for Load-store non-temporal register pair (offset) instructions
793 class A64I_LSPnontemp<bits<2> opc, bit v, bit l,
794                       dag outs, dag ins, string asmstr,
795                       list<dag> patterns, InstrItinClass itin>
796   : A64InstRtt2n<outs, ins, asmstr, patterns, itin> {
797   bits<7> SImm7;
798
799   let Inst{31-30} = opc;
800   let Inst{29-27} = 0b101;
801   let Inst{26} = v;
802   let Inst{25-23} = 0b000;
803   let Inst{22} = l;
804   let Inst{21-15} = SImm7;
805   // Inherit Rt2 in 14-10
806   // Inherit Rn in 9-5
807   // Inherit Rt in 4-0
808 }
809
810 // Format for Logical (immediate) instructions
811 class A64I_logicalimm<bit sf, bits<2> opc,
812                       dag outs, dag ins, string asmstr,
813                       list<dag> patterns, InstrItinClass itin>
814   : A64InstRdn<outs, ins, asmstr, patterns, itin> {
815   bit N;
816   bits<6> ImmR;
817   bits<6> ImmS;
818
819   // N, ImmR and ImmS have no separate existence in any assembly syntax (or for
820   // selection), so we'll combine them into a single field here.
821   bits<13> Imm;
822   // N = Imm{12};
823   // ImmR = Imm{11-6};
824   // ImmS = Imm{5-0};
825
826   let Inst{31} = sf;
827   let Inst{30-29} = opc;
828   let Inst{28-23} = 0b100100;
829   let Inst{22} = Imm{12};
830   let Inst{21-16} = Imm{11-6};
831   let Inst{15-10} = Imm{5-0};
832   // Rn inherited in 9-5
833   // Rd inherited in 4-0
834 }
835
836 // Format for Logical (shifted register) instructions
837 class A64I_logicalshift<bit sf, bits<2> opc, bits<2> shift, bit N,
838                         dag outs, dag ins, string asmstr,
839                         list<dag> patterns, InstrItinClass itin>
840   : A64InstRdnm<outs, ins, asmstr, patterns, itin> {
841   bits<6> Imm6;
842
843   let Inst{31} = sf;
844   let Inst{30-29} = opc;
845   let Inst{28-24} = 0b01010;
846   let Inst{23-22} = shift;
847   let Inst{21} = N;
848   // Rm inherited
849   let Inst{15-10} = Imm6;
850   // Rn inherited
851   // Rd inherited
852 }
853
854 // Format for Move wide (immediate)
855 class A64I_movw<bit sf, bits<2> opc,
856                 dag outs, dag ins, string asmstr,
857                 list<dag> patterns, InstrItinClass itin>
858   : A64InstRd<outs, ins, asmstr, patterns, itin> {
859   bits<16> UImm16;
860   bits<2> Shift; // Called "hw" officially
861
862   let Inst{31} = sf;
863   let Inst{30-29} = opc;
864   let Inst{28-23} = 0b100101;
865   let Inst{22-21} = Shift;
866   let Inst{20-5} = UImm16;
867   // Inherits Rd in 4-0
868 }
869
870 // Format for PC-relative addressing instructions, ADR and ADRP.
871 class A64I_PCADR<bit op,
872                  dag outs, dag ins, string asmstr,
873                  list<dag> patterns, InstrItinClass itin>
874   : A64InstRd<outs, ins, asmstr, patterns, itin> {
875   bits<21> Label;
876
877   let Inst{31} = op;
878   let Inst{30-29} = Label{1-0};
879   let Inst{28-24} = 0b10000;
880   let Inst{23-5} = Label{20-2};
881 }
882
883 // Format for system instructions
884 class A64I_system<bit l,
885                   dag outs, dag ins, string asmstr,
886                   list<dag> patterns, InstrItinClass itin>
887   : A64Inst<outs, ins, asmstr, patterns, itin> {
888   bits<2> Op0;
889   bits<3> Op1;
890   bits<4> CRn;
891   bits<4> CRm;
892   bits<3> Op2;
893   bits<5> Rt;
894
895   let Inst{31-22} = 0b1101010100;
896   let Inst{21} = l;
897   let Inst{20-19} = Op0;
898   let Inst{18-16} = Op1;
899   let Inst{15-12} = CRn;
900   let Inst{11-8} = CRm;
901   let Inst{7-5} = Op2;
902   let Inst{4-0} = Rt;
903
904   // These instructions can do horrible things.
905   let hasSideEffects = 1;
906 }
907
908 // Format for unconditional branch (immediate) instructions
909 class A64I_Bimm<bit op,
910                 dag outs, dag ins, string asmstr,
911                 list<dag> patterns, InstrItinClass itin>
912   : A64Inst<outs, ins, asmstr, patterns, itin> {
913   // Doubly special in not even sharing register fields with other
914   // instructions, so we create our own Rn here.
915   bits<26> Label;
916
917   let Inst{31} = op;
918   let Inst{30-26} = 0b00101;
919   let Inst{25-0} = Label;
920 }
921
922 // Format for Test & branch (immediate) instructions
923 class A64I_TBimm<bit op,
924                 dag outs, dag ins, string asmstr,
925                 list<dag> patterns, InstrItinClass itin>
926   : A64InstRt<outs, ins, asmstr, patterns, itin> {
927   // Doubly special in not even sharing register fields with other
928   // instructions, so we create our own Rn here.
929   bits<6> Imm;
930   bits<14> Label;
931
932   let Inst{31} = Imm{5};
933   let Inst{30-25} = 0b011011;
934   let Inst{24} = op;
935   let Inst{23-19} = Imm{4-0};
936   let Inst{18-5} = Label;
937   // Inherit Rt in 4-0
938 }
939
940 // Format for Unconditional branch (register) instructions, including
941 // RET.  Shares no fields with instructions further up the hierarchy
942 // so top-level.
943 class A64I_Breg<bits<4> opc, bits<5> op2, bits<6> op3, bits<5> op4,
944                 dag outs, dag ins, string asmstr,
945                 list<dag> patterns, InstrItinClass itin>
946   : A64Inst<outs, ins, asmstr, patterns, itin> {
947   // Doubly special in not even sharing register fields with other
948   // instructions, so we create our own Rn here.
949   bits<5> Rn;
950
951   let Inst{31-25} = 0b1101011;
952   let Inst{24-21} = opc;
953   let Inst{20-16} = op2;
954   let Inst{15-10} = op3;
955   let Inst{9-5}   = Rn;
956   let Inst{4-0}   = op4;
957 }
958