xref: /llvm-project/llvm/lib/Target/ARM/ARMInstrFormats.td (revision a10ce71ac4ef55cc9a80c0aece501a09bd39cc9a)
1//===-- ARMInstrFormats.td - ARM Instruction Formats -------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9//===----------------------------------------------------------------------===//
10//
11// ARM Instruction Format Definitions.
12//
13
14// Format specifies the encoding used by the instruction.  This is part of the
15// ad-hoc solution used to emit machine instruction encodings by our machine
16// code emitter.
17class Format<bits<6> val> {
18  bits<6> Value = val;
19}
20
21def Pseudo        : Format<0>;
22def MulFrm        : Format<1>;
23def BrFrm         : Format<2>;
24def BrMiscFrm     : Format<3>;
25
26def DPFrm         : Format<4>;
27def DPSoRegRegFrm    : Format<5>;
28
29def LdFrm         : Format<6>;
30def StFrm         : Format<7>;
31def LdMiscFrm     : Format<8>;
32def StMiscFrm     : Format<9>;
33def LdStMulFrm    : Format<10>;
34
35def LdStExFrm     : Format<11>;
36
37def ArithMiscFrm  : Format<12>;
38def SatFrm        : Format<13>;
39def ExtFrm        : Format<14>;
40
41def VFPUnaryFrm   : Format<15>;
42def VFPBinaryFrm  : Format<16>;
43def VFPConv1Frm   : Format<17>;
44def VFPConv2Frm   : Format<18>;
45def VFPConv3Frm   : Format<19>;
46def VFPConv4Frm   : Format<20>;
47def VFPConv5Frm   : Format<21>;
48def VFPLdStFrm    : Format<22>;
49def VFPLdStMulFrm : Format<23>;
50def VFPMiscFrm    : Format<24>;
51
52def ThumbFrm      : Format<25>;
53def MiscFrm       : Format<26>;
54
55def NGetLnFrm     : Format<27>;
56def NSetLnFrm     : Format<28>;
57def NDupFrm       : Format<29>;
58def NLdStFrm      : Format<30>;
59def N1RegModImmFrm: Format<31>;
60def N2RegFrm      : Format<32>;
61def NVCVTFrm      : Format<33>;
62def NVDupLnFrm    : Format<34>;
63def N2RegVShLFrm  : Format<35>;
64def N2RegVShRFrm  : Format<36>;
65def N3RegFrm      : Format<37>;
66def N3RegVShFrm   : Format<38>;
67def NVExtFrm      : Format<39>;
68def NVMulSLFrm    : Format<40>;
69def NVTBLFrm      : Format<41>;
70def DPSoRegImmFrm  : Format<42>;
71def N3RegCplxFrm  : Format<43>;
72
73// Misc flags.
74
75// The instruction has an Rn register operand.
76// UnaryDP - Indicates this is a unary data processing instruction, i.e.
77// it doesn't have a Rn operand.
78class UnaryDP    { bit isUnaryDataProc = 1; }
79
80// Xform16Bit - Indicates this Thumb2 instruction may be transformed into
81// a 16-bit Thumb instruction if certain conditions are met.
82class Xform16Bit { bit canXformTo16Bit = 1; }
83
84//===----------------------------------------------------------------------===//
85// ARM Instruction flags.  These need to match ARMBaseInstrInfo.h.
86//
87
88// FIXME: Once the JIT is MC-ized, these can go away.
89// Addressing mode.
90class AddrMode<bits<5> val> {
91  bits<5> Value = val;
92}
93def AddrModeNone    : AddrMode<0>;
94def AddrMode1       : AddrMode<1>;
95def AddrMode2       : AddrMode<2>;
96def AddrMode3       : AddrMode<3>;
97def AddrMode4       : AddrMode<4>;
98def AddrMode5       : AddrMode<5>;
99def AddrMode6       : AddrMode<6>;
100def AddrModeT1_1    : AddrMode<7>;
101def AddrModeT1_2    : AddrMode<8>;
102def AddrModeT1_4    : AddrMode<9>;
103def AddrModeT1_s    : AddrMode<10>;
104def AddrModeT2_i12  : AddrMode<11>;
105def AddrModeT2_i8   : AddrMode<12>;
106def AddrModeT2_i8pos : AddrMode<13>;
107def AddrModeT2_i8neg : AddrMode<14>;
108def AddrModeT2_so   : AddrMode<15>;
109def AddrModeT2_pc   : AddrMode<16>;
110def AddrModeT2_i8s4 : AddrMode<17>;
111def AddrMode_i12    : AddrMode<18>;
112def AddrMode5FP16   : AddrMode<19>;
113def AddrModeT2_ldrex : AddrMode<20>;
114def AddrModeT2_i7s4 : AddrMode<21>;
115def AddrModeT2_i7s2 : AddrMode<22>;
116def AddrModeT2_i7   : AddrMode<23>;
117
118// Load / store index mode.
119class IndexMode<bits<2> val> {
120  bits<2> Value = val;
121}
122def IndexModeNone : IndexMode<0>;
123def IndexModePre  : IndexMode<1>;
124def IndexModePost : IndexMode<2>;
125def IndexModeUpd  : IndexMode<3>;
126
127// Instruction execution domain.
128class Domain<bits<4> val> {
129  bits<4> Value = val;
130}
131def GenericDomain : Domain<0>;
132def VFPDomain     : Domain<1>; // Instructions in VFP domain only
133def NeonDomain    : Domain<2>; // Instructions in Neon domain only
134def VFPNeonDomain : Domain<3>; // Instructions in both VFP & Neon domains
135def VFPNeonA8Domain : Domain<5>; // Instructions in VFP & Neon under A8
136def MVEDomain : Domain<8>; // Instructions in MVE and ARMv8.1m
137
138//===----------------------------------------------------------------------===//
139// ARM special operands.
140//
141
142// ARM imod and iflag operands, used only by the CPS instruction.
143def imod_op : Operand<i32> {
144  let PrintMethod = "printCPSIMod";
145}
146
147def ProcIFlagsOperand : AsmOperandClass {
148  let Name = "ProcIFlags";
149  let ParserMethod = "parseProcIFlagsOperand";
150}
151def iflags_op : Operand<i32> {
152  let PrintMethod = "printCPSIFlag";
153  let ParserMatchClass = ProcIFlagsOperand;
154}
155
156// ARM Predicate operand. Default to 14 = always (AL). Second part is CC
157// register whose default is 0 (no register).
158def CondCodeOperand : AsmOperandClass {
159  let Name = "CondCode";
160  let DefaultMethod = "defaultCondCodeOp";
161  let IsOptional = true;
162}
163def pred : PredicateOperand<OtherVT, (ops i32imm, i32imm),
164                                     (ops (i32 14), (i32 zero_reg))> {
165  let PrintMethod = "printPredicateOperand";
166  let ParserMatchClass = CondCodeOperand;
167  let DecoderMethod = "DecodePredicateOperand";
168}
169
170// Conditional code result for instructions whose 's' bit is set, e.g. subs.
171def CCOutOperand : AsmOperandClass {
172  let Name = "CCOut";
173  let DefaultMethod = "defaultCCOutOp";
174  let IsOptional = true;
175}
176def cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 zero_reg))> {
177  let EncoderMethod = "getCCOutOpValue";
178  let PrintMethod = "printSBitModifierOperand";
179  let ParserMatchClass = CCOutOperand;
180  let DecoderMethod = "DecodeCCOutOperand";
181}
182
183// Same as cc_out except it defaults to setting CPSR.
184def s_cc_out : OptionalDefOperand<OtherVT, (ops CCR), (ops (i32 CPSR))> {
185  let EncoderMethod = "getCCOutOpValue";
186  let PrintMethod = "printSBitModifierOperand";
187  let ParserMatchClass = CCOutOperand;
188  let DecoderMethod = "DecodeCCOutOperand";
189}
190
191// Transform to generate the inverse of a condition code during ISel
192def inv_cond_XFORM : SDNodeXForm<imm, [{
193  ARMCC::CondCodes CC = static_cast<ARMCC::CondCodes>(N->getZExtValue());
194  return CurDAG->getTargetConstant(ARMCC::getOppositeCondition(CC), SDLoc(N),
195                                   MVT::i32);
196}]>;
197
198// VPT predicate
199
200def VPTPredNOperand : AsmOperandClass {
201  let Name = "VPTPredN";
202  let PredicateMethod = "isVPTPred";
203  let DefaultMethod = "defaultVPTPredOp";
204  let IsOptional = true;
205}
206def VPTPredROperand : AsmOperandClass {
207  let Name = "VPTPredR";
208  let PredicateMethod = "isVPTPred";
209  let DefaultMethod = "defaultVPTPredOp";
210  let IsOptional = true;
211}
212
213// Operand classes for the cluster of MC operands describing a
214// VPT-predicated MVE instruction.
215//
216// There are two of these classes. Both of them have the same first
217// two options:
218//
219// $cond (an integer) indicates the instruction's predication status:
220//   * ARMVCC::None means it's unpredicated
221//   * ARMVCC::Then means it's in a VPT block and appears with the T suffix
222//   * ARMVCC::Else means it's in a VPT block and appears with the E suffix.
223// During code generation, unpredicated and predicated instructions
224// are indicated by setting this parameter to 'None' or to 'Then'; the
225// third value 'Else' is only used for assembly and disassembly.
226//
227// $cond_reg (type VCCR) gives the input predicate register. This is
228// always either zero_reg or VPR, but needs to be modelled as an
229// explicit operand so that it can be register-allocated and spilled
230// when these operands are used in code generation).
231//
232// For 'vpred_r', there's an extra operand $inactive, which specifies
233// the vector register which will supply any lanes of the output
234// register that the predication mask prevents from being written by
235// this instruction. It's always tied to the actual output register
236// (i.e. must be allocated into the same physical reg), but again,
237// code generation will need to model it as a separate input value.
238//
239// 'vpred_n' doesn't have that extra operand: it only has $cond and
240// $cond_reg. This variant is used for any instruction that can't, or
241// doesn't want to, tie $inactive to the output register. Sometimes
242// that's because another input parameter is already tied to it (e.g.
243// instructions that both read and write their Qd register even when
244// unpredicated, either because they only partially overwrite it like
245// a narrowing integer conversion, or simply because the instruction
246// encoding doesn't have enough register fields to make the output
247// independent of all inputs). It can also be because the instruction
248// is defined to set disabled output lanes to zero rather than leaving
249// them unchanged (vector loads), or because it doesn't output a
250// vector register at all (stores, compares). In any of these
251// situations it's unnecessary to have an extra operand tied to the
252// output, and inconvenient to leave it there unused.
253
254// Base class for both kinds of vpred.
255class vpred_ops<dag extra_op, dag extra_mi> : OperandWithDefaultOps<OtherVT,
256            !con((ops (i32 0), (i32 zero_reg), (i32 zero_reg)), extra_op)> {
257  let PrintMethod = "printVPTPredicateOperand";
258  let OperandNamespace = "ARM";
259  let MIOperandInfo = !con((ops i32imm:$cond, VCCR:$cond_reg, GPRlr:$tp_reg), extra_mi);
260
261  // For convenience, we provide a string value that can be appended
262  // to the constraints string. It's empty for vpred_n, and for
263  // vpred_r it ties the $inactive operand to the output q-register
264  // (which by convention will be called $Qd).
265  string vpred_constraint;
266}
267
268def vpred_r : vpred_ops<(ops (v4i32 undef_tied_input)), (ops MQPR:$inactive)> {
269  let ParserMatchClass = VPTPredROperand;
270  let OperandType = "OPERAND_VPRED_R";
271  let DecoderMethod = "DecodeVpredROperand";
272  let vpred_constraint = ",$Qd = $vp.inactive";
273}
274
275def vpred_n : vpred_ops<(ops), (ops)> {
276  let ParserMatchClass = VPTPredNOperand;
277  let OperandType = "OPERAND_VPRED_N";
278  let DecoderMethod = "DecodeVpredNOperand";
279  let vpred_constraint = "";
280}
281
282// ARM special operands for disassembly only.
283//
284def SetEndAsmOperand : ImmAsmOperand<0,1> {
285  let Name = "SetEndImm";
286  let ParserMethod = "parseSetEndImm";
287}
288def setend_op : Operand<i32> {
289  let PrintMethod = "printSetendOperand";
290  let ParserMatchClass = SetEndAsmOperand;
291}
292
293def MSRMaskOperand : AsmOperandClass {
294  let Name = "MSRMask";
295  let ParserMethod = "parseMSRMaskOperand";
296}
297def msr_mask : Operand<i32> {
298  let PrintMethod = "printMSRMaskOperand";
299  let DecoderMethod = "DecodeMSRMask";
300  let ParserMatchClass = MSRMaskOperand;
301}
302
303def BankedRegOperand : AsmOperandClass {
304  let Name = "BankedReg";
305  let ParserMethod = "parseBankedRegOperand";
306}
307def banked_reg : Operand<i32> {
308  let PrintMethod = "printBankedRegOperand";
309  let DecoderMethod = "DecodeBankedReg";
310  let ParserMatchClass = BankedRegOperand;
311}
312
313// Shift Right Immediate - A shift right immediate is encoded differently from
314// other shift immediates. The imm6 field is encoded like so:
315//
316//    Offset    Encoding
317//     8        imm6<5:3> = '001', 8 - <imm> is encoded in imm6<2:0>
318//     16       imm6<5:4> = '01', 16 - <imm> is encoded in imm6<3:0>
319//     32       imm6<5> = '1', 32 - <imm> is encoded in imm6<4:0>
320//     64       64 - <imm> is encoded in imm6<5:0>
321def shr_imm8_asm_operand : ImmAsmOperand<1,8> { let Name = "ShrImm8"; }
322def shr_imm8  : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 8; }]> {
323  let EncoderMethod = "getShiftRight8Imm";
324  let DecoderMethod = "DecodeShiftRight8Imm";
325  let ParserMatchClass = shr_imm8_asm_operand;
326}
327def shr_imm16_asm_operand : ImmAsmOperand<1,16> { let Name = "ShrImm16"; }
328def shr_imm16 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 16; }]> {
329  let EncoderMethod = "getShiftRight16Imm";
330  let DecoderMethod = "DecodeShiftRight16Imm";
331  let ParserMatchClass = shr_imm16_asm_operand;
332}
333def shr_imm32_asm_operand : ImmAsmOperand<1,32> { let Name = "ShrImm32"; }
334def shr_imm32 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]> {
335  let EncoderMethod = "getShiftRight32Imm";
336  let DecoderMethod = "DecodeShiftRight32Imm";
337  let ParserMatchClass = shr_imm32_asm_operand;
338}
339def shr_imm64_asm_operand : ImmAsmOperand<1,64> { let Name = "ShrImm64"; }
340def shr_imm64 : Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 64; }]> {
341  let EncoderMethod = "getShiftRight64Imm";
342  let DecoderMethod = "DecodeShiftRight64Imm";
343  let ParserMatchClass = shr_imm64_asm_operand;
344}
345
346
347// ARM Assembler operand for ldr Rd, =expression which generates an offset
348// to a constant pool entry or a MOV depending on the value of expression
349def const_pool_asm_operand : AsmOperandClass { let Name = "ConstPoolAsmImm"; }
350def const_pool_asm_imm : Operand<i32> {
351  let ParserMatchClass = const_pool_asm_operand;
352}
353
354
355//===----------------------------------------------------------------------===//
356// ARM Assembler alias templates.
357//
358// Note: When EmitPriority == 1, the alias will be used for printing
359class ARMInstAlias<string Asm, dag Result, bit EmitPriority = 0>
360      : InstAlias<Asm, Result, EmitPriority>, Requires<[IsARM]>;
361class ARMInstSubst<string Asm, dag Result, bit EmitPriority = 0>
362      : InstAlias<Asm, Result, EmitPriority>,
363        Requires<[IsARM,UseNegativeImmediates]>;
364class  tInstAlias<string Asm, dag Result, bit EmitPriority = 0>
365      : InstAlias<Asm, Result, EmitPriority>, Requires<[IsThumb]>;
366class  tInstSubst<string Asm, dag Result, bit EmitPriority = 0>
367      : InstAlias<Asm, Result, EmitPriority>,
368        Requires<[IsThumb,UseNegativeImmediates]>;
369class t2InstAlias<string Asm, dag Result, bit EmitPriority = 0>
370      : InstAlias<Asm, Result, EmitPriority>, Requires<[IsThumb2]>;
371class t2InstSubst<string Asm, dag Result, bit EmitPriority = 0>
372      : InstAlias<Asm, Result, EmitPriority>,
373        Requires<[IsThumb2,UseNegativeImmediates]>;
374class VFP2InstAlias<string Asm, dag Result, bit EmitPriority = 0>
375      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP2]>;
376class VFP2DPInstAlias<string Asm, dag Result, bit EmitPriority = 0>
377      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP2,HasDPVFP]>;
378class VFP3InstAlias<string Asm, dag Result, bit EmitPriority = 0>
379      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasVFP3]>;
380class NEONInstAlias<string Asm, dag Result, bit EmitPriority = 0>
381      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasNEON]>;
382class MVEInstAlias<string Asm, dag Result, bit EmitPriority = 1>
383      : InstAlias<Asm, Result, EmitPriority>, Requires<[HasMVEInt, IsThumb]>;
384
385
386class VFP2MnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
387          Requires<[HasVFP2]>;
388class NEONMnemonicAlias<string src, string dst> : MnemonicAlias<src, dst>,
389          Requires<[HasNEON]>;
390
391//===----------------------------------------------------------------------===//
392// ARM Instruction templates.
393//
394
395
396class InstTemplate<AddrMode am, int sz, IndexMode im,
397                   Format f, Domain d, string cstr, InstrItinClass itin>
398  : Instruction {
399  let Namespace = "ARM";
400
401  AddrMode AM = am;
402  int Size = sz;
403  IndexMode IM = im;
404  bits<2> IndexModeBits = IM.Value;
405  Format F = f;
406  bits<6> Form = F.Value;
407  Domain D = d;
408  bit isUnaryDataProc = 0;
409  bit canXformTo16Bit = 0;
410  // The instruction is a 16-bit flag setting Thumb instruction. Used
411  // by the parser and if-converter to determine whether to require the 'S'
412  // suffix on the mnemonic (when not in an IT block) or preclude it (when
413  // in an IT block).
414  bit thumbArithFlagSetting = 0;
415
416  bits<2> VecSize = 0;
417  bit validForTailPredication = 0;
418  bit retainsPreviousHalfElement = 0;
419  bit horizontalReduction = 0;
420  bit doubleWidthResult = 0;
421
422  // If this is a pseudo instruction, mark it isCodeGenOnly.
423  let isCodeGenOnly = !eq(!cast<string>(f), "Pseudo");
424
425  // The layout of TSFlags should be kept in sync with ARMBaseInfo.h.
426  let TSFlags{4-0}   = AM.Value;
427  let TSFlags{6-5}   = IndexModeBits;
428  let TSFlags{12-7} = Form;
429  let TSFlags{13}    = isUnaryDataProc;
430  let TSFlags{14}    = canXformTo16Bit;
431  let TSFlags{18-15} = D.Value;
432  let TSFlags{19}    = thumbArithFlagSetting;
433  let TSFlags{20}    = validForTailPredication;
434  let TSFlags{21}    = retainsPreviousHalfElement;
435  let TSFlags{22}    = horizontalReduction;
436  let TSFlags{23}    = doubleWidthResult;
437  let TSFlags{25-24} = VecSize;
438
439  let Constraints = cstr;
440  let Itinerary = itin;
441}
442
443class Encoding {
444  field bits<32> Inst;
445  // Mask of bits that cause an encoding to be UNPREDICTABLE.
446  // If a bit is set, then if the corresponding bit in the
447  // target encoding differs from its value in the "Inst" field,
448  // the instruction is UNPREDICTABLE (SoftFail in abstract parlance).
449  field bits<32> Unpredictable = 0;
450  // SoftFail is the generic name for this field, but we alias it so
451  // as to make it more obvious what it means in ARM-land.
452  field bits<32> SoftFail = Unpredictable;
453}
454
455class InstARM<AddrMode am, int sz, IndexMode im,
456              Format f, Domain d, string cstr, InstrItinClass itin>
457  : InstTemplate<am, sz, im, f, d, cstr, itin>, Encoding {
458  let DecoderNamespace = "ARM";
459}
460
461// This Encoding-less class is used by Thumb1 to specify the encoding bits later
462// on by adding flavors to specific instructions.
463class InstThumb<AddrMode am, int sz, IndexMode im,
464                Format f, Domain d, string cstr, InstrItinClass itin>
465  : InstTemplate<am, sz, im, f, d, cstr, itin> {
466  let DecoderNamespace = "Thumb";
467}
468
469// Pseudo-instructions for alternate assembly syntax (never used by codegen).
470// These are aliases that require C++ handling to convert to the target
471// instruction, while InstAliases can be handled directly by tblgen.
472class AsmPseudoInst<string asm, dag iops, dag oops = (outs)>
473  : InstTemplate<AddrModeNone, 4, IndexModeNone, Pseudo, GenericDomain,
474                 "", NoItinerary> {
475  let OutOperandList = oops;
476  let InOperandList = iops;
477  let Pattern = [];
478  let isCodeGenOnly = 0; // So we get asm matcher for it.
479  let AsmString = asm;
480  let isPseudo = 1;
481  let hasNoSchedulingInfo = 1;
482}
483
484class ARMAsmPseudo<string asm, dag iops, dag oops = (outs)>
485  : AsmPseudoInst<asm, iops, oops>, Requires<[IsARM]>;
486class tAsmPseudo<string asm, dag iops, dag oops = (outs)>
487  : AsmPseudoInst<asm, iops, oops>, Requires<[IsThumb]>;
488class t2AsmPseudo<string asm, dag iops, dag oops = (outs)>
489  : AsmPseudoInst<asm, iops, oops>, Requires<[IsThumb2]>;
490class VFP2AsmPseudo<string asm, dag iops, dag oops = (outs)>
491  : AsmPseudoInst<asm, iops, oops>, Requires<[HasVFP2]>;
492class NEONAsmPseudo<string asm, dag iops, dag oops = (outs)>
493  : AsmPseudoInst<asm, iops, oops>, Requires<[HasNEON]>;
494class MVEAsmPseudo<string asm, dag iops, dag oops = (outs)>
495  : AsmPseudoInst<asm, iops, oops>, Requires<[HasMVEInt]>;
496
497// Pseudo instructions for the code generator.
498class PseudoInst<dag oops, dag iops, InstrItinClass itin, list<dag> pattern>
499  : InstTemplate<AddrModeNone, 0, IndexModeNone, Pseudo,
500                 GenericDomain, "", itin> {
501  let OutOperandList = oops;
502  let InOperandList = iops;
503  let Pattern = pattern;
504  let isCodeGenOnly = 1;
505  let isPseudo = 1;
506}
507
508// PseudoInst that's ARM-mode only.
509class ARMPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
510                    list<dag> pattern>
511  : PseudoInst<oops, iops, itin, pattern> {
512  let Size = sz;
513  list<Predicate> Predicates = [IsARM];
514}
515
516// PseudoInst that's Thumb-mode only.
517class tPseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
518                    list<dag> pattern>
519  : PseudoInst<oops, iops, itin, pattern> {
520  let Size = sz;
521  list<Predicate> Predicates = [IsThumb];
522}
523
524// PseudoInst that's in ARMv8-M baseline (Somewhere between Thumb and Thumb2)
525class t2basePseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
526                    list<dag> pattern>
527  : PseudoInst<oops, iops, itin, pattern> {
528  let Size = sz;
529  list<Predicate> Predicates = [IsThumb,HasV8MBaseline];
530}
531
532// PseudoInst that's Thumb2-mode only.
533class t2PseudoInst<dag oops, dag iops, int sz, InstrItinClass itin,
534                    list<dag> pattern>
535  : PseudoInst<oops, iops, itin, pattern> {
536  let Size = sz;
537  list<Predicate> Predicates = [IsThumb2];
538}
539
540class ARMPseudoExpand<dag oops, dag iops, int sz,
541                      InstrItinClass itin, list<dag> pattern,
542                      dag Result>
543  : ARMPseudoInst<oops, iops, sz, itin, pattern>,
544    PseudoInstExpansion<Result>;
545
546class tPseudoExpand<dag oops, dag iops, int sz,
547                    InstrItinClass itin, list<dag> pattern,
548                    dag Result>
549  : tPseudoInst<oops, iops, sz, itin, pattern>,
550    PseudoInstExpansion<Result>;
551
552class t2PseudoExpand<dag oops, dag iops, int sz,
553                    InstrItinClass itin, list<dag> pattern,
554                    dag Result>
555  : t2PseudoInst<oops, iops, sz, itin, pattern>,
556    PseudoInstExpansion<Result>;
557
558// Almost all ARM instructions are predicable.
559class I<dag oops, dag iops, AddrMode am, int sz,
560        IndexMode im, Format f, InstrItinClass itin,
561        string opc, string asm, string cstr,
562        list<dag> pattern>
563  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
564  bits<4> p;
565  let Inst{31-28} = p;
566  let OutOperandList = oops;
567  let InOperandList = !con(iops, (ins pred:$p));
568  let AsmString = !strconcat(opc, "${p}", asm);
569  let Pattern = pattern;
570  list<Predicate> Predicates = [IsARM];
571}
572
573// A few are not predicable
574class InoP<dag oops, dag iops, AddrMode am, int sz,
575           IndexMode im, Format f, InstrItinClass itin,
576           string opc, string asm, string cstr,
577           list<dag> pattern>
578  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
579  let OutOperandList = oops;
580  let InOperandList = iops;
581  let AsmString = !strconcat(opc, asm);
582  let Pattern = pattern;
583  let isPredicable = 0;
584  list<Predicate> Predicates = [IsARM];
585}
586
587// Same as I except it can optionally modify CPSR. Note it's modeled as an input
588// operand since by default it's a zero register. It will become an implicit def
589// once it's "flipped".
590class sI<dag oops, dag iops, AddrMode am, int sz,
591         IndexMode im, Format f, InstrItinClass itin,
592         string opc, string asm, string cstr,
593         list<dag> pattern>
594  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
595  bits<4> p; // Predicate operand
596  bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
597  let Inst{31-28} = p;
598  let Inst{20} = s;
599
600  let OutOperandList = oops;
601  let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
602  let AsmString = !strconcat(opc, "${s}${p}", asm);
603  let Pattern = pattern;
604  list<Predicate> Predicates = [IsARM];
605}
606
607// Special cases
608class XI<dag oops, dag iops, AddrMode am, int sz,
609         IndexMode im, Format f, InstrItinClass itin,
610         string asm, string cstr, list<dag> pattern>
611  : InstARM<am, sz, im, f, GenericDomain, cstr, itin> {
612  let OutOperandList = oops;
613  let InOperandList = iops;
614  let AsmString = asm;
615  let Pattern = pattern;
616  list<Predicate> Predicates = [IsARM];
617}
618
619class AI<dag oops, dag iops, Format f, InstrItinClass itin,
620         string opc, string asm, list<dag> pattern>
621  : I<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
622      opc, asm, "", pattern>;
623class AsI<dag oops, dag iops, Format f, InstrItinClass itin,
624          string opc, string asm, list<dag> pattern>
625  : sI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
626       opc, asm, "", pattern>;
627class AXI<dag oops, dag iops, Format f, InstrItinClass itin,
628          string asm, list<dag> pattern>
629  : XI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
630       asm, "", pattern>;
631class AXIM<dag oops, dag iops, AddrMode am, Format f, InstrItinClass itin,
632          string asm, list<dag> pattern>
633  : XI<oops, iops, am, 4, IndexModeNone, f, itin,
634       asm, "", pattern>;
635class AInoP<dag oops, dag iops, Format f, InstrItinClass itin,
636            string opc, string asm, list<dag> pattern>
637  : InoP<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
638         opc, asm, "", pattern>;
639
640// Ctrl flow instructions
641class ABI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
642          string opc, string asm, list<dag> pattern>
643  : I<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
644      opc, asm, "", pattern> {
645  let Inst{27-24} = opcod;
646}
647class ABXI<bits<4> opcod, dag oops, dag iops, InstrItinClass itin,
648           string asm, list<dag> pattern>
649  : XI<oops, iops, AddrModeNone, 4, IndexModeNone, BrFrm, itin,
650       asm, "", pattern> {
651  let Inst{27-24} = opcod;
652}
653
654// BR_JT instructions
655class JTI<dag oops, dag iops, InstrItinClass itin,
656          string asm, list<dag> pattern>
657  : XI<oops, iops, AddrModeNone, 0, IndexModeNone, BrMiscFrm, itin,
658       asm, "", pattern>;
659
660class AIldr_ex_or_acq<bits<2> opcod, bits<2> opcod2, dag oops, dag iops, InstrItinClass itin,
661              string opc, string asm, list<dag> pattern>
662  : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
663      opc, asm, "", pattern> {
664  bits<4> Rt;
665  bits<4> addr;
666  let Inst{27-23} = 0b00011;
667  let Inst{22-21} = opcod;
668  let Inst{20}    = 1;
669  let Inst{19-16} = addr;
670  let Inst{15-12} = Rt;
671  let Inst{11-10} = 0b11;
672  let Inst{9-8}   = opcod2;
673  let Inst{7-0}   = 0b10011111;
674}
675class AIstr_ex_or_rel<bits<2> opcod, bits<2> opcod2, dag oops, dag iops, InstrItinClass itin,
676              string opc, string asm, list<dag> pattern>
677  : I<oops, iops, AddrModeNone, 4, IndexModeNone, LdStExFrm, itin,
678      opc, asm, "", pattern> {
679  bits<4> Rt;
680  bits<4> addr;
681  let Inst{27-23} = 0b00011;
682  let Inst{22-21} = opcod;
683  let Inst{20}    = 0;
684  let Inst{19-16} = addr;
685  let Inst{11-10} = 0b11;
686  let Inst{9-8}   = opcod2;
687  let Inst{7-4}   = 0b1001;
688  let Inst{3-0}   = Rt;
689
690  let mayStore = 1;
691}
692// Atomic load/store instructions
693class AIldrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
694              string opc, string asm, list<dag> pattern>
695  : AIldr_ex_or_acq<opcod, 0b11, oops, iops, itin, opc, asm, pattern>;
696
697class AIstrex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
698              string opc, string asm, list<dag> pattern>
699  : AIstr_ex_or_rel<opcod, 0b11, oops, iops, itin, opc, asm, pattern> {
700  bits<4> Rd;
701  let Inst{15-12} = Rd;
702}
703
704// Exclusive load/store instructions
705
706class AIldaex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
707              string opc, string asm, list<dag> pattern>
708  : AIldr_ex_or_acq<opcod, 0b10, oops, iops, itin, opc, asm, pattern>,
709    Requires<[IsARM, HasAcquireRelease, HasV7Clrex]>;
710
711class AIstlex<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
712              string opc, string asm, list<dag> pattern>
713  : AIstr_ex_or_rel<opcod, 0b10, oops, iops, itin, opc, asm, pattern>,
714    Requires<[IsARM, HasAcquireRelease, HasV7Clrex]> {
715  bits<4> Rd;
716  let Inst{15-12} = Rd;
717}
718
719class AIswp<bit b, dag oops, dag iops, string opc, list<dag> pattern>
720  : AI<oops, iops, MiscFrm, NoItinerary, opc, "\t$Rt, $Rt2, $addr", pattern> {
721  bits<4> Rt;
722  bits<4> Rt2;
723  bits<4> addr;
724  let Inst{27-23} = 0b00010;
725  let Inst{22} = b;
726  let Inst{21-20} = 0b00;
727  let Inst{19-16} = addr;
728  let Inst{15-12} = Rt;
729  let Inst{11-4} = 0b00001001;
730  let Inst{3-0} = Rt2;
731
732  let Unpredictable{11-8} = 0b1111;
733  let DecoderMethod = "DecodeSwap";
734}
735// Acquire/Release load/store instructions
736class AIldracq<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
737              string opc, string asm, list<dag> pattern>
738  : AIldr_ex_or_acq<opcod, 0b00, oops, iops, itin, opc, asm, pattern>,
739    Requires<[IsARM, HasAcquireRelease]>;
740
741class AIstrrel<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
742              string opc, string asm, list<dag> pattern>
743  : AIstr_ex_or_rel<opcod, 0b00, oops, iops, itin, opc, asm, pattern>,
744    Requires<[IsARM, HasAcquireRelease]> {
745  let Inst{15-12}   = 0b1111;
746}
747
748// addrmode1 instructions
749class AI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
750          string opc, string asm, list<dag> pattern>
751  : I<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
752      opc, asm, "", pattern> {
753  let Inst{24-21} = opcod;
754  let Inst{27-26} = 0b00;
755}
756class AsI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
757           string opc, string asm, list<dag> pattern>
758  : sI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
759       opc, asm, "", pattern> {
760  let Inst{24-21} = opcod;
761  let Inst{27-26} = 0b00;
762}
763class AXI1<bits<4> opcod, dag oops, dag iops, Format f, InstrItinClass itin,
764           string asm, list<dag> pattern>
765  : XI<oops, iops, AddrMode1, 4, IndexModeNone, f, itin,
766       asm, "", pattern> {
767  let Inst{24-21} = opcod;
768  let Inst{27-26} = 0b00;
769}
770
771// loads
772
773// LDR/LDRB/STR/STRB/...
774class AI2ldst<bits<3> op, bit isLd, bit isByte, dag oops, dag iops, AddrMode am,
775             Format f, InstrItinClass itin, string opc, string asm,
776             list<dag> pattern>
777  : I<oops, iops, am, 4, IndexModeNone, f, itin, opc, asm,
778      "", pattern> {
779  let Inst{27-25} = op;
780  let Inst{24} = 1;  // 24 == P
781  // 23 == U
782  let Inst{22} = isByte;
783  let Inst{21} = 0;  // 21 == W
784  let Inst{20} = isLd;
785}
786// Indexed load/stores
787class AI2ldstidx<bit isLd, bit isByte, bit isPre, dag oops, dag iops,
788                IndexMode im, Format f, InstrItinClass itin, string opc,
789                string asm, string cstr, list<dag> pattern>
790  : I<oops, iops, AddrMode2, 4, im, f, itin,
791      opc, asm, cstr, pattern> {
792  bits<4> Rt;
793  let Inst{27-26} = 0b01;
794  let Inst{24}    = isPre; // P bit
795  let Inst{22}    = isByte; // B bit
796  let Inst{21}    = isPre; // W bit
797  let Inst{20}    = isLd; // L bit
798  let Inst{15-12} = Rt;
799}
800class AI2stridx_reg<bit isByte, bit isPre, dag oops, dag iops,
801                IndexMode im, Format f, InstrItinClass itin, string opc,
802                string asm, string cstr, list<dag> pattern>
803  : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
804               pattern> {
805  // AM2 store w/ two operands: (GPR, am2offset)
806  // {12}     isAdd
807  // {11-0}   imm12/Rm
808  bits<14> offset;
809  bits<4> Rn;
810  let Inst{25} = 1;
811  let Inst{23} = offset{12};
812  let Inst{19-16} = Rn;
813  let Inst{11-5} = offset{11-5};
814  let Inst{4} = 0;
815  let Inst{3-0} = offset{3-0};
816}
817
818class AI2stridx_imm<bit isByte, bit isPre, dag oops, dag iops,
819                IndexMode im, Format f, InstrItinClass itin, string opc,
820                string asm, string cstr, list<dag> pattern>
821  : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
822               pattern> {
823  // AM2 store w/ two operands: (GPR, am2offset)
824  // {12}     isAdd
825  // {11-0}   imm12/Rm
826  bits<14> offset;
827  bits<4> Rn;
828  let Inst{25} = 0;
829  let Inst{23} = offset{12};
830  let Inst{19-16} = Rn;
831  let Inst{11-0} = offset{11-0};
832}
833
834
835// FIXME: Merge with the above class when addrmode2 gets used for STR, STRB
836// but for now use this class for STRT and STRBT.
837class AI2stridxT<bit isByte, bit isPre, dag oops, dag iops,
838                IndexMode im, Format f, InstrItinClass itin, string opc,
839                string asm, string cstr, list<dag> pattern>
840  : AI2ldstidx<0, isByte, isPre, oops, iops, im, f, itin, opc, asm, cstr,
841               pattern> {
842  // AM2 store w/ two operands: (GPR, am2offset)
843  // {17-14}  Rn
844  // {13}     1 == Rm, 0 == imm12
845  // {12}     isAdd
846  // {11-0}   imm12/Rm
847  bits<18> addr;
848  let Inst{25} = addr{13};
849  let Inst{23} = addr{12};
850  let Inst{19-16} = addr{17-14};
851  let Inst{11-0} = addr{11-0};
852}
853
854// addrmode3 instructions
855class AI3ld<bits<4> op, bit op20, dag oops, dag iops, Format f,
856            InstrItinClass itin, string opc, string asm, list<dag> pattern>
857  : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
858      opc, asm, "", pattern> {
859  bits<14> addr;
860  bits<4> Rt;
861  let Inst{27-25} = 0b000;
862  let Inst{24}    = 1;            // P bit
863  let Inst{23}    = addr{8};      // U bit
864  let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
865  let Inst{21}    = 0;            // W bit
866  let Inst{20}    = op20;         // L bit
867  let Inst{19-16} = addr{12-9};   // Rn
868  let Inst{15-12} = Rt;           // Rt
869  let Inst{11-8}  = addr{7-4};    // imm7_4/zero
870  let Inst{7-4}   = op;
871  let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
872
873  let DecoderMethod = "DecodeAddrMode3Instruction";
874}
875
876class AI3ldstidx<bits<4> op, bit op20, bit isPre, dag oops, dag iops,
877                IndexMode im, Format f, InstrItinClass itin, string opc,
878                string asm, string cstr, list<dag> pattern>
879  : I<oops, iops, AddrMode3, 4, im, f, itin,
880      opc, asm, cstr, pattern> {
881  bits<4> Rt;
882  let Inst{27-25} = 0b000;
883  let Inst{24}    = isPre;        // P bit
884  let Inst{21}    = isPre;        // W bit
885  let Inst{20}    = op20;         // L bit
886  let Inst{15-12} = Rt;           // Rt
887  let Inst{7-4}   = op;
888}
889
890// FIXME: Merge with the above class when addrmode2 gets used for LDR, LDRB
891// but for now use this class for LDRSBT, LDRHT, LDSHT.
892class AI3ldstidxT<bits<4> op, bit isLoad, dag oops, dag iops,
893                  IndexMode im, Format f, InstrItinClass itin, string opc,
894                  string asm, string cstr, list<dag> pattern>
895  : I<oops, iops, AddrMode3, 4, im, f, itin, opc, asm, cstr, pattern> {
896  // {13}     1 == imm8, 0 == Rm
897  // {12-9}   Rn
898  // {8}      isAdd
899  // {7-4}    imm7_4/zero
900  // {3-0}    imm3_0/Rm
901  bits<4> addr;
902  bits<4> Rt;
903  let Inst{27-25} = 0b000;
904  let Inst{24}    = 0;            // P bit
905  let Inst{21}    = 1;
906  let Inst{20}    = isLoad;       // L bit
907  let Inst{19-16} = addr;         // Rn
908  let Inst{15-12} = Rt;           // Rt
909  let Inst{7-4}   = op;
910}
911
912// stores
913class AI3str<bits<4> op, dag oops, dag iops, Format f, InstrItinClass itin,
914             string opc, string asm, list<dag> pattern>
915  : I<oops, iops, AddrMode3, 4, IndexModeNone, f, itin,
916      opc, asm, "", pattern> {
917  bits<14> addr;
918  bits<4> Rt;
919  let Inst{27-25} = 0b000;
920  let Inst{24}    = 1;            // P bit
921  let Inst{23}    = addr{8};      // U bit
922  let Inst{22}    = addr{13};     // 1 == imm8, 0 == Rm
923  let Inst{21}    = 0;            // W bit
924  let Inst{20}    = 0;            // L bit
925  let Inst{19-16} = addr{12-9};   // Rn
926  let Inst{15-12} = Rt;           // Rt
927  let Inst{11-8}  = addr{7-4};    // imm7_4/zero
928  let Inst{7-4}   = op;
929  let Inst{3-0}   = addr{3-0};    // imm3_0/Rm
930  let DecoderMethod = "DecodeAddrMode3Instruction";
931}
932
933// addrmode4 instructions
934class AXI4<dag oops, dag iops, IndexMode im, Format f, InstrItinClass itin,
935           string asm, string cstr, list<dag> pattern>
936  : XI<oops, iops, AddrMode4, 4, im, f, itin, asm, cstr, pattern> {
937  bits<4>  p;
938  bits<16> regs;
939  bits<4>  Rn;
940  let Inst{31-28} = p;
941  let Inst{27-25} = 0b100;
942  let Inst{22}    = 0; // S bit
943  let Inst{19-16} = Rn;
944  let Inst{15-0}  = regs;
945}
946
947// Unsigned multiply, multiply-accumulate instructions.
948class AMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
949             string opc, string asm, list<dag> pattern>
950  : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
951      opc, asm, "", pattern> {
952  let Inst{7-4}   = 0b1001;
953  let Inst{20}    = 0; // S bit
954  let Inst{27-21} = opcod;
955}
956class AsMul1I<bits<7> opcod, dag oops, dag iops, InstrItinClass itin,
957              string opc, string asm, list<dag> pattern>
958  : sI<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
959       opc, asm, "", pattern> {
960  let Inst{7-4}   = 0b1001;
961  let Inst{27-21} = opcod;
962}
963
964// Most significant word multiply
965class AMul2I<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
966             InstrItinClass itin, string opc, string asm, list<dag> pattern>
967  : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
968      opc, asm, "", pattern> {
969  bits<4> Rd;
970  bits<4> Rn;
971  bits<4> Rm;
972  let Inst{7-4}   = opc7_4;
973  let Inst{20}    = 1;
974  let Inst{27-21} = opcod;
975  let Inst{19-16} = Rd;
976  let Inst{11-8}  = Rm;
977  let Inst{3-0}   = Rn;
978}
979// MSW multiple w/ Ra operand
980class AMul2Ia<bits<7> opcod, bits<4> opc7_4, dag oops, dag iops,
981              InstrItinClass itin, string opc, string asm, list<dag> pattern>
982  : AMul2I<opcod, opc7_4, oops, iops, itin, opc, asm, pattern> {
983  bits<4> Ra;
984  let Inst{15-12} = Ra;
985}
986
987// SMUL<x><y> / SMULW<y> / SMLA<x><y> / SMLAW<x><y>
988class AMulxyIbase<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
989              InstrItinClass itin, string opc, string asm, list<dag> pattern>
990  : I<oops, iops, AddrModeNone, 4, IndexModeNone, MulFrm, itin,
991      opc, asm, "", pattern> {
992  bits<4> Rn;
993  bits<4> Rm;
994  let Inst{4}     = 0;
995  let Inst{7}     = 1;
996  let Inst{20}    = 0;
997  let Inst{27-21} = opcod;
998  let Inst{6-5}   = bit6_5;
999  let Inst{11-8}  = Rm;
1000  let Inst{3-0}   = Rn;
1001}
1002class AMulxyI<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
1003              InstrItinClass itin, string opc, string asm, list<dag> pattern>
1004  : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
1005  bits<4> Rd;
1006  let Inst{19-16} = Rd;
1007}
1008
1009// AMulxyI with Ra operand
1010class AMulxyIa<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
1011              InstrItinClass itin, string opc, string asm, list<dag> pattern>
1012  : AMulxyI<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
1013  bits<4> Ra;
1014  let Inst{15-12} = Ra;
1015}
1016// SMLAL*
1017class AMulxyI64<bits<7> opcod, bits<2> bit6_5, dag oops, dag iops,
1018              InstrItinClass itin, string opc, string asm, list<dag> pattern>
1019  : AMulxyIbase<opcod, bit6_5, oops, iops, itin, opc, asm, pattern> {
1020  bits<4> RdLo;
1021  bits<4> RdHi;
1022  let Inst{19-16} = RdHi;
1023  let Inst{15-12} = RdLo;
1024}
1025
1026// Extend instructions.
1027class AExtI<bits<8> opcod, dag oops, dag iops, InstrItinClass itin,
1028            string opc, string asm, list<dag> pattern>
1029  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ExtFrm, itin,
1030      opc, asm, "", pattern> {
1031  // All AExtI instructions have Rd and Rm register operands.
1032  bits<4> Rd;
1033  bits<4> Rm;
1034  let Inst{15-12} = Rd;
1035  let Inst{3-0}   = Rm;
1036  let Inst{7-4}   = 0b0111;
1037  let Inst{9-8}   = 0b00;
1038  let Inst{27-20} = opcod;
1039
1040  let Unpredictable{9-8} = 0b11;
1041}
1042
1043// Misc Arithmetic instructions.
1044class AMiscA1I<bits<8> opcod, bits<4> opc7_4, dag oops, dag iops,
1045               InstrItinClass itin, string opc, string asm, list<dag> pattern>
1046  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
1047      opc, asm, "", pattern> {
1048  bits<4> Rd;
1049  bits<4> Rm;
1050  let Inst{27-20} = opcod;
1051  let Inst{19-16} = 0b1111;
1052  let Inst{15-12} = Rd;
1053  let Inst{11-8}  = 0b1111;
1054  let Inst{7-4}   = opc7_4;
1055  let Inst{3-0}   = Rm;
1056}
1057
1058// Division instructions.
1059class ADivA1I<bits<3> opcod, dag oops, dag iops,
1060              InstrItinClass itin, string opc, string asm, list<dag> pattern>
1061  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
1062      opc, asm, "", pattern> {
1063  bits<4> Rd;
1064  bits<4> Rn;
1065  bits<4> Rm;
1066  let Inst{27-23} = 0b01110;
1067  let Inst{22-20} = opcod;
1068  let Inst{19-16} = Rd;
1069  let Inst{15-12} = 0b1111;
1070  let Inst{11-8}  = Rm;
1071  let Inst{7-4}   = 0b0001;
1072  let Inst{3-0}   = Rn;
1073}
1074
1075// PKH instructions
1076def PKHLSLAsmOperand : ImmAsmOperand<0,31> {
1077  let Name = "PKHLSLImm";
1078  let ParserMethod = "parsePKHLSLImm";
1079}
1080def pkh_lsl_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm >= 0 && Imm < 32; }]>{
1081  let PrintMethod = "printPKHLSLShiftImm";
1082  let ParserMatchClass = PKHLSLAsmOperand;
1083}
1084def PKHASRAsmOperand : AsmOperandClass {
1085  let Name = "PKHASRImm";
1086  let ParserMethod = "parsePKHASRImm";
1087}
1088def pkh_asr_amt: Operand<i32>, ImmLeaf<i32, [{ return Imm > 0 && Imm <= 32; }]>{
1089  let PrintMethod = "printPKHASRShiftImm";
1090  let ParserMatchClass = PKHASRAsmOperand;
1091}
1092
1093class APKHI<bits<8> opcod, bit tb, dag oops, dag iops, InstrItinClass itin,
1094            string opc, string asm, list<dag> pattern>
1095  : I<oops, iops, AddrModeNone, 4, IndexModeNone, ArithMiscFrm, itin,
1096      opc, asm, "", pattern> {
1097  bits<4> Rd;
1098  bits<4> Rn;
1099  bits<4> Rm;
1100  bits<5> sh;
1101  let Inst{27-20} = opcod;
1102  let Inst{19-16} = Rn;
1103  let Inst{15-12} = Rd;
1104  let Inst{11-7}  = sh;
1105  let Inst{6}     = tb;
1106  let Inst{5-4}   = 0b01;
1107  let Inst{3-0}   = Rm;
1108}
1109
1110//===----------------------------------------------------------------------===//
1111
1112// ARMPat - Same as Pat<>, but requires that the compiler be in ARM mode.
1113class ARMPat<dag pattern, dag result> : Pat<pattern, result> {
1114  list<Predicate> Predicates = [IsARM];
1115}
1116class ARMV5TPat<dag pattern, dag result> : Pat<pattern, result> {
1117  list<Predicate> Predicates = [IsARM, HasV5T];
1118}
1119class ARMV5TEPat<dag pattern, dag result> : Pat<pattern, result> {
1120  list<Predicate> Predicates = [IsARM, HasV5TE];
1121}
1122// ARMV5MOPat - Same as ARMV5TEPat with UseMulOps.
1123class ARMV5MOPat<dag pattern, dag result> : Pat<pattern, result> {
1124  list<Predicate> Predicates = [IsARM, HasV5TE, UseMulOps];
1125}
1126class ARMV6Pat<dag pattern, dag result> : Pat<pattern, result> {
1127  list<Predicate> Predicates = [IsARM, HasV6];
1128}
1129class ARMV6T2Pat<dag pattern, dag result> : Pat<pattern, result> {
1130  list<Predicate> Predicates = [IsARM, HasV6T2];
1131}
1132class VFPPat<dag pattern, dag result> : Pat<pattern, result> {
1133  list<Predicate> Predicates = [HasVFP2];
1134}
1135class VFPNoNEONPat<dag pattern, dag result> : Pat<pattern, result> {
1136  list<Predicate> Predicates = [HasVFP2, DontUseNEONForFP];
1137}
1138class Thumb2DSPPat<dag pattern, dag result> : Pat<pattern, result> {
1139  list<Predicate> Predicates = [IsThumb2, HasDSP];
1140}
1141class Thumb2DSPMulPat<dag pattern, dag result> : Pat<pattern, result> {
1142  list<Predicate> Predicates = [IsThumb2, UseMulOps, HasDSP];
1143}
1144class FPRegs16Pat<dag pattern, dag result> : Pat<pattern, result> {
1145  list<Predicate> Predicates = [HasFPRegs16];
1146}
1147class FP16Pat<dag pattern, dag result> : Pat<pattern, result> {
1148  list<Predicate> Predicates = [HasFP16];
1149}
1150class FullFP16Pat<dag pattern, dag result> : Pat<pattern, result> {
1151  list<Predicate> Predicates = [HasFullFP16];
1152}
1153//===----------------------------------------------------------------------===//
1154// Thumb Instruction Format Definitions.
1155//
1156
1157class ThumbI<dag oops, dag iops, AddrMode am, int sz,
1158             InstrItinClass itin, string asm, string cstr, list<dag> pattern>
1159  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1160  let OutOperandList = oops;
1161  let InOperandList = iops;
1162  let AsmString = asm;
1163  let Pattern = pattern;
1164  list<Predicate> Predicates = [IsThumb];
1165}
1166
1167// TI - Thumb instruction.
1168class TI<dag oops, dag iops, InstrItinClass itin, string asm, list<dag> pattern>
1169  : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
1170
1171// Two-address instructions
1172class TIt<dag oops, dag iops, InstrItinClass itin, string asm,
1173          list<dag> pattern>
1174  : ThumbI<oops, iops, AddrModeNone, 2, itin, asm, "$lhs = $dst",
1175           pattern>;
1176
1177// tBL, tBX 32-bit instructions
1178class TIx2<bits<5> opcod1, bits<2> opcod2, bit opcod3,
1179           dag oops, dag iops, InstrItinClass itin, string asm,
1180           list<dag> pattern>
1181    : ThumbI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>,
1182      Encoding {
1183  let Inst{31-27} = opcod1;
1184  let Inst{15-14} = opcod2;
1185  let Inst{12}    = opcod3;
1186}
1187
1188// BR_JT instructions
1189class TJTI<dag oops, dag iops, InstrItinClass itin, string asm,
1190           list<dag> pattern>
1191  : ThumbI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
1192
1193// Thumb1 only
1194class Thumb1I<dag oops, dag iops, AddrMode am, int sz,
1195              InstrItinClass itin, string asm, string cstr, list<dag> pattern>
1196  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1197  let OutOperandList = oops;
1198  let InOperandList = iops;
1199  let AsmString = asm;
1200  let Pattern = pattern;
1201  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1202}
1203
1204class T1I<dag oops, dag iops, InstrItinClass itin,
1205          string asm, list<dag> pattern>
1206  : Thumb1I<oops, iops, AddrModeNone, 2, itin, asm, "", pattern>;
1207class T1Ix2<dag oops, dag iops, InstrItinClass itin,
1208            string asm, list<dag> pattern>
1209  : Thumb1I<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
1210
1211// Two-address instructions
1212class T1It<dag oops, dag iops, InstrItinClass itin,
1213           string asm, string cstr, list<dag> pattern>
1214  : Thumb1I<oops, iops, AddrModeNone, 2, itin,
1215            asm, cstr, pattern>;
1216
1217// Thumb1 instruction that can either be predicated or set CPSR.
1218class Thumb1sI<dag oops, dag iops, AddrMode am, int sz,
1219               InstrItinClass itin,
1220               string opc, string asm, string cstr, list<dag> pattern>
1221  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1222  let OutOperandList = !con(oops, (outs s_cc_out:$s));
1223  let InOperandList = !con(iops, (ins pred:$p));
1224  let AsmString = !strconcat(opc, "${s}${p}", asm);
1225  let Pattern = pattern;
1226  let thumbArithFlagSetting = 1;
1227  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1228  let DecoderNamespace = "ThumbSBit";
1229}
1230
1231class T1sI<dag oops, dag iops, InstrItinClass itin,
1232           string opc, string asm, list<dag> pattern>
1233  : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
1234
1235// Two-address instructions
1236class T1sIt<dag oops, dag iops, InstrItinClass itin,
1237            string opc, string asm, list<dag> pattern>
1238  : Thumb1sI<oops, iops, AddrModeNone, 2, itin, opc, asm,
1239             "$Rn = $Rdn", pattern>;
1240
1241// Thumb1 instruction that can be predicated.
1242class Thumb1pI<dag oops, dag iops, AddrMode am, int sz,
1243               InstrItinClass itin,
1244               string opc, string asm, string cstr, list<dag> pattern>
1245  : InstThumb<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1246  let OutOperandList = oops;
1247  let InOperandList = !con(iops, (ins pred:$p));
1248  let AsmString = !strconcat(opc, "${p}", asm);
1249  let Pattern = pattern;
1250  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1251}
1252
1253class T1pI<dag oops, dag iops, InstrItinClass itin,
1254           string opc, string asm, list<dag> pattern>
1255  : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm, "", pattern>;
1256
1257// Two-address instructions
1258class T1pIt<dag oops, dag iops, InstrItinClass itin,
1259            string opc, string asm, list<dag> pattern>
1260  : Thumb1pI<oops, iops, AddrModeNone, 2, itin, opc, asm,
1261             "$Rn = $Rdn", pattern>;
1262
1263class T1pIs<dag oops, dag iops,
1264            InstrItinClass itin, string opc, string asm, list<dag> pattern>
1265  : Thumb1pI<oops, iops, AddrModeT1_s, 2, itin, opc, asm, "", pattern>;
1266
1267class Encoding16 : Encoding {
1268  let Inst{31-16} = 0x0000;
1269}
1270
1271// A6.2 16-bit Thumb instruction encoding
1272class T1Encoding<bits<6> opcode> : Encoding16 {
1273  let Inst{15-10} = opcode;
1274}
1275
1276// A6.2.1 Shift (immediate), add, subtract, move, and compare encoding.
1277class T1General<bits<5> opcode> : Encoding16 {
1278  let Inst{15-14} = 0b00;
1279  let Inst{13-9} = opcode;
1280}
1281
1282// A6.2.2 Data-processing encoding.
1283class T1DataProcessing<bits<4> opcode> : Encoding16 {
1284  let Inst{15-10} = 0b010000;
1285  let Inst{9-6} = opcode;
1286}
1287
1288// A6.2.3 Special data instructions and branch and exchange encoding.
1289class T1Special<bits<4> opcode> : Encoding16 {
1290  let Inst{15-10} = 0b010001;
1291  let Inst{9-6}   = opcode;
1292}
1293
1294// A6.2.4 Load/store single data item encoding.
1295class T1LoadStore<bits<4> opA, bits<3> opB> : Encoding16 {
1296  let Inst{15-12} = opA;
1297  let Inst{11-9}  = opB;
1298}
1299class T1LdStSP<bits<3> opB>   : T1LoadStore<0b1001, opB>; // SP relative
1300
1301class T1BranchCond<bits<4> opcode> : Encoding16 {
1302  let Inst{15-12} = opcode;
1303}
1304
1305// Helper classes to encode Thumb1 loads and stores. For immediates, the
1306// following bits are used for "opA" (see A6.2.4):
1307//
1308//   0b0110 => Immediate, 4 bytes
1309//   0b1000 => Immediate, 2 bytes
1310//   0b0111 => Immediate, 1 byte
1311class T1pILdStEncode<bits<3> opcode, dag oops, dag iops, AddrMode am,
1312                     InstrItinClass itin, string opc, string asm,
1313                     list<dag> pattern>
1314  : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1315    T1LoadStore<0b0101, opcode> {
1316  bits<3> Rt;
1317  bits<8> addr;
1318  let Inst{8-6} = addr{5-3};    // Rm
1319  let Inst{5-3} = addr{2-0};    // Rn
1320  let Inst{2-0} = Rt;
1321}
1322class T1pILdStEncodeImm<bits<4> opA, bit opB, dag oops, dag iops, AddrMode am,
1323                        InstrItinClass itin, string opc, string asm,
1324                        list<dag> pattern>
1325  : Thumb1pI<oops, iops, am, 2, itin, opc, asm, "", pattern>,
1326    T1LoadStore<opA, {opB,?,?}> {
1327  bits<3> Rt;
1328  bits<8> addr;
1329  let Inst{10-6} = addr{7-3};   // imm5
1330  let Inst{5-3}  = addr{2-0};   // Rn
1331  let Inst{2-0}  = Rt;
1332}
1333
1334// A6.2.5 Miscellaneous 16-bit instructions encoding.
1335class T1Misc<bits<7> opcode> : Encoding16 {
1336  let Inst{15-12} = 0b1011;
1337  let Inst{11-5} = opcode;
1338}
1339
1340// Thumb2I - Thumb2 instruction. Almost all Thumb2 instructions are predicable.
1341class Thumb2I<dag oops, dag iops, AddrMode am, int sz,
1342              InstrItinClass itin,
1343              string opc, string asm, string cstr, list<dag> pattern>
1344  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1345  let OutOperandList = oops;
1346  let InOperandList = !con(iops, (ins pred:$p));
1347  let AsmString = !strconcat(opc, "${p}", asm);
1348  let Pattern = pattern;
1349  list<Predicate> Predicates = [IsThumb2];
1350  let DecoderNamespace = "Thumb2";
1351}
1352
1353// Same as Thumb2I except it can optionally modify CPSR. Note it's modeled as an
1354// input operand since by default it's a zero register. It will become an
1355// implicit def once it's "flipped".
1356//
1357// FIXME: This uses unified syntax so {s} comes before {p}. We should make it
1358// more consistent.
1359class Thumb2sI<dag oops, dag iops, AddrMode am, int sz,
1360               InstrItinClass itin,
1361               string opc, string asm, string cstr, list<dag> pattern>
1362  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1363  bits<1> s; // condition-code set flag ('1' if the insn should set the flags)
1364  let Inst{20} = s;
1365
1366  let OutOperandList = oops;
1367  let InOperandList = !con(iops, (ins pred:$p, cc_out:$s));
1368  let AsmString = !strconcat(opc, "${s}${p}", asm);
1369  let Pattern = pattern;
1370  list<Predicate> Predicates = [IsThumb2];
1371  let DecoderNamespace = "Thumb2";
1372}
1373
1374// Special cases
1375class Thumb2XI<dag oops, dag iops, AddrMode am, int sz,
1376               InstrItinClass itin,
1377               string asm, string cstr, list<dag> pattern>
1378  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1379  let OutOperandList = oops;
1380  let InOperandList = iops;
1381  let AsmString = asm;
1382  let Pattern = pattern;
1383  list<Predicate> Predicates = [IsThumb2];
1384  let DecoderNamespace = "Thumb2";
1385}
1386
1387class ThumbXI<dag oops, dag iops, AddrMode am, int sz,
1388              InstrItinClass itin,
1389              string asm, string cstr, list<dag> pattern>
1390  : InstARM<am, sz, IndexModeNone, ThumbFrm, GenericDomain, cstr, itin> {
1391  let OutOperandList = oops;
1392  let InOperandList = iops;
1393  let AsmString = asm;
1394  let Pattern = pattern;
1395  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1396  let DecoderNamespace = "Thumb";
1397}
1398
1399class T2I<dag oops, dag iops, InstrItinClass itin,
1400          string opc, string asm, list<dag> pattern, AddrMode am = AddrModeNone>
1401  : Thumb2I<oops, iops, am, 4, itin, opc, asm, "", pattern>;
1402class T2Ii12<dag oops, dag iops, InstrItinClass itin,
1403             string opc, string asm, list<dag> pattern>
1404  : Thumb2I<oops, iops, AddrModeT2_i12, 4, itin, opc, asm, "",pattern>;
1405class T2Ii8p<dag oops, dag iops, InstrItinClass itin,
1406             string opc, string asm, list<dag> pattern>
1407  : Thumb2I<oops, iops, AddrModeT2_i8pos, 4, itin, opc, asm, "", pattern>;
1408class T2Ii8n<dag oops, dag iops, InstrItinClass itin,
1409             string opc, string asm, list<dag> pattern>
1410  : Thumb2I<oops, iops, AddrModeT2_i8neg, 4, itin, opc, asm, "", pattern>;
1411class T2Iso<dag oops, dag iops, InstrItinClass itin,
1412            string opc, string asm, list<dag> pattern>
1413  : Thumb2I<oops, iops, AddrModeT2_so, 4, itin, opc, asm, "", pattern>;
1414class T2Ipc<dag oops, dag iops, InstrItinClass itin,
1415            string opc, string asm, list<dag> pattern>
1416  : Thumb2I<oops, iops, AddrModeT2_pc, 4, itin, opc, asm, "", pattern>;
1417class T2Ii8s4<bit P, bit W, bit isLoad, dag oops, dag iops, InstrItinClass itin,
1418              string opc, string asm, string cstr, list<dag> pattern>
1419  : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
1420            pattern> {
1421  bits<4> Rt;
1422  bits<4> Rt2;
1423  bits<13> addr;
1424  let Inst{31-25} = 0b1110100;
1425  let Inst{24}    = P;
1426  let Inst{23}    = addr{8};
1427  let Inst{22}    = 1;
1428  let Inst{21}    = W;
1429  let Inst{20}    = isLoad;
1430  let Inst{19-16} = addr{12-9};
1431  let Inst{15-12} = Rt{3-0};
1432  let Inst{11-8}  = Rt2{3-0};
1433  let Inst{7-0}   = addr{7-0};
1434}
1435class T2Ii8s4post<bit P, bit W, bit isLoad, dag oops, dag iops,
1436                  InstrItinClass itin, string opc, string asm, string cstr,
1437                  list<dag> pattern>
1438  : Thumb2I<oops, iops, AddrModeT2_i8s4, 4, itin, opc, asm, cstr,
1439            pattern> {
1440  bits<4> Rt;
1441  bits<4> Rt2;
1442  bits<4> addr;
1443  bits<9> imm;
1444  let Inst{31-25} = 0b1110100;
1445  let Inst{24}    = P;
1446  let Inst{23}    = imm{8};
1447  let Inst{22}    = 1;
1448  let Inst{21}    = W;
1449  let Inst{20}    = isLoad;
1450  let Inst{19-16} = addr;
1451  let Inst{15-12} = Rt{3-0};
1452  let Inst{11-8}  = Rt2{3-0};
1453  let Inst{7-0}   = imm{7-0};
1454}
1455
1456class T2sI<dag oops, dag iops, InstrItinClass itin,
1457           string opc, string asm, list<dag> pattern>
1458  : Thumb2sI<oops, iops, AddrModeNone, 4, itin, opc, asm, "", pattern>;
1459
1460class T2XI<dag oops, dag iops, InstrItinClass itin,
1461           string asm, list<dag> pattern>
1462  : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, "", pattern>;
1463class T2JTI<dag oops, dag iops, InstrItinClass itin,
1464            string asm, list<dag> pattern>
1465  : Thumb2XI<oops, iops, AddrModeNone, 0, itin, asm, "", pattern>;
1466
1467// Move to/from coprocessor instructions
1468class T2Cop<bits<4> opc, dag oops, dag iops, string opcstr, string asm,
1469            list<dag> pattern>
1470  : T2I <oops, iops, NoItinerary, opcstr, asm, pattern>, Requires<[IsThumb2]> {
1471  let Inst{31-28} = opc;
1472}
1473
1474// Two-address instructions
1475class T2XIt<dag oops, dag iops, InstrItinClass itin,
1476            string asm, string cstr, list<dag> pattern>
1477  : Thumb2XI<oops, iops, AddrModeNone, 4, itin, asm, cstr, pattern>;
1478
1479// T2Ipreldst - Thumb2 pre-indexed load / store instructions.
1480class T2Ipreldst<bit signed, bits<2> opcod, bit load, bit pre,
1481                 dag oops, dag iops,
1482                 AddrMode am, IndexMode im, InstrItinClass itin,
1483                 string opc, string asm, string cstr, list<dag> pattern>
1484  : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
1485  let OutOperandList = oops;
1486  let InOperandList = !con(iops, (ins pred:$p));
1487  let AsmString = !strconcat(opc, "${p}", asm);
1488  let Pattern = pattern;
1489  list<Predicate> Predicates = [IsThumb2];
1490  let DecoderNamespace = "Thumb2";
1491
1492  bits<4> Rt;
1493  bits<13> addr;
1494  let Inst{31-27} = 0b11111;
1495  let Inst{26-25} = 0b00;
1496  let Inst{24}    = signed;
1497  let Inst{23}    = 0;
1498  let Inst{22-21} = opcod;
1499  let Inst{20}    = load;
1500  let Inst{19-16} = addr{12-9};
1501  let Inst{15-12} = Rt{3-0};
1502  let Inst{11}    = 1;
1503  // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1504  let Inst{10}    = pre; // The P bit.
1505  let Inst{9}     = addr{8}; // Sign bit
1506  let Inst{8}     = 1; // The W bit.
1507  let Inst{7-0}   = addr{7-0};
1508
1509  let DecoderMethod = "DecodeT2LdStPre";
1510}
1511
1512// T2Ipostldst - Thumb2 post-indexed load / store instructions.
1513class T2Ipostldst<bit signed, bits<2> opcod, bit load, bit pre,
1514                 dag oops, dag iops,
1515                 AddrMode am, IndexMode im, InstrItinClass itin,
1516                 string opc, string asm, string cstr, list<dag> pattern>
1517  : InstARM<am, 4, im, ThumbFrm, GenericDomain, cstr, itin> {
1518  let OutOperandList = oops;
1519  let InOperandList = !con(iops, (ins pred:$p));
1520  let AsmString = !strconcat(opc, "${p}", asm);
1521  let Pattern = pattern;
1522  list<Predicate> Predicates = [IsThumb2];
1523  let DecoderNamespace = "Thumb2";
1524
1525  bits<4> Rt;
1526  bits<4> Rn;
1527  bits<9> offset;
1528  let Inst{31-27} = 0b11111;
1529  let Inst{26-25} = 0b00;
1530  let Inst{24}    = signed;
1531  let Inst{23}    = 0;
1532  let Inst{22-21} = opcod;
1533  let Inst{20}    = load;
1534  let Inst{19-16} = Rn;
1535  let Inst{15-12} = Rt{3-0};
1536  let Inst{11}    = 1;
1537  // (P, W) = (1, 1) Pre-indexed or (0, 1) Post-indexed
1538  let Inst{10}    = pre; // The P bit.
1539  let Inst{9}     = offset{8}; // Sign bit
1540  let Inst{8}     = 1; // The W bit.
1541  let Inst{7-0}   = offset{7-0};
1542
1543  let DecoderMethod = "DecodeT2LdStPre";
1544}
1545
1546// T1Pat - Same as Pat<>, but requires that the compiler be in Thumb1 mode.
1547class T1Pat<dag pattern, dag result> : Pat<pattern, result> {
1548  list<Predicate> Predicates = [IsThumb, IsThumb1Only];
1549}
1550
1551// T2v6Pat - Same as Pat<>, but requires V6T2 Thumb2 mode.
1552class T2v6Pat<dag pattern, dag result> : Pat<pattern, result> {
1553  list<Predicate> Predicates = [IsThumb2, HasV6T2];
1554}
1555
1556// T2Pat - Same as Pat<>, but requires that the compiler be in Thumb2 mode.
1557class T2Pat<dag pattern, dag result> : Pat<pattern, result> {
1558  list<Predicate> Predicates = [IsThumb2];
1559}
1560
1561//===----------------------------------------------------------------------===//
1562
1563//===----------------------------------------------------------------------===//
1564// ARM VFP Instruction templates.
1565//
1566
1567// Almost all VFP instructions are predicable.
1568class VFPI<dag oops, dag iops, AddrMode am, int sz,
1569           IndexMode im, Format f, InstrItinClass itin,
1570           string opc, string asm, string cstr, list<dag> pattern>
1571  : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1572  bits<4> p;
1573  let Inst{31-28} = p;
1574  let OutOperandList = oops;
1575  let InOperandList = !con(iops, (ins pred:$p));
1576  let AsmString = !strconcat(opc, "${p}", asm);
1577  let Pattern = pattern;
1578  let PostEncoderMethod = "VFPThumb2PostEncoder";
1579  let DecoderNamespace = "VFP";
1580  list<Predicate> Predicates = [HasVFP2];
1581}
1582
1583// Special cases
1584class VFPXI<dag oops, dag iops, AddrMode am, int sz,
1585            IndexMode im, Format f, InstrItinClass itin,
1586            string asm, string cstr, list<dag> pattern>
1587  : InstARM<am, sz, im, f, VFPDomain, cstr, itin> {
1588  bits<4> p;
1589  let Inst{31-28} = p;
1590  let OutOperandList = oops;
1591  let InOperandList = iops;
1592  let AsmString = asm;
1593  let Pattern = pattern;
1594  let PostEncoderMethod = "VFPThumb2PostEncoder";
1595  let DecoderNamespace = "VFP";
1596  list<Predicate> Predicates = [HasVFP2];
1597}
1598
1599class VFPAI<dag oops, dag iops, Format f, InstrItinClass itin,
1600            string opc, string asm, string cstr, list<dag> pattern>
1601  : VFPI<oops, iops, AddrModeNone, 4, IndexModeNone, f, itin,
1602         opc, asm, cstr, pattern> {
1603  let PostEncoderMethod = "VFPThumb2PostEncoder";
1604}
1605
1606// ARM VFP addrmode5 loads and stores
1607class ADI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1608           InstrItinClass itin,
1609           string opc, string asm, list<dag> pattern>
1610  : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1611         VFPLdStFrm, itin, opc, asm, "", pattern> {
1612  // Instruction operands.
1613  bits<5>  Dd;
1614  bits<13> addr;
1615
1616  // Encode instruction operands.
1617  let Inst{23}    = addr{8};      // U (add = (U == '1'))
1618  let Inst{22}    = Dd{4};
1619  let Inst{19-16} = addr{12-9};   // Rn
1620  let Inst{15-12} = Dd{3-0};
1621  let Inst{7-0}   = addr{7-0};    // imm8
1622
1623  let Inst{27-24} = opcod1;
1624  let Inst{21-20} = opcod2;
1625  let Inst{11-9}  = 0b101;
1626  let Inst{8}     = 1;          // Double precision
1627
1628  // Loads & stores operate on both NEON and VFP pipelines.
1629  let D = VFPNeonDomain;
1630}
1631
1632class ASI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1633           InstrItinClass itin,
1634           string opc, string asm, list<dag> pattern>
1635  : VFPI<oops, iops, AddrMode5, 4, IndexModeNone,
1636         VFPLdStFrm, itin, opc, asm, "", pattern> {
1637  // Instruction operands.
1638  bits<5>  Sd;
1639  bits<13> addr;
1640
1641  // Encode instruction operands.
1642  let Inst{23}    = addr{8};      // U (add = (U == '1'))
1643  let Inst{22}    = Sd{0};
1644  let Inst{19-16} = addr{12-9};   // Rn
1645  let Inst{15-12} = Sd{4-1};
1646  let Inst{7-0}   = addr{7-0};    // imm8
1647
1648  let Inst{27-24} = opcod1;
1649  let Inst{21-20} = opcod2;
1650  let Inst{11-9}  = 0b101;
1651  let Inst{8}     = 0;          // Single precision
1652
1653  // Loads & stores operate on both NEON and VFP pipelines.
1654  let D = VFPNeonDomain;
1655}
1656
1657class AHI5<bits<4> opcod1, bits<2> opcod2, dag oops, dag iops,
1658           InstrItinClass itin,
1659           string opc, string asm, list<dag> pattern>
1660  : VFPI<oops, iops, AddrMode5FP16, 4, IndexModeNone,
1661         VFPLdStFrm, itin, opc, asm, "", pattern> {
1662  list<Predicate> Predicates = [HasFullFP16];
1663
1664  // Instruction operands.
1665  bits<5>  Sd;
1666  bits<13> addr;
1667
1668  // Encode instruction operands.
1669  let Inst{23}    = addr{8};      // U (add = (U == '1'))
1670  let Inst{22}    = Sd{0};
1671  let Inst{19-16} = addr{12-9};   // Rn
1672  let Inst{15-12} = Sd{4-1};
1673  let Inst{7-0}   = addr{7-0};    // imm8
1674
1675  let Inst{27-24} = opcod1;
1676  let Inst{21-20} = opcod2;
1677  let Inst{11-8}  = 0b1001;     // Half precision
1678
1679  // Loads & stores operate on both NEON and VFP pipelines.
1680  let D = VFPNeonDomain;
1681
1682  let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
1683}
1684
1685// VFP Load / store multiple pseudo instructions.
1686class PseudoVFPLdStM<dag oops, dag iops, InstrItinClass itin, string cstr,
1687                     list<dag> pattern>
1688  : InstARM<AddrMode4, 4, IndexModeNone, Pseudo, VFPNeonDomain,
1689            cstr, itin> {
1690  let OutOperandList = oops;
1691  let InOperandList = !con(iops, (ins pred:$p));
1692  let Pattern = pattern;
1693  list<Predicate> Predicates = [HasVFP2];
1694}
1695
1696// Load / store multiple
1697
1698// Unknown precision
1699class AXXI4<dag oops, dag iops, IndexMode im,
1700            string asm, string cstr, list<dag> pattern>
1701  : VFPXI<oops, iops, AddrMode4, 4, im,
1702          VFPLdStFrm, NoItinerary, asm, cstr, pattern> {
1703  // Instruction operands.
1704  bits<4>  Rn;
1705  bits<13> regs;
1706
1707  // Encode instruction operands.
1708  let Inst{19-16} = Rn;
1709  let Inst{22}    = 0;
1710  let Inst{15-12} = regs{11-8};
1711  let Inst{7-1}   = regs{7-1};
1712
1713  let Inst{27-25} = 0b110;
1714  let Inst{11-8}  = 0b1011;
1715  let Inst{0}     = 1;
1716}
1717
1718// Double precision
1719class AXDI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1720            string asm, string cstr, list<dag> pattern>
1721  : VFPXI<oops, iops, AddrMode4, 4, im,
1722          VFPLdStMulFrm, itin, asm, cstr, pattern> {
1723  // Instruction operands.
1724  bits<4>  Rn;
1725  bits<13> regs;
1726
1727  // Encode instruction operands.
1728  let Inst{19-16} = Rn;
1729  let Inst{22}    = regs{12};
1730  let Inst{15-12} = regs{11-8};
1731  let Inst{7-1}   = regs{7-1};
1732
1733  let Inst{27-25} = 0b110;
1734  let Inst{11-9}  = 0b101;
1735  let Inst{8}     = 1;          // Double precision
1736  let Inst{0}     = 0;
1737}
1738
1739// Single Precision
1740class AXSI4<dag oops, dag iops, IndexMode im, InstrItinClass itin,
1741            string asm, string cstr, list<dag> pattern>
1742  : VFPXI<oops, iops, AddrMode4, 4, im,
1743          VFPLdStMulFrm, itin, asm, cstr, pattern> {
1744  // Instruction operands.
1745  bits<4> Rn;
1746  bits<13> regs;
1747
1748  // Encode instruction operands.
1749  let Inst{19-16} = Rn;
1750  let Inst{22}    = regs{8};
1751  let Inst{15-12} = regs{12-9};
1752  let Inst{7-0}   = regs{7-0};
1753
1754  let Inst{27-25} = 0b110;
1755  let Inst{11-9}  = 0b101;
1756  let Inst{8}     = 0;          // Single precision
1757}
1758
1759// Single Precision with fixed registers.
1760// For when the registers-to-be-stored/loaded are fixed, e.g. VLLDM and VLSTM
1761class AXSI4FR<string asm, bit et, bit load>
1762    : InstARM<AddrMode4, 4, IndexModeNone, VFPLdStMulFrm, VFPDomain, "", NoItinerary> {
1763  // Instruction operands.
1764  bits<4> Rn;
1765  bits<13> regs;    // Does not affect encoding, for assembly/disassembly only.
1766  list<Predicate> Predicates = [HasVFP2];
1767  let OutOperandList = (outs);
1768  let InOperandList = (ins GPRnopc:$Rn, pred:$p, dpr_reglist:$regs);
1769  let AsmString = asm;
1770  let Pattern = [];
1771  let DecoderNamespace = "VFP";
1772  // Encode instruction operands.
1773  let Inst{19-16} = Rn;
1774  let Inst{31-28} = 0b1110;
1775  let Inst{27-25} = 0b110;
1776  let Inst{24}    = 0b0;
1777  let Inst{23}    = 0b0;
1778  let Inst{22}    = 0b0;
1779  let Inst{21}    = 0b1;
1780  let Inst{20}    = load;       // Distinguishes vlldm from vlstm
1781  let Inst{15-12} = 0b0000;
1782  let Inst{11-9}  = 0b101;
1783  let Inst{8}     = 0;          // Single precision
1784  let Inst{7}     = et;         // encoding type, 0 for T1 and 1 for T2.
1785  let Inst{6-0}   = 0b0000000;
1786  let mayLoad     = load;
1787  let mayStore    = !eq(load, 0);
1788}
1789
1790// Double precision, unary
1791class ADuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1792           bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1793           string asm, string cstr, list<dag> pattern>
1794  : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, cstr, pattern> {
1795  // Instruction operands.
1796  bits<5> Dd;
1797  bits<5> Dm;
1798
1799  // Encode instruction operands.
1800  let Inst{3-0}   = Dm{3-0};
1801  let Inst{5}     = Dm{4};
1802  let Inst{15-12} = Dd{3-0};
1803  let Inst{22}    = Dd{4};
1804
1805  let Inst{27-23} = opcod1;
1806  let Inst{21-20} = opcod2;
1807  let Inst{19-16} = opcod3;
1808  let Inst{11-9}  = 0b101;
1809  let Inst{8}     = 1;          // Double precision
1810  let Inst{7-6}   = opcod4;
1811  let Inst{4}     = opcod5;
1812
1813  let Predicates = [HasVFP2, HasDPVFP];
1814}
1815
1816// Double precision, unary, not-predicated
1817class ADuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1818           bit opcod5, dag oops, dag iops, InstrItinClass itin,
1819           string asm, list<dag> pattern>
1820  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPUnaryFrm, itin, asm, "", pattern> {
1821  // Instruction operands.
1822  bits<5> Dd;
1823  bits<5> Dm;
1824
1825  let Inst{31-28} = 0b1111;
1826
1827  // Encode instruction operands.
1828  let Inst{3-0}   = Dm{3-0};
1829  let Inst{5}     = Dm{4};
1830  let Inst{15-12} = Dd{3-0};
1831  let Inst{22}    = Dd{4};
1832
1833  let Inst{27-23} = opcod1;
1834  let Inst{21-20} = opcod2;
1835  let Inst{19-16} = opcod3;
1836  let Inst{11-9}  = 0b101;
1837  let Inst{8}     = 1;          // Double precision
1838  let Inst{7-6}   = opcod4;
1839  let Inst{4}     = opcod5;
1840}
1841
1842// Double precision, binary
1843class ADbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
1844           dag iops, InstrItinClass itin, string opc, string asm,
1845           list<dag> pattern>
1846  : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, "", pattern> {
1847  // Instruction operands.
1848  bits<5> Dd;
1849  bits<5> Dn;
1850  bits<5> Dm;
1851
1852  // Encode instruction operands.
1853  let Inst{3-0}   = Dm{3-0};
1854  let Inst{5}     = Dm{4};
1855  let Inst{19-16} = Dn{3-0};
1856  let Inst{7}     = Dn{4};
1857  let Inst{15-12} = Dd{3-0};
1858  let Inst{22}    = Dd{4};
1859
1860  let Inst{27-23} = opcod1;
1861  let Inst{21-20} = opcod2;
1862  let Inst{11-9}  = 0b101;
1863  let Inst{8}     = 1;          // Double precision
1864  let Inst{6}     = op6;
1865  let Inst{4}     = op4;
1866
1867  let Predicates = [HasVFP2, HasDPVFP];
1868}
1869
1870// FP, binary, not predicated
1871class ADbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
1872           InstrItinClass itin, string asm, list<dag> pattern>
1873  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone, VFPBinaryFrm, itin,
1874          asm, "", pattern>
1875{
1876  // Instruction operands.
1877  bits<5> Dd;
1878  bits<5> Dn;
1879  bits<5> Dm;
1880
1881  let Inst{31-28} = 0b1111;
1882
1883  // Encode instruction operands.
1884  let Inst{3-0}   = Dm{3-0};
1885  let Inst{5}     = Dm{4};
1886  let Inst{19-16} = Dn{3-0};
1887  let Inst{7}     = Dn{4};
1888  let Inst{15-12} = Dd{3-0};
1889  let Inst{22}    = Dd{4};
1890
1891  let Inst{27-23} = opcod1;
1892  let Inst{21-20} = opcod2;
1893  let Inst{11-9}  = 0b101;
1894  let Inst{8}     = 1; // double precision
1895  let Inst{6}     = opcod3;
1896  let Inst{4}     = 0;
1897
1898  let Predicates = [HasVFP2, HasDPVFP];
1899}
1900
1901// Single precision, unary, predicated
1902class ASuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1903           bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1904           string asm, string cstr, list<dag> pattern>
1905  : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, cstr, pattern> {
1906  // Instruction operands.
1907  bits<5> Sd;
1908  bits<5> Sm;
1909
1910  // Encode instruction operands.
1911  let Inst{3-0}   = Sm{4-1};
1912  let Inst{5}     = Sm{0};
1913  let Inst{15-12} = Sd{4-1};
1914  let Inst{22}    = Sd{0};
1915
1916  let Inst{27-23} = opcod1;
1917  let Inst{21-20} = opcod2;
1918  let Inst{19-16} = opcod3;
1919  let Inst{11-9}  = 0b101;
1920  let Inst{8}     = 0;          // Single precision
1921  let Inst{7-6}   = opcod4;
1922  let Inst{4}     = opcod5;
1923}
1924
1925// Single precision, unary, non-predicated
1926class ASuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1927             bit opcod5, dag oops, dag iops, InstrItinClass itin,
1928             string asm, list<dag> pattern>
1929  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1930          VFPUnaryFrm, itin, asm, "", pattern> {
1931  // Instruction operands.
1932  bits<5> Sd;
1933  bits<5> Sm;
1934
1935  let Inst{31-28} = 0b1111;
1936
1937  // Encode instruction operands.
1938  let Inst{3-0}   = Sm{4-1};
1939  let Inst{5}     = Sm{0};
1940  let Inst{15-12} = Sd{4-1};
1941  let Inst{22}    = Sd{0};
1942
1943  let Inst{27-23} = opcod1;
1944  let Inst{21-20} = opcod2;
1945  let Inst{19-16} = opcod3;
1946  let Inst{11-9}  = 0b101;
1947  let Inst{8}     = 0;          // Single precision
1948  let Inst{7-6}   = opcod4;
1949  let Inst{4}     = opcod5;
1950}
1951
1952// Single precision unary, if no NEON. Same as ASuI except not available if
1953// NEON is enabled.
1954class ASuIn<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
1955            bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
1956            string asm, list<dag> pattern>
1957  : ASuI<opcod1, opcod2, opcod3, opcod4, opcod5, oops, iops, itin, opc, asm,
1958         "", pattern> {
1959  list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
1960}
1961
1962// Single precision, binary
1963class ASbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
1964           InstrItinClass itin, string opc, string asm, list<dag> pattern>
1965  : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, "", pattern> {
1966  // Instruction operands.
1967  bits<5> Sd;
1968  bits<5> Sn;
1969  bits<5> Sm;
1970
1971  // Encode instruction operands.
1972  let Inst{3-0}   = Sm{4-1};
1973  let Inst{5}     = Sm{0};
1974  let Inst{19-16} = Sn{4-1};
1975  let Inst{7}     = Sn{0};
1976  let Inst{15-12} = Sd{4-1};
1977  let Inst{22}    = Sd{0};
1978
1979  let Inst{27-23} = opcod1;
1980  let Inst{21-20} = opcod2;
1981  let Inst{11-9}  = 0b101;
1982  let Inst{8}     = 0;          // Single precision
1983  let Inst{6}     = op6;
1984  let Inst{4}     = op4;
1985}
1986
1987// Single precision, binary, not predicated
1988class ASbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
1989           InstrItinClass itin, string asm, list<dag> pattern>
1990  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
1991          VFPBinaryFrm, itin, asm, "", pattern>
1992{
1993  // Instruction operands.
1994  bits<5> Sd;
1995  bits<5> Sn;
1996  bits<5> Sm;
1997
1998  let Inst{31-28} = 0b1111;
1999
2000  // Encode instruction operands.
2001  let Inst{3-0}   = Sm{4-1};
2002  let Inst{5}     = Sm{0};
2003  let Inst{19-16} = Sn{4-1};
2004  let Inst{7}     = Sn{0};
2005  let Inst{15-12} = Sd{4-1};
2006  let Inst{22}    = Sd{0};
2007
2008  let Inst{27-23} = opcod1;
2009  let Inst{21-20} = opcod2;
2010  let Inst{11-9}  = 0b101;
2011  let Inst{8}     = 0; // Single precision
2012  let Inst{6}     = opcod3;
2013  let Inst{4}     = 0;
2014}
2015
2016// Single precision binary, if no NEON. Same as ASbI except not available if
2017// NEON is enabled.
2018class ASbIn<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops,
2019            dag iops, InstrItinClass itin, string opc, string asm,
2020            list<dag> pattern>
2021  : ASbI<opcod1, opcod2, op6, op4, oops, iops, itin, opc, asm, pattern> {
2022  list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
2023
2024  // Instruction operands.
2025  bits<5> Sd;
2026  bits<5> Sn;
2027  bits<5> Sm;
2028
2029  // Encode instruction operands.
2030  let Inst{3-0}   = Sm{4-1};
2031  let Inst{5}     = Sm{0};
2032  let Inst{19-16} = Sn{4-1};
2033  let Inst{7}     = Sn{0};
2034  let Inst{15-12} = Sd{4-1};
2035  let Inst{22}    = Sd{0};
2036}
2037
2038// Half precision, unary, predicated
2039class AHuI<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
2040           bit opcod5, dag oops, dag iops, InstrItinClass itin, string opc,
2041           string asm, list<dag> pattern>
2042  : VFPAI<oops, iops, VFPUnaryFrm, itin, opc, asm, "", pattern> {
2043  list<Predicate> Predicates = [HasFullFP16];
2044
2045  // Instruction operands.
2046  bits<5> Sd;
2047  bits<5> Sm;
2048
2049  // Encode instruction operands.
2050  let Inst{3-0}   = Sm{4-1};
2051  let Inst{5}     = Sm{0};
2052  let Inst{15-12} = Sd{4-1};
2053  let Inst{22}    = Sd{0};
2054
2055  let Inst{27-23} = opcod1;
2056  let Inst{21-20} = opcod2;
2057  let Inst{19-16} = opcod3;
2058  let Inst{11-8}  = 0b1001;   // Half precision
2059  let Inst{7-6}   = opcod4;
2060  let Inst{4}     = opcod5;
2061
2062  let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
2063}
2064
2065// Half precision, unary, non-predicated
2066class AHuInp<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<2> opcod4,
2067             bit opcod5, dag oops, dag iops, InstrItinClass itin,
2068             string asm, list<dag> pattern>
2069  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
2070          VFPUnaryFrm, itin, asm, "", pattern> {
2071  list<Predicate> Predicates = [HasFullFP16];
2072
2073  // Instruction operands.
2074  bits<5> Sd;
2075  bits<5> Sm;
2076
2077  let Inst{31-28} = 0b1111;
2078
2079  // Encode instruction operands.
2080  let Inst{3-0}   = Sm{4-1};
2081  let Inst{5}     = Sm{0};
2082  let Inst{15-12} = Sd{4-1};
2083  let Inst{22}    = Sd{0};
2084
2085  let Inst{27-23} = opcod1;
2086  let Inst{21-20} = opcod2;
2087  let Inst{19-16} = opcod3;
2088  let Inst{11-8}  = 0b1001;   // Half precision
2089  let Inst{7-6}   = opcod4;
2090  let Inst{4}     = opcod5;
2091
2092  let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
2093}
2094
2095// Half precision, binary
2096class AHbI<bits<5> opcod1, bits<2> opcod2, bit op6, bit op4, dag oops, dag iops,
2097           InstrItinClass itin, string opc, string asm, list<dag> pattern>
2098  : VFPAI<oops, iops, VFPBinaryFrm, itin, opc, asm, "", pattern> {
2099  list<Predicate> Predicates = [HasFullFP16];
2100
2101  // Instruction operands.
2102  bits<5> Sd;
2103  bits<5> Sn;
2104  bits<5> Sm;
2105
2106  // Encode instruction operands.
2107  let Inst{3-0}   = Sm{4-1};
2108  let Inst{5}     = Sm{0};
2109  let Inst{19-16} = Sn{4-1};
2110  let Inst{7}     = Sn{0};
2111  let Inst{15-12} = Sd{4-1};
2112  let Inst{22}    = Sd{0};
2113
2114  let Inst{27-23} = opcod1;
2115  let Inst{21-20} = opcod2;
2116  let Inst{11-8}  = 0b1001;   // Half precision
2117  let Inst{6}     = op6;
2118  let Inst{4}     = op4;
2119
2120  let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
2121}
2122
2123// Half precision, binary, not predicated
2124class AHbInp<bits<5> opcod1, bits<2> opcod2, bit opcod3, dag oops, dag iops,
2125           InstrItinClass itin, string asm, list<dag> pattern>
2126  : VFPXI<oops, iops, AddrModeNone, 4, IndexModeNone,
2127          VFPBinaryFrm, itin, asm, "", pattern> {
2128  list<Predicate> Predicates = [HasFullFP16];
2129
2130  // Instruction operands.
2131  bits<5> Sd;
2132  bits<5> Sn;
2133  bits<5> Sm;
2134
2135  let Inst{31-28} = 0b1111;
2136
2137  // Encode instruction operands.
2138  let Inst{3-0}   = Sm{4-1};
2139  let Inst{5}     = Sm{0};
2140  let Inst{19-16} = Sn{4-1};
2141  let Inst{7}     = Sn{0};
2142  let Inst{15-12} = Sd{4-1};
2143  let Inst{22}    = Sd{0};
2144
2145  let Inst{27-23} = opcod1;
2146  let Inst{21-20} = opcod2;
2147  let Inst{11-8}  = 0b1001;   // Half precision
2148  let Inst{6}     = opcod3;
2149  let Inst{4}     = 0;
2150
2151  let isUnpredicable = 1; // FP16 instructions cannot in general be conditional
2152}
2153
2154// VFP conversion instructions
2155class AVConv1I<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
2156               dag oops, dag iops, InstrItinClass itin, string opc, string asm,
2157               list<dag> pattern>
2158  : VFPAI<oops, iops, VFPConv1Frm, itin, opc, asm, "", pattern> {
2159  let Inst{27-23} = opcod1;
2160  let Inst{21-20} = opcod2;
2161  let Inst{19-16} = opcod3;
2162  let Inst{11-8}  = opcod4;
2163  let Inst{6}     = 1;
2164  let Inst{4}     = 0;
2165}
2166
2167// VFP conversion between floating-point and fixed-point
2168class AVConv1XI<bits<5> op1, bits<2> op2, bits<4> op3, bits<4> op4, bit op5,
2169                dag oops, dag iops, InstrItinClass itin, string opc, string asm,
2170                list<dag> pattern>
2171  : AVConv1I<op1, op2, op3, op4, oops, iops, itin, opc, asm, pattern> {
2172  bits<5> fbits;
2173  // size (fixed-point number): sx == 0 ? 16 : 32
2174  let Inst{7} = op5; // sx
2175  let Inst{5} = fbits{0};
2176  let Inst{3-0} = fbits{4-1};
2177}
2178
2179// VFP conversion instructions, if no NEON
2180class AVConv1In<bits<5> opcod1, bits<2> opcod2, bits<4> opcod3, bits<4> opcod4,
2181                dag oops, dag iops, InstrItinClass itin,
2182                string opc, string asm, list<dag> pattern>
2183  : AVConv1I<opcod1, opcod2, opcod3, opcod4, oops, iops, itin, opc, asm,
2184             pattern> {
2185  list<Predicate> Predicates = [HasVFP2,DontUseNEONForFP];
2186}
2187
2188class AVConvXI<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops, Format f,
2189               InstrItinClass itin,
2190               string opc, string asm, list<dag> pattern>
2191  : VFPAI<oops, iops, f, itin, opc, asm, "", pattern> {
2192  let Inst{27-20} = opcod1;
2193  let Inst{11-8}  = opcod2;
2194  let Inst{4}     = 1;
2195}
2196
2197class AVConv2I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2198               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2199  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv2Frm, itin, opc, asm, pattern>;
2200
2201class AVConv3I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2202               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2203  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv3Frm, itin, opc, asm, pattern>;
2204
2205class AVConv4I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2206               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2207  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv4Frm, itin, opc, asm, pattern>;
2208
2209class AVConv5I<bits<8> opcod1, bits<4> opcod2, dag oops, dag iops,
2210               InstrItinClass itin, string opc, string asm, list<dag> pattern>
2211  : AVConvXI<opcod1, opcod2, oops, iops, VFPConv5Frm, itin, opc, asm, pattern>;
2212
2213//===----------------------------------------------------------------------===//
2214
2215//===----------------------------------------------------------------------===//
2216// ARM NEON Instruction templates.
2217//
2218
2219class NeonI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
2220            InstrItinClass itin, string opc, string dt, string asm, string cstr,
2221            list<dag> pattern>
2222  : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
2223  let OutOperandList = oops;
2224  let InOperandList = !con(iops, (ins pred:$p));
2225  let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
2226  let Pattern = pattern;
2227  list<Predicate> Predicates = [HasNEON];
2228  let DecoderNamespace = "NEON";
2229}
2230
2231// Same as NeonI except it does not have a "data type" specifier.
2232class NeonXI<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
2233             InstrItinClass itin, string opc, string asm, string cstr,
2234             list<dag> pattern>
2235  : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
2236  let OutOperandList = oops;
2237  let InOperandList = !con(iops, (ins pred:$p));
2238  let AsmString = !strconcat(opc, "${p}", "\t", asm);
2239  let Pattern = pattern;
2240  list<Predicate> Predicates = [HasNEON];
2241  let DecoderNamespace = "NEON";
2242}
2243
2244// Same as NeonI except it is not predicated
2245class NeonInp<dag oops, dag iops, AddrMode am, IndexMode im, Format f,
2246            InstrItinClass itin, string opc, string dt, string asm, string cstr,
2247            list<dag> pattern>
2248  : InstARM<am, 4, im, f, NeonDomain, cstr, itin> {
2249  let OutOperandList = oops;
2250  let InOperandList = iops;
2251  let AsmString = !strconcat(opc, ".", dt, "\t", asm);
2252  let Pattern = pattern;
2253  list<Predicate> Predicates = [HasNEON];
2254  let DecoderNamespace = "NEON";
2255
2256  let Inst{31-28} = 0b1111;
2257}
2258
2259class NLdSt<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
2260            dag oops, dag iops, InstrItinClass itin,
2261            string opc, string dt, string asm, string cstr, list<dag> pattern>
2262  : NeonI<oops, iops, AddrMode6, IndexModeNone, NLdStFrm, itin, opc, dt, asm,
2263          cstr, pattern> {
2264  let Inst{31-24} = 0b11110100;
2265  let Inst{23}    = op23;
2266  let Inst{21-20} = op21_20;
2267  let Inst{11-8}  = op11_8;
2268  let Inst{7-4}   = op7_4;
2269
2270  let PostEncoderMethod = "NEONThumb2LoadStorePostEncoder";
2271  let DecoderNamespace = "NEONLoadStore";
2272
2273  bits<5> Vd;
2274  bits<6> Rn;
2275  bits<4> Rm;
2276
2277  let Inst{22}    = Vd{4};
2278  let Inst{15-12} = Vd{3-0};
2279  let Inst{19-16} = Rn{3-0};
2280  let Inst{3-0}   = Rm{3-0};
2281}
2282
2283class NLdStLn<bit op23, bits<2> op21_20, bits<4> op11_8, bits<4> op7_4,
2284            dag oops, dag iops, InstrItinClass itin,
2285            string opc, string dt, string asm, string cstr, list<dag> pattern>
2286  : NLdSt<op23, op21_20, op11_8, op7_4, oops, iops, itin, opc,
2287          dt, asm, cstr, pattern> {
2288  bits<3> lane;
2289}
2290
2291class PseudoNLdSt<dag oops, dag iops, InstrItinClass itin, string cstr>
2292  : InstARM<AddrMode6, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
2293            itin> {
2294  let OutOperandList = oops;
2295  let InOperandList = !con(iops, (ins pred:$p));
2296  list<Predicate> Predicates = [HasNEON];
2297}
2298
2299class PseudoNeonI<dag oops, dag iops, InstrItinClass itin, string cstr,
2300                  list<dag> pattern>
2301  : InstARM<AddrModeNone, 4, IndexModeNone, Pseudo, NeonDomain, cstr,
2302            itin> {
2303  let OutOperandList = oops;
2304  let InOperandList = !con(iops, (ins pred:$p));
2305  let Pattern = pattern;
2306  list<Predicate> Predicates = [HasNEON];
2307}
2308
2309class NDataI<dag oops, dag iops, Format f, InstrItinClass itin,
2310             string opc, string dt, string asm, string cstr, list<dag> pattern>
2311  : NeonI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, dt, asm, cstr,
2312          pattern> {
2313  let Inst{31-25} = 0b1111001;
2314  let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
2315  let DecoderNamespace = "NEONData";
2316}
2317
2318class NDataXI<dag oops, dag iops, Format f, InstrItinClass itin,
2319              string opc, string asm, string cstr, list<dag> pattern>
2320  : NeonXI<oops, iops, AddrModeNone, IndexModeNone, f, itin, opc, asm,
2321           cstr, pattern> {
2322  let Inst{31-25} = 0b1111001;
2323  let PostEncoderMethod = "NEONThumb2DataIPostEncoder";
2324  let DecoderNamespace = "NEONData";
2325}
2326
2327// NEON "one register and a modified immediate" format.
2328class N1ModImm<bit op23, bits<3> op21_19, bits<4> op11_8, bit op7, bit op6,
2329               bit op5, bit op4,
2330               dag oops, dag iops, InstrItinClass itin,
2331               string opc, string dt, string asm, string cstr,
2332               list<dag> pattern>
2333  : NDataI<oops, iops, N1RegModImmFrm, itin, opc, dt, asm, cstr, pattern> {
2334  let Inst{23}    = op23;
2335  let Inst{21-19} = op21_19;
2336  let Inst{11-8}  = op11_8;
2337  let Inst{7}     = op7;
2338  let Inst{6}     = op6;
2339  let Inst{5}     = op5;
2340  let Inst{4}     = op4;
2341
2342  // Instruction operands.
2343  bits<5> Vd;
2344  bits<13> SIMM;
2345
2346  let Inst{15-12} = Vd{3-0};
2347  let Inst{22}    = Vd{4};
2348  let Inst{24}    = SIMM{7};
2349  let Inst{18-16} = SIMM{6-4};
2350  let Inst{3-0}   = SIMM{3-0};
2351  let DecoderMethod = "DecodeVMOVModImmInstruction";
2352}
2353
2354// NEON 2 vector register format.
2355class N2V<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
2356          bits<5> op11_7, bit op6, bit op4,
2357          dag oops, dag iops, InstrItinClass itin,
2358          string opc, string dt, string asm, string cstr, list<dag> pattern>
2359  : NDataI<oops, iops, N2RegFrm, itin, opc, dt, asm, cstr, pattern> {
2360  let Inst{24-23} = op24_23;
2361  let Inst{21-20} = op21_20;
2362  let Inst{19-18} = op19_18;
2363  let Inst{17-16} = op17_16;
2364  let Inst{11-7}  = op11_7;
2365  let Inst{6}     = op6;
2366  let Inst{4}     = op4;
2367
2368  // Instruction operands.
2369  bits<5> Vd;
2370  bits<5> Vm;
2371
2372  let Inst{15-12} = Vd{3-0};
2373  let Inst{22}    = Vd{4};
2374  let Inst{3-0}   = Vm{3-0};
2375  let Inst{5}     = Vm{4};
2376}
2377
2378// Same as N2V but not predicated.
2379class N2Vnp<bits<2> op19_18, bits<2> op17_16, bits<3> op10_8, bit op7, bit op6,
2380            dag oops, dag iops, InstrItinClass itin, string OpcodeStr,
2381            string Dt, list<dag> pattern>
2382   : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N2RegFrm, itin,
2383             OpcodeStr, Dt, "$Vd, $Vm", "", pattern> {
2384  bits<5> Vd;
2385  bits<5> Vm;
2386
2387  // Encode instruction operands
2388  let Inst{22}    = Vd{4};
2389  let Inst{15-12} = Vd{3-0};
2390  let Inst{5}     = Vm{4};
2391  let Inst{3-0}   = Vm{3-0};
2392
2393  // Encode constant bits
2394  let Inst{27-23} = 0b00111;
2395  let Inst{21-20} = 0b11;
2396  let Inst{19-18} = op19_18;
2397  let Inst{17-16} = op17_16;
2398  let Inst{11} = 0;
2399  let Inst{10-8} = op10_8;
2400  let Inst{7} = op7;
2401  let Inst{6} = op6;
2402  let Inst{4} = 0;
2403
2404  let DecoderNamespace = "NEON";
2405}
2406
2407// Same as N2V except it doesn't have a datatype suffix.
2408class N2VX<bits<2> op24_23, bits<2> op21_20, bits<2> op19_18, bits<2> op17_16,
2409           bits<5> op11_7, bit op6, bit op4,
2410           dag oops, dag iops, InstrItinClass itin,
2411           string opc, string asm, string cstr, list<dag> pattern>
2412  : NDataXI<oops, iops, N2RegFrm, itin, opc, asm, cstr, pattern> {
2413  let Inst{24-23} = op24_23;
2414  let Inst{21-20} = op21_20;
2415  let Inst{19-18} = op19_18;
2416  let Inst{17-16} = op17_16;
2417  let Inst{11-7}  = op11_7;
2418  let Inst{6}     = op6;
2419  let Inst{4}     = op4;
2420
2421  // Instruction operands.
2422  bits<5> Vd;
2423  bits<5> Vm;
2424
2425  let Inst{15-12} = Vd{3-0};
2426  let Inst{22}    = Vd{4};
2427  let Inst{3-0}   = Vm{3-0};
2428  let Inst{5}     = Vm{4};
2429}
2430
2431// NEON 2 vector register with immediate.
2432class N2VImm<bit op24, bit op23, bits<4> op11_8, bit op7, bit op6, bit op4,
2433             dag oops, dag iops, Format f, InstrItinClass itin,
2434             string opc, string dt, string asm, string cstr, list<dag> pattern>
2435  : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2436  let Inst{24}   = op24;
2437  let Inst{23}   = op23;
2438  let Inst{11-8} = op11_8;
2439  let Inst{7}    = op7;
2440  let Inst{6}    = op6;
2441  let Inst{4}    = op4;
2442
2443  // Instruction operands.
2444  bits<5> Vd;
2445  bits<5> Vm;
2446  bits<6> SIMM;
2447
2448  let Inst{15-12} = Vd{3-0};
2449  let Inst{22}    = Vd{4};
2450  let Inst{3-0}   = Vm{3-0};
2451  let Inst{5}     = Vm{4};
2452  let Inst{21-16} = SIMM{5-0};
2453}
2454
2455// NEON 3 vector register format.
2456
2457class N3VCommon<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2458                bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2459                string opc, string dt, string asm, string cstr,
2460                list<dag> pattern>
2461  : NDataI<oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2462  let Inst{24}    = op24;
2463  let Inst{23}    = op23;
2464  let Inst{21-20} = op21_20;
2465  let Inst{11-8}  = op11_8;
2466  let Inst{6}     = op6;
2467  let Inst{4}     = op4;
2468}
2469
2470class N3V<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6, bit op4,
2471          dag oops, dag iops, Format f, InstrItinClass itin,
2472          string opc, string dt, string asm, string cstr, list<dag> pattern>
2473  : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2474              oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2475  // Instruction operands.
2476  bits<5> Vd;
2477  bits<5> Vn;
2478  bits<5> Vm;
2479
2480  let Inst{15-12} = Vd{3-0};
2481  let Inst{22}    = Vd{4};
2482  let Inst{19-16} = Vn{3-0};
2483  let Inst{7}     = Vn{4};
2484  let Inst{3-0}   = Vm{3-0};
2485  let Inst{5}     = Vm{4};
2486}
2487
2488class N3Vnp<bits<5> op27_23, bits<2> op21_20, bits<4> op11_8, bit op6,
2489                bit op4, dag oops, dag iops,Format f, InstrItinClass itin,
2490                string OpcodeStr, string Dt, list<dag> pattern>
2491  : NeonInp<oops, iops, AddrModeNone, IndexModeNone, f, itin, OpcodeStr,
2492            Dt, "$Vd, $Vn, $Vm", "", pattern> {
2493  bits<5> Vd;
2494  bits<5> Vn;
2495  bits<5> Vm;
2496
2497  // Encode instruction operands
2498  let Inst{22} = Vd{4};
2499  let Inst{15-12} = Vd{3-0};
2500  let Inst{19-16} = Vn{3-0};
2501  let Inst{7} = Vn{4};
2502  let Inst{5} = Vm{4};
2503  let Inst{3-0} = Vm{3-0};
2504
2505  // Encode constant bits
2506  let Inst{27-23} = op27_23;
2507  let Inst{21-20} = op21_20;
2508  let Inst{11-8}  = op11_8;
2509  let Inst{6}     = op6;
2510  let Inst{4}     = op4;
2511}
2512
2513class N3VLane32<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2514                bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2515                string opc, string dt, string asm, string cstr,
2516                list<dag> pattern>
2517  : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2518              oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2519
2520  // Instruction operands.
2521  bits<5> Vd;
2522  bits<5> Vn;
2523  bits<5> Vm;
2524  bit lane;
2525
2526  let Inst{15-12} = Vd{3-0};
2527  let Inst{22}    = Vd{4};
2528  let Inst{19-16} = Vn{3-0};
2529  let Inst{7}     = Vn{4};
2530  let Inst{3-0}   = Vm{3-0};
2531  let Inst{5}     = lane;
2532}
2533
2534class N3VLane16<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2535                bit op4, dag oops, dag iops, Format f, InstrItinClass itin,
2536                string opc, string dt, string asm, string cstr,
2537                list<dag> pattern>
2538  : N3VCommon<op24, op23, op21_20, op11_8, op6, op4,
2539              oops, iops, f, itin, opc, dt, asm, cstr, pattern> {
2540
2541  // Instruction operands.
2542  bits<5> Vd;
2543  bits<5> Vn;
2544  bits<5> Vm;
2545  bits<2> lane;
2546
2547  let Inst{15-12} = Vd{3-0};
2548  let Inst{22}    = Vd{4};
2549  let Inst{19-16} = Vn{3-0};
2550  let Inst{7}     = Vn{4};
2551  let Inst{2-0}   = Vm{2-0};
2552  let Inst{5}     = lane{1};
2553  let Inst{3}     = lane{0};
2554}
2555
2556// Same as N3V except it doesn't have a data type suffix.
2557class N3VX<bit op24, bit op23, bits<2> op21_20, bits<4> op11_8, bit op6,
2558           bit op4,
2559           dag oops, dag iops, Format f, InstrItinClass itin,
2560           string opc, string asm, string cstr, list<dag> pattern>
2561  : NDataXI<oops, iops, f, itin, opc, asm, cstr, pattern> {
2562  let Inst{24}    = op24;
2563  let Inst{23}    = op23;
2564  let Inst{21-20} = op21_20;
2565  let Inst{11-8}  = op11_8;
2566  let Inst{6}     = op6;
2567  let Inst{4}     = op4;
2568
2569  // Instruction operands.
2570  bits<5> Vd;
2571  bits<5> Vn;
2572  bits<5> Vm;
2573
2574  let Inst{15-12} = Vd{3-0};
2575  let Inst{22}    = Vd{4};
2576  let Inst{19-16} = Vn{3-0};
2577  let Inst{7}     = Vn{4};
2578  let Inst{3-0}   = Vm{3-0};
2579  let Inst{5}     = Vm{4};
2580}
2581
2582// NEON VMOVs between scalar and core registers.
2583class NVLaneOp<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2584               dag oops, dag iops, Format f, InstrItinClass itin,
2585               string opc, string dt, string asm, list<dag> pattern>
2586  : InstARM<AddrModeNone, 4, IndexModeNone, f, NeonDomain,
2587            "", itin> {
2588  let Inst{27-20} = opcod1;
2589  let Inst{11-8}  = opcod2;
2590  let Inst{6-5}   = opcod3;
2591  let Inst{4}     = 1;
2592  // A8.6.303, A8.6.328, A8.6.329
2593  let Inst{3-0}   = 0b0000;
2594
2595  let OutOperandList = oops;
2596  let InOperandList = !con(iops, (ins pred:$p));
2597  let AsmString = !strconcat(opc, "${p}", ".", dt, "\t", asm);
2598  let Pattern = pattern;
2599  list<Predicate> Predicates = [HasNEON];
2600
2601  let PostEncoderMethod = "NEONThumb2DupPostEncoder";
2602  let DecoderNamespace = "NEONDup";
2603
2604  bits<5> V;
2605  bits<4> R;
2606  bits<4> p;
2607  bits<4> lane;
2608
2609  let Inst{31-28} = p{3-0};
2610  let Inst{7}     = V{4};
2611  let Inst{19-16} = V{3-0};
2612  let Inst{15-12} = R{3-0};
2613}
2614class NVGetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2615                dag oops, dag iops, InstrItinClass itin,
2616                string opc, string dt, string asm, list<dag> pattern>
2617  : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NGetLnFrm, itin,
2618             opc, dt, asm, pattern>;
2619class NVSetLane<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2620                dag oops, dag iops, InstrItinClass itin,
2621                string opc, string dt, string asm, list<dag> pattern>
2622  : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NSetLnFrm, itin,
2623             opc, dt, asm, pattern>;
2624class NVDup<bits<8> opcod1, bits<4> opcod2, bits<2> opcod3,
2625            dag oops, dag iops, InstrItinClass itin,
2626            string opc, string dt, string asm, list<dag> pattern>
2627  : NVLaneOp<opcod1, opcod2, opcod3, oops, iops, NDupFrm, itin,
2628             opc, dt, asm, pattern>;
2629
2630// Vector Duplicate Lane (from scalar to all elements)
2631class NVDupLane<bits<4> op19_16, bit op6, dag oops, dag iops,
2632                InstrItinClass itin, string opc, string dt, string asm,
2633                list<dag> pattern>
2634  : NDataI<oops, iops, NVDupLnFrm, itin, opc, dt, asm, "", pattern> {
2635  let Inst{24-23} = 0b11;
2636  let Inst{21-20} = 0b11;
2637  let Inst{19-16} = op19_16;
2638  let Inst{11-7}  = 0b11000;
2639  let Inst{6}     = op6;
2640  let Inst{4}     = 0;
2641
2642  bits<5> Vd;
2643  bits<5> Vm;
2644
2645  let Inst{22}     = Vd{4};
2646  let Inst{15-12} = Vd{3-0};
2647  let Inst{5}     = Vm{4};
2648  let Inst{3-0} = Vm{3-0};
2649}
2650
2651// NEONFPPat - Same as Pat<>, but requires that the compiler be using NEON
2652// for single-precision FP.
2653class NEONFPPat<dag pattern, dag result> : Pat<pattern, result> {
2654  list<Predicate> Predicates = [HasNEON,UseNEONForFP];
2655}
2656
2657// VFP/NEON Instruction aliases for type suffices.
2658// Note: When EmitPriority == 1, the alias will be used for printing
2659class VFPDataTypeInstAlias<string opc, string dt, string asm, dag Result, bit EmitPriority = 0> :
2660  InstAlias<!strconcat(opc, dt, "\t", asm), Result, EmitPriority>, Requires<[HasFPRegs]>;
2661
2662// Note: When EmitPriority == 1, the alias will be used for printing
2663multiclass VFPDTAnyInstAlias<string opc, string asm, dag Result, bit EmitPriority = 0> {
2664  def : VFPDataTypeInstAlias<opc, ".8", asm, Result, EmitPriority>;
2665  def : VFPDataTypeInstAlias<opc, ".16", asm, Result, EmitPriority>;
2666  def : VFPDataTypeInstAlias<opc, ".32", asm, Result, EmitPriority>;
2667  def : VFPDataTypeInstAlias<opc, ".64", asm, Result, EmitPriority>;
2668}
2669
2670// Note: When EmitPriority == 1, the alias will be used for printing
2671multiclass NEONDTAnyInstAlias<string opc, string asm, dag Result, bit EmitPriority = 0> {
2672  let Predicates = [HasNEON] in {
2673  def : VFPDataTypeInstAlias<opc, ".8", asm, Result, EmitPriority>;
2674  def : VFPDataTypeInstAlias<opc, ".16", asm, Result, EmitPriority>;
2675  def : VFPDataTypeInstAlias<opc, ".32", asm, Result, EmitPriority>;
2676  def : VFPDataTypeInstAlias<opc, ".64", asm, Result, EmitPriority>;
2677}
2678}
2679
2680// The same alias classes using AsmPseudo instead, for the more complex
2681// stuff in NEON that InstAlias can't quite handle.
2682// Note that we can't use anonymous defm references here like we can
2683// above, as we care about the ultimate instruction enum names generated, unlike
2684// for instalias defs.
2685class NEONDataTypeAsmPseudoInst<string opc, string dt, string asm, dag iops> :
2686  AsmPseudoInst<!strconcat(opc, dt, "\t", asm), iops>, Requires<[HasNEON]>;
2687
2688// Extension of NEON 3-vector data processing instructions in coprocessor 8
2689// encoding space, introduced in ARMv8.3-A.
2690class N3VCP8<bits<2> op24_23, bits<2> op21_20, bit op6, bit op4,
2691             dag oops, dag iops, InstrItinClass itin,
2692             string opc, string dt, string asm, string cstr, list<dag> pattern>
2693  : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N3RegCplxFrm, itin, opc,
2694            dt, asm, cstr, pattern> {
2695  bits<5> Vd;
2696  bits<5> Vn;
2697  bits<5> Vm;
2698
2699  let DecoderNamespace = "VFPV8";
2700  // These have the same encodings in ARM and Thumb2
2701  let PostEncoderMethod = "";
2702
2703  let Inst{31-25} = 0b1111110;
2704  let Inst{24-23} = op24_23;
2705  let Inst{22}    = Vd{4};
2706  let Inst{21-20} = op21_20;
2707  let Inst{19-16} = Vn{3-0};
2708  let Inst{15-12} = Vd{3-0};
2709  let Inst{11-8}  = 0b1000;
2710  let Inst{7}     = Vn{4};
2711  let Inst{6}     = op6;
2712  let Inst{5}     = Vm{4};
2713  let Inst{4}     = op4;
2714  let Inst{3-0}   = Vm{3-0};
2715}
2716
2717// Extension of NEON 2-vector-and-scalar data processing instructions in
2718// coprocessor 8 encoding space, introduced in ARMv8.3-A.
2719class N3VLaneCP8<bit op23, bits<2> op21_20, bit op6, bit op4,
2720             dag oops, dag iops, InstrItinClass itin,
2721             string opc, string dt, string asm, string cstr, list<dag> pattern>
2722  : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N3RegCplxFrm, itin, opc,
2723            dt, asm, cstr, pattern> {
2724  bits<5> Vd;
2725  bits<5> Vn;
2726  bits<5> Vm;
2727
2728  let DecoderNamespace = "VFPV8";
2729  // These have the same encodings in ARM and Thumb2
2730  let PostEncoderMethod = "";
2731
2732  let Inst{31-24} = 0b11111110;
2733  let Inst{23}    = op23;
2734  let Inst{22}    = Vd{4};
2735  let Inst{21-20} = op21_20;
2736  let Inst{19-16} = Vn{3-0};
2737  let Inst{15-12} = Vd{3-0};
2738  let Inst{11-8}  = 0b1000;
2739  let Inst{7}     = Vn{4};
2740  let Inst{6}     = op6;
2741  // Bit 5 set by sub-classes
2742  let Inst{4}     = op4;
2743  let Inst{3-0}   = Vm{3-0};
2744}
2745
2746// In Armv8.2-A, some NEON instructions are added that encode Vn and Vm
2747// differently:
2748//    if Q == ‘1’ then UInt(N:Vn) else UInt(Vn:N);
2749//    if Q == ‘1’ then UInt(M:Vm) else UInt(Vm:M);
2750// Class N3VCP8 above describes the Q=1 case, and this class the Q=0 case.
2751class N3VCP8Q0<bits<2> op24_23, bits<2> op21_20, bit op6, bit op4,
2752             dag oops, dag iops, InstrItinClass itin,
2753             string opc, string dt, string asm, string cstr, list<dag> pattern>
2754  : NeonInp<oops, iops, AddrModeNone, IndexModeNone, N3RegCplxFrm, itin, opc, dt, asm, cstr, pattern> {
2755  bits<5> Vd;
2756  bits<5> Vn;
2757  bits<5> Vm;
2758
2759  let DecoderNamespace = "VFPV8";
2760  // These have the same encodings in ARM and Thumb2
2761  let PostEncoderMethod = "";
2762
2763  let Inst{31-25} = 0b1111110;
2764  let Inst{24-23} = op24_23;
2765  let Inst{22}    = Vd{4};
2766  let Inst{21-20} = op21_20;
2767  let Inst{19-16} = Vn{4-1};
2768  let Inst{15-12} = Vd{3-0};
2769  let Inst{11-8}  = 0b1000;
2770  let Inst{7}     = Vn{0};
2771  let Inst{6}     = op6;
2772  let Inst{5}     = Vm{0};
2773  let Inst{4}     = op4;
2774  let Inst{3-0}   = Vm{4-1};
2775}
2776
2777// Operand types for complex instructions
2778class ComplexRotationOperand<int Angle, int Remainder, string Type, string Diag>
2779  : AsmOperandClass {
2780  let PredicateMethod = "isComplexRotation<" # Angle # ", " # Remainder # ">";
2781  let DiagnosticString = "complex rotation must be " # Diag;
2782  let Name = "ComplexRotation" # Type;
2783}
2784def complexrotateop : Operand<i32> {
2785  let ParserMatchClass = ComplexRotationOperand<90, 0, "Even", "0, 90, 180 or 270">;
2786  let PrintMethod = "printComplexRotationOp<90, 0>";
2787}
2788def complexrotateopodd : Operand<i32> {
2789  let ParserMatchClass = ComplexRotationOperand<180, 90, "Odd", "90 or 270">;
2790  let PrintMethod = "printComplexRotationOp<180, 90>";
2791}
2792
2793def MveSaturateOperand : AsmOperandClass {
2794  let PredicateMethod = "isMveSaturateOp";
2795  let DiagnosticString = "saturate operand must be 48 or 64";
2796  let Name = "MveSaturate";
2797}
2798def saturateop : Operand<i32> {
2799  let ParserMatchClass = MveSaturateOperand;
2800  let PrintMethod = "printMveSaturateOp";
2801}
2802
2803// Data type suffix token aliases. Implements Table A7-3 in the ARM ARM.
2804def : TokenAlias<".s8", ".i8">;
2805def : TokenAlias<".u8", ".i8">;
2806def : TokenAlias<".s16", ".i16">;
2807def : TokenAlias<".u16", ".i16">;
2808def : TokenAlias<".s32", ".i32">;
2809def : TokenAlias<".u32", ".i32">;
2810def : TokenAlias<".s64", ".i64">;
2811def : TokenAlias<".u64", ".i64">;
2812
2813def : TokenAlias<".i8", ".8">;
2814def : TokenAlias<".i16", ".16">;
2815def : TokenAlias<".i32", ".32">;
2816def : TokenAlias<".i64", ".64">;
2817
2818def : TokenAlias<".p8", ".8">;
2819def : TokenAlias<".p16", ".16">;
2820
2821def : TokenAlias<".f32", ".32">;
2822def : TokenAlias<".f64", ".64">;
2823def : TokenAlias<".f", ".f32">;
2824def : TokenAlias<".d", ".f64">;
2825