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