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