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