c3d9e39dfa64dde538c64bee23e6d9952c3b5cc4
[oota-llvm.git] / lib / Target / ARM / ARMInstrFormats.td
1 //===- ARMInstrFormats.td - ARM 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 // ARM Instruction Format Definitions.
13 //
14
15 // Format specifies the encoding used by the instruction.  This is part of the
16 // ad-hoc solution used to emit machine instruction encodings by our machine
17 // code emitter.
18 class Format<bits<6> val> {
19   bits<6> Value = val;
20 }
21
22 def Pseudo        : Format<0>;
23 def MulFrm        : Format<1>;
24 def BrFrm         : Format<2>;
25 def BrMiscFrm     : Format<3>;
26
27 def DPFrm         : Format<4>;
28 def DPSoRegRegFrm    : Format<5>;
29
30 def LdFrm         : Format<6>;
31 def StFrm         : Format<7>;
32 def LdMiscFrm     : Format<8>;
33 def StMiscFrm     : Format<9>;
34 def LdStMulFrm    : Format<10>;
35
36 def LdStExFrm     : Format<11>;
37
38 def ArithMiscFrm  : Format<12>;
39 def SatFrm        : Format<13>;
40 def ExtFrm        : Format<14>;
41
42 def VFPUnaryFrm   : Format<15>;
43 def VFPBinaryFrm  : Format<16>;
44 def VFPConv1Frm   : Format<17>;
45 def VFPConv2Frm   : Format<18>;
46 def VFPConv3Frm   : Format<19>;
47 def VFPConv4Frm   : Format<20>;
48 def VFPConv5Frm   : Format<21>;
49 def VFPLdStFrm    : Format<22>;
50 def VFPLdStMulFrm : Format<23>;
51 def VFPMiscFrm    : Format<24>;
52
53 def ThumbFrm      : Format<25>;
54 def MiscFrm       : Format<26>;
55
56 def NGetLnFrm     : Format<27>;
57 def NSetLnFrm     : Format<28>;
58 def NDupFrm       : Format<29>;
59 def NLdStFrm      : Format<30>;
60 def N1RegModImmFrm: Format<31>;
61 def N2RegFrm      : Format<32>;
62 def NVCVTFrm      : Format<33>;
63 def NVDupLnFrm    : Format<34>;
64 def N2RegVShLFrm  : Format<35>;
65 def N2RegVShRFrm  : Format<36>;
66 def N3RegFrm      : Format<37>;
67 def N3RegVShFrm   : Format<38>;
68 def NVExtFrm      : Format<39>;
69 def NVMulSLFrm    : Format<40>;
70 def NVTBLFrm      : Format<41>;
71 def DPSoRegImmFrm  : Format<42>;
72
73 // Misc flags.
74
75 // The instruction has an Rn register operand.
76 // UnaryDP - Indicates this is a unary data processing instruction, i.e.
77 // it doesn't have a Rn operand.
78 class UnaryDP    { bit isUnaryDataProc = 1; }
79
80 // Xform16Bit - Indicates this Thumb2 instruction may be transformed into
81 // a 16-bit Thumb instruction if certain conditions are met.
82 class Xform16Bit { bit canXformTo16Bit = 1; }
83
84 //===----------------------------------------------------------------------===//
85 // ARM Instruction flags.  These need to match ARMBaseInstrInfo.h.
86 //
87
88 // FIXME: Once the JIT is MC-ized, these can go away.
89 // Addressing mode.
90 class AddrMode<bits<5> val> {
91   bits<5> Value = val;
92 }
93 def AddrModeNone    : AddrMode<0>;
94 def AddrMode1       : AddrMode<1>;
95 def AddrMode2       : AddrMode<2>;
96 def AddrMode3       : AddrMode<3>;
97 def AddrMode4       : AddrMode<4>;
98 def AddrMode5       : AddrMode<5>;
99 def AddrMode6       : AddrMode<6>;
100 def AddrModeT1_1    : AddrMode<7>;
101 def AddrModeT1_2    : AddrMode<8>;
102 def AddrModeT1_4    : AddrMode<9>;
103 def AddrModeT1_s    : AddrMode<10>;
104 def AddrModeT2_i12  : AddrMode<11>;
105 def AddrModeT2_i8   : AddrMode<12>;
106 def AddrModeT2_so   : AddrMode<13>;
107 def AddrModeT2_pc   : AddrMode<14>;
108 def AddrModeT2_i8s4 : AddrMode<15>;
109 def AddrMode_i12    : AddrMode<16>;
110
111 // Load / store index mode.
112 class IndexMode<bits<2> val> {
113   bits<2> Value = val;
114 }
115 def IndexModeNone : IndexMode<0>;
116 def IndexModePre  : IndexMode<1>;
117 def IndexModePost : IndexMode<2>;
118 def IndexModeUpd  : IndexMode<3>;
119
120 // Instruction execution domain.
121 class Domain<bits<3> val> {
122   bits<3> Value = val;
123 }
124 def GenericDomain : Domain<0>;
125 def VFPDomain     : Domain<1>; // Instructions in VFP domain only
126 def NeonDomain    : Domain<2>; // Instructions in Neon domain only
127 def VFPNeonDomain : Domain<3>; // Instructions in both VFP & Neon domains
128 def VFPNeonA8Domain : Domain<5>; // Instructions in VFP & Neon under A8
129
130 //===----------------------------------------------------------------------===//
131 // ARM special operands.
132 //
133
134 // ARM imod and iflag operands, used only by the CPS instruction.
135 def imod_op : Operand<i32> {
136   let PrintMethod = "printCPSIMod";
137 }
138
139 def ProcIFlagsOperand : AsmOperandClass {
140   let Name = "ProcIFlags";
141   let ParserMethod = "parseProcIFlagsOperand";
142 }
143 def iflags_op : Operand<i32> {
144   let PrintMethod = "printCPSIFlag";
145   let ParserMatchClass = ProcIFlagsOperand;
146 }
147
148 // ARM Predicate operand. Default to 14 = always (AL). Second part is CC
149 // register whose default is 0 (no register).
150 def CondCodeOperand : AsmOperandClass { let Name = "CondCode"; }
151 def pred : PredicateOperand<OtherVT, (ops i32imm, CCR),
152                                      (ops (i32 14), (i32 zero_reg))> {
153   let PrintMethod = "printPredicateOperand";
154   let ParserMatchClass = CondCodeOperand;
155 }
156
157 // Conditional code result for instructions whose 's' bit is set, e.g. subs.
158 def CCOutOperand : AsmOperandClass { let Name = "CCOut"; }
159 def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
160   let EncoderMethod = "getCCOutOpValue";
161   let PrintMethod = "printSBitModifierOperand";
162   let ParserMatchClass = CCOutOperand;
163 }
164
165 // Same as cc_out except it defaults to setting CPSR.
166 def s_cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 CPSR))> {
167   let EncoderMethod = "getCCOutOpValue";
168   let PrintMethod = "printSBitModifierOperand";
169   let ParserMatchClass = CCOutOperand;
170 }
171
172 // ARM special operands for disassembly only.
173 //
174 def SetEndAsmOperand : AsmOperandClass {
175   let Name = "SetEndImm";
176   let ParserMethod = "parseSetEndImm";
177 }
178 def setend_op : Operand<i32> {
179   let PrintMethod = "printSetendOperand";
180   let ParserMatchClass = SetEndAsmOperand;
181 }
182
183 def MSRMaskOperand : AsmOperandClass {
184   let Name = "MSRMask";
185   let ParserMethod = "parseMSRMaskOperand";
186 }
187 def msr_mask : Operand<i32> {
188   let PrintMethod = "printMSRMaskOperand";
189   let ParserMatchClass = MSRMaskOperand;
190 }
191
192 // Shift Right Immediate - A shift right immediate is encoded differently from
193 // other shift immediates. The imm6 field is encoded like so:
194 //
195 //    Offset    Encoding
196 //     8        imm6<5:3> = '001', 8 - <imm> is encoded in imm6<2:0>
197 //     16       imm6<5:4> = '01', 16 - <imm> is encoded in imm6<3:0>
198 //     32       imm6<5> = '1', 32 - <imm> is encoded in imm6<4:0>
199 //     64       64 - <imm> is encoded in imm6<5:0>
200 def shr_imm8  : Operand<i32> {
201   let EncoderMethod = "getShiftRight8Imm";
202 }
203 def shr_imm16 : Operand<i32> {
204   let EncoderMethod = "getShiftRight16Imm";
205 }
206 def shr_imm32 : Operand<i32> {
207   let EncoderMethod = "getShiftRight32Imm";
208 }
209 def shr_imm64 : Operand<i32> {
210   let EncoderMethod = "getShiftRight64Imm";
211 }
212
213 //===----------------------------------------------------------------------===//
214 // ARM Instruction templates.
215 //
216
217 class InstTemplate<AddrMode am, int sz, IndexMode im,
218                    Format f, Domain d, string cstr, InstrItinClass itin>
219   : Instruction {
220   let Namespace = "ARM";
221
222   AddrMode AM = am;
223   int Size = sz;
224   IndexMode IM = im;
225   bits<2> IndexModeBits = IM.Value;
226   Format F = f;
227   bits<6> Form = F.Value;
228   Domain D = d;
229   bit isUnaryDataProc = 0;
230   bit canXformTo16Bit = 0;
231
232   // If this is a pseudo instruction, mark it isCodeGenOnly.
233   let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
234
235   // The layout of TSFlags should be kept in sync with ARMBaseInstrInfo.h.
236   let TSFlags{4-0}   = AM.Value;
237   let TSFlags{6-5}   = IndexModeBits;
238   let TSFlags{12-7} = Form;
239   let TSFlags{13}    = isUnaryDataProc;
240   let TSFlags{14}    = canXformTo16Bit;
241   let TSFlags{17-15} = D.Value;
242
243   let Constraints = cstr;
244   let Itinerary = itin;
245 }
246
247 class Encoding {
248   field bits<32> Inst;
249 }
250
251 class InstARM<AddrMode am, int sz, IndexMode im,
252               Format f, Domain d, string cstr, InstrItinClass itin>
253   : InstTemplate<am, sz, im, f, d, cstr, itin>, Encoding {
254   let DecoderNamespace = "ARM";
255 }
256
257 // This Encoding-less class is used by Thumb1 to specify the encoding bits later
258 // on by adding flavors to specific instructions.
259 class InstThumb<AddrMode am, int sz, IndexMode im,
260                 Format f, Domain d, string cstr, InstrItinClass itin>
261   : InstTemplate<am, sz, im, f, d, cstr, itin> {
262   let DecoderNamespace = "Thumb";
263 }
264
265 class PseudoInst<dag oops, dag iops, InstrItinClass itin, list<dag> pattern>
266   : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo,
267                  GenericDomain, "", itin> {
268   let OutOperandList = oops;
269   let InOperandList = iops;
270   let Pattern = pattern;
271   let isCodeGenOnly = 1;
272   let isPseudo = 1;
273 }
274
275 // PseudoInst that's ARM-mode only.
276 class ARMPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
277                     list<dag> pattern>
278   : PseudoInst<oops, iops, itin, pattern> {
279   let Size = sz;
280   list<Predicate> Predicates = [IsARM];
281 }
282
283 // PseudoInst that's Thumb-mode only.
284 class tPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
285                     list<dag> pattern>
286   : PseudoInst<oops, iops, itin, pattern> {
287   let Size = sz;
288   list<Predicate> Predicates = [IsThumb];
289 }
290
291 // PseudoInst that's Thumb2-mode only.
292 class t2PseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
293                     list<dag> pattern>
294   : PseudoInst<oops, iops, itin, pattern> {
295   let Size = sz;
296   list<Predicate> Predicates = [IsThumb2];
297 }
298
299 class ARMPseudoExpand<dag oops, dag iops, int sz,
300                       InstrItinClass itin, list<dag> pattern,
301                       dag Result>
302   : ARMPseudoInst<oops, iops, sz, itin, pattern>,
303     PseudoInstExpansion<Result>;
304
305 class tPseudoExpand<dag oops, dag iops, int sz,
306                     InstrItinClass itin, list<dag> pattern,
307                     dag Result>
308   : tPseudoInst<oops, iops, sz, itin, pattern>,
309     PseudoInstExpansion<Result>;
310
311 class t2PseudoExpand<dag oops, dag iops, int sz,
312                     InstrItinClass itin, list<dag> pattern,
313                     dag Result>
314   : t2PseudoInst<oops, iops, sz, itin, pattern>,
315     PseudoInstExpansion<Result>;
316
317 // Almost all ARM instructions are predicable.
318 class I<dag oops, dag iops, AddrMode am, int sz,
319         IndexMode im, Format f, InstrItinClass itin,
320         string opc, string asm, string cstr,
321         list<dag> pattern>
322   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
323   bits<4> p;
324   let Inst{31-28} = p;
325   let OutOperandList = oops;
326   let InOperandList = !con(iops, (ins pred:$p));
327   let AsmString = !strconcat(opc, "${p}", asm);
328   let Pattern = pattern;
329   list<Predicate> Predicates = [IsARM];
330 }
331
332 // A few are not predicable
333 class InoP<dag oops, dag iops, AddrMode am, int sz,
334            IndexMode im, Format f, InstrItinClass itin,
335            string opc, string asm, string cstr,
336            list<dag> pattern>
337   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
338   let OutOperandList = oops;
339   let InOperandList = iops;
340   let AsmString = !strconcat(opc, asm);
341   let Pattern = pattern;
342   let isPredicable = 0;
343   list<Predicate> Predicates = [IsARM];
344 }
345
346 // Same as I except it can optionally modify CPSR. Note it's modeled as an input
347 // operand since by default it's a zero register. It will become an implicit def
348 // once it's "flipped".
349 class sI<dag oops, dag iops, AddrMode am, int sz,
350          IndexMode im, Format f, InstrItinClass itin,
351          string opc, string asm, string cstr,
352          list<dag> pattern>
353   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
354   bits<4> p; // Predicate operand
355   bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
356   let Inst{31-28} = p;
357   let Inst{20} = s;
358
359   let OutOperandList = oops;
360   let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
361   let AsmString = !strconcat(opc, "${s}${p}", asm);
362   let Pattern = pattern;
363   list<Predicate> Predicates = [IsARM];
364 }
365
366 // Special cases
367 class XI<dag oops, dag iops, AddrMode am, int sz,
368          IndexMode im, Format f, InstrItinClass itin,
369          string asm, string cstr, list<dag> pattern>
370   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
371   let OutOperandList = oops;
372   let InOperandList = iops;
373   let AsmString = asm;
374   let Pattern = pattern;
375   list<Predicate> Predicates = [IsARM];
376 }
377
378 class AI<dag oops, dag iops, Format f, InstrItinClass itin,
379          string opc, string asm, list<dag> pattern>
380   : I<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
381       opc, asm, "", pattern>;
382 class AsI<dag oops, dag iops, Format f, InstrItinClass itin,
383           string opc, string asm, list<dag> pattern>
384   : sI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
385        opc, asm, "", pattern>;
386 class AXI<dag oops, dag iops, Format f, InstrItinClass itin,
387           string asm, list<dag> pattern>
388   : XI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
389        asm, "", pattern>;
390 class AInoP<dag oops, dag iops, Format f, InstrItinClass itin,
391             string opc, string asm, list<dag> pattern>
392   : InoP<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
393          opc, asm, "", pattern>;
394
395 // Ctrl flow instructions
396 class ABI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
397           string opc, string asm, list<dag> pattern>
398   : I<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
399       opc, asm, "", pattern> {
400   let Inst{27-24} = opcod;
401 }
402 class ABXI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
403            string asm, list<dag> pattern>
404   : XI<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
405        asm, "", pattern> {
406   let Inst{27-24} = opcod;
407 }
408
409 // BR_JT instructions
410 class JTI<dag oops, dag iops, InstrItinClass itin,
411           string asm, list<dag> pattern>
412   : XI<oops, iops, AddrModeNone, 0, IndexModeNone, BrMiscFrm, itin,
413        asm, "", pattern>;
414
415 // Atomic load/store instructions
416 class AIldrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
417               string opc, string asm, list<dag> pattern>
418   : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
419       opc, asm, "", pattern> {
420   bits<4> Rt;
421   bits<4> addr;
422   let Inst{27-23} = 0b00011;
423   let Inst{22-21} = opcod;
424   let Inst{20}    = 1;
425   let Inst{19-16} = addr;
426   let Inst{15-12} = Rt;
427   let Inst{11-0}  = 0b111110011111;
428 }
429 class AIstrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
430               string opc, string asm, list<dag> pattern>
431   : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
432       opc, asm, "", pattern> {
433   bits<4> Rd;
434   bits<4> Rt;
435   bits<4> addr;
436   let Inst{27-23} = 0b00011;
437   let Inst{22-21} = opcod;
438   let Inst{20}    = 0;
439   let Inst{19-16} = addr;
440   let Inst{15-12} = Rd;
441   let Inst{11-4}  = 0b11111001;
442   let Inst{3-0}   = Rt;
443 }
444 class AIswp<bit b, dag oops, dag iops, string opc, list<dag> pattern>
445   : AI<oops, iops, MiscFrm, NoItinerary, opc, "\t$Rt, $Rt2, $addr", pattern> {
446   bits<4> Rt;
447   bits<4> Rt2;
448   bits<4> addr;
449   let Inst{27-23} = 0b00010;
450   let Inst{22} = b;
451   let Inst{21-20} = 0b00;
452   let Inst{19-16} = addr;
453   let Inst{15-12} = Rt;
454   let Inst{11-4} = 0b00001001;
455   let Inst{3-0} = Rt2;
456 }
457
458 // addrmode1 instructions
459 class AI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
460           string opc, string asm, list<dag> pattern>
461   : I<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
462       opc, asm, "", pattern> {
463   let Inst{24-21} = opcod;
464   let Inst{27-26} = 0b00;
465 }
466 class AsI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
467            string opc, string asm, list<dag> pattern>
468   : sI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
469        opc, asm, "", pattern> {
470   let Inst{24-21} = opcod;
471   let Inst{27-26} = 0b00;
472 }
473 class AXI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
474            string asm, list<dag> pattern>
475   : XI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
476        asm, "", pattern> {
477   let Inst{24-21} = opcod;
478   let Inst{27-26} = 0b00;
479 }
480
481 // loads
482
483 // LDR/LDRB/STR/STRB/...
484 class AI2ldst<bits<3> op, bit isLd, bit isByte, dag oops, dag iops, AddrMode am,
485              Format f, InstrItinClass itin, string opc, string asm,
486              list<dag> pattern>
487   : I<oops, iops, am, 4, IndexModeNone, f, itin, opc, asm,
488       "", pattern> {
489   let Inst{27-25} = op;
490   let Inst{24} = 1;  // 24 == P
491   // 23 == U
492   let Inst{22} = isByte;
493   let Inst{21} = 0;  // 21 == W
494   let Inst{20} = isLd;
495 }
496 // Indexed load/stores
497 class AI2ldstidx<bit isLd, bit isByte, bit isPre, dag oops, dag iops,
498                 IndexMode im, Format f, InstrItinClass itin, string opc,
499                 string asm, string cstr, list<dag> pattern>
500   : I<oops, iops, AddrMode2, 4, im, f, itin,
501       opc, asm, cstr, pattern> {
502   bits<4> Rt;
503   let Inst{27-26} = 0b01;
504   let Inst{24}    = isPre; // P bit
505   let Inst{22}    = isByte; // B bit
506   let Inst{21}    = isPre; // W bit
507   let Inst{20}    = isLd; // L bit
508   let Inst{15-12} = Rt;
509 }
510 class AI2stridx_reg<bit isByte, bit isPre, dag oops, dag iops,
511                 IndexMode im, Format f, InstrItinClass itin, string opc,
512                 string asm, string cstr, list<dag> pattern>
513   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
514                pattern> {
515   // AM2 store w/ two operands: (GPR, am2offset)
516   // {12}     isAdd
517   // {11-0}   imm12/Rm
518   bits<14> offset;
519   bits<4> Rn;
520   let Inst{25} = 1;
521   let Inst{23} = offset{12};
522   let Inst{19-16} = Rn;
523   let Inst{11-5} = offset{11-5};
524   let Inst{4} = 0;
525   let Inst{3-0} = offset{3-0};
526 }
527
528 class AI2stridx_imm<bit isByte, bit isPre, dag oops, dag iops,
529                 IndexMode im, Format f, InstrItinClass itin, string opc,
530                 string asm, string cstr, list<dag> pattern>
531   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
532                pattern> {
533   // AM2 store w/ two operands: (GPR, am2offset)
534   // {12}     isAdd
535   // {11-0}   imm12/Rm
536   bits<14> offset;
537   bits<4> Rn;
538   let Inst{25} = 0;
539   let Inst{23} = offset{12};
540   let Inst{19-16} = Rn;
541   let Inst{11-0} = offset{11-0};
542 }
543
544
545 // FIXME: Merge with the above class when addrmode2 gets used for STR, STRB
546 // but for now use this class for STRT and STRBT.
547 class AI2stridxT<bit isByte, bit isPre, dag oops, dag iops,
548                 IndexMode im, Format f, InstrItinClass itin, string opc,
549                 string asm, string cstr, list<dag> pattern>
550   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
551                pattern> {
552   // AM2 store w/ two operands: (GPR, am2offset)
553   // {17-14}  Rn
554   // {13}     1 == Rm, 0 == imm12
555   // {12}     isAdd
556   // {11-0}   imm12/Rm
557   bits<18> addr;
558   let Inst{25} = addr{13};
559   let Inst{23} = addr{12};
560   let Inst{19-16} = addr{17-14};
561   let Inst{11-0} = addr{11-0};
562 }
563
564 // addrmode3 instructions
565 class AI3ld<bits<4> op, bit op20, dag oops, dag iops, Format f,
566             InstrItinClass itin, string opc, string asm, list<dag> pattern>
567   : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
568       opc, asm, "", pattern> {
569   bits<14> addr;
570   bits<4> Rt;
571   let Inst{27-25} = 0b000;
572   let Inst{24}    = 1;            // P bit
573   let Inst{23}    = addr{8};      // U bit
574   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
575   let Inst{21}    = 0;            // W bit
576   let Inst{20}    = op20;         // L bit
577   let Inst{19-16} = addr{12-9};   // Rn
578   let Inst{15-12} = Rt;           // Rt
579   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
580   let Inst{7-4}   = op;
581   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
582 }
583
584 class AI3ldstidx<bits<4> op, bit op20, bit isLd, bit isPre, dag oops, dag iops,
585                 IndexMode im, Format f, InstrItinClass itin, string opc,
586                 string asm, string cstr, list<dag> pattern>
587   : I<oops, iops, AddrMode3, 4, im, f, itin,
588       opc, asm, cstr, pattern> {
589   bits<4> Rt;
590   let Inst{27-25} = 0b000;
591   let Inst{24}    = isPre;        // P bit
592   let Inst{21}    = isPre;        // W bit
593   let Inst{20}    = op20;         // L bit
594   let Inst{15-12} = Rt;           // Rt
595   let Inst{7-4}   = op;
596 }
597
598 // FIXME: Merge with the above class when addrmode2 gets used for LDR, LDRB
599 // but for now use this class for LDRSBT, LDRHT, LDSHT.
600 class AI3ldstidxT<bits<4> op, bit isLoad, dag oops, dag iops,
601                   IndexMode im, Format f, InstrItinClass itin, string opc,
602                   string asm, string cstr, list<dag> pattern>
603   : I<oops, iops, AddrMode3, 4, im, f, itin, opc, asm, cstr, pattern> {
604   // {13}     1 == imm8, 0 == Rm
605   // {12-9}   Rn
606   // {8}      isAdd
607   // {7-4}    imm7_4/zero
608   // {3-0}    imm3_0/Rm
609   bits<4> addr;
610   bits<4> Rt;
611   let Inst{27-25} = 0b000;
612   let Inst{24}    = 0;            // P bit
613   let Inst{21}    = 1;
614   let Inst{20}    = isLoad;       // L bit
615   let Inst{19-16} = addr;         // Rn
616   let Inst{15-12} = Rt;           // Rt
617   let Inst{7-4}   = op;
618 }
619
620 class AI3stridx<bits<4> op, bit isByte, bit isPre, dag oops, dag iops,
621                 IndexMode im, Format f, InstrItinClass itin, string opc,
622                 string asm, string cstr, list<dag> pattern>
623   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
624                pattern> {
625   // AM3 store w/ two operands: (GPR, am3offset)
626   bits<14> offset;
627   bits<4> Rt;
628   bits<4> Rn;
629   let Inst{27-25} = 0b000;
630   let Inst{23}    = offset{8};
631   let Inst{22}    = offset{9};
632   let Inst{19-16} = Rn;
633   let Inst{15-12} = Rt;           // Rt
634   let Inst{11-8}  = offset{7-4};  // imm7_4/zero
635   let Inst{7-4}   = op;
636   let Inst{3-0}   = offset{3-0};  // imm3_0/Rm
637 }
638
639 // stores
640 class AI3str<bits<4> op, dag oops, dag iops, Format f, InstrItinClass itin,
641              string opc, string asm, list<dag> pattern>
642   : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
643       opc, asm, "", pattern> {
644   bits<14> addr;
645   bits<4> Rt;
646   let Inst{27-25} = 0b000;
647   let Inst{24}    = 1;            // P bit
648   let Inst{23}    = addr{8};      // U bit
649   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
650   let Inst{21}    = 0;            // W bit
651   let Inst{20}    = 0;            // L bit
652   let Inst{19-16} = addr{12-9};   // Rn
653   let Inst{15-12} = Rt;           // Rt
654   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
655   let Inst{7-4}   = op;
656   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
657 }
658
659 // Pre-indexed stores
660 class AI3sthpr<dag oops, dag iops, Format f, InstrItinClass itin,
661                string opc, string asm, string cstr, list<dag> pattern>
662   : I<oops, iops, AddrMode3, 4, IndexModePre, f, itin,
663       opc, asm, cstr, pattern> {
664   let Inst{4}     = 1;
665   let Inst{5}     = 1; // H bit
666   let Inst{6}     = 0; // S bit
667   let Inst{7}     = 1;
668   let Inst{20}    = 0; // L bit
669   let Inst{21}    = 1; // W bit
670   let Inst{24}    = 1; // P bit
671   let Inst{27-25} = 0b000;
672 }
673 class AI3stdpr<dag oops, dag iops, Format f, InstrItinClass itin,
674              string opc, string asm, string cstr, list<dag> pattern>
675   : I<oops, iops, AddrMode3, 4, IndexModePre, f, itin,
676       opc, asm, cstr, pattern> {
677   let Inst{4}     = 1;
678   let Inst{5}     = 1; // H bit
679   let Inst{6}     = 1; // S bit
680   let Inst{7}     = 1;
681   let Inst{20}    = 0; // L bit
682   let Inst{21}    = 1; // W bit
683   let Inst{24}    = 1; // P bit
684   let Inst{27-25} = 0b000;
685 }
686
687 // Post-indexed stores
688 class AI3stdpo<dag oops, dag iops, Format f, InstrItinClass itin,
689              string opc, string asm, string cstr, list<dag> pattern>
690   : I<oops, iops, AddrMode3, 4, IndexModePost, f, itin,
691       opc, asm, cstr, pattern> {
692   let Inst{4}     = 1;
693   let Inst{5}     = 1; // H bit
694   let Inst{6}     = 1; // S bit
695   let Inst{7}     = 1;
696   let Inst{20}    = 0; // L bit
697   let Inst{21}    = 0; // W bit
698   let Inst{24}    = 0; // P bit
699   let Inst{27-25} = 0b000;
700 }
701
702 // addrmode4 instructions
703 class AXI4<dag oops, dag iops, IndexMode im, Format f, InstrItinClass itin,
704            string asm, string cstr, list<dag> pattern>
705   : XI<oops, iops, AddrMode4, 4, im, f, itin, asm, cstr, pattern> {
706   bits<4>  p;
707   bits<16> regs;
708   bits<4>  Rn;
709   let Inst{31-28} = p;
710   let Inst{27-25} = 0b100;
711   let Inst{22}    = 0; // S bit
712   let Inst{19-16} = Rn;
713   let Inst{15-0}  = regs;
714 }
715
716 // Unsigned multiply, multiply-accumulate instructions.
717 class AMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
718              string opc, string asm, list<dag> pattern>
719   : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
720       opc, asm, "", pattern> {
721   let Inst{7-4}   = 0b1001;
722   let Inst{20}    = 0; // S bit
723   let Inst{27-21} = opcod;
724 }
725 class AsMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
726               string opc, string asm, list<dag> pattern>
727   : sI<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
728        opc, asm, "", pattern> {
729   let Inst{7-4}   = 0b1001;
730   let Inst{27-21} = opcod;
731 }
732
733 // Most significant word multiply
734 class AMul2I<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
735              InstrItinClass itin, string opc, string asm, list<dag> pattern>
736   : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
737       opc, asm, "", pattern> {
738   bits<4> Rd;
739   bits<4> Rn;
740   bits<4> Rm;
741   let Inst{7-4}   = opc7_4;
742   let Inst{20}    = 1;
743   let Inst{27-21} = opcod;
744   let Inst{19-16} = Rd;
745   let Inst{11-8}  = Rm;
746   let Inst{3-0}   = Rn;
747 }
748 // MSW multiple w/ Ra operand
749 class AMul2Ia<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
750               InstrItinClass itin, string opc, string asm, list<dag> pattern>
751   : AMul2I<opcod, opc7_4, oops, iops, itin, opc, asm, pattern> {
752   bits<4> Ra;
753   let Inst{15-12} = Ra;
754 }
755
756 // SMUL<x><y> / SMULW<y> / SMLA<x><y> / SMLAW<x><y>
757 class AMulxyIbase<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
758               InstrItinClass itin, string opc, string asm, list<dag> pattern>
759   : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
760       opc, asm, "", pattern> {
761   bits<4> Rn;
762   bits<4> Rm;
763   let Inst{4}     = 0;
764   let Inst{7}     = 1;
765   let Inst{20}    = 0;
766   let Inst{27-21} = opcod;
767   let Inst{6-5}   = bit6_5;
768   let Inst{11-8}  = Rm;
769   let Inst{3-0}   = Rn;
770 }
771 class AMulxyI<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
772               InstrItinClass itin, string opc, string asm, list<dag> pattern>
773   : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
774   bits<4> Rd;
775   let Inst{19-16} = Rd;
776 }
777
778 // AMulxyI with Ra operand
779 class AMulxyIa<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
780               InstrItinClass itin, string opc, string asm, list<dag> pattern>
781   : AMulxyI<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
782   bits<4> Ra;
783   let Inst{15-12} = Ra;
784 }
785 // SMLAL*
786 class AMulxyI64<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
787               InstrItinClass itin, string opc, string asm, list<dag> pattern>
788   : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
789   bits<4> RdLo;
790   bits<4> RdHi;
791   let Inst{19-16} = RdHi;
792   let Inst{15-12} = RdLo;
793 }
794
795 // Extend instructions.
796 class AExtI<bits<8> opcod, dag oops, dag iops, InstrItinClass itin,
797             string opc, string asm, list<dag> pattern>
798   : I<oops, iops, AddrModeNone, 4, IndexModeNone, ExtFrm, itin,
799       opc, asm, "", pattern> {
800   // All AExtI instructions have Rd and Rm register operands.
801   bits<4> Rd;
802   bits<4> Rm;
803   let Inst{15-12} = Rd;
804   let Inst{3-0}   = Rm;
805   let Inst{7-4}   = 0b0111;
806   let Inst{9-8}   = 0b00;
807   let Inst{27-20} = opcod;
808 }
809
810 // Misc Arithmetic instructions.
811 class AMiscA1I<bits<8> opcod, bits<4> opc7_4, dag oops, dag iops,
812                InstrItinClass itin, string opc, string asm, list<dag> pattern>
813   : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
814       opc, asm, "", pattern> {
815   bits<4> Rd;
816   bits<4> Rm;
817   let Inst{27-20} = opcod;
818   let Inst{19-16} = 0b1111;
819   let Inst{15-12} = Rd;
820   let Inst{11-8}  = 0b1111;
821   let Inst{7-4}   = opc7_4;
822   let Inst{3-0}   = Rm;
823 }
824
825 // PKH instructions
826 def PKHLSLAsmOperand : AsmOperandClass {
827   let Name = "PKHLSLImm";
828   let ParserMethod = "parsePKHLSLImm";
829 }
830 def pkh_lsl_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 32; }]>{
831   let PrintMethod = "printPKHLSLShiftImm";
832   let ParserMatchClass = PKHLSLAsmOperand;
833 }
834 def PKHASRAsmOperand : AsmOperandClass {
835   let Name = "PKHASRImm";
836   let ParserMethod = "parsePKHASRImm";
837 }
838 def pkh_asr_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]>{
839   let PrintMethod = "printPKHASRShiftImm";
840   let ParserMatchClass = PKHASRAsmOperand;
841 }
842
843 class APKHI<bits<8> opcod, bit tb, dag oops, dag iops, InstrItinClass itin,
844             string opc, string asm, list<dag> pattern>
845   : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
846       opc, asm, "", pattern> {
847   bits<4> Rd;
848   bits<4> Rn;
849   bits<4> Rm;
850   bits<5> sh;
851   let Inst{27-20} = opcod;
852   let Inst{19-16} = Rn;
853   let Inst{15-12} = Rd;
854   let Inst{11-7}  = sh;
855   let Inst{6}     = tb;
856   let Inst{5-4}   = 0b01;
857   let Inst{3-0}   = Rm;
858 }
859
860 //===----------------------------------------------------------------------===//
861
862 // ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
863 class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
864   list<Predicate> Predicates = [IsARM];
865 }
866 class ARMV5TPat<dag pattern, dag result> : Pat<pattern, result> {
867   list<Predicate> Predicates = [IsARM, HasV5T];
868 }
869 class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
870   list<Predicate> Predicates = [IsARM, HasV5TE];
871 }
872 class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
873   list<Predicate> Predicates = [IsARM, HasV6];
874 }
875
876 //===----------------------------------------------------------------------===//
877 // Thumb Instruction Format Definitions.
878 //
879
880 class ThumbI<dag oops, dag iops, AddrMode am, int sz,
881              InstrItinClass itin, string asm, string cstr, list<dag> pattern>
882   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
883   let OutOperandList = oops;
884   let InOperandList = iops;
885   let AsmString = asm;
886   let Pattern = pattern;
887   list<Predicate> Predicates = [IsThumb];
888 }
889
890 // TI - Thumb instruction.
891 class TI<dag oops, dag iops, InstrItinClass itin, string asm, list<dag> pattern>
892   : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
893
894 // Two-address instructions
895 class TIt<dag oops, dag iops, InstrItinClass itin, string asm,
896           list<dag> pattern>
897   : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "$lhs = $dst",
898            pattern>;
899
900 // tBL, tBX 32-bit instructions
901 class TIx2<bits<5> opcod1, bits<2> opcod2, bit opcod3,
902            dag oops, dag iops, InstrItinClass itin, string asm,
903            list<dag> pattern>
904     : ThumbI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>,
905       Encoding {
906   let Inst{31-27} = opcod1;
907   let Inst{15-14} = opcod2;
908   let Inst{12}    = opcod3;
909 }
910
911 // BR_JT instructions
912 class TJTI<dag oops, dag iops, InstrItinClass itin, string asm,
913            list<dag> pattern>
914   : ThumbI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
915
916 // Thumb1 only
917 class Thumb1I<dag oops, dag iops, AddrMode am, int sz,
918               InstrItinClass itin, string asm, string cstr, list<dag> pattern>
919   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
920   let OutOperandList = oops;
921   let InOperandList = iops;
922   let AsmString = asm;
923   let Pattern = pattern;
924   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
925 }
926
927 class T1I<dag oops, dag iops, InstrItinClass itin,
928           string asm, list<dag> pattern>
929   : Thumb1I<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
930 class T1Ix2<dag oops, dag iops, InstrItinClass itin,
931             string asm, list<dag> pattern>
932   : Thumb1I<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
933
934 // Two-address instructions
935 class T1It<dag oops, dag iops, InstrItinClass itin,
936            string asm, string cstr, list<dag> pattern>
937   : Thumb1I<oops, iops, AddrModeNone, 2, itin,
938             asm, cstr, pattern>;
939
940 // Thumb1 instruction that can either be predicated or set CPSR.
941 class Thumb1sI<dag oops, dag iops, AddrMode am, int sz,
942                InstrItinClass itin,
943                string opc, string asm, string cstr, list<dag> pattern>
944   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
945   let OutOperandList = !con(oops, (outs s_cc_out:$s));
946   let InOperandList = !con(iops, (ins pred:$p));
947   let AsmString = !strconcat(opc, "${s}${p}", asm);
948   let Pattern = pattern;
949   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
950 }
951
952 class T1sI<dag oops, dag iops, InstrItinClass itin,
953            string opc, string asm, list<dag> pattern>
954   : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
955
956 // Two-address instructions
957 class T1sIt<dag oops, dag iops, InstrItinClass itin,
958             string opc, string asm, list<dag> pattern>
959   : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm,
960              "$Rn = $Rdn", pattern>;
961
962 // Thumb1 instruction that can be predicated.
963 class Thumb1pI<dag oops, dag iops, AddrMode am, int sz,
964                InstrItinClass itin,
965                string opc, string asm, string cstr, list<dag> pattern>
966   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
967   let OutOperandList = oops;
968   let InOperandList = !con(iops, (ins pred:$p));
969   let AsmString = !strconcat(opc, "${p}", asm);
970   let Pattern = pattern;
971   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
972 }
973
974 class T1pI<dag oops, dag iops, InstrItinClass itin,
975            string opc, string asm, list<dag> pattern>
976   : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
977
978 // Two-address instructions
979 class T1pIt<dag oops, dag iops, InstrItinClass itin,
980             string opc, string asm, list<dag> pattern>
981   : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm,
982              "$Rn = $Rdn", pattern>;
983
984 class T1pIs<dag oops, dag iops,
985             InstrItinClass itin, string opc, string asm, list<dag> pattern>
986   : Thumb1pI<oops, iops, AddrModeT1_s, 2, itin, opc, asm, "", pattern>;
987
988 class Encoding16 : Encoding {
989   let Inst{31-16} = 0x0000;
990 }
991
992 // A6.2 16-bit Thumb instruction encoding
993 class T1Encoding<bits<6> opcode> : Encoding16 {
994   let Inst{15-10} = opcode;
995 }
996
997 // A6.2.1 Shift (immediate), add, subtract, move, and compare encoding.
998 class T1General<bits<5> opcode> : Encoding16 {
999   let Inst{15-14} = 0b00;
1000   let Inst{13-9} = opcode;
1001 }
1002
1003 // A6.2.2 Data-processing encoding.
1004 class T1DataProcessing<bits<4> opcode> : Encoding16 {
1005   let Inst{15-10} = 0b010000;
1006   let Inst{9-6} = opcode;
1007 }
1008
1009 // A6.2.3 Special data instructions and branch and exchange encoding.
1010 class T1Special<bits<4> opcode> : Encoding16 {
1011   let Inst{15-10} = 0b010001;
1012   let Inst{9-6}   = opcode;
1013 }
1014
1015 // A6.2.4 Load/store single data item encoding.
1016 class T1LoadStore<bits<4> opA, bits<3> opB> : Encoding16 {
1017   let Inst{15-12} = opA;
1018   let Inst{11-9}  = opB;
1019 }
1020 class T1LdStSP<bits<3> opB>   : T1LoadStore<0b1001, opB>; // SP relative
1021
1022 class T1BranchCond<bits<4> opcode> : Encoding16 {
1023   let Inst{15-12} = opcode;
1024 }
1025
1026 // Helper classes to encode Thumb1 loads and stores. For immediates, the
1027 // following bits are used for "opA" (see A6.2.4):
1028 //
1029 //   0b0110 => Immediate, 4 bytes
1030 //   0b1000 => Immediate, 2 bytes
1031 //   0b0111 => Immediate, 1 byte
1032 class T1pILdStEncode<bits<3> opcode, dag oops, dag iops, AddrMode am,
1033                      InstrItinClass itin, string opc, string asm,
1034                      list<dag> pattern>
1035   : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1036     T1LoadStore<0b0101, opcode> {
1037   bits<3> Rt;
1038   bits<8> addr;
1039   let Inst{8-6} = addr{5-3};    // Rm
1040   let Inst{5-3} = addr{2-0};    // Rn
1041   let Inst{2-0} = Rt;
1042 }
1043 class T1pILdStEncodeImm<bits<4> opA, bit opB, dag oops, dag iops, AddrMode am,
1044                         InstrItinClass itin, string opc, string asm,
1045                         list<dag> pattern>
1046   : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1047     T1LoadStore<opA, {opB,?,?}> {
1048   bits<3> Rt;
1049   bits<8> addr;
1050   let Inst{10-6} = addr{7-3};   // imm5
1051   let Inst{5-3}  = addr{2-0};   // Rn
1052   let Inst{2-0}  = Rt;
1053 }
1054
1055 // A6.2.5 Miscellaneous 16-bit instructions encoding.
1056 class T1Misc<bits<7> opcode> : Encoding16 {
1057   let Inst{15-12} = 0b1011;
1058   let Inst{11-5} = opcode;
1059 }
1060
1061 // Thumb2I - Thumb2 instruction. Almost all Thumb2 instructions are predicable.
1062 class Thumb2I<dag oops, dag iops, AddrMode am, int sz,
1063               InstrItinClass itin,
1064               string opc, string asm, string cstr, list<dag> pattern>
1065   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1066   let OutOperandList = oops;
1067   let InOperandList = !con(iops, (ins pred:$p));
1068   let AsmString = !strconcat(opc, "${p}", asm);
1069   let Pattern = pattern;
1070   list<Predicate> Predicates = [IsThumb2];
1071   let DecoderNamespace = "Thumb2";
1072 }
1073
1074 // Same as Thumb2I except it can optionally modify CPSR. Note it's modeled as an
1075 // input operand since by default it's a zero register. It will become an
1076 // implicit def once it's "flipped".
1077 //
1078 // FIXME: This uses unified syntax so {s} comes before {p}. We should make it
1079 // more consistent.
1080 class Thumb2sI<dag oops, dag iops, AddrMode am, int sz,
1081                InstrItinClass itin,
1082                string opc, string asm, string cstr, list<dag> pattern>
1083   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1084   bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
1085   let Inst{20} = s;
1086
1087   let OutOperandList = oops;
1088   let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
1089   let AsmString = !strconcat(opc, "${s}${p}", asm);
1090   let Pattern = pattern;
1091   list<Predicate> Predicates = [IsThumb2];
1092   let DecoderNamespace = "Thumb2";
1093 }
1094
1095 // Special cases
1096 class Thumb2XI<dag oops, dag iops, AddrMode am, int sz,
1097                InstrItinClass itin,
1098                string asm, string cstr, list<dag> pattern>
1099   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1100   let OutOperandList = oops;
1101   let InOperandList = iops;
1102   let AsmString = asm;
1103   let Pattern = pattern;
1104   list<Predicate> Predicates = [IsThumb2];
1105   let DecoderNamespace = "Thumb2";
1106 }
1107
1108 class ThumbXI<dag oops, dag iops, AddrMode am, int sz,
1109               InstrItinClass itin,
1110               string asm, string cstr, list<dag> pattern>
1111   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1112   let OutOperandList = oops;
1113   let InOperandList = iops;
1114   let AsmString = asm;
1115   let Pattern = pattern;
1116   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1117   let DecoderNamespace = "Thumb";
1118 }
1119
1120 class T2I<dag oops, dag iops, InstrItinClass itin,
1121           string opc, string asm, list<dag> pattern>
1122   : Thumb2I<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
1123 class T2Ii12<dag oops, dag iops, InstrItinClass itin,
1124              string opc, string asm, list<dag> pattern>
1125   : Thumb2I<oops, iops, AddrModeT2_i12, 4, itin, opc, asm, "",pattern>;
1126 class T2Ii8<dag oops, dag iops, InstrItinClass itin,
1127             string opc, string asm, list<dag> pattern>
1128   : Thumb2I<oops, iops, AddrModeT2_i8, 4, itin, opc, asm, "", pattern>;
1129 class T2Iso<dag oops, dag iops, InstrItinClass itin,
1130             string opc, string asm, list<dag> pattern>
1131   : Thumb2I<oops, iops, AddrModeT2_so, 4, itin, opc, asm, "", pattern>;
1132 class T2Ipc<dag oops, dag iops, InstrItinClass itin,
1133             string opc, string asm, list<dag> pattern>
1134   : Thumb2I<oops, iops, AddrModeT2_pc, 4, itin, opc, asm, "", pattern>;
1135 class T2Ii8s4<bit P, bit W, bit isLoad, dag oops, dag iops, InstrItinClass itin,
1136               string opc, string asm, list<dag> pattern>
1137   : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, "",
1138             pattern> {
1139   bits<4> Rt;
1140   bits<4> Rt2;
1141   bits<13> addr;
1142   let Inst{31-25} = 0b1110100;
1143   let Inst{24}    = P;
1144   let Inst{23}    = addr{8};
1145   let Inst{22}    = 1;
1146   let Inst{21}    = W;
1147   let Inst{20}    = isLoad;
1148   let Inst{19-16} = addr{12-9};
1149   let Inst{15-12} = Rt{3-0};
1150   let Inst{11-8}  = Rt2{3-0};
1151   let Inst{7-0}   = addr{7-0};
1152 }
1153
1154 class T2sI<dag oops, dag iops, InstrItinClass itin,
1155            string opc, string asm, list<dag> pattern>
1156   : Thumb2sI<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
1157
1158 class T2XI<dag oops, dag iops, InstrItinClass itin,
1159            string asm, list<dag> pattern>
1160   : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
1161 class T2JTI<dag oops, dag iops, InstrItinClass itin,
1162             string asm, list<dag> pattern>
1163   : Thumb2XI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
1164
1165 // Move to/from coprocessor instructions
1166 class T2Cop<bits<4> opc, dag oops, dag iops, string asm, list<dag> pattern>
1167   : T2XI <oops, iops, NoItinerary, asm, pattern>, Requires<[IsThumb2]> {
1168   let Inst{31-28} = opc;
1169 }
1170
1171 // Two-address instructions
1172 class T2XIt<dag oops, dag iops, InstrItinClass itin,
1173             string asm, string cstr, list<dag> pattern>
1174   : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, cstr, pattern>;
1175
1176 // T2Iidxldst - Thumb2 indexed load / store instructions.
1177 class T2Iidxldst<bit signed, bits<2> opcod, bit load, bit pre,
1178                  dag oops, dag iops,
1179                  AddrMode am, IndexMode im, InstrItinClass itin,
1180                  string opc, string asm, string cstr, list<dag> pattern>
1181   : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
1182   let OutOperandList = oops;
1183   let InOperandList = !con(iops, (ins pred:$p));
1184   let AsmString = !strconcat(opc, "${p}", asm);
1185   let Pattern = pattern;
1186   list<Predicate> Predicates = [IsThumb2];
1187   let DecoderNamespace = "Thumb2";
1188   let Inst{31-27} = 0b11111;
1189   let Inst{26-25} = 0b00;
1190   let Inst{24}    = signed;
1191   let Inst{23}    = 0;
1192   let Inst{22-21} = opcod;
1193   let Inst{20}    = load;
1194   let Inst{11}    = 1;
1195   // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1196   let Inst{10}    = pre; // The P bit.
1197   let Inst{8}     = 1; // The W bit.
1198
1199   bits<9> addr;
1200   let Inst{7-0} = addr{7-0};
1201   let Inst{9}   = addr{8}; // Sign bit
1202
1203   bits<4> Rt;
1204   bits<4> Rn;
1205   let Inst{15-12} = Rt{3-0};
1206   let Inst{19-16} = Rn{3-0};
1207 }
1208
1209 // Tv5Pat - Same as Pat<>, but requires V5T Thumb mode.
1210 class Tv5Pat<dag pattern, dag result> : Pat<pattern, result> {
1211   list<Predicate> Predicates = [IsThumb, IsThumb1Only, HasV5T];
1212 }
1213
1214 // T1Pat - Same as Pat<>, but requires that the compiler be in Thumb1 mode.
1215 class T1Pat<dag pattern, dag result> : Pat<pattern, result> {
1216   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1217 }
1218
1219 // T2v6Pat - Same as Pat<>, but requires V6T2 Thumb2 mode.
1220 class T2v6Pat<dag pattern, dag result> : Pat<pattern, result> {
1221   list<Predicate> Predicates = [IsThumb2, HasV6T2];
1222 }
1223
1224 // T2Pat - Same as Pat<>, but requires that the compiler be in Thumb2 mode.
1225 class T2Pat<dag pattern, dag result> : Pat<pattern, result> {
1226   list<Predicate> Predicates = [IsThumb2];
1227 }
1228
1229 //===----------------------------------------------------------------------===//
1230
1231 //===----------------------------------------------------------------------===//
1232 // ARM VFP Instruction templates.
1233 //
1234
1235 // Almost all VFP instructions are predicable.
1236 class VFPI<dag oops, dag iops, AddrMode am, int sz,
1237            IndexMode im, Format f, InstrItinClass itin,
1238            string opc, string asm, string cstr, list<dag> pattern>
1239   : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1240   bits<4> p;
1241   let Inst{31-28} = p;
1242   let OutOperandList = oops;
1243   let InOperandList = !con(iops, (ins pred:$p));
1244   let AsmString = !strconcat(opc, "${p}", asm);
1245   let Pattern = pattern;
1246   let PostEncoderMethod = "VFPThumb2PostEncoder";
1247   list<Predicate> Predicates = [HasVFP2];
1248 }
1249
1250 // Special cases
1251 class VFPXI<dag oops, dag iops, AddrMode am, int sz,
1252             IndexMode im, Format f, InstrItinClass itin,
1253             string asm, string cstr, list<dag> pattern>
1254   : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1255   bits<4> p;
1256   let Inst{31-28} = p;
1257   let OutOperandList = oops;
1258   let InOperandList = iops;
1259   let AsmString = asm;
1260   let Pattern = pattern;
1261   let PostEncoderMethod = "VFPThumb2PostEncoder";
1262   list<Predicate> Predicates = [HasVFP2];
1263 }
1264
1265 class VFPAI<dag oops, dag iops, Format f, InstrItinClass itin,
1266             string opc, string asm, list<dag> pattern>
1267   : VFPI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
1268          opc, asm, "", pattern> {
1269   let PostEncoderMethod = "VFPThumb2PostEncoder";
1270 }
1271
1272 // ARM VFP addrmode5 loads and stores
1273 class ADI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1274            InstrItinClass itin,
1275            string opc, string asm, list<dag> pattern>
1276   : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1277          VFPLdStFrm, itin, opc, asm, "", pattern> {
1278   // Instruction operands.
1279   bits<5>  Dd;
1280   bits<13> addr;
1281
1282   // Encode instruction operands.
1283   let Inst{23}    = addr{8};      // U (add = (U == '1'))
1284   let Inst{22}    = Dd{4};
1285   let Inst{19-16} = addr{12-9};   // Rn
1286   let Inst{15-12} = Dd{3-0};
1287   let Inst{7-0}   = addr{7-0};    // imm8
1288
1289   // TODO: Mark the instructions with the appropriate subtarget info.
1290   let Inst{27-24} = opcod1;
1291   let Inst{21-20} = opcod2;
1292   let Inst{11-9}  = 0b101;
1293   let Inst{8}     = 1;          // Double precision
1294
1295   // Loads & stores operate on both NEON and VFP pipelines.
1296   let D = VFPNeonDomain;
1297 }
1298
1299 class ASI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1300            InstrItinClass itin,
1301            string opc, string asm, list<dag> pattern>
1302   : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1303          VFPLdStFrm, itin, opc, asm, "", pattern> {
1304   // Instruction operands.
1305   bits<5>  Sd;
1306   bits<13> addr;
1307
1308   // Encode instruction operands.
1309   let Inst{23}    = addr{8};      // U (add = (U == '1'))
1310   let Inst{22}    = Sd{0};
1311   let Inst{19-16} = addr{12-9};   // Rn
1312   let Inst{15-12} = Sd{4-1};
1313   let Inst{7-0}   = addr{7-0};    // imm8
1314
1315   // TODO: Mark the instructions with the appropriate subtarget info.
1316   let Inst{27-24} = opcod1;
1317   let Inst{21-20} = opcod2;
1318   let Inst{11-9}  = 0b101;
1319   let Inst{8}     = 0;          // Single precision
1320
1321   // Loads & stores operate on both NEON and VFP pipelines.
1322   let D = VFPNeonDomain;
1323 }
1324
1325 // VFP Load / store multiple pseudo instructions.
1326 class PseudoVFPLdStM<dag oops, dag iops, InstrItinClass itin, string cstr,
1327                      list<dag> pattern>
1328   : InstARM<AddrMode4, 4, IndexModeNone, Pseudo, VFPNeonDomain,
1329             cstr, itin> {
1330   let OutOperandList = oops;
1331   let InOperandList = !con(iops, (ins pred:$p));
1332   let Pattern = pattern;
1333   list<Predicate> Predicates = [HasVFP2];
1334 }
1335
1336 // Load / store multiple
1337 class AXDI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1338             string asm, string cstr, list<dag> pattern>
1339   : VFPXI<oops, iops, AddrMode4, 4, im,
1340           VFPLdStMulFrm, itin, asm, cstr, pattern> {
1341   // Instruction operands.
1342   bits<4>  Rn;
1343   bits<13> regs;
1344
1345   // Encode instruction operands.
1346   let Inst{19-16} = Rn;
1347   let Inst{22}    = regs{12};
1348   let Inst{15-12} = regs{11-8};
1349   let Inst{7-0}   = regs{7-0};
1350
1351   // TODO: Mark the instructions with the appropriate subtarget info.
1352   let Inst{27-25} = 0b110;
1353   let Inst{11-9}  = 0b101;
1354   let Inst{8}     = 1;          // Double precision
1355 }
1356
1357 class AXSI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1358             string asm, string cstr, list<dag> pattern>
1359   : VFPXI<oops, iops, AddrMode4, 4, im,
1360           VFPLdStMulFrm, itin, asm, cstr, pattern> {
1361   // Instruction operands.
1362   bits<4> Rn;
1363   bits<13> regs;
1364
1365   // Encode instruction operands.
1366   let Inst{19-16} = Rn;
1367   let Inst{22}    = regs{8};
1368   let Inst{15-12} = regs{12-9};
1369   let Inst{7-0}   = regs{7-0};
1370
1371   // TODO: Mark the instructions with the appropriate subtarget info.
1372   let Inst{27-25} = 0b110;
1373   let Inst{11-9}  = 0b101;
1374   let Inst{8}     = 0;          // Single precision
1375 }
1376
1377 // Double precision, unary
1378 class ADuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1379            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1380            string asm, list<dag> pattern>
1381   : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1382   // Instruction operands.
1383   bits<5> Dd;
1384   bits<5> Dm;
1385
1386   // Encode instruction operands.
1387   let Inst{3-0}   = Dm{3-0};
1388   let Inst{5}     = Dm{4};
1389   let Inst{15-12} = Dd{3-0};
1390   let Inst{22}    = Dd{4};
1391
1392   let Inst{27-23} = opcod1;
1393   let Inst{21-20} = opcod2;
1394   let Inst{19-16} = opcod3;
1395   let Inst{11-9}  = 0b101;
1396   let Inst{8}     = 1;          // Double precision
1397   let Inst{7-6}   = opcod4;
1398   let Inst{4}     = opcod5;
1399 }
1400
1401 // Double precision, binary
1402 class ADbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1403            dag iops, InstrItinClass itin, string opc, string asm,
1404            list<dag> pattern>
1405   : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1406   // Instruction operands.
1407   bits<5> Dd;
1408   bits<5> Dn;
1409   bits<5> Dm;
1410
1411   // Encode instruction operands.
1412   let Inst{3-0}   = Dm{3-0};
1413   let Inst{5}     = Dm{4};
1414   let Inst{19-16} = Dn{3-0};
1415   let Inst{7}     = Dn{4};
1416   let Inst{15-12} = Dd{3-0};
1417   let Inst{22}    = Dd{4};
1418
1419   let Inst{27-23} = opcod1;
1420   let Inst{21-20} = opcod2;
1421   let Inst{11-9}  = 0b101;
1422   let Inst{8}     = 1;          // Double precision
1423   let Inst{6}     = op6;
1424   let Inst{4}     = op4;
1425 }
1426
1427 // Single precision, unary
1428 class ASuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1429            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1430            string asm, list<dag> pattern>
1431   : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1432   // Instruction operands.
1433   bits<5> Sd;
1434   bits<5> Sm;
1435
1436   // Encode instruction operands.
1437   let Inst{3-0}   = Sm{4-1};
1438   let Inst{5}     = Sm{0};
1439   let Inst{15-12} = Sd{4-1};
1440   let Inst{22}    = Sd{0};
1441
1442   let Inst{27-23} = opcod1;
1443   let Inst{21-20} = opcod2;
1444   let Inst{19-16} = opcod3;
1445   let Inst{11-9}  = 0b101;
1446   let Inst{8}     = 0;          // Single precision
1447   let Inst{7-6}   = opcod4;
1448   let Inst{4}     = opcod5;
1449 }
1450
1451 // Single precision unary, if no NEON. Same as ASuI except not available if
1452 // NEON is enabled.
1453 class ASuIn<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1454             bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1455             string asm, list<dag> pattern>
1456   : ASuI<opcod1, opcod2, opcod3, opcod4, opcod5, oops, iops, itin, opc, asm,
1457          pattern> {
1458   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1459 }
1460
1461 // Single precision, binary
1462 class ASbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
1463            InstrItinClass itin, string opc, string asm, list<dag> pattern>
1464   : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1465   // Instruction operands.
1466   bits<5> Sd;
1467   bits<5> Sn;
1468   bits<5> Sm;
1469
1470   // Encode instruction operands.
1471   let Inst{3-0}   = Sm{4-1};
1472   let Inst{5}     = Sm{0};
1473   let Inst{19-16} = Sn{4-1};
1474   let Inst{7}     = Sn{0};
1475   let Inst{15-12} = Sd{4-1};
1476   let Inst{22}    = Sd{0};
1477
1478   let Inst{27-23} = opcod1;
1479   let Inst{21-20} = opcod2;
1480   let Inst{11-9}  = 0b101;
1481   let Inst{8}     = 0;          // Single precision
1482   let Inst{6}     = op6;
1483   let Inst{4}     = op4;
1484 }
1485
1486 // Single precision binary, if no NEON. Same as ASbI except not available if
1487 // NEON is enabled.
1488 class ASbIn<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1489             dag iops, InstrItinClass itin, string opc, string asm,
1490             list<dag> pattern>
1491   : ASbI<opcod1, opcod2, op6, op4, oops, iops, itin, opc, asm, pattern> {
1492   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1493
1494   // Instruction operands.
1495   bits<5> Sd;
1496   bits<5> Sn;
1497   bits<5> Sm;
1498
1499   // Encode instruction operands.
1500   let Inst{3-0}   = Sm{4-1};
1501   let Inst{5}     = Sm{0};
1502   let Inst{19-16} = Sn{4-1};
1503   let Inst{7}     = Sn{0};
1504   let Inst{15-12} = Sd{4-1};
1505   let Inst{22}    = Sd{0};
1506 }
1507
1508 // VFP conversion instructions
1509 class AVConv1I<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
1510                dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1511                list<dag> pattern>
1512   : VFPAI<oops, iops, VFPConv1Frm, itin, opc, asm, pattern> {
1513   let Inst{27-23} = opcod1;
1514   let Inst{21-20} = opcod2;
1515   let Inst{19-16} = opcod3;
1516   let Inst{11-8}  = opcod4;
1517   let Inst{6}     = 1;
1518   let Inst{4}     = 0;
1519 }
1520
1521 // VFP conversion between floating-point and fixed-point
1522 class AVConv1XI<bits<5> op1, bits<2> op2, bits<4> op3, bits<4> op4, bit op5,
1523                 dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1524                 list<dag> pattern>
1525   : AVConv1I<op1, op2, op3, op4, oops, iops, itin, opc, asm, pattern> {
1526   // size (fixed-point number): sx == 0 ? 16 : 32
1527   let Inst{7} = op5; // sx
1528 }
1529
1530 // VFP conversion instructions, if no NEON
1531 class AVConv1In<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
1532                 dag oops, dag iops, InstrItinClass itin,
1533                 string opc, string asm, list<dag> pattern>
1534   : AVConv1I<opcod1, opcod2, opcod3, opcod4, oops, iops, itin, opc, asm,
1535              pattern> {
1536   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1537 }
1538
1539 class AVConvXI<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops, Format f,
1540                InstrItinClass itin,
1541                string opc, string asm, list<dag> pattern>
1542   : VFPAI<oops, iops, f, itin, opc, asm, pattern> {
1543   let Inst{27-20} = opcod1;
1544   let Inst{11-8}  = opcod2;
1545   let Inst{4}     = 1;
1546 }
1547
1548 class AVConv2I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1549                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1550   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv2Frm, itin, opc, asm, pattern>;
1551
1552 class AVConv3I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1553                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1554   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv3Frm, itin, opc, asm, pattern>;
1555
1556 class AVConv4I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1557                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1558   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv4Frm, itin, opc, asm, pattern>;
1559
1560 class AVConv5I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1561                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1562   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv5Frm, itin, opc, asm, pattern>;
1563
1564 //===----------------------------------------------------------------------===//
1565
1566 //===----------------------------------------------------------------------===//
1567 // ARM NEON Instruction templates.
1568 //
1569
1570 class NeonI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
1571             InstrItinClass itin, string opc, string dt, string asm, string cstr,
1572             list<dag> pattern>
1573   : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
1574   let OutOperandList = oops;
1575   let InOperandList = !con(iops, (ins pred:$p));
1576   let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
1577   let Pattern = pattern;
1578   list<Predicate> Predicates = [HasNEON];
1579 }
1580
1581 // Same as NeonI except it does not have a "data type" specifier.
1582 class NeonXI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
1583              InstrItinClass itin, string opc, string asm, string cstr,
1584              list<dag> pattern>
1585   : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
1586   let OutOperandList = oops;
1587   let InOperandList = !con(iops, (ins pred:$p));
1588   let AsmString = !strconcat(opc, "${p}", "\t", asm);
1589   let Pattern = pattern;
1590   list<Predicate> Predicates = [HasNEON];
1591 }
1592
1593 class NLdSt<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
1594             dag oops, dag iops, InstrItinClass itin,
1595             string opc, string dt, string asm, string cstr, list<dag> pattern>
1596   : NeonI<oops, iops, AddrMode6, IndexModeNone, NLdStFrm, itin, opc, dt, asm,
1597           cstr, pattern> {
1598   let Inst{31-24} = 0b11110100;
1599   let Inst{23}    = op23;
1600   let Inst{21-20} = op21_20;
1601   let Inst{11-8}  = op11_8;
1602   let Inst{7-4}   = op7_4;
1603
1604   let PostEncoderMethod = "NEONThumb2LoadStorePostEncoder";
1605
1606   bits<5> Vd;
1607   bits<6> Rn;
1608   bits<4> Rm;
1609
1610   let Inst{22}    = Vd{4};
1611   let Inst{15-12} = Vd{3-0};
1612   let Inst{19-16} = Rn{3-0};
1613   let Inst{3-0}   = Rm{3-0};
1614 }
1615
1616 class NLdStLn<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
1617             dag oops, dag iops, InstrItinClass itin,
1618             string opc, string dt, string asm, string cstr, list<dag> pattern>
1619   : NLdSt<op23, op21_20, op11_8, op7_4, oops, iops, itin, opc,
1620           dt, asm, cstr, pattern> {
1621   bits<3> lane;
1622 }
1623
1624 class PseudoNLdSt<dag oops, dag iops, InstrItinClass itin, string cstr>
1625   : InstARM<AddrMode6, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
1626             itin> {
1627   let OutOperandList = oops;
1628   let InOperandList = !con(iops, (ins pred:$p));
1629   list<Predicate> Predicates = [HasNEON];
1630 }
1631
1632 class PseudoNeonI<dag oops, dag iops, InstrItinClass itin, string cstr,
1633                   list<dag> pattern>
1634   : InstARM<AddrModeNone, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
1635             itin> {
1636   let OutOperandList = oops;
1637   let InOperandList = !con(iops, (ins pred:$p));
1638   let Pattern = pattern;
1639   list<Predicate> Predicates = [HasNEON];
1640 }
1641
1642 class NDataI<dag oops, dag iops, Format f, InstrItinClass itin,
1643              string opc, string dt, string asm, string cstr, list<dag> pattern>
1644   : NeonI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, dt, asm, cstr,
1645           pattern> {
1646   let Inst{31-25} = 0b1111001;
1647   let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
1648 }
1649
1650 class NDataXI<dag oops, dag iops, Format f, InstrItinClass itin,
1651               string opc, string asm, string cstr, list<dag> pattern>
1652   : NeonXI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, asm,
1653            cstr, pattern> {
1654   let Inst{31-25} = 0b1111001;
1655   let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
1656 }
1657
1658 // NEON "one register and a modified immediate" format.
1659 class N1ModImm<bit op23, bits<3> op21_19, bits<4> op11_8, bit op7, bit op6,
1660                bit op5, bit op4,
1661                dag oops, dag iops, InstrItinClass itin,
1662                string opc, string dt, string asm, string cstr,
1663                list<dag> pattern>
1664   : NDataI<oops, iops, N1RegModImmFrm, itin, opc, dt, asm, cstr, pattern> {
1665   let Inst{23}    = op23;
1666   let Inst{21-19} = op21_19;
1667   let Inst{11-8}  = op11_8;
1668   let Inst{7}     = op7;
1669   let Inst{6}     = op6;
1670   let Inst{5}     = op5;
1671   let Inst{4}     = op4;
1672
1673   // Instruction operands.
1674   bits<5> Vd;
1675   bits<13> SIMM;
1676
1677   let Inst{15-12} = Vd{3-0};
1678   let Inst{22}    = Vd{4};
1679   let Inst{24}    = SIMM{7};
1680   let Inst{18-16} = SIMM{6-4};
1681   let Inst{3-0}   = SIMM{3-0};
1682 }
1683
1684 // NEON 2 vector register format.
1685 class N2V<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
1686           bits<5> op11_7, bit op6, bit op4,
1687           dag oops, dag iops, InstrItinClass itin,
1688           string opc, string dt, string asm, string cstr, list<dag> pattern>
1689   : NDataI<oops, iops, N2RegFrm, itin, opc, dt, asm, cstr, pattern> {
1690   let Inst{24-23} = op24_23;
1691   let Inst{21-20} = op21_20;
1692   let Inst{19-18} = op19_18;
1693   let Inst{17-16} = op17_16;
1694   let Inst{11-7}  = op11_7;
1695   let Inst{6}     = op6;
1696   let Inst{4}     = op4;
1697
1698   // Instruction operands.
1699   bits<5> Vd;
1700   bits<5> Vm;
1701
1702   let Inst{15-12} = Vd{3-0};
1703   let Inst{22}    = Vd{4};
1704   let Inst{3-0}   = Vm{3-0};
1705   let Inst{5}     = Vm{4};
1706 }
1707
1708 // Same as N2V except it doesn't have a datatype suffix.
1709 class N2VX<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
1710            bits<5> op11_7, bit op6, bit op4,
1711            dag oops, dag iops, InstrItinClass itin,
1712            string opc, string asm, string cstr, list<dag> pattern>
1713   : NDataXI<oops, iops, N2RegFrm, itin, opc, asm, cstr, pattern> {
1714   let Inst{24-23} = op24_23;
1715   let Inst{21-20} = op21_20;
1716   let Inst{19-18} = op19_18;
1717   let Inst{17-16} = op17_16;
1718   let Inst{11-7}  = op11_7;
1719   let Inst{6}     = op6;
1720   let Inst{4}     = op4;
1721
1722   // Instruction operands.
1723   bits<5> Vd;
1724   bits<5> Vm;
1725
1726   let Inst{15-12} = Vd{3-0};
1727   let Inst{22}    = Vd{4};
1728   let Inst{3-0}   = Vm{3-0};
1729   let Inst{5}     = Vm{4};
1730 }
1731
1732 // NEON 2 vector register with immediate.
1733 class N2VImm<bit op24, bit op23, bits<4> op11_8, bit op7, bit op6, bit op4,
1734              dag oops, dag iops, Format f, InstrItinClass itin,
1735              string opc, string dt, string asm, string cstr, list<dag> pattern>
1736   : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1737   let Inst{24}   = op24;
1738   let Inst{23}   = op23;
1739   let Inst{11-8} = op11_8;
1740   let Inst{7}    = op7;
1741   let Inst{6}    = op6;
1742   let Inst{4}    = op4;
1743
1744   // Instruction operands.
1745   bits<5> Vd;
1746   bits<5> Vm;
1747   bits<6> SIMM;
1748
1749   let Inst{15-12} = Vd{3-0};
1750   let Inst{22}    = Vd{4};
1751   let Inst{3-0}   = Vm{3-0};
1752   let Inst{5}     = Vm{4};
1753   let Inst{21-16} = SIMM{5-0};
1754 }
1755
1756 // NEON 3 vector register format.
1757
1758 class N3VCommon<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
1759                 bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
1760                 string opc, string dt, string asm, string cstr,
1761                 list<dag> pattern>
1762   : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1763   let Inst{24}    = op24;
1764   let Inst{23}    = op23;
1765   let Inst{21-20} = op21_20;
1766   let Inst{11-8}  = op11_8;
1767   let Inst{6}     = op6;
1768   let Inst{4}     = op4;
1769 }
1770
1771 class N3V<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6, bit op4,
1772           dag oops, dag iops, Format f, InstrItinClass itin,
1773           string opc, string dt, string asm, string cstr, list<dag> pattern>
1774   : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
1775               oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1776
1777   // Instruction operands.
1778   bits<5> Vd;
1779   bits<5> Vn;
1780   bits<5> Vm;
1781
1782   let Inst{15-12} = Vd{3-0};
1783   let Inst{22}    = Vd{4};
1784   let Inst{19-16} = Vn{3-0};
1785   let Inst{7}     = Vn{4};
1786   let Inst{3-0}   = Vm{3-0};
1787   let Inst{5}     = Vm{4};
1788 }
1789
1790 class N3VLane32<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
1791                 bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
1792                 string opc, string dt, string asm, string cstr,
1793                 list<dag> pattern>
1794   : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
1795               oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1796
1797   // Instruction operands.
1798   bits<5> Vd;
1799   bits<5> Vn;
1800   bits<5> Vm;
1801   bit lane;
1802
1803   let Inst{15-12} = Vd{3-0};
1804   let Inst{22}    = Vd{4};
1805   let Inst{19-16} = Vn{3-0};
1806   let Inst{7}     = Vn{4};
1807   let Inst{3-0}   = Vm{3-0};
1808   let Inst{5}     = lane;
1809 }
1810
1811 class N3VLane16<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
1812                 bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
1813                 string opc, string dt, string asm, string cstr,
1814                 list<dag> pattern>
1815   : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
1816               oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1817
1818   // Instruction operands.
1819   bits<5> Vd;
1820   bits<5> Vn;
1821   bits<5> Vm;
1822   bits<2> lane;
1823
1824   let Inst{15-12} = Vd{3-0};
1825   let Inst{22}    = Vd{4};
1826   let Inst{19-16} = Vn{3-0};
1827   let Inst{7}     = Vn{4};
1828   let Inst{2-0}   = Vm{2-0};
1829   let Inst{5}     = lane{1};
1830   let Inst{3}     = lane{0};
1831 }
1832
1833 // Same as N3V except it doesn't have a data type suffix.
1834 class N3VX<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
1835            bit op4,
1836            dag oops, dag iops, Format f, InstrItinClass itin,
1837            string opc, string asm, string cstr, list<dag> pattern>
1838   : NDataXI<oops, iops, f, itin, opc, asm, cstr, pattern> {
1839   let Inst{24}    = op24;
1840   let Inst{23}    = op23;
1841   let Inst{21-20} = op21_20;
1842   let Inst{11-8}  = op11_8;
1843   let Inst{6}     = op6;
1844   let Inst{4}     = op4;
1845
1846   // Instruction operands.
1847   bits<5> Vd;
1848   bits<5> Vn;
1849   bits<5> Vm;
1850
1851   let Inst{15-12} = Vd{3-0};
1852   let Inst{22}    = Vd{4};
1853   let Inst{19-16} = Vn{3-0};
1854   let Inst{7}     = Vn{4};
1855   let Inst{3-0}   = Vm{3-0};
1856   let Inst{5}     = Vm{4};
1857 }
1858
1859 // NEON VMOVs between scalar and core registers.
1860 class NVLaneOp<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1861                dag oops, dag iops, Format f, InstrItinClass itin,
1862                string opc, string dt, string asm, list<dag> pattern>
1863   : InstARM<AddrModeNone, 4, IndexModeNone, f, NeonDomain,
1864             "", itin> {
1865   let Inst{27-20} = opcod1;
1866   let Inst{11-8}  = opcod2;
1867   let Inst{6-5}   = opcod3;
1868   let Inst{4}     = 1;
1869   // A8.6.303, A8.6.328, A8.6.329
1870   let Inst{3-0}   = 0b0000;
1871
1872   let OutOperandList = oops;
1873   let InOperandList = !con(iops, (ins pred:$p));
1874   let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
1875   let Pattern = pattern;
1876   list<Predicate> Predicates = [HasNEON];
1877
1878   let PostEncoderMethod = "NEONThumb2DupPostEncoder";
1879
1880   bits<5> V;
1881   bits<4> R;
1882   bits<4> p;
1883   bits<4> lane;
1884
1885   let Inst{31-28} = p{3-0};
1886   let Inst{7}     = V{4};
1887   let Inst{19-16} = V{3-0};
1888   let Inst{15-12} = R{3-0};
1889 }
1890 class NVGetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1891                 dag oops, dag iops, InstrItinClass itin,
1892                 string opc, string dt, string asm, list<dag> pattern>
1893   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NGetLnFrm, itin,
1894              opc, dt, asm, pattern>;
1895 class NVSetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1896                 dag oops, dag iops, InstrItinClass itin,
1897                 string opc, string dt, string asm, list<dag> pattern>
1898   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NSetLnFrm, itin,
1899              opc, dt, asm, pattern>;
1900 class NVDup<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
1901             dag oops, dag iops, InstrItinClass itin,
1902             string opc, string dt, string asm, list<dag> pattern>
1903   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NDupFrm, itin,
1904              opc, dt, asm, pattern>;
1905
1906 // Vector Duplicate Lane (from scalar to all elements)
1907 class NVDupLane<bits<4> op19_16, bit op6, dag oops, dag iops,
1908                 InstrItinClass itin, string opc, string dt, string asm,
1909                 list<dag> pattern>
1910   : NDataI<oops, iops, NVDupLnFrm, itin, opc, dt, asm, "", pattern> {
1911   let Inst{24-23} = 0b11;
1912   let Inst{21-20} = 0b11;
1913   let Inst{19-16} = op19_16;
1914   let Inst{11-7}  = 0b11000;
1915   let Inst{6}     = op6;
1916   let Inst{4}     = 0;
1917
1918   bits<5> Vd;
1919   bits<5> Vm;
1920   bits<4> lane;
1921
1922   let Inst{22}     = Vd{4};
1923   let Inst{15-12} = Vd{3-0};
1924   let Inst{5}     = Vm{4};
1925   let Inst{3-0} = Vm{3-0};
1926 }
1927
1928 // NEONFPPat - Same as Pat<>, but requires that the compiler be using NEON
1929 // for single-precision FP.
1930 class NEONFPPat<dag pattern, dag result> : Pat<pattern, result> {
1931   list<Predicate> Predicates = [HasNEON,UseNEONForFP];
1932 }