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