OSDN Git Service

Add MC assembly/disassembly support for VRINT{A, N, P, M} to V8FP.
[android-x86/external-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, i32imm),
152                                      (ops (i32 14), (i32 zero_reg))> {
153   let PrintMethod = "printPredicateOperand";
154   let ParserMatchClass = CondCodeOperand;
155   let DecoderMethod = "DecodePredicateOperand";
156 }
157
158 // Conditional code result for instructions whose 's' bit is set, e.g. subs.
159 def CCOutOperand : AsmOperandClass { let Name = "CCOut"; }
160 def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
161   let EncoderMethod = "getCCOutOpValue";
162   let PrintMethod = "printSBitModifierOperand";
163   let ParserMatchClass = CCOutOperand;
164   let DecoderMethod = "DecodeCCOutOperand";
165 }
166
167 // Same as cc_out except it defaults to setting CPSR.
168 def s_cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 CPSR))> {
169   let EncoderMethod = "getCCOutOpValue";
170   let PrintMethod = "printSBitModifierOperand";
171   let ParserMatchClass = CCOutOperand;
172   let DecoderMethod = "DecodeCCOutOperand";
173 }
174
175 // ARM special operands for disassembly only.
176 //
177 def SetEndAsmOperand : ImmAsmOperand {
178   let Name = "SetEndImm";
179   let ParserMethod = "parseSetEndImm";
180 }
181 def setend_op : Operand<i32> {
182   let PrintMethod = "printSetendOperand";
183   let ParserMatchClass = SetEndAsmOperand;
184 }
185
186 def MSRMaskOperand : AsmOperandClass {
187   let Name = "MSRMask";
188   let ParserMethod = "parseMSRMaskOperand";
189 }
190 def msr_mask : Operand<i32> {
191   let PrintMethod = "printMSRMaskOperand";
192   let DecoderMethod = "DecodeMSRMask";
193   let ParserMatchClass = MSRMaskOperand;
194 }
195
196 // Shift Right Immediate - A shift right immediate is encoded differently from
197 // other shift immediates. The imm6 field is encoded like so:
198 //
199 //    Offset    Encoding
200 //     8        imm6<5:3> = '001', 8 - <imm> is encoded in imm6<2:0>
201 //     16       imm6<5:4> = '01', 16 - <imm> is encoded in imm6<3:0>
202 //     32       imm6<5> = '1', 32 - <imm> is encoded in imm6<4:0>
203 //     64       64 - <imm> is encoded in imm6<5:0>
204 def shr_imm8_asm_operand : ImmAsmOperand { let Name = "ShrImm8"; }
205 def shr_imm8  : Operand<i32> {
206   let EncoderMethod = "getShiftRight8Imm";
207   let DecoderMethod = "DecodeShiftRight8Imm";
208   let ParserMatchClass = shr_imm8_asm_operand;
209 }
210 def shr_imm16_asm_operand : ImmAsmOperand { let Name = "ShrImm16"; }
211 def shr_imm16 : Operand<i32> {
212   let EncoderMethod = "getShiftRight16Imm";
213   let DecoderMethod = "DecodeShiftRight16Imm";
214   let ParserMatchClass = shr_imm16_asm_operand;
215 }
216 def shr_imm32_asm_operand : ImmAsmOperand { let Name = "ShrImm32"; }
217 def shr_imm32 : Operand<i32> {
218   let EncoderMethod = "getShiftRight32Imm";
219   let DecoderMethod = "DecodeShiftRight32Imm";
220   let ParserMatchClass = shr_imm32_asm_operand;
221 }
222 def shr_imm64_asm_operand : ImmAsmOperand { let Name = "ShrImm64"; }
223 def shr_imm64 : Operand<i32> {
224   let EncoderMethod = "getShiftRight64Imm";
225   let DecoderMethod = "DecodeShiftRight64Imm";
226   let ParserMatchClass = shr_imm64_asm_operand;
227 }
228
229 //===----------------------------------------------------------------------===//
230 // ARM Assembler alias templates.
231 //
232 class ARMInstAlias<string Asm, dag Result, bit Emit = 0b1>
233       : InstAlias<Asm, Result, Emit>, Requires<[IsARM]>;
234 class  tInstAlias<string Asm, dag Result, bit Emit = 0b1>
235       : InstAlias<Asm, Result, Emit>, Requires<[IsThumb]>;
236 class t2InstAlias<string Asm, dag Result, bit Emit = 0b1>
237       : InstAlias<Asm, Result, Emit>, Requires<[IsThumb2]>;
238 class VFP2InstAlias<string Asm, dag Result, bit Emit = 0b1>
239       : InstAlias<Asm, Result, Emit>, Requires<[HasVFP2]>;
240 class VFP3InstAlias<string Asm, dag Result, bit Emit = 0b1>
241       : InstAlias<Asm, Result, Emit>, Requires<[HasVFP3]>;
242 class NEONInstAlias<string Asm, dag Result, bit Emit = 0b1>
243       : InstAlias<Asm, Result, Emit>, Requires<[HasNEON]>;
244
245
246 class VFP2MnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
247           Requires<[HasVFP2]>;
248 class NEONMnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
249           Requires<[HasNEON]>;
250
251 //===----------------------------------------------------------------------===//
252 // ARM Instruction templates.
253 //
254
255
256 class InstTemplate<AddrMode am, int sz, IndexMode im,
257                    Format f, Domain d, string cstr, InstrItinClass itin>
258   : Instruction {
259   let Namespace = "ARM";
260
261   AddrMode AM = am;
262   int Size = sz;
263   IndexMode IM = im;
264   bits<2> IndexModeBits = IM.Value;
265   Format F = f;
266   bits<6> Form = F.Value;
267   Domain D = d;
268   bit isUnaryDataProc = 0;
269   bit canXformTo16Bit = 0;
270   // The instruction is a 16-bit flag setting Thumb instruction. Used
271   // by the parser to determine whether to require the 'S' suffix on the
272   // mnemonic (when not in an IT block) or preclude it (when in an IT block).
273   bit thumbArithFlagSetting = 0;
274
275   // If this is a pseudo instruction, mark it isCodeGenOnly.
276   let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
277
278   // The layout of TSFlags should be kept in sync with ARMBaseInfo.h.
279   let TSFlags{4-0}   = AM.Value;
280   let TSFlags{6-5}   = IndexModeBits;
281   let TSFlags{12-7} = Form;
282   let TSFlags{13}    = isUnaryDataProc;
283   let TSFlags{14}    = canXformTo16Bit;
284   let TSFlags{17-15} = D.Value;
285   let TSFlags{18}    = thumbArithFlagSetting;
286
287   let Constraints = cstr;
288   let Itinerary = itin;
289 }
290
291 class Encoding {
292   field bits<32> Inst;
293   // Mask of bits that cause an encoding to be UNPREDICTABLE.
294   // If a bit is set, then if the corresponding bit in the
295   // target encoding differs from its value in the "Inst" field,
296   // the instruction is UNPREDICTABLE (SoftFail in abstract parlance).
297   field bits<32> Unpredictable = 0;
298   // SoftFail is the generic name for this field, but we alias it so
299   // as to make it more obvious what it means in ARM-land.
300   field bits<32> SoftFail = Unpredictable;
301 }
302
303 class InstARM<AddrMode am, int sz, IndexMode im,
304               Format f, Domain d, string cstr, InstrItinClass itin>
305   : InstTemplate<am, sz, im, f, d, cstr, itin>, Encoding {
306   let DecoderNamespace = "ARM";
307 }
308
309 // This Encoding-less class is used by Thumb1 to specify the encoding bits later
310 // on by adding flavors to specific instructions.
311 class InstThumb<AddrMode am, int sz, IndexMode im,
312                 Format f, Domain d, string cstr, InstrItinClass itin>
313   : InstTemplate<am, sz, im, f, d, cstr, itin> {
314   let DecoderNamespace = "Thumb";
315 }
316
317 // Pseudo-instructions for alternate assembly syntax (never used by codegen).
318 // These are aliases that require C++ handling to convert to the target
319 // instruction, while InstAliases can be handled directly by tblgen.
320 class AsmPseudoInst<string asm, dag iops>
321   : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo, GenericDomain,
322                  "", NoItinerary> {
323   let OutOperandList = (outs);
324   let InOperandList = iops;
325   let Pattern = [];
326   let isCodeGenOnly = 0; // So we get asm matcher for it.
327   let AsmString = asm;
328   let isPseudo = 1;
329 }
330
331 class ARMAsmPseudo<string asm, dag iops> : AsmPseudoInst<asm, iops>,
332         Requires<[IsARM]>;
333 class tAsmPseudo<string asm, dag iops> : AsmPseudoInst<asm, iops>,
334         Requires<[IsThumb]>;
335 class t2AsmPseudo<string asm, dag iops> : AsmPseudoInst<asm, iops>,
336         Requires<[IsThumb2]>;
337 class VFP2AsmPseudo<string asm, dag iops> : AsmPseudoInst<asm, iops>,
338         Requires<[HasVFP2]>;
339 class NEONAsmPseudo<string asm, dag iops> : AsmPseudoInst<asm, iops>,
340         Requires<[HasNEON]>;
341
342 // Pseudo instructions for the code generator.
343 class PseudoInst<dag oops, dag iops, InstrItinClass itin, list<dag> pattern>
344   : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo,
345                  GenericDomain, "", itin> {
346   let OutOperandList = oops;
347   let InOperandList = iops;
348   let Pattern = pattern;
349   let isCodeGenOnly = 1;
350   let isPseudo = 1;
351 }
352
353 // PseudoInst that's ARM-mode only.
354 class ARMPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
355                     list<dag> pattern>
356   : PseudoInst<oops, iops, itin, pattern> {
357   let Size = sz;
358   list<Predicate> Predicates = [IsARM];
359 }
360
361 // PseudoInst that's Thumb-mode only.
362 class tPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
363                     list<dag> pattern>
364   : PseudoInst<oops, iops, itin, pattern> {
365   let Size = sz;
366   list<Predicate> Predicates = [IsThumb];
367 }
368
369 // PseudoInst that's Thumb2-mode only.
370 class t2PseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
371                     list<dag> pattern>
372   : PseudoInst<oops, iops, itin, pattern> {
373   let Size = sz;
374   list<Predicate> Predicates = [IsThumb2];
375 }
376
377 class ARMPseudoExpand<dag oops, dag iops, int sz,
378                       InstrItinClass itin, list<dag> pattern,
379                       dag Result>
380   : ARMPseudoInst<oops, iops, sz, itin, pattern>,
381     PseudoInstExpansion<Result>;
382
383 class tPseudoExpand<dag oops, dag iops, int sz,
384                     InstrItinClass itin, list<dag> pattern,
385                     dag Result>
386   : tPseudoInst<oops, iops, sz, itin, pattern>,
387     PseudoInstExpansion<Result>;
388
389 class t2PseudoExpand<dag oops, dag iops, int sz,
390                     InstrItinClass itin, list<dag> pattern,
391                     dag Result>
392   : t2PseudoInst<oops, iops, sz, itin, pattern>,
393     PseudoInstExpansion<Result>;
394
395 // Almost all ARM instructions are predicable.
396 class I<dag oops, dag iops, AddrMode am, int sz,
397         IndexMode im, Format f, InstrItinClass itin,
398         string opc, string asm, string cstr,
399         list<dag> pattern>
400   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
401   bits<4> p;
402   let Inst{31-28} = p;
403   let OutOperandList = oops;
404   let InOperandList = !con(iops, (ins pred:$p));
405   let AsmString = !strconcat(opc, "${p}", asm);
406   let Pattern = pattern;
407   list<Predicate> Predicates = [IsARM];
408 }
409
410 // A few are not predicable
411 class InoP<dag oops, dag iops, AddrMode am, int sz,
412            IndexMode im, Format f, InstrItinClass itin,
413            string opc, string asm, string cstr,
414            list<dag> pattern>
415   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
416   let OutOperandList = oops;
417   let InOperandList = iops;
418   let AsmString = !strconcat(opc, asm);
419   let Pattern = pattern;
420   let isPredicable = 0;
421   list<Predicate> Predicates = [IsARM];
422 }
423
424 // Same as I except it can optionally modify CPSR. Note it's modeled as an input
425 // operand since by default it's a zero register. It will become an implicit def
426 // once it's "flipped".
427 class sI<dag oops, dag iops, AddrMode am, int sz,
428          IndexMode im, Format f, InstrItinClass itin,
429          string opc, string asm, string cstr,
430          list<dag> pattern>
431   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
432   bits<4> p; // Predicate operand
433   bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
434   let Inst{31-28} = p;
435   let Inst{20} = s;
436
437   let OutOperandList = oops;
438   let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
439   let AsmString = !strconcat(opc, "${s}${p}", asm);
440   let Pattern = pattern;
441   list<Predicate> Predicates = [IsARM];
442 }
443
444 // Special cases
445 class XI<dag oops, dag iops, AddrMode am, int sz,
446          IndexMode im, Format f, InstrItinClass itin,
447          string asm, string cstr, list<dag> pattern>
448   : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
449   let OutOperandList = oops;
450   let InOperandList = iops;
451   let AsmString = asm;
452   let Pattern = pattern;
453   list<Predicate> Predicates = [IsARM];
454 }
455
456 class AI<dag oops, dag iops, Format f, InstrItinClass itin,
457          string opc, string asm, list<dag> pattern>
458   : I<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
459       opc, asm, "", pattern>;
460 class AsI<dag oops, dag iops, Format f, InstrItinClass itin,
461           string opc, string asm, list<dag> pattern>
462   : sI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
463        opc, asm, "", pattern>;
464 class AXI<dag oops, dag iops, Format f, InstrItinClass itin,
465           string asm, list<dag> pattern>
466   : XI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
467        asm, "", pattern>;
468 class AInoP<dag oops, dag iops, Format f, InstrItinClass itin,
469             string opc, string asm, list<dag> pattern>
470   : InoP<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
471          opc, asm, "", pattern>;
472
473 // Ctrl flow instructions
474 class ABI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
475           string opc, string asm, list<dag> pattern>
476   : I<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
477       opc, asm, "", pattern> {
478   let Inst{27-24} = opcod;
479 }
480 class ABXI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
481            string asm, list<dag> pattern>
482   : XI<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
483        asm, "", pattern> {
484   let Inst{27-24} = opcod;
485 }
486
487 // BR_JT instructions
488 class JTI<dag oops, dag iops, InstrItinClass itin,
489           string asm, list<dag> pattern>
490   : XI<oops, iops, AddrModeNone, 0, IndexModeNone, BrMiscFrm, itin,
491        asm, "", pattern>;
492
493 // Atomic load/store instructions
494 class AIldrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
495               string opc, string asm, list<dag> pattern>
496   : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
497       opc, asm, "", pattern> {
498   bits<4> Rt;
499   bits<4> addr;
500   let Inst{27-23} = 0b00011;
501   let Inst{22-21} = opcod;
502   let Inst{20}    = 1;
503   let Inst{19-16} = addr;
504   let Inst{15-12} = Rt;
505   let Inst{11-0}  = 0b111110011111;
506 }
507 class AIstrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
508               string opc, string asm, list<dag> pattern>
509   : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
510       opc, asm, "", pattern> {
511   bits<4> Rd;
512   bits<4> Rt;
513   bits<4> addr;
514   let Inst{27-23} = 0b00011;
515   let Inst{22-21} = opcod;
516   let Inst{20}    = 0;
517   let Inst{19-16} = addr;
518   let Inst{15-12} = Rd;
519   let Inst{11-4}  = 0b11111001;
520   let Inst{3-0}   = Rt;
521 }
522 class AIswp<bit b, dag oops, dag iops, string opc, list<dag> pattern>
523   : AI<oops, iops, MiscFrm, NoItinerary, opc, "\t$Rt, $Rt2, $addr", pattern> {
524   bits<4> Rt;
525   bits<4> Rt2;
526   bits<4> addr;
527   let Inst{27-23} = 0b00010;
528   let Inst{22} = b;
529   let Inst{21-20} = 0b00;
530   let Inst{19-16} = addr;
531   let Inst{15-12} = Rt;
532   let Inst{11-4} = 0b00001001;
533   let Inst{3-0} = Rt2;
534
535   let Unpredictable{11-8} = 0b1111;
536   let DecoderMethod = "DecodeSwap";
537 }
538
539 // addrmode1 instructions
540 class AI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
541           string opc, string asm, list<dag> pattern>
542   : I<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
543       opc, asm, "", pattern> {
544   let Inst{24-21} = opcod;
545   let Inst{27-26} = 0b00;
546 }
547 class AsI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
548            string opc, string asm, list<dag> pattern>
549   : sI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
550        opc, asm, "", pattern> {
551   let Inst{24-21} = opcod;
552   let Inst{27-26} = 0b00;
553 }
554 class AXI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
555            string asm, list<dag> pattern>
556   : XI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
557        asm, "", pattern> {
558   let Inst{24-21} = opcod;
559   let Inst{27-26} = 0b00;
560 }
561
562 // loads
563
564 // LDR/LDRB/STR/STRB/...
565 class AI2ldst<bits<3> op, bit isLd, bit isByte, dag oops, dag iops, AddrMode am,
566              Format f, InstrItinClass itin, string opc, string asm,
567              list<dag> pattern>
568   : I<oops, iops, am, 4, IndexModeNone, f, itin, opc, asm,
569       "", pattern> {
570   let Inst{27-25} = op;
571   let Inst{24} = 1;  // 24 == P
572   // 23 == U
573   let Inst{22} = isByte;
574   let Inst{21} = 0;  // 21 == W
575   let Inst{20} = isLd;
576 }
577 // Indexed load/stores
578 class AI2ldstidx<bit isLd, bit isByte, bit isPre, dag oops, dag iops,
579                 IndexMode im, Format f, InstrItinClass itin, string opc,
580                 string asm, string cstr, list<dag> pattern>
581   : I<oops, iops, AddrMode2, 4, im, f, itin,
582       opc, asm, cstr, pattern> {
583   bits<4> Rt;
584   let Inst{27-26} = 0b01;
585   let Inst{24}    = isPre; // P bit
586   let Inst{22}    = isByte; // B bit
587   let Inst{21}    = isPre; // W bit
588   let Inst{20}    = isLd; // L bit
589   let Inst{15-12} = Rt;
590 }
591 class AI2stridx_reg<bit isByte, bit isPre, dag oops, dag iops,
592                 IndexMode im, Format f, InstrItinClass itin, string opc,
593                 string asm, string cstr, list<dag> pattern>
594   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
595                pattern> {
596   // AM2 store w/ two operands: (GPR, am2offset)
597   // {12}     isAdd
598   // {11-0}   imm12/Rm
599   bits<14> offset;
600   bits<4> Rn;
601   let Inst{25} = 1;
602   let Inst{23} = offset{12};
603   let Inst{19-16} = Rn;
604   let Inst{11-5} = offset{11-5};
605   let Inst{4} = 0;
606   let Inst{3-0} = offset{3-0};
607 }
608
609 class AI2stridx_imm<bit isByte, bit isPre, dag oops, dag iops,
610                 IndexMode im, Format f, InstrItinClass itin, string opc,
611                 string asm, string cstr, list<dag> pattern>
612   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
613                pattern> {
614   // AM2 store w/ two operands: (GPR, am2offset)
615   // {12}     isAdd
616   // {11-0}   imm12/Rm
617   bits<14> offset;
618   bits<4> Rn;
619   let Inst{25} = 0;
620   let Inst{23} = offset{12};
621   let Inst{19-16} = Rn;
622   let Inst{11-0} = offset{11-0};
623 }
624
625
626 // FIXME: Merge with the above class when addrmode2 gets used for STR, STRB
627 // but for now use this class for STRT and STRBT.
628 class AI2stridxT<bit isByte, bit isPre, dag oops, dag iops,
629                 IndexMode im, Format f, InstrItinClass itin, string opc,
630                 string asm, string cstr, list<dag> pattern>
631   : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
632                pattern> {
633   // AM2 store w/ two operands: (GPR, am2offset)
634   // {17-14}  Rn
635   // {13}     1 == Rm, 0 == imm12
636   // {12}     isAdd
637   // {11-0}   imm12/Rm
638   bits<18> addr;
639   let Inst{25} = addr{13};
640   let Inst{23} = addr{12};
641   let Inst{19-16} = addr{17-14};
642   let Inst{11-0} = addr{11-0};
643 }
644
645 // addrmode3 instructions
646 class AI3ld<bits<4> op, bit op20, dag oops, dag iops, Format f,
647             InstrItinClass itin, string opc, string asm, list<dag> pattern>
648   : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
649       opc, asm, "", pattern> {
650   bits<14> addr;
651   bits<4> Rt;
652   let Inst{27-25} = 0b000;
653   let Inst{24}    = 1;            // P bit
654   let Inst{23}    = addr{8};      // U bit
655   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
656   let Inst{21}    = 0;            // W bit
657   let Inst{20}    = op20;         // L bit
658   let Inst{19-16} = addr{12-9};   // Rn
659   let Inst{15-12} = Rt;           // Rt
660   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
661   let Inst{7-4}   = op;
662   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
663
664   let DecoderMethod = "DecodeAddrMode3Instruction";
665 }
666
667 class AI3ldstidx<bits<4> op, bit op20, bit isPre, dag oops, dag iops,
668                 IndexMode im, Format f, InstrItinClass itin, string opc,
669                 string asm, string cstr, list<dag> pattern>
670   : I<oops, iops, AddrMode3, 4, im, f, itin,
671       opc, asm, cstr, pattern> {
672   bits<4> Rt;
673   let Inst{27-25} = 0b000;
674   let Inst{24}    = isPre;        // P bit
675   let Inst{21}    = isPre;        // W bit
676   let Inst{20}    = op20;         // L bit
677   let Inst{15-12} = Rt;           // Rt
678   let Inst{7-4}   = op;
679 }
680
681 // FIXME: Merge with the above class when addrmode2 gets used for LDR, LDRB
682 // but for now use this class for LDRSBT, LDRHT, LDSHT.
683 class AI3ldstidxT<bits<4> op, bit isLoad, dag oops, dag iops,
684                   IndexMode im, Format f, InstrItinClass itin, string opc,
685                   string asm, string cstr, list<dag> pattern>
686   : I<oops, iops, AddrMode3, 4, im, f, itin, opc, asm, cstr, pattern> {
687   // {13}     1 == imm8, 0 == Rm
688   // {12-9}   Rn
689   // {8}      isAdd
690   // {7-4}    imm7_4/zero
691   // {3-0}    imm3_0/Rm
692   bits<4> addr;
693   bits<4> Rt;
694   let Inst{27-25} = 0b000;
695   let Inst{24}    = 0;            // P bit
696   let Inst{21}    = 1;
697   let Inst{20}    = isLoad;       // L bit
698   let Inst{19-16} = addr;         // Rn
699   let Inst{15-12} = Rt;           // Rt
700   let Inst{7-4}   = op;
701 }
702
703 // stores
704 class AI3str<bits<4> op, dag oops, dag iops, Format f, InstrItinClass itin,
705              string opc, string asm, list<dag> pattern>
706   : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
707       opc, asm, "", pattern> {
708   bits<14> addr;
709   bits<4> Rt;
710   let Inst{27-25} = 0b000;
711   let Inst{24}    = 1;            // P bit
712   let Inst{23}    = addr{8};      // U bit
713   let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
714   let Inst{21}    = 0;            // W bit
715   let Inst{20}    = 0;            // L bit
716   let Inst{19-16} = addr{12-9};   // Rn
717   let Inst{15-12} = Rt;           // Rt
718   let Inst{11-8}  = addr{7-4};    // imm7_4/zero
719   let Inst{7-4}   = op;
720   let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
721   let DecoderMethod = "DecodeAddrMode3Instruction";
722 }
723
724 // addrmode4 instructions
725 class AXI4<dag oops, dag iops, IndexMode im, Format f, InstrItinClass itin,
726            string asm, string cstr, list<dag> pattern>
727   : XI<oops, iops, AddrMode4, 4, im, f, itin, asm, cstr, pattern> {
728   bits<4>  p;
729   bits<16> regs;
730   bits<4>  Rn;
731   let Inst{31-28} = p;
732   let Inst{27-25} = 0b100;
733   let Inst{22}    = 0; // S bit
734   let Inst{19-16} = Rn;
735   let Inst{15-0}  = regs;
736 }
737
738 // Unsigned multiply, multiply-accumulate instructions.
739 class AMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
740              string opc, string asm, list<dag> pattern>
741   : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
742       opc, asm, "", pattern> {
743   let Inst{7-4}   = 0b1001;
744   let Inst{20}    = 0; // S bit
745   let Inst{27-21} = opcod;
746 }
747 class AsMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
748               string opc, string asm, list<dag> pattern>
749   : sI<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
750        opc, asm, "", pattern> {
751   let Inst{7-4}   = 0b1001;
752   let Inst{27-21} = opcod;
753 }
754
755 // Most significant word multiply
756 class AMul2I<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
757              InstrItinClass itin, string opc, string asm, list<dag> pattern>
758   : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
759       opc, asm, "", pattern> {
760   bits<4> Rd;
761   bits<4> Rn;
762   bits<4> Rm;
763   let Inst{7-4}   = opc7_4;
764   let Inst{20}    = 1;
765   let Inst{27-21} = opcod;
766   let Inst{19-16} = Rd;
767   let Inst{11-8}  = Rm;
768   let Inst{3-0}   = Rn;
769 }
770 // MSW multiple w/ Ra operand
771 class AMul2Ia<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
772               InstrItinClass itin, string opc, string asm, list<dag> pattern>
773   : AMul2I<opcod, opc7_4, oops, iops, itin, opc, asm, pattern> {
774   bits<4> Ra;
775   let Inst{15-12} = Ra;
776 }
777
778 // SMUL<x><y> / SMULW<y> / SMLA<x><y> / SMLAW<x><y>
779 class AMulxyIbase<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
780               InstrItinClass itin, string opc, string asm, list<dag> pattern>
781   : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
782       opc, asm, "", pattern> {
783   bits<4> Rn;
784   bits<4> Rm;
785   let Inst{4}     = 0;
786   let Inst{7}     = 1;
787   let Inst{20}    = 0;
788   let Inst{27-21} = opcod;
789   let Inst{6-5}   = bit6_5;
790   let Inst{11-8}  = Rm;
791   let Inst{3-0}   = Rn;
792 }
793 class AMulxyI<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
794               InstrItinClass itin, string opc, string asm, list<dag> pattern>
795   : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
796   bits<4> Rd;
797   let Inst{19-16} = Rd;
798 }
799
800 // AMulxyI with Ra operand
801 class AMulxyIa<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
802               InstrItinClass itin, string opc, string asm, list<dag> pattern>
803   : AMulxyI<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
804   bits<4> Ra;
805   let Inst{15-12} = Ra;
806 }
807 // SMLAL*
808 class AMulxyI64<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
809               InstrItinClass itin, string opc, string asm, list<dag> pattern>
810   : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
811   bits<4> RdLo;
812   bits<4> RdHi;
813   let Inst{19-16} = RdHi;
814   let Inst{15-12} = RdLo;
815 }
816
817 // Extend instructions.
818 class AExtI<bits<8> opcod, dag oops, dag iops, InstrItinClass itin,
819             string opc, string asm, list<dag> pattern>
820   : I<oops, iops, AddrModeNone, 4, IndexModeNone, ExtFrm, itin,
821       opc, asm, "", pattern> {
822   // All AExtI instructions have Rd and Rm register operands.
823   bits<4> Rd;
824   bits<4> Rm;
825   let Inst{15-12} = Rd;
826   let Inst{3-0}   = Rm;
827   let Inst{7-4}   = 0b0111;
828   let Inst{9-8}   = 0b00;
829   let Inst{27-20} = opcod;
830
831   let Unpredictable{9-8} = 0b11;
832 }
833
834 // Misc Arithmetic instructions.
835 class AMiscA1I<bits<8> opcod, bits<4> opc7_4, dag oops, dag iops,
836                InstrItinClass itin, string opc, string asm, list<dag> pattern>
837   : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
838       opc, asm, "", pattern> {
839   bits<4> Rd;
840   bits<4> Rm;
841   let Inst{27-20} = opcod;
842   let Inst{19-16} = 0b1111;
843   let Inst{15-12} = Rd;
844   let Inst{11-8}  = 0b1111;
845   let Inst{7-4}   = opc7_4;
846   let Inst{3-0}   = Rm;
847 }
848
849 // Division instructions.
850 class ADivA1I<bits<3> opcod, dag oops, dag iops,
851               InstrItinClass itin, string opc, string asm, list<dag> pattern>
852   : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
853       opc, asm, "", pattern> {
854   bits<4> Rd;
855   bits<4> Rn;
856   bits<4> Rm;
857   let Inst{27-23} = 0b01110;
858   let Inst{22-20} = opcod;
859   let Inst{19-16} = Rd;
860   let Inst{15-12} = 0b1111;
861   let Inst{11-8}  = Rm;
862   let Inst{7-4}   = 0b0001;
863   let Inst{3-0}   = Rn;
864 }
865
866 // PKH instructions
867 def PKHLSLAsmOperand : ImmAsmOperand {
868   let Name = "PKHLSLImm";
869   let ParserMethod = "parsePKHLSLImm";
870 }
871 def pkh_lsl_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 32; }]>{
872   let PrintMethod = "printPKHLSLShiftImm";
873   let ParserMatchClass = PKHLSLAsmOperand;
874 }
875 def PKHASRAsmOperand : AsmOperandClass {
876   let Name = "PKHASRImm";
877   let ParserMethod = "parsePKHASRImm";
878 }
879 def pkh_asr_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]>{
880   let PrintMethod = "printPKHASRShiftImm";
881   let ParserMatchClass = PKHASRAsmOperand;
882 }
883
884 class APKHI<bits<8> opcod, bit tb, dag oops, dag iops, InstrItinClass itin,
885             string opc, string asm, list<dag> pattern>
886   : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
887       opc, asm, "", pattern> {
888   bits<4> Rd;
889   bits<4> Rn;
890   bits<4> Rm;
891   bits<5> sh;
892   let Inst{27-20} = opcod;
893   let Inst{19-16} = Rn;
894   let Inst{15-12} = Rd;
895   let Inst{11-7}  = sh;
896   let Inst{6}     = tb;
897   let Inst{5-4}   = 0b01;
898   let Inst{3-0}   = Rm;
899 }
900
901 //===----------------------------------------------------------------------===//
902
903 // ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
904 class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
905   list<Predicate> Predicates = [IsARM];
906 }
907 class ARMV5TPat<dag pattern, dag result> : Pat<pattern, result> {
908   list<Predicate> Predicates = [IsARM, HasV5T];
909 }
910 class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
911   list<Predicate> Predicates = [IsARM, HasV5TE];
912 }
913 // ARMV5MOPat - Same as ARMV5TEPat with UseMulOps.
914 class ARMV5MOPat<dag pattern, dag result> : Pat<pattern, result> {
915   list<Predicate> Predicates = [IsARM, HasV5TE, UseMulOps];
916 }
917 class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
918   list<Predicate> Predicates = [IsARM, HasV6];
919 }
920
921 //===----------------------------------------------------------------------===//
922 // Thumb Instruction Format Definitions.
923 //
924
925 class ThumbI<dag oops, dag iops, AddrMode am, int sz,
926              InstrItinClass itin, string asm, string cstr, list<dag> pattern>
927   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
928   let OutOperandList = oops;
929   let InOperandList = iops;
930   let AsmString = asm;
931   let Pattern = pattern;
932   list<Predicate> Predicates = [IsThumb];
933 }
934
935 // TI - Thumb instruction.
936 class TI<dag oops, dag iops, InstrItinClass itin, string asm, list<dag> pattern>
937   : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
938
939 // Two-address instructions
940 class TIt<dag oops, dag iops, InstrItinClass itin, string asm,
941           list<dag> pattern>
942   : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "$lhs = $dst",
943            pattern>;
944
945 // tBL, tBX 32-bit instructions
946 class TIx2<bits<5> opcod1, bits<2> opcod2, bit opcod3,
947            dag oops, dag iops, InstrItinClass itin, string asm,
948            list<dag> pattern>
949     : ThumbI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>,
950       Encoding {
951   let Inst{31-27} = opcod1;
952   let Inst{15-14} = opcod2;
953   let Inst{12}    = opcod3;
954 }
955
956 // BR_JT instructions
957 class TJTI<dag oops, dag iops, InstrItinClass itin, string asm,
958            list<dag> pattern>
959   : ThumbI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
960
961 // Thumb1 only
962 class Thumb1I<dag oops, dag iops, AddrMode am, int sz,
963               InstrItinClass itin, string asm, string cstr, list<dag> pattern>
964   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
965   let OutOperandList = oops;
966   let InOperandList = iops;
967   let AsmString = asm;
968   let Pattern = pattern;
969   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
970 }
971
972 class T1I<dag oops, dag iops, InstrItinClass itin,
973           string asm, list<dag> pattern>
974   : Thumb1I<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
975 class T1Ix2<dag oops, dag iops, InstrItinClass itin,
976             string asm, list<dag> pattern>
977   : Thumb1I<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
978
979 // Two-address instructions
980 class T1It<dag oops, dag iops, InstrItinClass itin,
981            string asm, string cstr, list<dag> pattern>
982   : Thumb1I<oops, iops, AddrModeNone, 2, itin,
983             asm, cstr, pattern>;
984
985 // Thumb1 instruction that can either be predicated or set CPSR.
986 class Thumb1sI<dag oops, dag iops, AddrMode am, int sz,
987                InstrItinClass itin,
988                string opc, string asm, string cstr, list<dag> pattern>
989   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
990   let OutOperandList = !con(oops, (outs s_cc_out:$s));
991   let InOperandList = !con(iops, (ins pred:$p));
992   let AsmString = !strconcat(opc, "${s}${p}", asm);
993   let Pattern = pattern;
994   let thumbArithFlagSetting = 1;
995   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
996   let DecoderNamespace = "ThumbSBit";
997 }
998
999 class T1sI<dag oops, dag iops, InstrItinClass itin,
1000            string opc, string asm, list<dag> pattern>
1001   : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
1002
1003 // Two-address instructions
1004 class T1sIt<dag oops, dag iops, InstrItinClass itin,
1005             string opc, string asm, list<dag> pattern>
1006   : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm,
1007              "$Rn = $Rdn", pattern>;
1008
1009 // Thumb1 instruction that can be predicated.
1010 class Thumb1pI<dag oops, dag iops, AddrMode am, int sz,
1011                InstrItinClass itin,
1012                string opc, string asm, string cstr, list<dag> pattern>
1013   : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1014   let OutOperandList = oops;
1015   let InOperandList = !con(iops, (ins pred:$p));
1016   let AsmString = !strconcat(opc, "${p}", asm);
1017   let Pattern = pattern;
1018   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1019 }
1020
1021 class T1pI<dag oops, dag iops, InstrItinClass itin,
1022            string opc, string asm, list<dag> pattern>
1023   : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
1024
1025 // Two-address instructions
1026 class T1pIt<dag oops, dag iops, InstrItinClass itin,
1027             string opc, string asm, list<dag> pattern>
1028   : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm,
1029              "$Rn = $Rdn", pattern>;
1030
1031 class T1pIs<dag oops, dag iops,
1032             InstrItinClass itin, string opc, string asm, list<dag> pattern>
1033   : Thumb1pI<oops, iops, AddrModeT1_s, 2, itin, opc, asm, "", pattern>;
1034
1035 class Encoding16 : Encoding {
1036   let Inst{31-16} = 0x0000;
1037 }
1038
1039 // A6.2 16-bit Thumb instruction encoding
1040 class T1Encoding<bits<6> opcode> : Encoding16 {
1041   let Inst{15-10} = opcode;
1042 }
1043
1044 // A6.2.1 Shift (immediate), add, subtract, move, and compare encoding.
1045 class T1General<bits<5> opcode> : Encoding16 {
1046   let Inst{15-14} = 0b00;
1047   let Inst{13-9} = opcode;
1048 }
1049
1050 // A6.2.2 Data-processing encoding.
1051 class T1DataProcessing<bits<4> opcode> : Encoding16 {
1052   let Inst{15-10} = 0b010000;
1053   let Inst{9-6} = opcode;
1054 }
1055
1056 // A6.2.3 Special data instructions and branch and exchange encoding.
1057 class T1Special<bits<4> opcode> : Encoding16 {
1058   let Inst{15-10} = 0b010001;
1059   let Inst{9-6}   = opcode;
1060 }
1061
1062 // A6.2.4 Load/store single data item encoding.
1063 class T1LoadStore<bits<4> opA, bits<3> opB> : Encoding16 {
1064   let Inst{15-12} = opA;
1065   let Inst{11-9}  = opB;
1066 }
1067 class T1LdStSP<bits<3> opB>   : T1LoadStore<0b1001, opB>; // SP relative
1068
1069 class T1BranchCond<bits<4> opcode> : Encoding16 {
1070   let Inst{15-12} = opcode;
1071 }
1072
1073 // Helper classes to encode Thumb1 loads and stores. For immediates, the
1074 // following bits are used for "opA" (see A6.2.4):
1075 //
1076 //   0b0110 => Immediate, 4 bytes
1077 //   0b1000 => Immediate, 2 bytes
1078 //   0b0111 => Immediate, 1 byte
1079 class T1pILdStEncode<bits<3> opcode, dag oops, dag iops, AddrMode am,
1080                      InstrItinClass itin, string opc, string asm,
1081                      list<dag> pattern>
1082   : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1083     T1LoadStore<0b0101, opcode> {
1084   bits<3> Rt;
1085   bits<8> addr;
1086   let Inst{8-6} = addr{5-3};    // Rm
1087   let Inst{5-3} = addr{2-0};    // Rn
1088   let Inst{2-0} = Rt;
1089 }
1090 class T1pILdStEncodeImm<bits<4> opA, bit opB, dag oops, dag iops, AddrMode am,
1091                         InstrItinClass itin, string opc, string asm,
1092                         list<dag> pattern>
1093   : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1094     T1LoadStore<opA, {opB,?,?}> {
1095   bits<3> Rt;
1096   bits<8> addr;
1097   let Inst{10-6} = addr{7-3};   // imm5
1098   let Inst{5-3}  = addr{2-0};   // Rn
1099   let Inst{2-0}  = Rt;
1100 }
1101
1102 // A6.2.5 Miscellaneous 16-bit instructions encoding.
1103 class T1Misc<bits<7> opcode> : Encoding16 {
1104   let Inst{15-12} = 0b1011;
1105   let Inst{11-5} = opcode;
1106 }
1107
1108 // Thumb2I - Thumb2 instruction. Almost all Thumb2 instructions are predicable.
1109 class Thumb2I<dag oops, dag iops, AddrMode am, int sz,
1110               InstrItinClass itin,
1111               string opc, string asm, string cstr, list<dag> pattern>
1112   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1113   let OutOperandList = oops;
1114   let InOperandList = !con(iops, (ins pred:$p));
1115   let AsmString = !strconcat(opc, "${p}", asm);
1116   let Pattern = pattern;
1117   list<Predicate> Predicates = [IsThumb2];
1118   let DecoderNamespace = "Thumb2";
1119 }
1120
1121 // Same as Thumb2I except it can optionally modify CPSR. Note it's modeled as an
1122 // input operand since by default it's a zero register. It will become an
1123 // implicit def once it's "flipped".
1124 //
1125 // FIXME: This uses unified syntax so {s} comes before {p}. We should make it
1126 // more consistent.
1127 class Thumb2sI<dag oops, dag iops, AddrMode am, int sz,
1128                InstrItinClass itin,
1129                string opc, string asm, string cstr, list<dag> pattern>
1130   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1131   bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
1132   let Inst{20} = s;
1133
1134   let OutOperandList = oops;
1135   let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
1136   let AsmString = !strconcat(opc, "${s}${p}", asm);
1137   let Pattern = pattern;
1138   list<Predicate> Predicates = [IsThumb2];
1139   let DecoderNamespace = "Thumb2";
1140 }
1141
1142 // Special cases
1143 class Thumb2XI<dag oops, dag iops, AddrMode am, int sz,
1144                InstrItinClass itin,
1145                string asm, string cstr, list<dag> pattern>
1146   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1147   let OutOperandList = oops;
1148   let InOperandList = iops;
1149   let AsmString = asm;
1150   let Pattern = pattern;
1151   list<Predicate> Predicates = [IsThumb2];
1152   let DecoderNamespace = "Thumb2";
1153 }
1154
1155 class ThumbXI<dag oops, dag iops, AddrMode am, int sz,
1156               InstrItinClass itin,
1157               string asm, string cstr, list<dag> pattern>
1158   : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1159   let OutOperandList = oops;
1160   let InOperandList = iops;
1161   let AsmString = asm;
1162   let Pattern = pattern;
1163   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1164   let DecoderNamespace = "Thumb";
1165 }
1166
1167 class T2I<dag oops, dag iops, InstrItinClass itin,
1168           string opc, string asm, list<dag> pattern>
1169   : Thumb2I<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
1170 class T2Ii12<dag oops, dag iops, InstrItinClass itin,
1171              string opc, string asm, list<dag> pattern>
1172   : Thumb2I<oops, iops, AddrModeT2_i12, 4, itin, opc, asm, "",pattern>;
1173 class T2Ii8<dag oops, dag iops, InstrItinClass itin,
1174             string opc, string asm, list<dag> pattern>
1175   : Thumb2I<oops, iops, AddrModeT2_i8, 4, itin, opc, asm, "", pattern>;
1176 class T2Iso<dag oops, dag iops, InstrItinClass itin,
1177             string opc, string asm, list<dag> pattern>
1178   : Thumb2I<oops, iops, AddrModeT2_so, 4, itin, opc, asm, "", pattern>;
1179 class T2Ipc<dag oops, dag iops, InstrItinClass itin,
1180             string opc, string asm, list<dag> pattern>
1181   : Thumb2I<oops, iops, AddrModeT2_pc, 4, itin, opc, asm, "", pattern>;
1182 class T2Ii8s4<bit P, bit W, bit isLoad, dag oops, dag iops, InstrItinClass itin,
1183               string opc, string asm, string cstr, list<dag> pattern>
1184   : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
1185             pattern> {
1186   bits<4> Rt;
1187   bits<4> Rt2;
1188   bits<13> addr;
1189   let Inst{31-25} = 0b1110100;
1190   let Inst{24}    = P;
1191   let Inst{23}    = addr{8};
1192   let Inst{22}    = 1;
1193   let Inst{21}    = W;
1194   let Inst{20}    = isLoad;
1195   let Inst{19-16} = addr{12-9};
1196   let Inst{15-12} = Rt{3-0};
1197   let Inst{11-8}  = Rt2{3-0};
1198   let Inst{7-0}   = addr{7-0};
1199 }
1200 class T2Ii8s4post<bit P, bit W, bit isLoad, dag oops, dag iops,
1201                   InstrItinClass itin, string opc, string asm, string cstr,
1202                   list<dag> pattern>
1203   : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
1204             pattern> {
1205   bits<4> Rt;
1206   bits<4> Rt2;
1207   bits<4> addr;
1208   bits<9> imm;
1209   let Inst{31-25} = 0b1110100;
1210   let Inst{24}    = P;
1211   let Inst{23}    = imm{8};
1212   let Inst{22}    = 1;
1213   let Inst{21}    = W;
1214   let Inst{20}    = isLoad;
1215   let Inst{19-16} = addr;
1216   let Inst{15-12} = Rt{3-0};
1217   let Inst{11-8}  = Rt2{3-0};
1218   let Inst{7-0}   = imm{7-0};
1219 }
1220
1221 class T2sI<dag oops, dag iops, InstrItinClass itin,
1222            string opc, string asm, list<dag> pattern>
1223   : Thumb2sI<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
1224
1225 class T2XI<dag oops, dag iops, InstrItinClass itin,
1226            string asm, list<dag> pattern>
1227   : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
1228 class T2JTI<dag oops, dag iops, InstrItinClass itin,
1229             string asm, list<dag> pattern>
1230   : Thumb2XI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
1231
1232 // Move to/from coprocessor instructions
1233 class T2Cop<bits<4> opc, dag oops, dag iops, string opcstr, string asm,
1234             list<dag> pattern>
1235   : T2I <oops, iops, NoItinerary, opcstr, asm, pattern>, Requires<[IsThumb2]> {
1236   let Inst{31-28} = opc;
1237 }
1238
1239 // Two-address instructions
1240 class T2XIt<dag oops, dag iops, InstrItinClass itin,
1241             string asm, string cstr, list<dag> pattern>
1242   : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, cstr, pattern>;
1243
1244 // T2Ipreldst - Thumb2 pre-indexed load / store instructions.
1245 class T2Ipreldst<bit signed, bits<2> opcod, bit load, bit pre,
1246                  dag oops, dag iops,
1247                  AddrMode am, IndexMode im, InstrItinClass itin,
1248                  string opc, string asm, string cstr, list<dag> pattern>
1249   : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
1250   let OutOperandList = oops;
1251   let InOperandList = !con(iops, (ins pred:$p));
1252   let AsmString = !strconcat(opc, "${p}", asm);
1253   let Pattern = pattern;
1254   list<Predicate> Predicates = [IsThumb2];
1255   let DecoderNamespace = "Thumb2";
1256
1257   bits<4> Rt;
1258   bits<13> addr;
1259   let Inst{31-27} = 0b11111;
1260   let Inst{26-25} = 0b00;
1261   let Inst{24}    = signed;
1262   let Inst{23}    = 0;
1263   let Inst{22-21} = opcod;
1264   let Inst{20}    = load;
1265   let Inst{19-16} = addr{12-9};
1266   let Inst{15-12} = Rt{3-0};
1267   let Inst{11}    = 1;
1268   // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1269   let Inst{10}    = pre; // The P bit.
1270   let Inst{9}     = addr{8}; // Sign bit
1271   let Inst{8}     = 1; // The W bit.
1272   let Inst{7-0}   = addr{7-0};
1273
1274   let DecoderMethod = "DecodeT2LdStPre";
1275 }
1276
1277 // T2Ipostldst - Thumb2 post-indexed load / store instructions.
1278 class T2Ipostldst<bit signed, bits<2> opcod, bit load, bit pre,
1279                  dag oops, dag iops,
1280                  AddrMode am, IndexMode im, InstrItinClass itin,
1281                  string opc, string asm, string cstr, list<dag> pattern>
1282   : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
1283   let OutOperandList = oops;
1284   let InOperandList = !con(iops, (ins pred:$p));
1285   let AsmString = !strconcat(opc, "${p}", asm);
1286   let Pattern = pattern;
1287   list<Predicate> Predicates = [IsThumb2];
1288   let DecoderNamespace = "Thumb2";
1289
1290   bits<4> Rt;
1291   bits<4> Rn;
1292   bits<9> offset;
1293   let Inst{31-27} = 0b11111;
1294   let Inst{26-25} = 0b00;
1295   let Inst{24}    = signed;
1296   let Inst{23}    = 0;
1297   let Inst{22-21} = opcod;
1298   let Inst{20}    = load;
1299   let Inst{19-16} = Rn;
1300   let Inst{15-12} = Rt{3-0};
1301   let Inst{11}    = 1;
1302   // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1303   let Inst{10}    = pre; // The P bit.
1304   let Inst{9}     = offset{8}; // Sign bit
1305   let Inst{8}     = 1; // The W bit.
1306   let Inst{7-0}   = offset{7-0};
1307
1308   let DecoderMethod = "DecodeT2LdStPre";
1309 }
1310
1311 // Tv5Pat - Same as Pat<>, but requires V5T Thumb mode.
1312 class Tv5Pat<dag pattern, dag result> : Pat<pattern, result> {
1313   list<Predicate> Predicates = [IsThumb, IsThumb1Only, HasV5T];
1314 }
1315
1316 // T1Pat - Same as Pat<>, but requires that the compiler be in Thumb1 mode.
1317 class T1Pat<dag pattern, dag result> : Pat<pattern, result> {
1318   list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1319 }
1320
1321 // T2v6Pat - Same as Pat<>, but requires V6T2 Thumb2 mode.
1322 class T2v6Pat<dag pattern, dag result> : Pat<pattern, result> {
1323   list<Predicate> Predicates = [IsThumb2, HasV6T2];
1324 }
1325
1326 // T2Pat - Same as Pat<>, but requires that the compiler be in Thumb2 mode.
1327 class T2Pat<dag pattern, dag result> : Pat<pattern, result> {
1328   list<Predicate> Predicates = [IsThumb2];
1329 }
1330
1331 //===----------------------------------------------------------------------===//
1332
1333 //===----------------------------------------------------------------------===//
1334 // ARM VFP Instruction templates.
1335 //
1336
1337 // Almost all VFP instructions are predicable.
1338 class VFPI<dag oops, dag iops, AddrMode am, int sz,
1339            IndexMode im, Format f, InstrItinClass itin,
1340            string opc, string asm, string cstr, list<dag> pattern>
1341   : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1342   bits<4> p;
1343   let Inst{31-28} = p;
1344   let OutOperandList = oops;
1345   let InOperandList = !con(iops, (ins pred:$p));
1346   let AsmString = !strconcat(opc, "${p}", asm);
1347   let Pattern = pattern;
1348   let PostEncoderMethod = "VFPThumb2PostEncoder";
1349   let DecoderNamespace = "VFP";
1350   list<Predicate> Predicates = [HasVFP2];
1351 }
1352
1353 // Special cases
1354 class VFPXI<dag oops, dag iops, AddrMode am, int sz,
1355             IndexMode im, Format f, InstrItinClass itin,
1356             string asm, string cstr, list<dag> pattern>
1357   : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1358   bits<4> p;
1359   let Inst{31-28} = p;
1360   let OutOperandList = oops;
1361   let InOperandList = iops;
1362   let AsmString = asm;
1363   let Pattern = pattern;
1364   let PostEncoderMethod = "VFPThumb2PostEncoder";
1365   let DecoderNamespace = "VFP";
1366   list<Predicate> Predicates = [HasVFP2];
1367 }
1368
1369 class VFPAI<dag oops, dag iops, Format f, InstrItinClass itin,
1370             string opc, string asm, list<dag> pattern>
1371   : VFPI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
1372          opc, asm, "", pattern> {
1373   let PostEncoderMethod = "VFPThumb2PostEncoder";
1374 }
1375
1376 // ARM VFP addrmode5 loads and stores
1377 class ADI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1378            InstrItinClass itin,
1379            string opc, string asm, list<dag> pattern>
1380   : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1381          VFPLdStFrm, itin, opc, asm, "", pattern> {
1382   // Instruction operands.
1383   bits<5>  Dd;
1384   bits<13> addr;
1385
1386   // Encode instruction operands.
1387   let Inst{23}    = addr{8};      // U (add = (U == '1'))
1388   let Inst{22}    = Dd{4};
1389   let Inst{19-16} = addr{12-9};   // Rn
1390   let Inst{15-12} = Dd{3-0};
1391   let Inst{7-0}   = addr{7-0};    // imm8
1392
1393   let Inst{27-24} = opcod1;
1394   let Inst{21-20} = opcod2;
1395   let Inst{11-9}  = 0b101;
1396   let Inst{8}     = 1;          // Double precision
1397
1398   // Loads & stores operate on both NEON and VFP pipelines.
1399   let D = VFPNeonDomain;
1400 }
1401
1402 class ASI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1403            InstrItinClass itin,
1404            string opc, string asm, list<dag> pattern>
1405   : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1406          VFPLdStFrm, itin, opc, asm, "", pattern> {
1407   // Instruction operands.
1408   bits<5>  Sd;
1409   bits<13> addr;
1410
1411   // Encode instruction operands.
1412   let Inst{23}    = addr{8};      // U (add = (U == '1'))
1413   let Inst{22}    = Sd{0};
1414   let Inst{19-16} = addr{12-9};   // Rn
1415   let Inst{15-12} = Sd{4-1};
1416   let Inst{7-0}   = addr{7-0};    // imm8
1417
1418   let Inst{27-24} = opcod1;
1419   let Inst{21-20} = opcod2;
1420   let Inst{11-9}  = 0b101;
1421   let Inst{8}     = 0;          // Single precision
1422
1423   // Loads & stores operate on both NEON and VFP pipelines.
1424   let D = VFPNeonDomain;
1425 }
1426
1427 // VFP Load / store multiple pseudo instructions.
1428 class PseudoVFPLdStM<dag oops, dag iops, InstrItinClass itin, string cstr,
1429                      list<dag> pattern>
1430   : InstARM<AddrMode4, 4, IndexModeNone, Pseudo, VFPNeonDomain,
1431             cstr, itin> {
1432   let OutOperandList = oops;
1433   let InOperandList = !con(iops, (ins pred:$p));
1434   let Pattern = pattern;
1435   list<Predicate> Predicates = [HasVFP2];
1436 }
1437
1438 // Load / store multiple
1439
1440 // Unknown precision
1441 class AXXI4<dag oops, dag iops, IndexMode im,
1442             string asm, string cstr, list<dag> pattern>
1443   : VFPXI<oops, iops, AddrMode4, 4, im,
1444           VFPLdStFrm, NoItinerary, asm, cstr, pattern> {
1445   // Instruction operands.
1446   bits<4>  Rn;
1447   bits<13> regs;
1448
1449   // Encode instruction operands.
1450   let Inst{19-16} = Rn;
1451   let Inst{22}    = 0;
1452   let Inst{15-12} = regs{11-8};
1453   let Inst{7-1}   = regs{7-1};
1454
1455   let Inst{27-25} = 0b110;
1456   let Inst{11-8}  = 0b1011;
1457   let Inst{0}     = 1;
1458 }
1459
1460 // Double precision
1461 class AXDI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1462             string asm, string cstr, list<dag> pattern>
1463   : VFPXI<oops, iops, AddrMode4, 4, im,
1464           VFPLdStMulFrm, itin, asm, cstr, pattern> {
1465   // Instruction operands.
1466   bits<4>  Rn;
1467   bits<13> regs;
1468
1469   // Encode instruction operands.
1470   let Inst{19-16} = Rn;
1471   let Inst{22}    = regs{12};
1472   let Inst{15-12} = regs{11-8};
1473   let Inst{7-1}   = regs{7-1};
1474
1475   let Inst{27-25} = 0b110;
1476   let Inst{11-9}  = 0b101;
1477   let Inst{8}     = 1;          // Double precision
1478   let Inst{0}     = 0;
1479 }
1480
1481 // Single Precision
1482 class AXSI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1483             string asm, string cstr, list<dag> pattern>
1484   : VFPXI<oops, iops, AddrMode4, 4, im,
1485           VFPLdStMulFrm, itin, asm, cstr, pattern> {
1486   // Instruction operands.
1487   bits<4> Rn;
1488   bits<13> regs;
1489
1490   // Encode instruction operands.
1491   let Inst{19-16} = Rn;
1492   let Inst{22}    = regs{8};
1493   let Inst{15-12} = regs{12-9};
1494   let Inst{7-0}   = regs{7-0};
1495
1496   let Inst{27-25} = 0b110;
1497   let Inst{11-9}  = 0b101;
1498   let Inst{8}     = 0;          // Single precision
1499 }
1500
1501 // Double precision, unary
1502 class ADuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1503            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1504            string asm, list<dag> pattern>
1505   : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1506   // Instruction operands.
1507   bits<5> Dd;
1508   bits<5> Dm;
1509
1510   // Encode instruction operands.
1511   let Inst{3-0}   = Dm{3-0};
1512   let Inst{5}     = Dm{4};
1513   let Inst{15-12} = Dd{3-0};
1514   let Inst{22}    = Dd{4};
1515
1516   let Inst{27-23} = opcod1;
1517   let Inst{21-20} = opcod2;
1518   let Inst{19-16} = opcod3;
1519   let Inst{11-9}  = 0b101;
1520   let Inst{8}     = 1;          // Double precision
1521   let Inst{7-6}   = opcod4;
1522   let Inst{4}     = opcod5;
1523 }
1524
1525 // Double precision, unary, not-predicated
1526 class ADuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1527            bit opcod5, dag oops, dag iops, InstrItinClass itin,
1528            string asm, list<dag> pattern>
1529   : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPUnaryFrm, itin, asm, "", pattern> {
1530   // Instruction operands.
1531   bits<5> Dd;
1532   bits<5> Dm;
1533
1534   let Inst{31-28} = 0b1111;
1535
1536   // Encode instruction operands.
1537   let Inst{3-0}   = Dm{3-0};
1538   let Inst{5}     = Dm{4};
1539   let Inst{15-12} = Dd{3-0};
1540   let Inst{22}    = Dd{4};
1541
1542   let Inst{27-23} = opcod1;
1543   let Inst{21-20} = opcod2;
1544   let Inst{19-16} = opcod3;
1545   let Inst{11-9}  = 0b101;
1546   let Inst{8}     = 1;          // Double precision
1547   let Inst{7-6}   = opcod4;
1548   let Inst{4}     = opcod5;
1549 }
1550
1551 // Double precision, binary
1552 class ADbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1553            dag iops, InstrItinClass itin, string opc, string asm,
1554            list<dag> pattern>
1555   : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1556   // Instruction operands.
1557   bits<5> Dd;
1558   bits<5> Dn;
1559   bits<5> Dm;
1560
1561   // Encode instruction operands.
1562   let Inst{3-0}   = Dm{3-0};
1563   let Inst{5}     = Dm{4};
1564   let Inst{19-16} = Dn{3-0};
1565   let Inst{7}     = Dn{4};
1566   let Inst{15-12} = Dd{3-0};
1567   let Inst{22}    = Dd{4};
1568
1569   let Inst{27-23} = opcod1;
1570   let Inst{21-20} = opcod2;
1571   let Inst{11-9}  = 0b101;
1572   let Inst{8}     = 1;          // Double precision
1573   let Inst{6}     = op6;
1574   let Inst{4}     = op4;
1575 }
1576
1577 // FP, binary, not predicated
1578 class ADbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
1579            InstrItinClass itin, string asm, list<dag> pattern>
1580   : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPBinaryFrm, itin,
1581           asm, "", pattern>
1582 {
1583   // Instruction operands.
1584   bits<5> Dd;
1585   bits<5> Dn;
1586   bits<5> Dm;
1587
1588   let Inst{31-28} = 0b1111;
1589
1590   // Encode instruction operands.
1591   let Inst{3-0}   = Dm{3-0};
1592   let Inst{5}     = Dm{4};
1593   let Inst{19-16} = Dn{3-0};
1594   let Inst{7}     = Dn{4};
1595   let Inst{15-12} = Dd{3-0};
1596   let Inst{22}    = Dd{4};
1597
1598   let Inst{27-23} = opcod1;
1599   let Inst{21-20} = opcod2;
1600   let Inst{11-9}  = 0b101;
1601   let Inst{8}     = 1; // double precision
1602   let Inst{6}     = opcod3;
1603   let Inst{4}     = 0;
1604 }
1605
1606 // Single precision, unary, predicated
1607 class ASuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1608            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1609            string asm, list<dag> pattern>
1610   : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, pattern> {
1611   // Instruction operands.
1612   bits<5> Sd;
1613   bits<5> Sm;
1614
1615   // Encode instruction operands.
1616   let Inst{3-0}   = Sm{4-1};
1617   let Inst{5}     = Sm{0};
1618   let Inst{15-12} = Sd{4-1};
1619   let Inst{22}    = Sd{0};
1620
1621   let Inst{27-23} = opcod1;
1622   let Inst{21-20} = opcod2;
1623   let Inst{19-16} = opcod3;
1624   let Inst{11-9}  = 0b101;
1625   let Inst{8}     = 0;          // Single precision
1626   let Inst{7-6}   = opcod4;
1627   let Inst{4}     = opcod5;
1628 }
1629
1630 // Single precision, unary, non-predicated
1631 class ASuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1632              bit opcod5, dag oops, dag iops, InstrItinClass itin,
1633              string asm, list<dag> pattern>
1634   : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1635           VFPUnaryFrm, itin, asm, "", pattern> {
1636   // Instruction operands.
1637   bits<5> Sd;
1638   bits<5> Sm;
1639
1640   let Inst{31-28} = 0b1111;
1641
1642   // Encode instruction operands.
1643   let Inst{3-0}   = Sm{4-1};
1644   let Inst{5}     = Sm{0};
1645   let Inst{15-12} = Sd{4-1};
1646   let Inst{22}    = Sd{0};
1647
1648   let Inst{27-23} = opcod1;
1649   let Inst{21-20} = opcod2;
1650   let Inst{19-16} = opcod3;
1651   let Inst{11-9}  = 0b101;
1652   let Inst{8}     = 0;          // Single precision
1653   let Inst{7-6}   = opcod4;
1654   let Inst{4}     = opcod5;
1655 }
1656
1657 // Single precision unary, if no NEON. Same as ASuI except not available if
1658 // NEON is enabled.
1659 class ASuIn<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1660             bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1661             string asm, list<dag> pattern>
1662   : ASuI<opcod1, opcod2, opcod3, opcod4, opcod5, oops, iops, itin, opc, asm,
1663          pattern> {
1664   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1665 }
1666
1667 // Single precision, binary
1668 class ASbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
1669            InstrItinClass itin, string opc, string asm, list<dag> pattern>
1670   : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, pattern> {
1671   // Instruction operands.
1672   bits<5> Sd;
1673   bits<5> Sn;
1674   bits<5> Sm;
1675
1676   // Encode instruction operands.
1677   let Inst{3-0}   = Sm{4-1};
1678   let Inst{5}     = Sm{0};
1679   let Inst{19-16} = Sn{4-1};
1680   let Inst{7}     = Sn{0};
1681   let Inst{15-12} = Sd{4-1};
1682   let Inst{22}    = Sd{0};
1683
1684   let Inst{27-23} = opcod1;
1685   let Inst{21-20} = opcod2;
1686   let Inst{11-9}  = 0b101;
1687   let Inst{8}     = 0;          // Single precision
1688   let Inst{6}     = op6;
1689   let Inst{4}     = op4;
1690 }
1691
1692 // Single precision, binary, not predicated
1693 class ASbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
1694            InstrItinClass itin, string asm, list<dag> pattern>
1695   : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1696           VFPBinaryFrm, itin, asm, "", pattern>
1697 {
1698   // Instruction operands.
1699   bits<5> Sd;
1700   bits<5> Sn;
1701   bits<5> Sm;
1702
1703   let Inst{31-28} = 0b1111;
1704
1705   // Encode instruction operands.
1706   let Inst{3-0}   = Sm{4-1};
1707   let Inst{5}     = Sm{0};
1708   let Inst{19-16} = Sn{4-1};
1709   let Inst{7}     = Sn{0};
1710   let Inst{15-12} = Sd{4-1};
1711   let Inst{22}    = Sd{0};
1712
1713   let Inst{27-23} = opcod1;
1714   let Inst{21-20} = opcod2;
1715   let Inst{11-9}  = 0b101;
1716   let Inst{8}     = 0; // Single precision
1717   let Inst{6}     = opcod3;
1718   let Inst{4}     = 0;
1719 }
1720
1721 // Single precision binary, if no NEON. Same as ASbI except not available if
1722 // NEON is enabled.
1723 class ASbIn<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1724             dag iops, InstrItinClass itin, string opc, string asm,
1725             list<dag> pattern>
1726   : ASbI<opcod1, opcod2, op6, op4, oops, iops, itin, opc, asm, pattern> {
1727   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1728
1729   // Instruction operands.
1730   bits<5> Sd;
1731   bits<5> Sn;
1732   bits<5> Sm;
1733
1734   // Encode instruction operands.
1735   let Inst{3-0}   = Sm{4-1};
1736   let Inst{5}     = Sm{0};
1737   let Inst{19-16} = Sn{4-1};
1738   let Inst{7}     = Sn{0};
1739   let Inst{15-12} = Sd{4-1};
1740   let Inst{22}    = Sd{0};
1741 }
1742
1743 // VFP conversion instructions
1744 class AVConv1I<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
1745                dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1746                list<dag> pattern>
1747   : VFPAI<oops, iops, VFPConv1Frm, itin, opc, asm, pattern> {
1748   let Inst{27-23} = opcod1;
1749   let Inst{21-20} = opcod2;
1750   let Inst{19-16} = opcod3;
1751   let Inst{11-8}  = opcod4;
1752   let Inst{6}     = 1;
1753   let Inst{4}     = 0;
1754 }
1755
1756 // VFP conversion between floating-point and fixed-point
1757 class AVConv1XI<bits<5> op1, bits<2> op2, bits<4> op3, bits<4> op4, bit op5,
1758                 dag oops, dag iops, InstrItinClass itin, string opc, string asm,
1759                 list<dag> pattern>
1760   : AVConv1I<op1, op2, op3, op4, oops, iops, itin, opc, asm, pattern> {
1761   bits<5> fbits;
1762   // size (fixed-point number): sx == 0 ? 16 : 32
1763   let Inst{7} = op5; // sx
1764   let Inst{5} = fbits{0};
1765   let Inst{3-0} = fbits{4-1};
1766 }
1767
1768 // VFP conversion instructions, if no NEON
1769 class AVConv1In<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
1770                 dag oops, dag iops, InstrItinClass itin,
1771                 string opc, string asm, list<dag> pattern>
1772   : AVConv1I<opcod1, opcod2, opcod3, opcod4, oops, iops, itin, opc, asm,
1773              pattern> {
1774   list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1775 }
1776
1777 class AVConvXI<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops, Format f,
1778                InstrItinClass itin,
1779                string opc, string asm, list<dag> pattern>
1780   : VFPAI<oops, iops, f, itin, opc, asm, pattern> {
1781   let Inst{27-20} = opcod1;
1782   let Inst{11-8}  = opcod2;
1783   let Inst{4}     = 1;
1784 }
1785
1786 class AVConv2I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1787                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1788   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv2Frm, itin, opc, asm, pattern>;
1789
1790 class AVConv3I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1791                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1792   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv3Frm, itin, opc, asm, pattern>;
1793
1794 class AVConv4I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1795                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1796   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv4Frm, itin, opc, asm, pattern>;
1797
1798 class AVConv5I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
1799                InstrItinClass itin, string opc, string asm, list<dag> pattern>
1800   : AVConvXI<opcod1, opcod2, oops, iops, VFPConv5Frm, itin, opc, asm, pattern>;
1801
1802 //===----------------------------------------------------------------------===//
1803
1804 //===----------------------------------------------------------------------===//
1805 // ARM NEON Instruction templates.
1806 //
1807
1808 class NeonI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
1809             InstrItinClass itin, string opc, string dt, string asm, string cstr,
1810             list<dag> pattern>
1811   : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
1812   let OutOperandList = oops;
1813   let InOperandList = !con(iops, (ins pred:$p));
1814   let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
1815   let Pattern = pattern;
1816   list<Predicate> Predicates = [HasNEON];
1817   let DecoderNamespace = "NEON";
1818 }
1819
1820 // Same as NeonI except it does not have a "data type" specifier.
1821 class NeonXI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
1822              InstrItinClass itin, string opc, string asm, string cstr,
1823              list<dag> pattern>
1824   : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
1825   let OutOperandList = oops;
1826   let InOperandList = !con(iops, (ins pred:$p));
1827   let AsmString = !strconcat(opc, "${p}", "\t", asm);
1828   let Pattern = pattern;
1829   list<Predicate> Predicates = [HasNEON];
1830   let DecoderNamespace = "NEON";
1831 }
1832
1833 class NLdSt<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
1834             dag oops, dag iops, InstrItinClass itin,
1835             string opc, string dt, string asm, string cstr, list<dag> pattern>
1836   : NeonI<oops, iops, AddrMode6, IndexModeNone, NLdStFrm, itin, opc, dt, asm,
1837           cstr, pattern> {
1838   let Inst{31-24} = 0b11110100;
1839   let Inst{23}    = op23;
1840   let Inst{21-20} = op21_20;
1841   let Inst{11-8}  = op11_8;
1842   let Inst{7-4}   = op7_4;
1843
1844   let PostEncoderMethod = "NEONThumb2LoadStorePostEncoder";
1845   let DecoderNamespace = "NEONLoadStore";
1846
1847   bits<5> Vd;
1848   bits<6> Rn;
1849   bits<4> Rm;
1850
1851   let Inst{22}    = Vd{4};
1852   let Inst{15-12} = Vd{3-0};
1853   let Inst{19-16} = Rn{3-0};
1854   let Inst{3-0}   = Rm{3-0};
1855 }
1856
1857 class NLdStLn<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
1858             dag oops, dag iops, InstrItinClass itin,
1859             string opc, string dt, string asm, string cstr, list<dag> pattern>
1860   : NLdSt<op23, op21_20, op11_8, op7_4, oops, iops, itin, opc,
1861           dt, asm, cstr, pattern> {
1862   bits<3> lane;
1863 }
1864
1865 class PseudoNLdSt<dag oops, dag iops, InstrItinClass itin, string cstr>
1866   : InstARM<AddrMode6, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
1867             itin> {
1868   let OutOperandList = oops;
1869   let InOperandList = !con(iops, (ins pred:$p));
1870   list<Predicate> Predicates = [HasNEON];
1871 }
1872
1873 class PseudoNeonI<dag oops, dag iops, InstrItinClass itin, string cstr,
1874                   list<dag> pattern>
1875   : InstARM<AddrModeNone, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
1876             itin> {
1877   let OutOperandList = oops;
1878   let InOperandList = !con(iops, (ins pred:$p));
1879   let Pattern = pattern;
1880   list<Predicate> Predicates = [HasNEON];
1881 }
1882
1883 class NDataI<dag oops, dag iops, Format f, InstrItinClass itin,
1884              string opc, string dt, string asm, string cstr, list<dag> pattern>
1885   : NeonI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, dt, asm, cstr,
1886           pattern> {
1887   let Inst{31-25} = 0b1111001;
1888   let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
1889   let DecoderNamespace = "NEONData";
1890 }
1891
1892 class NDataXI<dag oops, dag iops, Format f, InstrItinClass itin,
1893               string opc, string asm, string cstr, list<dag> pattern>
1894   : NeonXI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, asm,
1895            cstr, pattern> {
1896   let Inst{31-25} = 0b1111001;
1897   let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
1898   let DecoderNamespace = "NEONData";
1899 }
1900
1901 // NEON "one register and a modified immediate" format.
1902 class N1ModImm<bit op23, bits<3> op21_19, bits<4> op11_8, bit op7, bit op6,
1903                bit op5, bit op4,
1904                dag oops, dag iops, InstrItinClass itin,
1905                string opc, string dt, string asm, string cstr,
1906                list<dag> pattern>
1907   : NDataI<oops, iops, N1RegModImmFrm, itin, opc, dt, asm, cstr, pattern> {
1908   let Inst{23}    = op23;
1909   let Inst{21-19} = op21_19;
1910   let Inst{11-8}  = op11_8;
1911   let Inst{7}     = op7;
1912   let Inst{6}     = op6;
1913   let Inst{5}     = op5;
1914   let Inst{4}     = op4;
1915
1916   // Instruction operands.
1917   bits<5> Vd;
1918   bits<13> SIMM;
1919
1920   let Inst{15-12} = Vd{3-0};
1921   let Inst{22}    = Vd{4};
1922   let Inst{24}    = SIMM{7};
1923   let Inst{18-16} = SIMM{6-4};
1924   let Inst{3-0}   = SIMM{3-0};
1925   let DecoderMethod = "DecodeNEONModImmInstruction";
1926 }
1927
1928 // NEON 2 vector register format.
1929 class N2V<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
1930           bits<5> op11_7, bit op6, bit op4,
1931           dag oops, dag iops, InstrItinClass itin,
1932           string opc, string dt, string asm, string cstr, list<dag> pattern>
1933   : NDataI<oops, iops, N2RegFrm, itin, opc, dt, asm, cstr, pattern> {
1934   let Inst{24-23} = op24_23;
1935   let Inst{21-20} = op21_20;
1936   let Inst{19-18} = op19_18;
1937   let Inst{17-16} = op17_16;
1938   let Inst{11-7}  = op11_7;
1939   let Inst{6}     = op6;
1940   let Inst{4}     = op4;
1941
1942   // Instruction operands.
1943   bits<5> Vd;
1944   bits<5> Vm;
1945
1946   let Inst{15-12} = Vd{3-0};
1947   let Inst{22}    = Vd{4};
1948   let Inst{3-0}   = Vm{3-0};
1949   let Inst{5}     = Vm{4};
1950 }
1951
1952 // Same as N2V except it doesn't have a datatype suffix.
1953 class N2VX<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
1954            bits<5> op11_7, bit op6, bit op4,
1955            dag oops, dag iops, InstrItinClass itin,
1956            string opc, string asm, string cstr, list<dag> pattern>
1957   : NDataXI<oops, iops, N2RegFrm, itin, opc, asm, cstr, pattern> {
1958   let Inst{24-23} = op24_23;
1959   let Inst{21-20} = op21_20;
1960   let Inst{19-18} = op19_18;
1961   let Inst{17-16} = op17_16;
1962   let Inst{11-7}  = op11_7;
1963   let Inst{6}     = op6;
1964   let Inst{4}     = op4;
1965
1966   // Instruction operands.
1967   bits<5> Vd;
1968   bits<5> Vm;
1969
1970   let Inst{15-12} = Vd{3-0};
1971   let Inst{22}    = Vd{4};
1972   let Inst{3-0}   = Vm{3-0};
1973   let Inst{5}     = Vm{4};
1974 }
1975
1976 // NEON 2 vector register with immediate.
1977 class N2VImm<bit op24, bit op23, bits<4> op11_8, bit op7, bit op6, bit op4,
1978              dag oops, dag iops, Format f, InstrItinClass itin,
1979              string opc, string dt, string asm, string cstr, list<dag> pattern>
1980   : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
1981   let Inst{24}   = op24;
1982   let Inst{23}   = op23;
1983   let Inst{11-8} = op11_8;
1984   let Inst{7}    = op7;
1985   let Inst{6}    = op6;
1986   let Inst{4}    = op4;
1987
1988   // Instruction operands.
1989   bits<5> Vd;
1990   bits<5> Vm;
1991   bits<6> SIMM;
1992
1993   let Inst{15-12} = Vd{3-0};
1994   let Inst{22}    = Vd{4};
1995   let Inst{3-0}   = Vm{3-0};
1996   let Inst{5}     = Vm{4};
1997   let Inst{21-16} = SIMM{5-0};
1998 }
1999
2000 // NEON 3 vector register format.
2001
2002 class N3VCommon<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2003                 bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2004                 string opc, string dt, string asm, string cstr,
2005                 list<dag> pattern>
2006   : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2007   let Inst{24}    = op24;
2008   let Inst{23}    = op23;
2009   let Inst{21-20} = op21_20;
2010   let Inst{11-8}  = op11_8;
2011   let Inst{6}     = op6;
2012   let Inst{4}     = op4;
2013 }
2014
2015 class N3V<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6, bit op4,
2016           dag oops, dag iops, Format f, InstrItinClass itin,
2017           string opc, string dt, string asm, string cstr, list<dag> pattern>
2018   : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2019               oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2020   // Instruction operands.
2021   bits<5> Vd;
2022   bits<5> Vn;
2023   bits<5> Vm;
2024
2025   let Inst{15-12} = Vd{3-0};
2026   let Inst{22}    = Vd{4};
2027   let Inst{19-16} = Vn{3-0};
2028   let Inst{7}     = Vn{4};
2029   let Inst{3-0}   = Vm{3-0};
2030   let Inst{5}     = Vm{4};
2031 }
2032
2033 class N3VLane32<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2034                 bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2035                 string opc, string dt, string asm, string cstr,
2036                 list<dag> pattern>
2037   : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2038               oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2039
2040   // Instruction operands.
2041   bits<5> Vd;
2042   bits<5> Vn;
2043   bits<5> Vm;
2044   bit lane;
2045
2046   let Inst{15-12} = Vd{3-0};
2047   let Inst{22}    = Vd{4};
2048   let Inst{19-16} = Vn{3-0};
2049   let Inst{7}     = Vn{4};
2050   let Inst{3-0}   = Vm{3-0};
2051   let Inst{5}     = lane;
2052 }
2053
2054 class N3VLane16<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2055                 bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2056                 string opc, string dt, string asm, string cstr,
2057                 list<dag> pattern>
2058   : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2059               oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2060
2061   // Instruction operands.
2062   bits<5> Vd;
2063   bits<5> Vn;
2064   bits<5> Vm;
2065   bits<2> lane;
2066
2067   let Inst{15-12} = Vd{3-0};
2068   let Inst{22}    = Vd{4};
2069   let Inst{19-16} = Vn{3-0};
2070   let Inst{7}     = Vn{4};
2071   let Inst{2-0}   = Vm{2-0};
2072   let Inst{5}     = lane{1};
2073   let Inst{3}     = lane{0};
2074 }
2075
2076 // Same as N3V except it doesn't have a data type suffix.
2077 class N3VX<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2078            bit op4,
2079            dag oops, dag iops, Format f, InstrItinClass itin,
2080            string opc, string asm, string cstr, list<dag> pattern>
2081   : NDataXI<oops, iops, f, itin, opc, asm, cstr, pattern> {
2082   let Inst{24}    = op24;
2083   let Inst{23}    = op23;
2084   let Inst{21-20} = op21_20;
2085   let Inst{11-8}  = op11_8;
2086   let Inst{6}     = op6;
2087   let Inst{4}     = op4;
2088
2089   // Instruction operands.
2090   bits<5> Vd;
2091   bits<5> Vn;
2092   bits<5> Vm;
2093
2094   let Inst{15-12} = Vd{3-0};
2095   let Inst{22}    = Vd{4};
2096   let Inst{19-16} = Vn{3-0};
2097   let Inst{7}     = Vn{4};
2098   let Inst{3-0}   = Vm{3-0};
2099   let Inst{5}     = Vm{4};
2100 }
2101
2102 // NEON VMOVs between scalar and core registers.
2103 class NVLaneOp<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2104                dag oops, dag iops, Format f, InstrItinClass itin,
2105                string opc, string dt, string asm, list<dag> pattern>
2106   : InstARM<AddrModeNone, 4, IndexModeNone, f, NeonDomain,
2107             "", itin> {
2108   let Inst{27-20} = opcod1;
2109   let Inst{11-8}  = opcod2;
2110   let Inst{6-5}   = opcod3;
2111   let Inst{4}     = 1;
2112   // A8.6.303, A8.6.328, A8.6.329
2113   let Inst{3-0}   = 0b0000;
2114
2115   let OutOperandList = oops;
2116   let InOperandList = !con(iops, (ins pred:$p));
2117   let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
2118   let Pattern = pattern;
2119   list<Predicate> Predicates = [HasNEON];
2120
2121   let PostEncoderMethod = "NEONThumb2DupPostEncoder";
2122   let DecoderNamespace = "NEONDup";
2123
2124   bits<5> V;
2125   bits<4> R;
2126   bits<4> p;
2127   bits<4> lane;
2128
2129   let Inst{31-28} = p{3-0};
2130   let Inst{7}     = V{4};
2131   let Inst{19-16} = V{3-0};
2132   let Inst{15-12} = R{3-0};
2133 }
2134 class NVGetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2135                 dag oops, dag iops, InstrItinClass itin,
2136                 string opc, string dt, string asm, list<dag> pattern>
2137   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NGetLnFrm, itin,
2138              opc, dt, asm, pattern>;
2139 class NVSetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2140                 dag oops, dag iops, InstrItinClass itin,
2141                 string opc, string dt, string asm, list<dag> pattern>
2142   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NSetLnFrm, itin,
2143              opc, dt, asm, pattern>;
2144 class NVDup<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2145             dag oops, dag iops, InstrItinClass itin,
2146             string opc, string dt, string asm, list<dag> pattern>
2147   : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NDupFrm, itin,
2148              opc, dt, asm, pattern>;
2149
2150 // Vector Duplicate Lane (from scalar to all elements)
2151 class NVDupLane<bits<4> op19_16, bit op6, dag oops, dag iops,
2152                 InstrItinClass itin, string opc, string dt, string asm,
2153                 list<dag> pattern>
2154   : NDataI<oops, iops, NVDupLnFrm, itin, opc, dt, asm, "", pattern> {
2155   let Inst{24-23} = 0b11;
2156   let Inst{21-20} = 0b11;
2157   let Inst{19-16} = op19_16;
2158   let Inst{11-7}  = 0b11000;
2159   let Inst{6}     = op6;
2160   let Inst{4}     = 0;
2161
2162   bits<5> Vd;
2163   bits<5> Vm;
2164
2165   let Inst{22}     = Vd{4};
2166   let Inst{15-12} = Vd{3-0};
2167   let Inst{5}     = Vm{4};
2168   let Inst{3-0} = Vm{3-0};
2169 }
2170
2171 // NEONFPPat - Same as Pat<>, but requires that the compiler be using NEON
2172 // for single-precision FP.
2173 class NEONFPPat<dag pattern, dag result> : Pat<pattern, result> {
2174   list<Predicate> Predicates = [HasNEON,UseNEONForFP];
2175 }
2176
2177 // VFP/NEON Instruction aliases for type suffices.
2178 class VFPDataTypeInstAlias<string opc, string dt, string asm, dag Result> :
2179   InstAlias<!strconcat(opc, dt, "\t", asm), Result>, Requires<[HasVFP2]>;
2180
2181 multiclass VFPDTAnyInstAlias<string opc, string asm, dag Result> {
2182   def : VFPDataTypeInstAlias<opc, ".8", asm, Result>;
2183   def : VFPDataTypeInstAlias<opc, ".16", asm, Result>;
2184   def : VFPDataTypeInstAlias<opc, ".32", asm, Result>;
2185   def : VFPDataTypeInstAlias<opc, ".64", asm, Result>;
2186 }
2187
2188 multiclass NEONDTAnyInstAlias<string opc, string asm, dag Result> {
2189   let Predicates = [HasNEON] in {
2190   def : VFPDataTypeInstAlias<opc, ".8", asm, Result>;
2191   def : VFPDataTypeInstAlias<opc, ".16", asm, Result>;
2192   def : VFPDataTypeInstAlias<opc, ".32", asm, Result>;
2193   def : VFPDataTypeInstAlias<opc, ".64", asm, Result>;
2194 }
2195 }
2196
2197 // The same alias classes using AsmPseudo instead, for the more complex
2198 // stuff in NEON that InstAlias can't quite handle.
2199 // Note that we can't use anonymous defm references here like we can
2200 // above, as we care about the ultimate instruction enum names generated, unlike
2201 // for instalias defs.
2202 class NEONDataTypeAsmPseudoInst<string opc, string dt, string asm, dag iops> :
2203   AsmPseudoInst<!strconcat(opc, dt, "\t", asm), iops>, Requires<[HasNEON]>;
2204
2205 // Data type suffix token aliases. Implements Table A7-3 in the ARM ARM.
2206 def : TokenAlias<".s8", ".i8">;
2207 def : TokenAlias<".u8", ".i8">;
2208 def : TokenAlias<".s16", ".i16">;
2209 def : TokenAlias<".u16", ".i16">;
2210 def : TokenAlias<".s32", ".i32">;
2211 def : TokenAlias<".u32", ".i32">;
2212 def : TokenAlias<".s64", ".i64">;
2213 def : TokenAlias<".u64", ".i64">;
2214
2215 def : TokenAlias<".i8", ".8">;
2216 def : TokenAlias<".i16", ".16">;
2217 def : TokenAlias<".i32", ".32">;
2218 def : TokenAlias<".i64", ".64">;
2219
2220 def : TokenAlias<".p8", ".8">;
2221 def : TokenAlias<".p16", ".16">;
2222
2223 def : TokenAlias<".f32", ".32">;
2224 def : TokenAlias<".f64", ".64">;
2225 def : TokenAlias<".f", ".f32">;
2226 def : TokenAlias<".d", ".f64">;