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