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