1 //==- HexagonInstrInfo.td - Target Description for Hexagon -*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the Hexagon instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 include "HexagonInstrFormats.td"
15 include "HexagonOperands.td"
16 include "HexagonInstrEnc.td"
17 // Pattern fragment that combines the value type and the register class
18 // into a single parameter.
19 // The pat frags in the definitions below need to have a named register,
20 // otherwise i32 will be assumed regardless of the register class. The
21 // name of the register does not matter.
22 def I1 : PatLeaf<(i1 PredRegs:$R)>;
23 def I32 : PatLeaf<(i32 IntRegs:$R)>;
24 def I64 : PatLeaf<(i64 DoubleRegs:$R)>;
25 def F32 : PatLeaf<(f32 IntRegs:$R)>;
26 def F64 : PatLeaf<(f64 DoubleRegs:$R)>;
28 // Pattern fragments to extract the low and high subregisters from a
30 def LoReg: OutPatFrag<(ops node:$Rs),
31 (EXTRACT_SUBREG (i64 $Rs), subreg_loreg)>;
32 def HiReg: OutPatFrag<(ops node:$Rs),
33 (EXTRACT_SUBREG (i64 $Rs), subreg_hireg)>;
35 def orisadd: PatFrag<(ops node:$Addr, node:$off),
36 (or node:$Addr, node:$off), [{ return orIsAdd(N); }]>;
38 // SDNode for converting immediate C to C-1.
39 def DEC_CONST_SIGNED : SDNodeXForm<imm, [{
40 // Return the byte immediate const-1 as an SDNode.
41 int32_t imm = N->getSExtValue();
42 return XformSToSM1Imm(imm, SDLoc(N));
45 // SDNode for converting immediate C to C-2.
46 def DEC2_CONST_SIGNED : SDNodeXForm<imm, [{
47 // Return the byte immediate const-2 as an SDNode.
48 int32_t imm = N->getSExtValue();
49 return XformSToSM2Imm(imm, SDLoc(N));
52 // SDNode for converting immediate C to C-3.
53 def DEC3_CONST_SIGNED : SDNodeXForm<imm, [{
54 // Return the byte immediate const-3 as an SDNode.
55 int32_t imm = N->getSExtValue();
56 return XformSToSM3Imm(imm, SDLoc(N));
59 // SDNode for converting immediate C to C-1.
60 def DEC_CONST_UNSIGNED : SDNodeXForm<imm, [{
61 // Return the byte immediate const-1 as an SDNode.
62 uint32_t imm = N->getZExtValue();
63 return XformUToUM1Imm(imm, SDLoc(N));
66 //===----------------------------------------------------------------------===//
68 //===----------------------------------------------------------------------===//
69 let hasSideEffects = 0, isCompare = 1, InputType = "imm", isExtendable = 1,
71 class T_CMP <string mnemonic, bits<2> MajOp, bit isNot, Operand ImmOp>
72 : ALU32Inst <(outs PredRegs:$dst),
73 (ins IntRegs:$src1, ImmOp:$src2),
74 "$dst = "#!if(isNot, "!","")#mnemonic#"($src1, #$src2)",
75 [], "",ALU32_2op_tc_2early_SLOT0123 >, ImmRegRel {
79 let CextOpcode = mnemonic;
80 let opExtentBits = !if(!eq(mnemonic, "cmp.gtu"), 9, 10);
81 let isExtentSigned = !if(!eq(mnemonic, "cmp.gtu"), 0, 1);
85 let Inst{27-24} = 0b0101;
86 let Inst{23-22} = MajOp;
87 let Inst{21} = !if(!eq(mnemonic, "cmp.gtu"), 0, src2{9});
88 let Inst{20-16} = src1;
89 let Inst{13-5} = src2{8-0};
95 def C2_cmpeqi : T_CMP <"cmp.eq", 0b00, 0, s10Ext>;
96 def C2_cmpgti : T_CMP <"cmp.gt", 0b01, 0, s10Ext>;
97 def C2_cmpgtui : T_CMP <"cmp.gtu", 0b10, 0, u9Ext>;
99 class T_CMP_pat <InstHexagon MI, PatFrag OpNode, PatLeaf ImmPred>
100 : Pat<(i1 (OpNode (i32 IntRegs:$src1), ImmPred:$src2)),
101 (MI IntRegs:$src1, ImmPred:$src2)>;
103 def : T_CMP_pat <C2_cmpeqi, seteq, s10ImmPred>;
104 def : T_CMP_pat <C2_cmpgti, setgt, s10ImmPred>;
105 def : T_CMP_pat <C2_cmpgtui, setugt, u9ImmPred>;
107 //===----------------------------------------------------------------------===//
109 //===----------------------------------------------------------------------===//
112 def SDT_Int32Leaf : SDTypeProfile<1, 0, [SDTCisVT<0, i32>]>;
113 def SDT_Int32Unary : SDTypeProfile<1, 1, [SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
115 def SDTHexagonI64I32I32 : SDTypeProfile<1, 2,
116 [SDTCisVT<0, i64>, SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>;
118 def HexagonCOMBINE : SDNode<"HexagonISD::COMBINE", SDTHexagonI64I32I32>;
119 def HexagonPACKHL : SDNode<"HexagonISD::PACKHL", SDTHexagonI64I32I32>;
121 let hasSideEffects = 0, hasNewValue = 1, InputType = "reg" in
122 class T_ALU32_3op<string mnemonic, bits<3> MajOp, bits<3> MinOp, bit OpsRev,
124 : ALU32_rr<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
125 "$Rd = "#mnemonic#"($Rs, $Rt)",
126 [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel, PredRel {
127 let isCommutable = IsComm;
128 let BaseOpcode = mnemonic#_rr;
129 let CextOpcode = mnemonic;
137 let Inst{26-24} = MajOp;
138 let Inst{23-21} = MinOp;
139 let Inst{20-16} = !if(OpsRev,Rt,Rs);
140 let Inst{12-8} = !if(OpsRev,Rs,Rt);
144 let hasSideEffects = 0, hasNewValue = 1 in
145 class T_ALU32_3op_pred<string mnemonic, bits<3> MajOp, bits<3> MinOp,
146 bit OpsRev, bit PredNot, bit PredNew>
147 : ALU32_rr<(outs IntRegs:$Rd), (ins PredRegs:$Pu, IntRegs:$Rs, IntRegs:$Rt),
148 "if ("#!if(PredNot,"!","")#"$Pu"#!if(PredNew,".new","")#") "#
149 "$Rd = "#mnemonic#"($Rs, $Rt)",
150 [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel, PredNewRel {
151 let isPredicated = 1;
152 let isPredicatedFalse = PredNot;
153 let isPredicatedNew = PredNew;
154 let BaseOpcode = mnemonic#_rr;
155 let CextOpcode = mnemonic;
164 let Inst{26-24} = MajOp;
165 let Inst{23-21} = MinOp;
166 let Inst{20-16} = !if(OpsRev,Rt,Rs);
167 let Inst{13} = PredNew;
168 let Inst{12-8} = !if(OpsRev,Rs,Rt);
169 let Inst{7} = PredNot;
174 class T_ALU32_combineh<string Op1, string Op2, bits<3> MajOp, bits<3> MinOp,
176 : T_ALU32_3op<"", MajOp, MinOp, OpsRev, 0> {
177 let AsmString = "$Rd = combine($Rs"#Op1#", $Rt"#Op2#")";
180 def A2_combine_hh : T_ALU32_combineh<".h", ".h", 0b011, 0b100, 1>;
181 def A2_combine_hl : T_ALU32_combineh<".h", ".l", 0b011, 0b101, 1>;
182 def A2_combine_lh : T_ALU32_combineh<".l", ".h", 0b011, 0b110, 1>;
183 def A2_combine_ll : T_ALU32_combineh<".l", ".l", 0b011, 0b111, 1>;
185 class T_ALU32_3op_sfx<string mnemonic, string suffix, bits<3> MajOp,
186 bits<3> MinOp, bit OpsRev, bit IsComm>
187 : T_ALU32_3op<"", MajOp, MinOp, OpsRev, IsComm> {
188 let AsmString = "$Rd = "#mnemonic#"($Rs, $Rt)"#suffix;
191 def A2_svaddh : T_ALU32_3op<"vaddh", 0b110, 0b000, 0, 1>;
192 def A2_svsubh : T_ALU32_3op<"vsubh", 0b110, 0b100, 1, 0>;
194 let Defs = [USR_OVF], Itinerary = ALU32_3op_tc_2_SLOT0123 in {
195 def A2_svaddhs : T_ALU32_3op_sfx<"vaddh", ":sat", 0b110, 0b001, 0, 1>;
196 def A2_addsat : T_ALU32_3op_sfx<"add", ":sat", 0b110, 0b010, 0, 1>;
197 def A2_svadduhs : T_ALU32_3op_sfx<"vadduh", ":sat", 0b110, 0b011, 0, 1>;
198 def A2_svsubhs : T_ALU32_3op_sfx<"vsubh", ":sat", 0b110, 0b101, 1, 0>;
199 def A2_subsat : T_ALU32_3op_sfx<"sub", ":sat", 0b110, 0b110, 1, 0>;
200 def A2_svsubuhs : T_ALU32_3op_sfx<"vsubuh", ":sat", 0b110, 0b111, 1, 0>;
203 let Itinerary = ALU32_3op_tc_2_SLOT0123 in
204 def A2_svavghs : T_ALU32_3op_sfx<"vavgh", ":rnd", 0b111, 0b001, 0, 1>;
206 def A2_svavgh : T_ALU32_3op<"vavgh", 0b111, 0b000, 0, 1>;
207 def A2_svnavgh : T_ALU32_3op<"vnavgh", 0b111, 0b011, 1, 0>;
209 multiclass T_ALU32_3op_p<string mnemonic, bits<3> MajOp, bits<3> MinOp,
211 def t : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 0, 0>;
212 def f : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 1, 0>;
213 def tnew : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 0, 1>;
214 def fnew : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 1, 1>;
217 multiclass T_ALU32_3op_A2<string mnemonic, bits<3> MajOp, bits<3> MinOp,
218 bit OpsRev, bit IsComm> {
219 let isPredicable = 1 in
220 def A2_#NAME : T_ALU32_3op <mnemonic, MajOp, MinOp, OpsRev, IsComm>;
221 defm A2_p#NAME : T_ALU32_3op_p<mnemonic, MajOp, MinOp, OpsRev>;
224 defm add : T_ALU32_3op_A2<"add", 0b011, 0b000, 0, 1>;
225 defm and : T_ALU32_3op_A2<"and", 0b001, 0b000, 0, 1>;
226 defm or : T_ALU32_3op_A2<"or", 0b001, 0b001, 0, 1>;
227 defm sub : T_ALU32_3op_A2<"sub", 0b011, 0b001, 1, 0>;
228 defm xor : T_ALU32_3op_A2<"xor", 0b001, 0b011, 0, 1>;
230 // Pats for instruction selection.
231 class BinOp32_pat<SDNode Op, InstHexagon MI, ValueType ResT>
232 : Pat<(ResT (Op (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))),
233 (ResT (MI IntRegs:$Rs, IntRegs:$Rt))>;
235 def: BinOp32_pat<add, A2_add, i32>;
236 def: BinOp32_pat<and, A2_and, i32>;
237 def: BinOp32_pat<or, A2_or, i32>;
238 def: BinOp32_pat<sub, A2_sub, i32>;
239 def: BinOp32_pat<xor, A2_xor, i32>;
241 // A few special cases producing register pairs:
242 let OutOperandList = (outs DoubleRegs:$Rd), hasNewValue = 0 in {
243 def S2_packhl : T_ALU32_3op <"packhl", 0b101, 0b100, 0, 0>;
245 let isPredicable = 1 in
246 def A2_combinew : T_ALU32_3op <"combine", 0b101, 0b000, 0, 0>;
248 // Conditional combinew uses "newt/f" instead of "t/fnew".
249 def C2_ccombinewt : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 0, 0>;
250 def C2_ccombinewf : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 1, 0>;
251 def C2_ccombinewnewt : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 0, 1>;
252 def C2_ccombinewnewf : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 1, 1>;
255 def: BinOp32_pat<HexagonCOMBINE, A2_combinew, i64>;
256 def: BinOp32_pat<HexagonPACKHL, S2_packhl, i64>;
258 let hasSideEffects = 0, hasNewValue = 1, isCompare = 1, InputType = "reg" in
259 class T_ALU32_3op_cmp<string mnemonic, bits<2> MinOp, bit IsNeg, bit IsComm>
260 : ALU32_rr<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
261 "$Pd = "#mnemonic#"($Rs, $Rt)",
262 [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel {
263 let CextOpcode = mnemonic;
264 let isCommutable = IsComm;
270 let Inst{27-24} = 0b0010;
271 let Inst{22-21} = MinOp;
272 let Inst{20-16} = Rs;
275 let Inst{3-2} = 0b00;
279 let Itinerary = ALU32_3op_tc_2early_SLOT0123 in {
280 def C2_cmpeq : T_ALU32_3op_cmp< "cmp.eq", 0b00, 0, 1>;
281 def C2_cmpgt : T_ALU32_3op_cmp< "cmp.gt", 0b10, 0, 0>;
282 def C2_cmpgtu : T_ALU32_3op_cmp< "cmp.gtu", 0b11, 0, 0>;
285 // Patfrag to convert the usual comparison patfrags (e.g. setlt) to ones
286 // that reverse the order of the operands.
287 class RevCmp<PatFrag F> : PatFrag<(ops node:$rhs, node:$lhs), F.Fragment>;
289 // Pats for compares. They use PatFrags as operands, not SDNodes,
290 // since seteq/setgt/etc. are defined as ParFrags.
291 class T_cmp32_rr_pat<InstHexagon MI, PatFrag Op, ValueType VT>
292 : Pat<(VT (Op (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))),
293 (VT (MI IntRegs:$Rs, IntRegs:$Rt))>;
295 def: T_cmp32_rr_pat<C2_cmpeq, seteq, i1>;
296 def: T_cmp32_rr_pat<C2_cmpgt, setgt, i1>;
297 def: T_cmp32_rr_pat<C2_cmpgtu, setugt, i1>;
299 def: T_cmp32_rr_pat<C2_cmpgt, RevCmp<setlt>, i1>;
300 def: T_cmp32_rr_pat<C2_cmpgtu, RevCmp<setult>, i1>;
302 let CextOpcode = "MUX", InputType = "reg", hasNewValue = 1 in
303 def C2_mux: ALU32_rr<(outs IntRegs:$Rd),
304 (ins PredRegs:$Pu, IntRegs:$Rs, IntRegs:$Rt),
305 "$Rd = mux($Pu, $Rs, $Rt)", [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel {
311 let CextOpcode = "mux";
312 let InputType = "reg";
313 let hasSideEffects = 0;
316 let Inst{27-24} = 0b0100;
317 let Inst{20-16} = Rs;
323 def: Pat<(i32 (select (i1 PredRegs:$Pu), (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))),
324 (C2_mux PredRegs:$Pu, IntRegs:$Rs, IntRegs:$Rt)>;
326 // Combines the two immediates into a double register.
327 // Increase complexity to make it greater than any complexity of a combine
328 // that involves a register.
330 let isReMaterializable = 1, isMoveImm = 1, isAsCheapAsAMove = 1,
331 isExtentSigned = 1, isExtendable = 1, opExtentBits = 8, opExtendable = 1,
332 AddedComplexity = 75 in
333 def A2_combineii: ALU32Inst <(outs DoubleRegs:$Rdd), (ins s8Ext:$s8, s8Imm:$S8),
334 "$Rdd = combine(#$s8, #$S8)",
335 [(set (i64 DoubleRegs:$Rdd),
336 (i64 (HexagonCOMBINE(i32 s32ImmPred:$s8), (i32 s8ImmPred:$S8))))]> {
342 let Inst{27-23} = 0b11000;
343 let Inst{22-16} = S8{7-1};
344 let Inst{13} = S8{0};
349 //===----------------------------------------------------------------------===//
350 // Template class for predicated ADD of a reg and an Immediate value.
351 //===----------------------------------------------------------------------===//
352 let hasNewValue = 1, hasSideEffects = 0 in
353 class T_Addri_Pred <bit PredNot, bit PredNew>
354 : ALU32_ri <(outs IntRegs:$Rd),
355 (ins PredRegs:$Pu, IntRegs:$Rs, s8Ext:$s8),
356 !if(PredNot, "if (!$Pu", "if ($Pu")#!if(PredNew,".new) $Rd = ",
357 ") $Rd = ")#"add($Rs, #$s8)"> {
363 let isPredicatedNew = PredNew;
366 let Inst{27-24} = 0b0100;
367 let Inst{23} = PredNot;
368 let Inst{22-21} = Pu;
369 let Inst{20-16} = Rs;
370 let Inst{13} = PredNew;
375 //===----------------------------------------------------------------------===//
376 // A2_addi: Add a signed immediate to a register.
377 //===----------------------------------------------------------------------===//
378 let hasNewValue = 1, hasSideEffects = 0 in
379 class T_Addri <Operand immOp>
380 : ALU32_ri <(outs IntRegs:$Rd),
381 (ins IntRegs:$Rs, immOp:$s16),
382 "$Rd = add($Rs, #$s16)", [], "", ALU32_ADDI_tc_1_SLOT0123> {
389 let Inst{27-21} = s16{15-9};
390 let Inst{20-16} = Rs;
391 let Inst{13-5} = s16{8-0};
395 //===----------------------------------------------------------------------===//
396 // Multiclass for ADD of a register and an immediate value.
397 //===----------------------------------------------------------------------===//
398 multiclass Addri_Pred<string mnemonic, bit PredNot> {
399 let isPredicatedFalse = PredNot in {
400 def NAME : T_Addri_Pred<PredNot, 0>;
402 def NAME#new : T_Addri_Pred<PredNot, 1>;
406 let isExtendable = 1, isExtentSigned = 1, InputType = "imm" in
407 multiclass Addri_base<string mnemonic, SDNode OpNode> {
408 let CextOpcode = mnemonic, BaseOpcode = mnemonic#_ri in {
409 let opExtendable = 2, opExtentBits = 16, isPredicable = 1 in
410 def A2_#NAME : T_Addri<s16Ext>;
412 let opExtendable = 3, opExtentBits = 8, isPredicated = 1 in {
413 defm A2_p#NAME#t : Addri_Pred<mnemonic, 0>;
414 defm A2_p#NAME#f : Addri_Pred<mnemonic, 1>;
419 defm addi : Addri_base<"add", add>, ImmRegRel, PredNewRel;
421 def: Pat<(i32 (add I32:$Rs, s32ImmPred:$s16)),
422 (i32 (A2_addi I32:$Rs, imm:$s16))>;
424 let hasNewValue = 1, hasSideEffects = 0, isPseudo = 1 in
426 : ALU32_ri <(outs IntRegs:$Rd),
427 (ins s23_2Imm:$s23_2),
428 "$Rd = iconst(#$s23_2)"> {}
430 //===----------------------------------------------------------------------===//
431 // Template class used for the following ALU32 instructions.
434 //===----------------------------------------------------------------------===//
435 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 10,
436 InputType = "imm", hasNewValue = 1 in
437 class T_ALU32ri_logical <string mnemonic, SDNode OpNode, bits<2> MinOp>
438 : ALU32_ri <(outs IntRegs:$Rd),
439 (ins IntRegs:$Rs, s10Ext:$s10),
440 "$Rd = "#mnemonic#"($Rs, #$s10)" ,
441 [(set (i32 IntRegs:$Rd), (OpNode (i32 IntRegs:$Rs), s32ImmPred:$s10))]> {
445 let CextOpcode = mnemonic;
449 let Inst{27-24} = 0b0110;
450 let Inst{23-22} = MinOp;
451 let Inst{21} = s10{9};
452 let Inst{20-16} = Rs;
453 let Inst{13-5} = s10{8-0};
457 def A2_orir : T_ALU32ri_logical<"or", or, 0b10>, ImmRegRel;
458 def A2_andir : T_ALU32ri_logical<"and", and, 0b00>, ImmRegRel;
460 // Subtract register from immediate
461 // Rd32=sub(#s10,Rs32)
462 let isExtendable = 1, CextOpcode = "sub", opExtendable = 1, isExtentSigned = 1,
463 opExtentBits = 10, InputType = "imm", hasNewValue = 1, hasSideEffects = 0 in
464 def A2_subri: ALU32_ri <(outs IntRegs:$Rd), (ins s10Ext:$s10, IntRegs:$Rs),
465 "$Rd = sub(#$s10, $Rs)", []>, ImmRegRel {
472 let Inst{27-22} = 0b011001;
473 let Inst{21} = s10{9};
474 let Inst{20-16} = Rs;
475 let Inst{13-5} = s10{8-0};
480 let hasSideEffects = 0 in
481 def A2_nop: ALU32Inst <(outs), (ins), "nop" > {
483 let Inst{27-24} = 0b1111;
486 def: Pat<(sub s32ImmPred:$s10, IntRegs:$Rs),
487 (A2_subri imm:$s10, IntRegs:$Rs)>;
489 // Rd = not(Rs) gets mapped to Rd=sub(#-1, Rs).
490 def: Pat<(not (i32 IntRegs:$src1)),
491 (A2_subri -1, IntRegs:$src1)>;
493 let hasSideEffects = 0, hasNewValue = 1 in
494 class T_tfr16<bit isHi>
495 : ALU32Inst <(outs IntRegs:$Rx), (ins IntRegs:$src1, u16Imm:$u16),
496 "$Rx"#!if(isHi, ".h", ".l")#" = #$u16",
497 [], "$src1 = $Rx" > {
502 let Inst{27-26} = 0b00;
503 let Inst{25-24} = !if(isHi, 0b10, 0b01);
504 let Inst{23-22} = u16{15-14};
506 let Inst{20-16} = Rx;
507 let Inst{13-0} = u16{13-0};
510 def A2_tfril: T_tfr16<0>;
511 def A2_tfrih: T_tfr16<1>;
513 // Conditional transfer is an alias to conditional "Rd = add(Rs, #0)".
514 let isPredicated = 1, hasNewValue = 1, opNewValue = 0 in
515 class T_tfr_pred<bit isPredNot, bit isPredNew>
516 : ALU32Inst<(outs IntRegs:$dst),
517 (ins PredRegs:$src1, IntRegs:$src2),
518 "if ("#!if(isPredNot, "!", "")#
519 "$src1"#!if(isPredNew, ".new", "")#
525 let isPredicatedFalse = isPredNot;
526 let isPredicatedNew = isPredNew;
529 let Inst{27-24} = 0b0100;
530 let Inst{23} = isPredNot;
531 let Inst{13} = isPredNew;
534 let Inst{22-21} = src1;
535 let Inst{20-16} = src2;
538 let isPredicable = 1 in
539 class T_tfr : ALU32Inst<(outs IntRegs:$dst), (ins IntRegs:$src),
546 let Inst{27-21} = 0b0000011;
547 let Inst{20-16} = src;
552 let InputType = "reg", hasNewValue = 1, hasSideEffects = 0 in
553 multiclass tfr_base<string CextOp> {
554 let CextOpcode = CextOp, BaseOpcode = CextOp in {
558 def t : T_tfr_pred<0, 0>;
559 def f : T_tfr_pred<1, 0>;
561 def tnew : T_tfr_pred<0, 1>;
562 def fnew : T_tfr_pred<1, 1>;
566 // Assembler mapped to C2_ccombinew[t|f|newt|newf].
567 // Please don't add bits to this instruction as it'll be converted into
568 // 'combine' before object code emission.
569 let isPredicated = 1 in
570 class T_tfrp_pred<bit PredNot, bit PredNew>
571 : ALU32_rr <(outs DoubleRegs:$dst),
572 (ins PredRegs:$src1, DoubleRegs:$src2),
573 "if ("#!if(PredNot, "!", "")#"$src1"
574 #!if(PredNew, ".new", "")#") $dst = $src2" > {
575 let isPredicatedFalse = PredNot;
576 let isPredicatedNew = PredNew;
579 // Assembler mapped to A2_combinew.
580 // Please don't add bits to this instruction as it'll be converted into
581 // 'combine' before object code emission.
582 class T_tfrp : ALU32Inst <(outs DoubleRegs:$dst),
583 (ins DoubleRegs:$src),
586 let hasSideEffects = 0 in
587 multiclass TFR64_base<string BaseName> {
588 let BaseOpcode = BaseName in {
589 let isPredicable = 1 in
592 def t : T_tfrp_pred <0, 0>;
593 def f : T_tfrp_pred <1, 0>;
595 def tnew : T_tfrp_pred <0, 1>;
596 def fnew : T_tfrp_pred <1, 1>;
600 let InputType = "imm", isExtendable = 1, isExtentSigned = 1, opExtentBits = 12,
601 isMoveImm = 1, opExtendable = 2, BaseOpcode = "TFRI", CextOpcode = "TFR",
602 hasSideEffects = 0, isPredicated = 1, hasNewValue = 1 in
603 class T_TFRI_Pred<bit PredNot, bit PredNew>
604 : ALU32_ri<(outs IntRegs:$Rd), (ins PredRegs:$Pu, s12Ext:$s12),
605 "if ("#!if(PredNot,"!","")#"$Pu"#!if(PredNew,".new","")#") $Rd = #$s12",
606 [], "", ALU32_2op_tc_1_SLOT0123>, ImmRegRel, PredNewRel {
607 let isPredicatedFalse = PredNot;
608 let isPredicatedNew = PredNew;
615 let Inst{27-24} = 0b1110;
616 let Inst{23} = PredNot;
617 let Inst{22-21} = Pu;
619 let Inst{19-16,12-5} = s12;
620 let Inst{13} = PredNew;
624 def C2_cmoveit : T_TFRI_Pred<0, 0>;
625 def C2_cmoveif : T_TFRI_Pred<1, 0>;
626 def C2_cmovenewit : T_TFRI_Pred<0, 1>;
627 def C2_cmovenewif : T_TFRI_Pred<1, 1>;
629 let InputType = "imm", isExtendable = 1, isExtentSigned = 1,
630 CextOpcode = "TFR", BaseOpcode = "TFRI", hasNewValue = 1, opNewValue = 0,
631 isAsCheapAsAMove = 1 , opExtendable = 1, opExtentBits = 16, isMoveImm = 1,
632 isPredicated = 0, isPredicable = 1, isReMaterializable = 1 in
633 def A2_tfrsi : ALU32Inst<(outs IntRegs:$Rd), (ins s16Ext:$s16), "$Rd = #$s16",
634 [(set (i32 IntRegs:$Rd), s32ImmPred:$s16)], "", ALU32_2op_tc_1_SLOT0123>,
640 let Inst{27-24} = 0b1000;
641 let Inst{23-22,20-16,13-5} = s16;
645 defm A2_tfr : tfr_base<"TFR">, ImmRegRel, PredNewRel;
646 let isAsmParserOnly = 1 in
647 defm A2_tfrp : TFR64_base<"TFR64">, PredNewRel;
650 let isReMaterializable = 1, isMoveImm = 1, isAsCheapAsAMove = 1,
651 isAsmParserOnly = 1 in
652 def A2_tfrpi : ALU64_rr<(outs DoubleRegs:$dst), (ins s8Imm64:$src1),
654 [(set (i64 DoubleRegs:$dst), s8Imm64Pred:$src1)]>;
656 // TODO: see if this instruction can be deleted..
657 let isExtendable = 1, opExtendable = 1, opExtentBits = 6,
658 isAsmParserOnly = 1 in {
659 def TFRI64_V4 : ALU64_rr<(outs DoubleRegs:$dst), (ins u64Imm:$src1),
661 def TFRI64_V2_ext : ALU64_rr<(outs DoubleRegs:$dst),
662 (ins s8Ext:$src1, s8Imm:$src2),
663 "$dst = combine(##$src1, #$src2)">;
666 //===----------------------------------------------------------------------===//
668 //===----------------------------------------------------------------------===//
671 //===----------------------------------------------------------------------===//
673 //===----------------------------------------------------------------------===//
674 // Scalar mux register immediate.
675 let hasSideEffects = 0, isExtentSigned = 1, CextOpcode = "MUX",
676 InputType = "imm", hasNewValue = 1, isExtendable = 1, opExtentBits = 8 in
677 class T_MUX1 <bit MajOp, dag ins, string AsmStr>
678 : ALU32Inst <(outs IntRegs:$Rd), ins, AsmStr>, ImmRegRel {
685 let Inst{27-24} = 0b0011;
686 let Inst{23} = MajOp;
687 let Inst{22-21} = Pu;
688 let Inst{20-16} = Rs;
694 let opExtendable = 2 in
695 def C2_muxri : T_MUX1<0b1, (ins PredRegs:$Pu, s8Ext:$s8, IntRegs:$Rs),
696 "$Rd = mux($Pu, #$s8, $Rs)">;
698 let opExtendable = 3 in
699 def C2_muxir : T_MUX1<0b0, (ins PredRegs:$Pu, IntRegs:$Rs, s8Ext:$s8),
700 "$Rd = mux($Pu, $Rs, #$s8)">;
702 def : Pat<(i32 (select I1:$Pu, s32ImmPred:$s8, I32:$Rs)),
703 (C2_muxri I1:$Pu, s32ImmPred:$s8, I32:$Rs)>;
705 def : Pat<(i32 (select I1:$Pu, I32:$Rs, s32ImmPred:$s8)),
706 (C2_muxir I1:$Pu, I32:$Rs, s32ImmPred:$s8)>;
708 // C2_muxii: Scalar mux immediates.
709 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1,
710 opExtentBits = 8, opExtendable = 2 in
711 def C2_muxii: ALU32Inst <(outs IntRegs:$Rd),
712 (ins PredRegs:$Pu, s8Ext:$s8, s8Imm:$S8),
713 "$Rd = mux($Pu, #$s8, #$S8)" ,
714 [(set (i32 IntRegs:$Rd),
715 (i32 (select I1:$Pu, s32ImmPred:$s8, s8ImmPred:$S8)))] > {
723 let Inst{27-25} = 0b101;
724 let Inst{24-23} = Pu;
725 let Inst{22-16} = S8{7-1};
726 let Inst{13} = S8{0};
731 let isCodeGenOnly = 1, isPseudo = 1 in
732 def PS_pselect : ALU64_rr<(outs DoubleRegs:$Rd),
733 (ins PredRegs:$Pu, DoubleRegs:$Rs, DoubleRegs:$Rt),
734 ".error \"should not emit\" ", []>;
737 //===----------------------------------------------------------------------===//
738 // template class for non-predicated alu32_2op instructions
739 // - aslh, asrh, sxtb, sxth, zxth
740 //===----------------------------------------------------------------------===//
741 let hasNewValue = 1, opNewValue = 0 in
742 class T_ALU32_2op <string mnemonic, bits<3> minOp> :
743 ALU32Inst <(outs IntRegs:$Rd), (ins IntRegs:$Rs),
744 "$Rd = "#mnemonic#"($Rs)", [] > {
750 let Inst{27-24} = 0b0000;
751 let Inst{23-21} = minOp;
754 let Inst{20-16} = Rs;
757 //===----------------------------------------------------------------------===//
758 // template class for predicated alu32_2op instructions
759 // - aslh, asrh, sxtb, sxth, zxtb, zxth
760 //===----------------------------------------------------------------------===//
761 let hasSideEffects = 0, hasNewValue = 1, opNewValue = 0 in
762 class T_ALU32_2op_Pred <string mnemonic, bits<3> minOp, bit isPredNot,
764 ALU32Inst <(outs IntRegs:$Rd), (ins PredRegs:$Pu, IntRegs:$Rs),
765 !if(isPredNot, "if (!$Pu", "if ($Pu")
766 #!if(isPredNew, ".new) ",") ")#"$Rd = "#mnemonic#"($Rs)"> {
773 let Inst{27-24} = 0b0000;
774 let Inst{23-21} = minOp;
776 let Inst{11} = isPredNot;
777 let Inst{10} = isPredNew;
780 let Inst{20-16} = Rs;
783 multiclass ALU32_2op_Pred<string mnemonic, bits<3> minOp, bit PredNot> {
784 let isPredicatedFalse = PredNot in {
785 def NAME : T_ALU32_2op_Pred<mnemonic, minOp, PredNot, 0>;
788 let isPredicatedNew = 1 in
789 def NAME#new : T_ALU32_2op_Pred<mnemonic, minOp, PredNot, 1>;
793 multiclass ALU32_2op_base<string mnemonic, bits<3> minOp> {
794 let BaseOpcode = mnemonic in {
795 let isPredicable = 1, hasSideEffects = 0 in
796 def A2_#NAME : T_ALU32_2op<mnemonic, minOp>;
798 let isPredicated = 1, hasSideEffects = 0 in {
799 defm A4_p#NAME#t : ALU32_2op_Pred<mnemonic, minOp, 0>;
800 defm A4_p#NAME#f : ALU32_2op_Pred<mnemonic, minOp, 1>;
805 defm aslh : ALU32_2op_base<"aslh", 0b000>, PredNewRel;
806 defm asrh : ALU32_2op_base<"asrh", 0b001>, PredNewRel;
807 defm sxtb : ALU32_2op_base<"sxtb", 0b101>, PredNewRel;
808 defm sxth : ALU32_2op_base<"sxth", 0b111>, PredNewRel;
809 defm zxth : ALU32_2op_base<"zxth", 0b110>, PredNewRel;
811 // Rd=zxtb(Rs): assembler mapped to Rd=and(Rs,#255).
812 // Compiler would want to generate 'zxtb' instead of 'and' becuase 'zxtb' has
813 // predicated forms while 'and' doesn't. Since integrated assembler can't
814 // handle 'mapped' instructions, we need to encode 'zxtb' same as 'and' where
815 // immediate operand is set to '255'.
817 let hasNewValue = 1, opNewValue = 0 in
818 class T_ZXTB: ALU32Inst < (outs IntRegs:$Rd), (ins IntRegs:$Rs),
819 "$Rd = zxtb($Rs)", [] > { // Rd = and(Rs,255)
826 let Inst{27-22} = 0b011000;
828 let Inst{20-16} = Rs;
829 let Inst{21} = s10{9};
830 let Inst{13-5} = s10{8-0};
833 //Rd=zxtb(Rs): assembler mapped to "Rd=and(Rs,#255)
834 multiclass ZXTB_base <string mnemonic, bits<3> minOp> {
835 let BaseOpcode = mnemonic in {
836 let isPredicable = 1, hasSideEffects = 0 in
837 def A2_#NAME : T_ZXTB;
839 let isPredicated = 1, hasSideEffects = 0 in {
840 defm A4_p#NAME#t : ALU32_2op_Pred<mnemonic, minOp, 0>;
841 defm A4_p#NAME#f : ALU32_2op_Pred<mnemonic, minOp, 1>;
846 defm zxtb : ZXTB_base<"zxtb",0b100>, PredNewRel;
848 def: Pat<(shl I32:$src1, (i32 16)), (A2_aslh I32:$src1)>;
849 def: Pat<(sra I32:$src1, (i32 16)), (A2_asrh I32:$src1)>;
850 def: Pat<(sext_inreg I32:$src1, i8), (A2_sxtb I32:$src1)>;
851 def: Pat<(sext_inreg I32:$src1, i16), (A2_sxth I32:$src1)>;
853 //===----------------------------------------------------------------------===//
854 // Template class for vector add and avg
855 //===----------------------------------------------------------------------===//
857 class T_VectALU_64 <string opc, bits<3> majOp, bits<3> minOp,
858 bit isSat, bit isRnd, bit isCrnd, bit SwapOps >
859 : ALU64_rr < (outs DoubleRegs:$Rdd),
860 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
861 "$Rdd = "#opc#"($Rss, $Rtt)"#!if(isRnd, ":rnd", "")
862 #!if(isCrnd,":crnd","")
863 #!if(isSat, ":sat", ""),
864 [], "", ALU64_tc_2_SLOT23 > {
871 let Inst{27-24} = 0b0011;
872 let Inst{23-21} = majOp;
873 let Inst{20-16} = !if (SwapOps, Rtt, Rss);
874 let Inst{12-8} = !if (SwapOps, Rss, Rtt);
875 let Inst{7-5} = minOp;
879 // ALU64 - Vector add
880 // Rdd=vadd[u][bhw](Rss,Rtt)
881 let Itinerary = ALU64_tc_1_SLOT23 in {
882 def A2_vaddub : T_VectALU_64 < "vaddub", 0b000, 0b000, 0, 0, 0, 0>;
883 def A2_vaddh : T_VectALU_64 < "vaddh", 0b000, 0b010, 0, 0, 0, 0>;
884 def A2_vaddw : T_VectALU_64 < "vaddw", 0b000, 0b101, 0, 0, 0, 0>;
887 // Rdd=vadd[u][bhw](Rss,Rtt):sat
888 let Defs = [USR_OVF] in {
889 def A2_vaddubs : T_VectALU_64 < "vaddub", 0b000, 0b001, 1, 0, 0, 0>;
890 def A2_vaddhs : T_VectALU_64 < "vaddh", 0b000, 0b011, 1, 0, 0, 0>;
891 def A2_vadduhs : T_VectALU_64 < "vadduh", 0b000, 0b100, 1, 0, 0, 0>;
892 def A2_vaddws : T_VectALU_64 < "vaddw", 0b000, 0b110, 1, 0, 0, 0>;
895 // ALU64 - Vector average
896 // Rdd=vavg[u][bhw](Rss,Rtt)
897 let Itinerary = ALU64_tc_1_SLOT23 in {
898 def A2_vavgub : T_VectALU_64 < "vavgub", 0b010, 0b000, 0, 0, 0, 0>;
899 def A2_vavgh : T_VectALU_64 < "vavgh", 0b010, 0b010, 0, 0, 0, 0>;
900 def A2_vavguh : T_VectALU_64 < "vavguh", 0b010, 0b101, 0, 0, 0, 0>;
901 def A2_vavgw : T_VectALU_64 < "vavgw", 0b011, 0b000, 0, 0, 0, 0>;
902 def A2_vavguw : T_VectALU_64 < "vavguw", 0b011, 0b011, 0, 0, 0, 0>;
905 // Rdd=vavg[u][bhw](Rss,Rtt)[:rnd|:crnd]
906 def A2_vavgubr : T_VectALU_64 < "vavgub", 0b010, 0b001, 0, 1, 0, 0>;
907 def A2_vavghr : T_VectALU_64 < "vavgh", 0b010, 0b011, 0, 1, 0, 0>;
908 def A2_vavghcr : T_VectALU_64 < "vavgh", 0b010, 0b100, 0, 0, 1, 0>;
909 def A2_vavguhr : T_VectALU_64 < "vavguh", 0b010, 0b110, 0, 1, 0, 0>;
911 def A2_vavgwr : T_VectALU_64 < "vavgw", 0b011, 0b001, 0, 1, 0, 0>;
912 def A2_vavgwcr : T_VectALU_64 < "vavgw", 0b011, 0b010, 0, 0, 1, 0>;
913 def A2_vavguwr : T_VectALU_64 < "vavguw", 0b011, 0b100, 0, 1, 0, 0>;
915 // Rdd=vnavg[bh](Rss,Rtt)
916 let Itinerary = ALU64_tc_1_SLOT23 in {
917 def A2_vnavgh : T_VectALU_64 < "vnavgh", 0b100, 0b000, 0, 0, 0, 1>;
918 def A2_vnavgw : T_VectALU_64 < "vnavgw", 0b100, 0b011, 0, 0, 0, 1>;
921 // Rdd=vnavg[bh](Rss,Rtt)[:rnd|:crnd]:sat
922 let Defs = [USR_OVF] in {
923 def A2_vnavghr : T_VectALU_64 < "vnavgh", 0b100, 0b001, 1, 1, 0, 1>;
924 def A2_vnavghcr : T_VectALU_64 < "vnavgh", 0b100, 0b010, 1, 0, 1, 1>;
925 def A2_vnavgwr : T_VectALU_64 < "vnavgw", 0b100, 0b100, 1, 1, 0, 1>;
926 def A2_vnavgwcr : T_VectALU_64 < "vnavgw", 0b100, 0b110, 1, 0, 1, 1>;
929 // Rdd=vsub[u][bh](Rss,Rtt)
930 let Itinerary = ALU64_tc_1_SLOT23 in {
931 def A2_vsubub : T_VectALU_64 < "vsubub", 0b001, 0b000, 0, 0, 0, 1>;
932 def A2_vsubh : T_VectALU_64 < "vsubh", 0b001, 0b010, 0, 0, 0, 1>;
933 def A2_vsubw : T_VectALU_64 < "vsubw", 0b001, 0b101, 0, 0, 0, 1>;
936 // Rdd=vsub[u][bh](Rss,Rtt):sat
937 let Defs = [USR_OVF] in {
938 def A2_vsububs : T_VectALU_64 < "vsubub", 0b001, 0b001, 1, 0, 0, 1>;
939 def A2_vsubhs : T_VectALU_64 < "vsubh", 0b001, 0b011, 1, 0, 0, 1>;
940 def A2_vsubuhs : T_VectALU_64 < "vsubuh", 0b001, 0b100, 1, 0, 0, 1>;
941 def A2_vsubws : T_VectALU_64 < "vsubw", 0b001, 0b110, 1, 0, 0, 1>;
944 // Rdd=vmax[u][bhw](Rss,Rtt)
945 def A2_vmaxb : T_VectALU_64 < "vmaxb", 0b110, 0b110, 0, 0, 0, 1>;
946 def A2_vmaxub : T_VectALU_64 < "vmaxub", 0b110, 0b000, 0, 0, 0, 1>;
947 def A2_vmaxh : T_VectALU_64 < "vmaxh", 0b110, 0b001, 0, 0, 0, 1>;
948 def A2_vmaxuh : T_VectALU_64 < "vmaxuh", 0b110, 0b010, 0, 0, 0, 1>;
949 def A2_vmaxw : T_VectALU_64 < "vmaxw", 0b110, 0b011, 0, 0, 0, 1>;
950 def A2_vmaxuw : T_VectALU_64 < "vmaxuw", 0b101, 0b101, 0, 0, 0, 1>;
952 // Rdd=vmin[u][bhw](Rss,Rtt)
953 def A2_vminb : T_VectALU_64 < "vminb", 0b110, 0b111, 0, 0, 0, 1>;
954 def A2_vminub : T_VectALU_64 < "vminub", 0b101, 0b000, 0, 0, 0, 1>;
955 def A2_vminh : T_VectALU_64 < "vminh", 0b101, 0b001, 0, 0, 0, 1>;
956 def A2_vminuh : T_VectALU_64 < "vminuh", 0b101, 0b010, 0, 0, 0, 1>;
957 def A2_vminw : T_VectALU_64 < "vminw", 0b101, 0b011, 0, 0, 0, 1>;
958 def A2_vminuw : T_VectALU_64 < "vminuw", 0b101, 0b100, 0, 0, 0, 1>;
960 //===----------------------------------------------------------------------===//
961 // Template class for vector compare
962 //===----------------------------------------------------------------------===//
963 let hasSideEffects = 0 in
964 class T_vcmp <string Str, bits<4> minOp>
965 : ALU64_rr <(outs PredRegs:$Pd),
966 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
967 "$Pd = "#Str#"($Rss, $Rtt)", [],
968 "", ALU64_tc_2early_SLOT23> {
975 let Inst{27-23} = 0b00100;
976 let Inst{13} = minOp{3};
977 let Inst{7-5} = minOp{2-0};
979 let Inst{20-16} = Rss;
980 let Inst{12-8} = Rtt;
983 class T_vcmp_pat<InstHexagon MI, PatFrag Op, ValueType T>
984 : Pat<(i1 (Op (T DoubleRegs:$Rss), (T DoubleRegs:$Rtt))),
985 (i1 (MI DoubleRegs:$Rss, DoubleRegs:$Rtt))>;
987 // Vector compare bytes
988 def A2_vcmpbeq : T_vcmp <"vcmpb.eq", 0b0110>;
989 def A2_vcmpbgtu : T_vcmp <"vcmpb.gtu", 0b0111>;
991 // Vector compare halfwords
992 def A2_vcmpheq : T_vcmp <"vcmph.eq", 0b0011>;
993 def A2_vcmphgt : T_vcmp <"vcmph.gt", 0b0100>;
994 def A2_vcmphgtu : T_vcmp <"vcmph.gtu", 0b0101>;
996 // Vector compare words
997 def A2_vcmpweq : T_vcmp <"vcmpw.eq", 0b0000>;
998 def A2_vcmpwgt : T_vcmp <"vcmpw.gt", 0b0001>;
999 def A2_vcmpwgtu : T_vcmp <"vcmpw.gtu", 0b0010>;
1001 def: T_vcmp_pat<A2_vcmpbeq, seteq, v8i8>;
1002 def: T_vcmp_pat<A2_vcmpbgtu, setugt, v8i8>;
1003 def: T_vcmp_pat<A2_vcmpheq, seteq, v4i16>;
1004 def: T_vcmp_pat<A2_vcmphgt, setgt, v4i16>;
1005 def: T_vcmp_pat<A2_vcmphgtu, setugt, v4i16>;
1006 def: T_vcmp_pat<A2_vcmpweq, seteq, v2i32>;
1007 def: T_vcmp_pat<A2_vcmpwgt, setgt, v2i32>;
1008 def: T_vcmp_pat<A2_vcmpwgtu, setugt, v2i32>;
1010 //===----------------------------------------------------------------------===//
1012 //===----------------------------------------------------------------------===//
1015 //===----------------------------------------------------------------------===//
1017 //===----------------------------------------------------------------------===//
1018 // No bits needed. If cmp.ge is found the assembler parser will
1019 // transform it to cmp.gt subtracting 1 from the immediate.
1020 let isPseudo = 1 in {
1021 def C2_cmpgei: ALU32Inst <
1022 (outs PredRegs:$Pd), (ins IntRegs:$Rs, s8Ext:$s8),
1023 "$Pd = cmp.ge($Rs, #$s8)">;
1024 def C2_cmpgeui: ALU32Inst <
1025 (outs PredRegs:$Pd), (ins IntRegs:$Rs, u8Ext:$s8),
1026 "$Pd = cmp.geu($Rs, #$s8)">;
1030 //===----------------------------------------------------------------------===//
1032 //===----------------------------------------------------------------------===//
1035 //===----------------------------------------------------------------------===//
1037 //===----------------------------------------------------------------------===//
1039 //===----------------------------------------------------------------------===//
1041 // Add/Subtract halfword
1042 // Rd=add(Rt.L,Rs.[HL])[:sat]
1043 // Rd=sub(Rt.L,Rs.[HL])[:sat]
1044 // Rd=add(Rt.[LH],Rs.[HL])[:sat][:<16]
1045 // Rd=sub(Rt.[LH],Rs.[HL])[:sat][:<16]
1046 //===----------------------------------------------------------------------===//
1048 let hasNewValue = 1, opNewValue = 0 in
1049 class T_XTYPE_ADD_SUB <bits<2> LHbits, bit isSat, bit hasShift, bit isSub>
1050 : ALU64Inst <(outs IntRegs:$Rd), (ins IntRegs:$Rt, IntRegs:$Rs),
1051 "$Rd = "#!if(isSub,"sub","add")#"($Rt."
1052 #!if(hasShift, !if(LHbits{1},"h","l"),"l") #", $Rs."
1053 #!if(hasShift, !if(LHbits{0},"h)","l)"), !if(LHbits{1},"h)","l)"))
1054 #!if(isSat,":sat","")
1055 #!if(hasShift,":<<16",""), [], "", ALU64_tc_1_SLOT23> {
1059 let IClass = 0b1101;
1061 let Inst{27-23} = 0b01010;
1062 let Inst{22} = hasShift;
1063 let Inst{21} = isSub;
1064 let Inst{7} = isSat;
1065 let Inst{6-5} = LHbits;
1067 let Inst{12-8} = Rt;
1068 let Inst{20-16} = Rs;
1071 //Rd=sub(Rt.L,Rs.[LH])
1072 def A2_subh_l16_ll : T_XTYPE_ADD_SUB <0b00, 0, 0, 1>;
1073 def A2_subh_l16_hl : T_XTYPE_ADD_SUB <0b10, 0, 0, 1>;
1075 //Rd=add(Rt.L,Rs.[LH])
1076 def A2_addh_l16_ll : T_XTYPE_ADD_SUB <0b00, 0, 0, 0>;
1077 def A2_addh_l16_hl : T_XTYPE_ADD_SUB <0b10, 0, 0, 0>;
1079 let Itinerary = ALU64_tc_2_SLOT23, Defs = [USR_OVF] in {
1080 //Rd=sub(Rt.L,Rs.[LH]):sat
1081 def A2_subh_l16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 0, 1>;
1082 def A2_subh_l16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 0, 1>;
1084 //Rd=add(Rt.L,Rs.[LH]):sat
1085 def A2_addh_l16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 0, 0>;
1086 def A2_addh_l16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 0, 0>;
1089 //Rd=sub(Rt.[LH],Rs.[LH]):<<16
1090 def A2_subh_h16_ll : T_XTYPE_ADD_SUB <0b00, 0, 1, 1>;
1091 def A2_subh_h16_lh : T_XTYPE_ADD_SUB <0b01, 0, 1, 1>;
1092 def A2_subh_h16_hl : T_XTYPE_ADD_SUB <0b10, 0, 1, 1>;
1093 def A2_subh_h16_hh : T_XTYPE_ADD_SUB <0b11, 0, 1, 1>;
1095 //Rd=add(Rt.[LH],Rs.[LH]):<<16
1096 def A2_addh_h16_ll : T_XTYPE_ADD_SUB <0b00, 0, 1, 0>;
1097 def A2_addh_h16_lh : T_XTYPE_ADD_SUB <0b01, 0, 1, 0>;
1098 def A2_addh_h16_hl : T_XTYPE_ADD_SUB <0b10, 0, 1, 0>;
1099 def A2_addh_h16_hh : T_XTYPE_ADD_SUB <0b11, 0, 1, 0>;
1101 let Itinerary = ALU64_tc_2_SLOT23, Defs = [USR_OVF] in {
1102 //Rd=sub(Rt.[LH],Rs.[LH]):sat:<<16
1103 def A2_subh_h16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 1, 1>;
1104 def A2_subh_h16_sat_lh : T_XTYPE_ADD_SUB <0b01, 1, 1, 1>;
1105 def A2_subh_h16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 1, 1>;
1106 def A2_subh_h16_sat_hh : T_XTYPE_ADD_SUB <0b11, 1, 1, 1>;
1108 //Rd=add(Rt.[LH],Rs.[LH]):sat:<<16
1109 def A2_addh_h16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 1, 0>;
1110 def A2_addh_h16_sat_lh : T_XTYPE_ADD_SUB <0b01, 1, 1, 0>;
1111 def A2_addh_h16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 1, 0>;
1112 def A2_addh_h16_sat_hh : T_XTYPE_ADD_SUB <0b11, 1, 1, 0>;
1116 def: Pat<(sext_inreg (add I32:$src1, I32:$src2), i16),
1117 (A2_addh_l16_ll I32:$src1, I32:$src2)>;
1119 def: Pat<(sra (add (shl I32:$src1, (i32 16)), I32:$src2), (i32 16)),
1120 (A2_addh_l16_hl I32:$src1, I32:$src2)>;
1122 def: Pat<(shl (add I32:$src1, I32:$src2), (i32 16)),
1123 (A2_addh_h16_ll I32:$src1, I32:$src2)>;
1125 // Subtract halfword.
1126 def: Pat<(sext_inreg (sub I32:$src1, I32:$src2), i16),
1127 (A2_subh_l16_ll I32:$src1, I32:$src2)>;
1129 def: Pat<(shl (sub I32:$src1, I32:$src2), (i32 16)),
1130 (A2_subh_h16_ll I32:$src1, I32:$src2)>;
1132 let hasSideEffects = 0, hasNewValue = 1 in
1133 def S2_parityp: ALU64Inst<(outs IntRegs:$Rd),
1134 (ins DoubleRegs:$Rs, DoubleRegs:$Rt),
1135 "$Rd = parity($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1140 let IClass = 0b1101;
1141 let Inst{27-24} = 0b0000;
1142 let Inst{20-16} = Rs;
1143 let Inst{12-8} = Rt;
1147 let hasNewValue = 1, opNewValue = 0, hasSideEffects = 0 in
1148 class T_XTYPE_MIN_MAX < bit isMax, bit isUnsigned >
1149 : ALU64Inst < (outs IntRegs:$Rd), (ins IntRegs:$Rt, IntRegs:$Rs),
1150 "$Rd = "#!if(isMax,"max","min")#!if(isUnsigned,"u","")
1151 #"($Rt, $Rs)", [], "", ALU64_tc_2_SLOT23> {
1156 let IClass = 0b1101;
1158 let Inst{27-23} = 0b01011;
1159 let Inst{22-21} = !if(isMax, 0b10, 0b01);
1160 let Inst{7} = isUnsigned;
1162 let Inst{12-8} = !if(isMax, Rs, Rt);
1163 let Inst{20-16} = !if(isMax, Rt, Rs);
1166 def A2_min : T_XTYPE_MIN_MAX < 0, 0 >;
1167 def A2_minu : T_XTYPE_MIN_MAX < 0, 1 >;
1168 def A2_max : T_XTYPE_MIN_MAX < 1, 0 >;
1169 def A2_maxu : T_XTYPE_MIN_MAX < 1, 1 >;
1171 // Here, depending on the operand being selected, we'll either generate a
1172 // min or max instruction.
1174 // (a>b)?a:b --> max(a,b) => Here check performed is '>' and the value selected
1175 // is the larger of two. So, the corresponding HexagonInst is passed in 'Inst'.
1176 // (a>b)?b:a --> min(a,b) => Here check performed is '>' but the smaller value
1177 // is selected and the corresponding HexagonInst is passed in 'SwapInst'.
1179 multiclass T_MinMax_pats <PatFrag Op, RegisterClass RC, ValueType VT,
1180 InstHexagon Inst, InstHexagon SwapInst> {
1181 def: Pat<(select (i1 (Op (VT RC:$src1), (VT RC:$src2))),
1182 (VT RC:$src1), (VT RC:$src2)),
1183 (Inst RC:$src1, RC:$src2)>;
1184 def: Pat<(select (i1 (Op (VT RC:$src1), (VT RC:$src2))),
1185 (VT RC:$src2), (VT RC:$src1)),
1186 (SwapInst RC:$src1, RC:$src2)>;
1190 multiclass MinMax_pats <PatFrag Op, InstHexagon Inst, InstHexagon SwapInst> {
1191 defm: T_MinMax_pats<Op, IntRegs, i32, Inst, SwapInst>;
1193 def: Pat<(sext_inreg (i32 (select (i1 (Op (i32 PositiveHalfWord:$src1),
1194 (i32 PositiveHalfWord:$src2))),
1195 (i32 PositiveHalfWord:$src1),
1196 (i32 PositiveHalfWord:$src2))), i16),
1197 (Inst IntRegs:$src1, IntRegs:$src2)>;
1199 def: Pat<(sext_inreg (i32 (select (i1 (Op (i32 PositiveHalfWord:$src1),
1200 (i32 PositiveHalfWord:$src2))),
1201 (i32 PositiveHalfWord:$src2),
1202 (i32 PositiveHalfWord:$src1))), i16),
1203 (SwapInst IntRegs:$src1, IntRegs:$src2)>;
1206 let AddedComplexity = 200 in {
1207 defm: MinMax_pats<setge, A2_max, A2_min>;
1208 defm: MinMax_pats<setgt, A2_max, A2_min>;
1209 defm: MinMax_pats<setle, A2_min, A2_max>;
1210 defm: MinMax_pats<setlt, A2_min, A2_max>;
1211 defm: MinMax_pats<setuge, A2_maxu, A2_minu>;
1212 defm: MinMax_pats<setugt, A2_maxu, A2_minu>;
1213 defm: MinMax_pats<setule, A2_minu, A2_maxu>;
1214 defm: MinMax_pats<setult, A2_minu, A2_maxu>;
1217 class T_cmp64_rr<string mnemonic, bits<3> MinOp, bit IsComm>
1218 : ALU64_rr<(outs PredRegs:$Pd), (ins DoubleRegs:$Rs, DoubleRegs:$Rt),
1219 "$Pd = "#mnemonic#"($Rs, $Rt)", [], "", ALU64_tc_2early_SLOT23> {
1221 let isCommutable = IsComm;
1222 let hasSideEffects = 0;
1228 let IClass = 0b1101;
1229 let Inst{27-21} = 0b0010100;
1230 let Inst{20-16} = Rs;
1231 let Inst{12-8} = Rt;
1232 let Inst{7-5} = MinOp;
1236 def C2_cmpeqp : T_cmp64_rr<"cmp.eq", 0b000, 1>;
1237 def C2_cmpgtp : T_cmp64_rr<"cmp.gt", 0b010, 0>;
1238 def C2_cmpgtup : T_cmp64_rr<"cmp.gtu", 0b100, 0>;
1240 class T_cmp64_rr_pat<InstHexagon MI, PatFrag CmpOp>
1241 : Pat<(i1 (CmpOp (i64 DoubleRegs:$Rs), (i64 DoubleRegs:$Rt))),
1242 (i1 (MI DoubleRegs:$Rs, DoubleRegs:$Rt))>;
1244 def: T_cmp64_rr_pat<C2_cmpeqp, seteq>;
1245 def: T_cmp64_rr_pat<C2_cmpgtp, setgt>;
1246 def: T_cmp64_rr_pat<C2_cmpgtup, setugt>;
1247 def: T_cmp64_rr_pat<C2_cmpgtp, RevCmp<setlt>>;
1248 def: T_cmp64_rr_pat<C2_cmpgtup, RevCmp<setult>>;
1250 def C2_vmux : ALU64_rr<(outs DoubleRegs:$Rd),
1251 (ins PredRegs:$Pu, DoubleRegs:$Rs, DoubleRegs:$Rt),
1252 "$Rd = vmux($Pu, $Rs, $Rt)", [], "", ALU64_tc_1_SLOT23> {
1253 let hasSideEffects = 0;
1260 let IClass = 0b1101;
1261 let Inst{27-24} = 0b0001;
1262 let Inst{20-16} = Rs;
1263 let Inst{12-8} = Rt;
1268 class T_ALU64_rr<string mnemonic, string suffix, bits<4> RegType,
1269 bits<3> MajOp, bits<3> MinOp, bit OpsRev, bit IsComm,
1271 : ALU64_rr<(outs DoubleRegs:$Rd), (ins DoubleRegs:$Rs, DoubleRegs:$Rt),
1272 "$Rd = " #mnemonic# "($Rs, " #Op2Pfx# "$Rt)" #suffix, [],
1273 "", ALU64_tc_1_SLOT23> {
1274 let hasSideEffects = 0;
1275 let isCommutable = IsComm;
1281 let IClass = 0b1101;
1282 let Inst{27-24} = RegType;
1283 let Inst{23-21} = MajOp;
1284 let Inst{20-16} = !if (OpsRev,Rt,Rs);
1285 let Inst{12-8} = !if (OpsRev,Rs,Rt);
1286 let Inst{7-5} = MinOp;
1290 class T_ALU64_arith<string mnemonic, bits<3> MajOp, bits<3> MinOp, bit IsSat,
1291 bit OpsRev, bit IsComm>
1292 : T_ALU64_rr<mnemonic, !if(IsSat,":sat",""), 0b0011, MajOp, MinOp, OpsRev,
1295 def A2_addp : T_ALU64_arith<"add", 0b000, 0b111, 0, 0, 1>;
1296 def A2_subp : T_ALU64_arith<"sub", 0b001, 0b111, 0, 1, 0>;
1298 def: Pat<(i64 (add I64:$Rs, I64:$Rt)), (A2_addp I64:$Rs, I64:$Rt)>;
1299 def: Pat<(i64 (sub I64:$Rs, I64:$Rt)), (A2_subp I64:$Rs, I64:$Rt)>;
1301 class T_ALU64_logical<string mnemonic, bits<3> MinOp, bit OpsRev, bit IsComm,
1303 : T_ALU64_rr<mnemonic, "", 0b0011, 0b111, MinOp, OpsRev, IsComm,
1306 def A2_andp : T_ALU64_logical<"and", 0b000, 0, 1, 0>;
1307 def A2_orp : T_ALU64_logical<"or", 0b010, 0, 1, 0>;
1308 def A2_xorp : T_ALU64_logical<"xor", 0b100, 0, 1, 0>;
1310 def: Pat<(i64 (and I64:$Rs, I64:$Rt)), (A2_andp I64:$Rs, I64:$Rt)>;
1311 def: Pat<(i64 (or I64:$Rs, I64:$Rt)), (A2_orp I64:$Rs, I64:$Rt)>;
1312 def: Pat<(i64 (xor I64:$Rs, I64:$Rt)), (A2_xorp I64:$Rs, I64:$Rt)>;
1314 //===----------------------------------------------------------------------===//
1316 //===----------------------------------------------------------------------===//
1318 //===----------------------------------------------------------------------===//
1320 //===----------------------------------------------------------------------===//
1322 //===----------------------------------------------------------------------===//
1324 //===----------------------------------------------------------------------===//
1326 //===----------------------------------------------------------------------===//
1328 //===----------------------------------------------------------------------===//
1330 //===----------------------------------------------------------------------===//
1332 //===----------------------------------------------------------------------===//
1334 //===----------------------------------------------------------------------===//
1336 //===----------------------------------------------------------------------===//
1337 // Logical reductions on predicates.
1339 // Looping instructions.
1341 // Pipelined looping instructions.
1343 // Logical operations on predicates.
1344 let hasSideEffects = 0 in
1345 class T_LOGICAL_1OP<string MnOp, bits<2> OpBits>
1346 : CRInst<(outs PredRegs:$Pd), (ins PredRegs:$Ps),
1347 "$Pd = " # MnOp # "($Ps)", [], "", CR_tc_2early_SLOT23> {
1351 let IClass = 0b0110;
1352 let Inst{27-23} = 0b10111;
1353 let Inst{22-21} = OpBits;
1355 let Inst{17-16} = Ps;
1360 def C2_any8 : T_LOGICAL_1OP<"any8", 0b00>;
1361 def C2_all8 : T_LOGICAL_1OP<"all8", 0b01>;
1362 def C2_not : T_LOGICAL_1OP<"not", 0b10>;
1364 def: Pat<(i1 (not (i1 PredRegs:$Ps))),
1365 (C2_not PredRegs:$Ps)>;
1367 let hasSideEffects = 0 in
1368 class T_LOGICAL_2OP<string MnOp, bits<3> OpBits, bit IsNeg, bit Rev>
1369 : CRInst<(outs PredRegs:$Pd), (ins PredRegs:$Ps, PredRegs:$Pt),
1370 "$Pd = " # MnOp # "($Ps, " # !if (IsNeg,"!","") # "$Pt)",
1371 [], "", CR_tc_2early_SLOT23> {
1376 let IClass = 0b0110;
1377 let Inst{27-24} = 0b1011;
1378 let Inst{23-21} = OpBits;
1380 let Inst{17-16} = !if(Rev,Pt,Ps); // Rs and Rt are reversed for some
1381 let Inst{13} = 0b0; // instructions.
1382 let Inst{9-8} = !if(Rev,Ps,Pt);
1386 def C2_and : T_LOGICAL_2OP<"and", 0b000, 0, 1>;
1387 def C2_or : T_LOGICAL_2OP<"or", 0b001, 0, 1>;
1388 def C2_xor : T_LOGICAL_2OP<"xor", 0b010, 0, 0>;
1389 def C2_andn : T_LOGICAL_2OP<"and", 0b011, 1, 1>;
1390 def C2_orn : T_LOGICAL_2OP<"or", 0b111, 1, 1>;
1392 def: Pat<(i1 (and I1:$Ps, I1:$Pt)), (C2_and I1:$Ps, I1:$Pt)>;
1393 def: Pat<(i1 (or I1:$Ps, I1:$Pt)), (C2_or I1:$Ps, I1:$Pt)>;
1394 def: Pat<(i1 (xor I1:$Ps, I1:$Pt)), (C2_xor I1:$Ps, I1:$Pt)>;
1395 def: Pat<(i1 (and I1:$Ps, (not I1:$Pt))), (C2_andn I1:$Ps, I1:$Pt)>;
1396 def: Pat<(i1 (or I1:$Ps, (not I1:$Pt))), (C2_orn I1:$Ps, I1:$Pt)>;
1398 let hasSideEffects = 0, hasNewValue = 1 in
1399 def C2_vitpack : SInst<(outs IntRegs:$Rd), (ins PredRegs:$Ps, PredRegs:$Pt),
1400 "$Rd = vitpack($Ps, $Pt)", [], "", S_2op_tc_1_SLOT23> {
1405 let IClass = 0b1000;
1406 let Inst{27-24} = 0b1001;
1407 let Inst{22-21} = 0b00;
1408 let Inst{17-16} = Ps;
1413 let hasSideEffects = 0 in
1414 def C2_mask : SInst<(outs DoubleRegs:$Rd), (ins PredRegs:$Pt),
1415 "$Rd = mask($Pt)", [], "", S_2op_tc_1_SLOT23> {
1419 let IClass = 0b1000;
1420 let Inst{27-24} = 0b0110;
1425 // User control register transfer.
1426 //===----------------------------------------------------------------------===//
1428 //===----------------------------------------------------------------------===//
1430 //===----------------------------------------------------------------------===//
1432 //===----------------------------------------------------------------------===//
1434 def retflag : SDNode<"HexagonISD::RET_FLAG", SDTNone,
1435 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
1436 def eh_return: SDNode<"HexagonISD::EH_RETURN", SDTNone, [SDNPHasChain]>;
1438 class CondStr<string CReg, bit True, bit New> {
1439 string S = "if (" # !if(True,"","!") # CReg # !if(New,".new","") # ") ";
1441 class JumpOpcStr<string Mnemonic, bit New, bit Taken> {
1442 string S = Mnemonic # !if(Taken, ":t", ":nt");
1445 let isBranch = 1, isBarrier = 1, Defs = [PC], hasSideEffects = 0,
1447 isExtendable = 1, opExtendable = 0, isExtentSigned = 1,
1448 opExtentBits = 24, opExtentAlign = 2, InputType = "imm" in
1449 class T_JMP<string ExtStr>
1450 : JInst_CJUMP_UCJUMP<(outs), (ins brtarget:$dst),
1451 "jump " # ExtStr # "$dst",
1452 [], "", J_tc_2early_CJUMP_UCJUMP_ARCHDEPSLOT> {
1454 let IClass = 0b0101;
1456 let Inst{27-25} = 0b100;
1457 let Inst{24-16} = dst{23-15};
1458 let Inst{13-1} = dst{14-2};
1461 let isBranch = 1, Defs = [PC], hasSideEffects = 0, isPredicated = 1,
1462 isExtendable = 1, opExtendable = 1, isExtentSigned = 1,
1463 opExtentBits = 17, opExtentAlign = 2, InputType = "imm" in
1464 class T_JMP_c<bit PredNot, bit isPredNew, bit isTak, string ExtStr>
1465 : JInst_CJUMP_UCJUMP<(outs), (ins PredRegs:$src, brtarget:$dst),
1466 CondStr<"$src", !if(PredNot,0,1), isPredNew>.S #
1467 JumpOpcStr<"jump", isPredNew, isTak>.S # " " #
1469 [], "", J_tc_2early_CJUMP_UCJUMP_ARCHDEPSLOT>, ImmRegRel {
1470 let isTaken = isTak;
1471 let isPredicatedFalse = PredNot;
1472 let isPredicatedNew = isPredNew;
1476 let IClass = 0b0101;
1478 let Inst{27-24} = 0b1100;
1479 let Inst{21} = PredNot;
1480 let Inst{12} = isTak;
1481 let Inst{11} = isPredNew;
1482 let Inst{9-8} = src;
1483 let Inst{23-22} = dst{16-15};
1484 let Inst{20-16} = dst{14-10};
1485 let Inst{13} = dst{9};
1486 let Inst{7-1} = dst{8-2};
1489 multiclass JMP_Pred<bit PredNot, string ExtStr> {
1490 def NAME : T_JMP_c<PredNot, 0, 0, ExtStr>; // not taken
1492 def NAME#newpt : T_JMP_c<PredNot, 1, 1, ExtStr>; // taken
1493 def NAME#new : T_JMP_c<PredNot, 1, 0, ExtStr>; // not taken
1496 multiclass JMP_base<string BaseOp, string ExtStr> {
1497 let BaseOpcode = BaseOp in {
1498 def NAME : T_JMP<ExtStr>;
1499 defm t : JMP_Pred<0, ExtStr>;
1500 defm f : JMP_Pred<1, ExtStr>;
1504 // Jumps to address stored in a register, JUMPR_MISC
1505 // if ([[!]P[.new]]) jumpr[:t/nt] Rs
1506 let isBranch = 1, isIndirectBranch = 1, isBarrier = 1, Defs = [PC],
1507 isPredicable = 1, hasSideEffects = 0, InputType = "reg" in
1509 : JRInst<(outs), (ins IntRegs:$dst),
1510 "jumpr $dst", [], "", J_tc_2early_SLOT2> {
1513 let IClass = 0b0101;
1514 let Inst{27-21} = 0b0010100;
1515 let Inst{20-16} = dst;
1518 let isBranch = 1, isIndirectBranch = 1, Defs = [PC], isPredicated = 1,
1519 hasSideEffects = 0, InputType = "reg" in
1520 class T_JMPr_c <bit PredNot, bit isPredNew, bit isTak>
1521 : JRInst <(outs), (ins PredRegs:$src, IntRegs:$dst),
1522 CondStr<"$src", !if(PredNot,0,1), isPredNew>.S #
1523 JumpOpcStr<"jumpr", isPredNew, isTak>.S # " $dst", [],
1524 "", J_tc_2early_SLOT2> {
1526 let isTaken = isTak;
1527 let isPredicatedFalse = PredNot;
1528 let isPredicatedNew = isPredNew;
1532 let IClass = 0b0101;
1534 let Inst{27-22} = 0b001101;
1535 let Inst{21} = PredNot;
1536 let Inst{20-16} = dst;
1537 let Inst{12} = isTak;
1538 let Inst{11} = isPredNew;
1539 let Inst{9-8} = src;
1542 multiclass JMPR_Pred<bit PredNot> {
1543 def NAME : T_JMPr_c<PredNot, 0, 0>; // not taken
1545 def NAME#newpt : T_JMPr_c<PredNot, 1, 1>; // taken
1546 def NAME#new : T_JMPr_c<PredNot, 1, 0>; // not taken
1549 multiclass JMPR_base<string BaseOp> {
1550 let BaseOpcode = BaseOp in {
1552 defm t : JMPR_Pred<0>;
1553 defm f : JMPR_Pred<1>;
1557 let isCall = 1, hasSideEffects = 1 in
1558 class JUMPR_MISC_CALLR<bit isPred, bit isPredNot,
1559 dag InputDag = (ins IntRegs:$Rs)>
1560 : JRInst<(outs), InputDag,
1561 !if(isPred, !if(isPredNot, "if (!$Pu) callr $Rs",
1562 "if ($Pu) callr $Rs"),
1564 [], "", J_tc_2early_SLOT2> {
1567 let isPredicated = isPred;
1568 let isPredicatedFalse = isPredNot;
1570 let IClass = 0b0101;
1571 let Inst{27-25} = 0b000;
1572 let Inst{24-23} = !if (isPred, 0b10, 0b01);
1574 let Inst{21} = isPredNot;
1575 let Inst{9-8} = !if (isPred, Pu, 0b00);
1576 let Inst{20-16} = Rs;
1580 let Defs = VolatileV3.Regs in {
1581 def J2_callrt : JUMPR_MISC_CALLR<1, 0, (ins PredRegs:$Pu, IntRegs:$Rs)>;
1582 def J2_callrf : JUMPR_MISC_CALLR<1, 1, (ins PredRegs:$Pu, IntRegs:$Rs)>;
1585 let isTerminator = 1, hasSideEffects = 0 in {
1586 defm J2_jump : JMP_base<"JMP", "">, PredNewRel;
1588 defm J2_jumpr : JMPR_base<"JMPr">, PredNewRel;
1590 let isReturn = 1, isPseudo = 1, isCodeGenOnly = 1 in
1591 defm PS_jmpret : JMPR_base<"JMPret">, PredNewRel;
1594 let validSubTargets = HasV60SubT in
1595 multiclass JMPpt_base<string BaseOp> {
1596 let BaseOpcode = BaseOp in {
1597 def tpt : T_JMP_c <0, 0, 1, "">; // Predicate true - taken
1598 def fpt : T_JMP_c <1, 0, 1, "">; // Predicate false - taken
1602 let validSubTargets = HasV60SubT in
1603 multiclass JMPRpt_base<string BaseOp> {
1604 let BaseOpcode = BaseOp in {
1605 def tpt : T_JMPr_c<0, 0, 1>; // predicate true - taken
1606 def fpt : T_JMPr_c<1, 0, 1>; // predicate false - taken
1610 defm J2_jumpr : JMPRpt_base<"JMPr">;
1611 defm J2_jump : JMPpt_base<"JMP">;
1613 def: Pat<(br bb:$dst),
1614 (J2_jump brtarget:$dst)>;
1616 (PS_jmpret (i32 R31))>;
1617 def: Pat<(brcond (i1 PredRegs:$src1), bb:$offset),
1618 (J2_jumpt PredRegs:$src1, bb:$offset)>;
1620 // A return through builtin_eh_return.
1621 let isReturn = 1, isTerminator = 1, isBarrier = 1, hasSideEffects = 0,
1622 isCodeGenOnly = 1, Defs = [PC], Uses = [R28], isPredicable = 0 in
1623 def EH_RETURN_JMPR : T_JMPr;
1625 def: Pat<(eh_return),
1626 (EH_RETURN_JMPR (i32 R31))>;
1627 def: Pat<(brind (i32 IntRegs:$dst)),
1628 (J2_jumpr IntRegs:$dst)>;
1630 //===----------------------------------------------------------------------===//
1632 //===----------------------------------------------------------------------===//
1634 //===----------------------------------------------------------------------===//
1636 //===----------------------------------------------------------------------===//
1638 // Load - Base with Immediate offset addressing mode
1639 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, AddedComplexity = 20 in
1640 class T_load_io <string mnemonic, RegisterClass RC, bits<4> MajOp,
1642 : LDInst<(outs RC:$dst), (ins IntRegs:$src1, ImmOp:$offset),
1643 "$dst = "#mnemonic#"($src1 + #$offset)", []>, AddrModeRel {
1648 bits<11> offsetBits;
1650 string ImmOpStr = !cast<string>(ImmOp);
1651 let offsetBits = !if (!eq(ImmOpStr, "s11_3Ext"), offset{13-3},
1652 !if (!eq(ImmOpStr, "s11_2Ext"), offset{12-2},
1653 !if (!eq(ImmOpStr, "s11_1Ext"), offset{11-1},
1654 /* s11_0Ext */ offset{10-0})));
1655 let opExtentBits = !if (!eq(ImmOpStr, "s11_3Ext"), 14,
1656 !if (!eq(ImmOpStr, "s11_2Ext"), 13,
1657 !if (!eq(ImmOpStr, "s11_1Ext"), 12,
1658 /* s11_0Ext */ 11)));
1659 let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
1661 let IClass = 0b1001;
1664 let Inst{26-25} = offsetBits{10-9};
1665 let Inst{24-21} = MajOp;
1666 let Inst{20-16} = src1;
1667 let Inst{13-5} = offsetBits{8-0};
1668 let Inst{4-0} = dst;
1671 let opExtendable = 3, isExtentSigned = 0, isPredicated = 1 in
1672 class T_pload_io <string mnemonic, RegisterClass RC, bits<4>MajOp,
1673 Operand ImmOp, bit isNot, bit isPredNew>
1674 : LDInst<(outs RC:$dst),
1675 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$offset),
1676 "if ("#!if(isNot, "!$src1", "$src1")
1677 #!if(isPredNew, ".new", "")
1678 #") $dst = "#mnemonic#"($src2 + #$offset)",
1679 [],"", V2LDST_tc_ld_SLOT01> , AddrModeRel {
1685 string ImmOpStr = !cast<string>(ImmOp);
1687 let offsetBits = !if (!eq(ImmOpStr, "u6_3Ext"), offset{8-3},
1688 !if (!eq(ImmOpStr, "u6_2Ext"), offset{7-2},
1689 !if (!eq(ImmOpStr, "u6_1Ext"), offset{6-1},
1690 /* u6_0Ext */ offset{5-0})));
1691 let opExtentBits = !if (!eq(ImmOpStr, "u6_3Ext"), 9,
1692 !if (!eq(ImmOpStr, "u6_2Ext"), 8,
1693 !if (!eq(ImmOpStr, "u6_1Ext"), 7,
1695 let hasNewValue = !if (!eq(ImmOpStr, "u6_3Ext"), 0, 1);
1696 let isPredicatedNew = isPredNew;
1697 let isPredicatedFalse = isNot;
1699 let IClass = 0b0100;
1703 let Inst{26} = isNot;
1704 let Inst{25} = isPredNew;
1705 let Inst{24-21} = MajOp;
1706 let Inst{20-16} = src2;
1708 let Inst{12-11} = src1;
1709 let Inst{10-5} = offsetBits;
1710 let Inst{4-0} = dst;
1713 let isExtendable = 1, hasSideEffects = 0, addrMode = BaseImmOffset in
1714 multiclass LD_Idxd<string mnemonic, string CextOp, RegisterClass RC,
1715 Operand ImmOp, Operand predImmOp, bits<4>MajOp> {
1716 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
1717 let isPredicable = 1 in
1718 def L2_#NAME#_io : T_load_io <mnemonic, RC, MajOp, ImmOp>;
1721 def L2_p#NAME#t_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 0, 0>;
1722 def L2_p#NAME#f_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 1, 0>;
1725 def L2_p#NAME#tnew_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 0, 1>;
1726 def L2_p#NAME#fnew_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 1, 1>;
1730 let accessSize = ByteAccess in {
1731 defm loadrb: LD_Idxd <"memb", "LDrib", IntRegs, s11_0Ext, u6_0Ext, 0b1000>;
1732 defm loadrub: LD_Idxd <"memub", "LDriub", IntRegs, s11_0Ext, u6_0Ext, 0b1001>;
1735 let accessSize = HalfWordAccess, opExtentAlign = 1 in {
1736 defm loadrh: LD_Idxd <"memh", "LDrih", IntRegs, s11_1Ext, u6_1Ext, 0b1010>;
1737 defm loadruh: LD_Idxd <"memuh", "LDriuh", IntRegs, s11_1Ext, u6_1Ext, 0b1011>;
1740 let accessSize = WordAccess, opExtentAlign = 2 in
1741 defm loadri: LD_Idxd <"memw", "LDriw", IntRegs, s11_2Ext, u6_2Ext, 0b1100>;
1743 let accessSize = DoubleWordAccess, opExtentAlign = 3 in
1744 defm loadrd: LD_Idxd <"memd", "LDrid", DoubleRegs, s11_3Ext, u6_3Ext, 0b1110>;
1746 let accessSize = HalfWordAccess, opExtentAlign = 1 in {
1747 def L2_loadbsw2_io: T_load_io<"membh", IntRegs, 0b0001, s11_1Ext>;
1748 def L2_loadbzw2_io: T_load_io<"memubh", IntRegs, 0b0011, s11_1Ext>;
1751 let accessSize = WordAccess, opExtentAlign = 2 in {
1752 def L2_loadbzw4_io: T_load_io<"memubh", DoubleRegs, 0b0101, s11_2Ext>;
1753 def L2_loadbsw4_io: T_load_io<"membh", DoubleRegs, 0b0111, s11_2Ext>;
1756 let addrMode = BaseImmOffset, isExtendable = 1, hasSideEffects = 0,
1757 opExtendable = 3, isExtentSigned = 1 in
1758 class T_loadalign_io <string str, bits<4> MajOp, Operand ImmOp>
1759 : LDInst<(outs DoubleRegs:$dst),
1760 (ins DoubleRegs:$src1, IntRegs:$src2, ImmOp:$offset),
1761 "$dst = "#str#"($src2 + #$offset)", [],
1762 "$src1 = $dst">, AddrModeRel {
1767 bits<11> offsetBits;
1769 let offsetBits = !if (!eq(!cast<string>(ImmOp), "s11_1Ext"), offset{11-1},
1770 /* s11_0Ext */ offset{10-0});
1771 let IClass = 0b1001;
1774 let Inst{26-25} = offsetBits{10-9};
1775 let Inst{24-21} = MajOp;
1776 let Inst{20-16} = src2;
1777 let Inst{13-5} = offsetBits{8-0};
1778 let Inst{4-0} = dst;
1781 let accessSize = HalfWordAccess, opExtentBits = 12, opExtentAlign = 1 in
1782 def L2_loadalignh_io: T_loadalign_io <"memh_fifo", 0b0010, s11_1Ext>;
1784 let accessSize = ByteAccess, opExtentBits = 11 in
1785 def L2_loadalignb_io: T_loadalign_io <"memb_fifo", 0b0100, s11_0Ext>;
1787 // Patterns to select load-indexed (i.e. load from base+offset).
1788 multiclass Loadx_pat<PatFrag Load, ValueType VT, PatLeaf ImmPred,
1790 def: Pat<(VT (Load AddrFI:$fi)), (VT (MI AddrFI:$fi, 0))>;
1791 def: Pat<(VT (Load (add (i32 AddrFI:$fi), ImmPred:$Off))),
1792 (VT (MI AddrFI:$fi, imm:$Off))>;
1793 def: Pat<(VT (Load (orisadd (i32 AddrFI:$fi), ImmPred:$Off))),
1794 (VT (MI AddrFI:$fi, imm:$Off))>;
1795 def: Pat<(VT (Load (add (i32 IntRegs:$Rs), ImmPred:$Off))),
1796 (VT (MI IntRegs:$Rs, imm:$Off))>;
1797 def: Pat<(VT (Load (i32 IntRegs:$Rs))), (VT (MI IntRegs:$Rs, 0))>;
1800 let AddedComplexity = 20 in {
1801 defm: Loadx_pat<load, i32, s30_2ImmPred, L2_loadri_io>;
1802 defm: Loadx_pat<load, i64, s29_3ImmPred, L2_loadrd_io>;
1803 defm: Loadx_pat<atomic_load_8 , i32, s32_0ImmPred, L2_loadrub_io>;
1804 defm: Loadx_pat<atomic_load_16, i32, s31_1ImmPred, L2_loadruh_io>;
1805 defm: Loadx_pat<atomic_load_32, i32, s30_2ImmPred, L2_loadri_io>;
1806 defm: Loadx_pat<atomic_load_64, i64, s29_3ImmPred, L2_loadrd_io>;
1808 defm: Loadx_pat<extloadi1, i32, s32_0ImmPred, L2_loadrub_io>;
1809 defm: Loadx_pat<extloadi8, i32, s32_0ImmPred, L2_loadrub_io>;
1810 defm: Loadx_pat<extloadi16, i32, s31_1ImmPred, L2_loadruh_io>;
1811 defm: Loadx_pat<sextloadi8, i32, s32_0ImmPred, L2_loadrb_io>;
1812 defm: Loadx_pat<sextloadi16, i32, s31_1ImmPred, L2_loadrh_io>;
1813 defm: Loadx_pat<zextloadi1, i32, s32_0ImmPred, L2_loadrub_io>;
1814 defm: Loadx_pat<zextloadi8, i32, s32_0ImmPred, L2_loadrub_io>;
1815 defm: Loadx_pat<zextloadi16, i32, s31_1ImmPred, L2_loadruh_io>;
1819 // Sign-extending loads of i1 need to replicate the lowest bit throughout
1820 // the 32-bit value. Since the loaded value can only be 0 or 1, 0-v should
1822 let AddedComplexity = 20 in
1823 def: Pat<(i32 (sextloadi1 (i32 IntRegs:$Rs))),
1824 (A2_subri 0, (L2_loadrub_io IntRegs:$Rs, 0))>;
1826 //===----------------------------------------------------------------------===//
1827 // Post increment load
1828 //===----------------------------------------------------------------------===//
1829 //===----------------------------------------------------------------------===//
1830 // Template class for non-predicated post increment loads with immediate offset.
1831 //===----------------------------------------------------------------------===//
1832 let hasSideEffects = 0, addrMode = PostInc in
1833 class T_load_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
1835 : LDInstPI <(outs RC:$dst, IntRegs:$dst2),
1836 (ins IntRegs:$src1, ImmOp:$offset),
1837 "$dst = "#mnemonic#"($src1++#$offset)" ,
1846 string ImmOpStr = !cast<string>(ImmOp);
1847 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
1848 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1849 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1850 /* s4_0Imm */ offset{3-0})));
1851 let hasNewValue = !if (!eq(ImmOpStr, "s4_3Imm"), 0, 1);
1853 let IClass = 0b1001;
1855 let Inst{27-25} = 0b101;
1856 let Inst{24-21} = MajOp;
1857 let Inst{20-16} = src1;
1858 let Inst{13-12} = 0b00;
1859 let Inst{8-5} = offsetBits;
1860 let Inst{4-0} = dst;
1863 //===----------------------------------------------------------------------===//
1864 // Template class for predicated post increment loads with immediate offset.
1865 //===----------------------------------------------------------------------===//
1866 let isPredicated = 1, hasSideEffects = 0, addrMode = PostInc in
1867 class T_pload_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
1868 bits<4> MajOp, bit isPredNot, bit isPredNew >
1869 : LDInst <(outs RC:$dst, IntRegs:$dst2),
1870 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$offset),
1871 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1872 ") ")#"$dst = "#mnemonic#"($src2++#$offset)",
1882 let isPredicatedNew = isPredNew;
1883 let isPredicatedFalse = isPredNot;
1885 string ImmOpStr = !cast<string>(ImmOp);
1886 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
1887 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1888 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1889 /* s4_0Imm */ offset{3-0})));
1890 let hasNewValue = !if (!eq(ImmOpStr, "s4_3Imm"), 0, 1);
1892 let IClass = 0b1001;
1894 let Inst{27-25} = 0b101;
1895 let Inst{24-21} = MajOp;
1896 let Inst{20-16} = src2;
1898 let Inst{12} = isPredNew;
1899 let Inst{11} = isPredNot;
1900 let Inst{10-9} = src1;
1901 let Inst{8-5} = offsetBits;
1902 let Inst{4-0} = dst;
1905 //===----------------------------------------------------------------------===//
1906 // Multiclass for post increment loads with immediate offset.
1907 //===----------------------------------------------------------------------===//
1909 multiclass LD_PostInc <string mnemonic, string BaseOp, RegisterClass RC,
1910 Operand ImmOp, bits<4> MajOp> {
1911 let BaseOpcode = "POST_"#BaseOp in {
1912 let isPredicable = 1 in
1913 def L2_#NAME#_pi : T_load_pi < mnemonic, RC, ImmOp, MajOp>;
1916 def L2_p#NAME#t_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 0, 0>;
1917 def L2_p#NAME#f_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 1, 0>;
1920 def L2_p#NAME#tnew_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 0, 1>;
1921 def L2_p#NAME#fnew_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 1, 1>;
1925 // post increment byte loads with immediate offset
1926 let accessSize = ByteAccess in {
1927 defm loadrb : LD_PostInc <"memb", "LDrib", IntRegs, s4_0Imm, 0b1000>;
1928 defm loadrub : LD_PostInc <"memub", "LDriub", IntRegs, s4_0Imm, 0b1001>;
1931 // post increment halfword loads with immediate offset
1932 let accessSize = HalfWordAccess, opExtentAlign = 1 in {
1933 defm loadrh : LD_PostInc <"memh", "LDrih", IntRegs, s4_1Imm, 0b1010>;
1934 defm loadruh : LD_PostInc <"memuh", "LDriuh", IntRegs, s4_1Imm, 0b1011>;
1937 // post increment word loads with immediate offset
1938 let accessSize = WordAccess, opExtentAlign = 2 in
1939 defm loadri : LD_PostInc <"memw", "LDriw", IntRegs, s4_2Imm, 0b1100>;
1941 // post increment doubleword loads with immediate offset
1942 let accessSize = DoubleWordAccess, opExtentAlign = 3 in
1943 defm loadrd : LD_PostInc <"memd", "LDrid", DoubleRegs, s4_3Imm, 0b1110>;
1945 // Rd=memb[u]h(Rx++#s4:1)
1946 // Rdd=memb[u]h(Rx++#s4:2)
1947 let accessSize = HalfWordAccess, opExtentAlign = 1 in {
1948 def L2_loadbsw2_pi : T_load_pi <"membh", IntRegs, s4_1Imm, 0b0001>;
1949 def L2_loadbzw2_pi : T_load_pi <"memubh", IntRegs, s4_1Imm, 0b0011>;
1951 let accessSize = WordAccess, opExtentAlign = 2, hasNewValue = 0 in {
1952 def L2_loadbsw4_pi : T_load_pi <"membh", DoubleRegs, s4_2Imm, 0b0111>;
1953 def L2_loadbzw4_pi : T_load_pi <"memubh", DoubleRegs, s4_2Imm, 0b0101>;
1956 //===----------------------------------------------------------------------===//
1957 // Template class for post increment fifo loads with immediate offset.
1958 //===----------------------------------------------------------------------===//
1959 let hasSideEffects = 0, addrMode = PostInc in
1960 class T_loadalign_pi <string mnemonic, Operand ImmOp, bits<4> MajOp >
1961 : LDInstPI <(outs DoubleRegs:$dst, IntRegs:$dst2),
1962 (ins DoubleRegs:$src1, IntRegs:$src2, ImmOp:$offset),
1963 "$dst = "#mnemonic#"($src2++#$offset)" ,
1964 [], "$src2 = $dst2, $src1 = $dst" > ,
1971 let offsetBits = !if (!eq(!cast<string>(ImmOp), "s4_1Imm"), offset{4-1},
1972 /* s4_0Imm */ offset{3-0});
1973 let IClass = 0b1001;
1975 let Inst{27-25} = 0b101;
1976 let Inst{24-21} = MajOp;
1977 let Inst{20-16} = src2;
1978 let Inst{13-12} = 0b00;
1979 let Inst{8-5} = offsetBits;
1980 let Inst{4-0} = dst;
1983 // Ryy=memh_fifo(Rx++#s4:1)
1984 // Ryy=memb_fifo(Rx++#s4:0)
1985 let accessSize = ByteAccess in
1986 def L2_loadalignb_pi : T_loadalign_pi <"memb_fifo", s4_0Imm, 0b0100>;
1988 let accessSize = HalfWordAccess, opExtentAlign = 1 in
1989 def L2_loadalignh_pi : T_loadalign_pi <"memh_fifo", s4_1Imm, 0b0010>;
1991 //===----------------------------------------------------------------------===//
1992 // Template class for post increment loads with register offset.
1993 //===----------------------------------------------------------------------===//
1994 let hasSideEffects = 0, addrMode = PostInc in
1995 class T_load_pr <string mnemonic, RegisterClass RC, bits<4> MajOp,
1996 MemAccessSize AccessSz>
1997 : LDInstPI <(outs RC:$dst, IntRegs:$_dst_),
1998 (ins IntRegs:$src1, ModRegs:$src2),
1999 "$dst = "#mnemonic#"($src1++$src2)" ,
2000 [], "$src1 = $_dst_" > {
2005 let accessSize = AccessSz;
2006 let IClass = 0b1001;
2008 let Inst{27-25} = 0b110;
2009 let Inst{24-21} = MajOp;
2010 let Inst{20-16} = src1;
2011 let Inst{13} = src2;
2014 let Inst{4-0} = dst;
2017 let hasNewValue = 1 in {
2018 def L2_loadrb_pr : T_load_pr <"memb", IntRegs, 0b1000, ByteAccess>;
2019 def L2_loadrub_pr : T_load_pr <"memub", IntRegs, 0b1001, ByteAccess>;
2020 def L2_loadrh_pr : T_load_pr <"memh", IntRegs, 0b1010, HalfWordAccess>;
2021 def L2_loadruh_pr : T_load_pr <"memuh", IntRegs, 0b1011, HalfWordAccess>;
2022 def L2_loadri_pr : T_load_pr <"memw", IntRegs, 0b1100, WordAccess>;
2024 def L2_loadbzw2_pr : T_load_pr <"memubh", IntRegs, 0b0011, HalfWordAccess>;
2027 def L2_loadrd_pr : T_load_pr <"memd", DoubleRegs, 0b1110, DoubleWordAccess>;
2028 def L2_loadbzw4_pr : T_load_pr <"memubh", DoubleRegs, 0b0101, WordAccess>;
2031 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 13,
2032 isCodeGenOnly = 1, isPseudo = 1, hasSideEffects = 0 in
2033 def LDriw_pred : LDInst<(outs PredRegs:$dst),
2034 (ins IntRegs:$addr, s11_2Ext:$off),
2035 ".error \"should not emit\"", []>;
2037 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 13,
2038 isCodeGenOnly = 1, isPseudo = 1, hasSideEffects = 0 in
2039 def LDriw_mod : LDInst<(outs ModRegs:$dst),
2040 (ins IntRegs:$addr, s11_2Ext:$off),
2041 ".error \"should not emit\"", []>;
2043 let Defs = [R29, R30, R31], Uses = [R30], hasSideEffects = 0 in
2044 def L2_deallocframe : LDInst<(outs), (ins),
2047 let IClass = 0b1001;
2049 let Inst{27-16} = 0b000000011110;
2051 let Inst{4-0} = 0b11110;
2054 // Load / Post increment circular addressing mode.
2055 let Uses = [CS], hasSideEffects = 0, addrMode = PostInc in
2056 class T_load_pcr<string mnemonic, RegisterClass RC, bits<4> MajOp>
2057 : LDInst <(outs RC:$dst, IntRegs:$_dst_),
2058 (ins IntRegs:$Rz, ModRegs:$Mu),
2059 "$dst = "#mnemonic#"($Rz ++ I:circ($Mu))", [],
2065 let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
2066 let IClass = 0b1001;
2068 let Inst{27-25} = 0b100;
2069 let Inst{24-21} = MajOp;
2070 let Inst{20-16} = Rz;
2075 let Inst{4-0} = dst;
2078 let accessSize = ByteAccess in {
2079 def L2_loadrb_pcr : T_load_pcr <"memb", IntRegs, 0b1000>;
2080 def L2_loadrub_pcr : T_load_pcr <"memub", IntRegs, 0b1001>;
2083 let accessSize = HalfWordAccess in {
2084 def L2_loadrh_pcr : T_load_pcr <"memh", IntRegs, 0b1010>;
2085 def L2_loadruh_pcr : T_load_pcr <"memuh", IntRegs, 0b1011>;
2086 def L2_loadbsw2_pcr : T_load_pcr <"membh", IntRegs, 0b0001>;
2087 def L2_loadbzw2_pcr : T_load_pcr <"memubh", IntRegs, 0b0011>;
2090 let accessSize = WordAccess in {
2091 def L2_loadri_pcr : T_load_pcr <"memw", IntRegs, 0b1100>;
2092 let hasNewValue = 0 in {
2093 def L2_loadbzw4_pcr : T_load_pcr <"memubh", DoubleRegs, 0b0101>;
2094 def L2_loadbsw4_pcr : T_load_pcr <"membh", DoubleRegs, 0b0111>;
2098 let accessSize = DoubleWordAccess in
2099 def L2_loadrd_pcr : T_load_pcr <"memd", DoubleRegs, 0b1110>;
2101 // Load / Post increment circular addressing mode.
2102 let Uses = [CS], hasSideEffects = 0, addrMode = PostInc in
2103 class T_loadalign_pcr<string mnemonic, bits<4> MajOp, MemAccessSize AccessSz >
2104 : LDInst <(outs DoubleRegs:$dst, IntRegs:$_dst_),
2105 (ins DoubleRegs:$_src_, IntRegs:$Rz, ModRegs:$Mu),
2106 "$dst = "#mnemonic#"($Rz ++ I:circ($Mu))", [],
2107 "$Rz = $_dst_, $dst = $_src_" > {
2112 let accessSize = AccessSz;
2113 let IClass = 0b1001;
2115 let Inst{27-25} = 0b100;
2116 let Inst{24-21} = MajOp;
2117 let Inst{20-16} = Rz;
2122 let Inst{4-0} = dst;
2125 def L2_loadalignb_pcr : T_loadalign_pcr <"memb_fifo", 0b0100, ByteAccess>;
2126 def L2_loadalignh_pcr : T_loadalign_pcr <"memh_fifo", 0b0010, HalfWordAccess>;
2128 //===----------------------------------------------------------------------===//
2129 // Circular loads with immediate offset.
2130 //===----------------------------------------------------------------------===//
2131 let Uses = [CS], mayLoad = 1, hasSideEffects = 0, addrMode = PostInc in
2132 class T_load_pci <string mnemonic, RegisterClass RC,
2133 Operand ImmOp, bits<4> MajOp>
2134 : LDInstPI<(outs RC:$dst, IntRegs:$_dst_),
2135 (ins IntRegs:$Rz, ImmOp:$offset, ModRegs:$Mu),
2136 "$dst = "#mnemonic#"($Rz ++ #$offset:circ($Mu))", [],
2144 string ImmOpStr = !cast<string>(ImmOp);
2145 let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
2146 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
2147 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
2148 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
2149 /* s4_0Imm */ offset{3-0})));
2150 let IClass = 0b1001;
2151 let Inst{27-25} = 0b100;
2152 let Inst{24-21} = MajOp;
2153 let Inst{20-16} = Rz;
2157 let Inst{8-5} = offsetBits;
2158 let Inst{4-0} = dst;
2161 // Byte variants of circ load
2162 let accessSize = ByteAccess in {
2163 def L2_loadrb_pci : T_load_pci <"memb", IntRegs, s4_0Imm, 0b1000>;
2164 def L2_loadrub_pci : T_load_pci <"memub", IntRegs, s4_0Imm, 0b1001>;
2167 // Half word variants of circ load
2168 let accessSize = HalfWordAccess in {
2169 def L2_loadrh_pci : T_load_pci <"memh", IntRegs, s4_1Imm, 0b1010>;
2170 def L2_loadruh_pci : T_load_pci <"memuh", IntRegs, s4_1Imm, 0b1011>;
2171 def L2_loadbzw2_pci : T_load_pci <"memubh", IntRegs, s4_1Imm, 0b0011>;
2172 def L2_loadbsw2_pci : T_load_pci <"membh", IntRegs, s4_1Imm, 0b0001>;
2175 // Word variants of circ load
2176 let accessSize = WordAccess in
2177 def L2_loadri_pci : T_load_pci <"memw", IntRegs, s4_2Imm, 0b1100>;
2179 let accessSize = WordAccess, hasNewValue = 0 in {
2180 def L2_loadbzw4_pci : T_load_pci <"memubh", DoubleRegs, s4_2Imm, 0b0101>;
2181 def L2_loadbsw4_pci : T_load_pci <"membh", DoubleRegs, s4_2Imm, 0b0111>;
2184 let accessSize = DoubleWordAccess, hasNewValue = 0 in
2185 def L2_loadrd_pci : T_load_pci <"memd", DoubleRegs, s4_3Imm, 0b1110>;
2188 // TODO: memb_fifo and memh_fifo must take destination register as input.
2189 // One-off circ loads - not enough in common to break into a class.
2190 let accessSize = ByteAccess in
2191 def L2_loadalignb_pci : T_load_pci <"memb_fifo", DoubleRegs, s4_0Imm, 0b0100>;
2193 let accessSize = HalfWordAccess, opExtentAlign = 1 in
2194 def L2_loadalignh_pci : T_load_pci <"memh_fifo", DoubleRegs, s4_1Imm, 0b0010>;
2196 // L[24]_load[wd]_locked: Load word/double with lock.
2198 class T_load_locked <string mnemonic, RegisterClass RC>
2199 : LD0Inst <(outs RC:$dst),
2201 "$dst = "#mnemonic#"($src)"> {
2204 let IClass = 0b1001;
2205 let Inst{27-21} = 0b0010000;
2206 let Inst{20-16} = src;
2207 let Inst{13-12} = !if (!eq(mnemonic, "memd_locked"), 0b01, 0b00);
2209 let Inst{4-0} = dst;
2211 let hasNewValue = 1, accessSize = WordAccess, opNewValue = 0 in
2212 def L2_loadw_locked : T_load_locked <"memw_locked", IntRegs>;
2213 let accessSize = DoubleWordAccess in
2214 def L4_loadd_locked : T_load_locked <"memd_locked", DoubleRegs>;
2216 // S[24]_store[wd]_locked: Store word/double conditionally.
2217 let isSoloAX = 1, isPredicateLate = 1 in
2218 class T_store_locked <string mnemonic, RegisterClass RC>
2219 : ST0Inst <(outs PredRegs:$Pd), (ins IntRegs:$Rs, RC:$Rt),
2220 mnemonic#"($Rs, $Pd) = $Rt"> {
2225 let IClass = 0b1010;
2226 let Inst{27-23} = 0b00001;
2227 let Inst{22} = !if (!eq(mnemonic, "memw_locked"), 0b0, 0b1);
2229 let Inst{20-16} = Rs;
2230 let Inst{12-8} = Rt;
2234 let accessSize = WordAccess in
2235 def S2_storew_locked : T_store_locked <"memw_locked", IntRegs>;
2237 let accessSize = DoubleWordAccess in
2238 def S4_stored_locked : T_store_locked <"memd_locked", DoubleRegs>;
2240 //===----------------------------------------------------------------------===//
2241 // Bit-reversed loads with auto-increment register
2242 //===----------------------------------------------------------------------===//
2243 let hasSideEffects = 0, addrMode = PostInc in
2244 class T_load_pbr<string mnemonic, RegisterClass RC,
2245 MemAccessSize addrSize, bits<4> majOp>
2247 <(outs RC:$dst, IntRegs:$_dst_),
2248 (ins IntRegs:$Rz, ModRegs:$Mu),
2249 "$dst = "#mnemonic#"($Rz ++ $Mu:brev)" ,
2250 [] , "$Rz = $_dst_" > {
2252 let accessSize = addrSize;
2258 let IClass = 0b1001;
2260 let Inst{27-25} = 0b111;
2261 let Inst{24-21} = majOp;
2262 let Inst{20-16} = Rz;
2266 let Inst{4-0} = dst;
2269 let hasNewValue =1, opNewValue = 0 in {
2270 def L2_loadrb_pbr : T_load_pbr <"memb", IntRegs, ByteAccess, 0b1000>;
2271 def L2_loadrub_pbr : T_load_pbr <"memub", IntRegs, ByteAccess, 0b1001>;
2272 def L2_loadrh_pbr : T_load_pbr <"memh", IntRegs, HalfWordAccess, 0b1010>;
2273 def L2_loadruh_pbr : T_load_pbr <"memuh", IntRegs, HalfWordAccess, 0b1011>;
2274 def L2_loadbsw2_pbr : T_load_pbr <"membh", IntRegs, HalfWordAccess, 0b0001>;
2275 def L2_loadbzw2_pbr : T_load_pbr <"memubh", IntRegs, HalfWordAccess, 0b0011>;
2276 def L2_loadri_pbr : T_load_pbr <"memw", IntRegs, WordAccess, 0b1100>;
2279 def L2_loadbzw4_pbr : T_load_pbr <"memubh", DoubleRegs, WordAccess, 0b0101>;
2280 def L2_loadbsw4_pbr : T_load_pbr <"membh", DoubleRegs, WordAccess, 0b0111>;
2281 def L2_loadrd_pbr : T_load_pbr <"memd", DoubleRegs, DoubleWordAccess, 0b1110>;
2283 def L2_loadalignb_pbr :T_load_pbr <"memb_fifo", DoubleRegs, ByteAccess, 0b0100>;
2284 def L2_loadalignh_pbr :T_load_pbr <"memh_fifo", DoubleRegs,
2285 HalfWordAccess, 0b0010>;
2287 //===----------------------------------------------------------------------===//
2289 //===----------------------------------------------------------------------===//
2291 //===----------------------------------------------------------------------===//
2293 //===----------------------------------------------------------------------===//
2294 //===----------------------------------------------------------------------===//
2296 //===----------------------------------------------------------------------===//
2298 //===----------------------------------------------------------------------===//
2300 //===----------------------------------------------------------------------===//
2301 //===----------------------------------------------------------------------===//
2303 //===----------------------------------------------------------------------===//
2305 //===----------------------------------------------------------------------===//
2307 //===----------------------------------------------------------------------===//
2309 //===----------------------------------------------------------------------===//
2311 // MPYS / Multipy signed/unsigned halfwords
2312 //Rd=mpy[u](Rs.[H|L],Rt.[H|L])[:<<1][:rnd][:sat]
2313 //===----------------------------------------------------------------------===//
2315 let hasNewValue = 1, opNewValue = 0 in
2316 class T_M2_mpy < bits<2> LHbits, bit isSat, bit isRnd,
2317 bit hasShift, bit isUnsigned>
2318 : MInst < (outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
2319 "$Rd = "#!if(isUnsigned,"mpyu","mpy")#"($Rs."#!if(LHbits{1},"h","l")
2320 #", $Rt."#!if(LHbits{0},"h)","l)")
2321 #!if(hasShift,":<<1","")
2322 #!if(isRnd,":rnd","")
2323 #!if(isSat,":sat",""),
2324 [], "", M_tc_3x_SLOT23 > {
2329 let IClass = 0b1110;
2331 let Inst{27-24} = 0b1100;
2332 let Inst{23} = hasShift;
2333 let Inst{22} = isUnsigned;
2334 let Inst{21} = isRnd;
2335 let Inst{7} = isSat;
2336 let Inst{6-5} = LHbits;
2338 let Inst{20-16} = Rs;
2339 let Inst{12-8} = Rt;
2342 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1]
2343 def M2_mpy_ll_s1: T_M2_mpy<0b00, 0, 0, 1, 0>;
2344 def M2_mpy_ll_s0: T_M2_mpy<0b00, 0, 0, 0, 0>;
2345 def M2_mpy_lh_s1: T_M2_mpy<0b01, 0, 0, 1, 0>;
2346 def M2_mpy_lh_s0: T_M2_mpy<0b01, 0, 0, 0, 0>;
2347 def M2_mpy_hl_s1: T_M2_mpy<0b10, 0, 0, 1, 0>;
2348 def M2_mpy_hl_s0: T_M2_mpy<0b10, 0, 0, 0, 0>;
2349 def M2_mpy_hh_s1: T_M2_mpy<0b11, 0, 0, 1, 0>;
2350 def M2_mpy_hh_s0: T_M2_mpy<0b11, 0, 0, 0, 0>;
2352 //Rd=mpyu(Rs.[H|L],Rt.[H|L])[:<<1]
2353 def M2_mpyu_ll_s1: T_M2_mpy<0b00, 0, 0, 1, 1>;
2354 def M2_mpyu_ll_s0: T_M2_mpy<0b00, 0, 0, 0, 1>;
2355 def M2_mpyu_lh_s1: T_M2_mpy<0b01, 0, 0, 1, 1>;
2356 def M2_mpyu_lh_s0: T_M2_mpy<0b01, 0, 0, 0, 1>;
2357 def M2_mpyu_hl_s1: T_M2_mpy<0b10, 0, 0, 1, 1>;
2358 def M2_mpyu_hl_s0: T_M2_mpy<0b10, 0, 0, 0, 1>;
2359 def M2_mpyu_hh_s1: T_M2_mpy<0b11, 0, 0, 1, 1>;
2360 def M2_mpyu_hh_s0: T_M2_mpy<0b11, 0, 0, 0, 1>;
2362 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1]:rnd
2363 def M2_mpy_rnd_ll_s1: T_M2_mpy <0b00, 0, 1, 1, 0>;
2364 def M2_mpy_rnd_ll_s0: T_M2_mpy <0b00, 0, 1, 0, 0>;
2365 def M2_mpy_rnd_lh_s1: T_M2_mpy <0b01, 0, 1, 1, 0>;
2366 def M2_mpy_rnd_lh_s0: T_M2_mpy <0b01, 0, 1, 0, 0>;
2367 def M2_mpy_rnd_hl_s1: T_M2_mpy <0b10, 0, 1, 1, 0>;
2368 def M2_mpy_rnd_hl_s0: T_M2_mpy <0b10, 0, 1, 0, 0>;
2369 def M2_mpy_rnd_hh_s1: T_M2_mpy <0b11, 0, 1, 1, 0>;
2370 def M2_mpy_rnd_hh_s0: T_M2_mpy <0b11, 0, 1, 0, 0>;
2372 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1][:sat]
2373 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1][:rnd][:sat]
2374 let Defs = [USR_OVF] in {
2375 def M2_mpy_sat_ll_s1: T_M2_mpy <0b00, 1, 0, 1, 0>;
2376 def M2_mpy_sat_ll_s0: T_M2_mpy <0b00, 1, 0, 0, 0>;
2377 def M2_mpy_sat_lh_s1: T_M2_mpy <0b01, 1, 0, 1, 0>;
2378 def M2_mpy_sat_lh_s0: T_M2_mpy <0b01, 1, 0, 0, 0>;
2379 def M2_mpy_sat_hl_s1: T_M2_mpy <0b10, 1, 0, 1, 0>;
2380 def M2_mpy_sat_hl_s0: T_M2_mpy <0b10, 1, 0, 0, 0>;
2381 def M2_mpy_sat_hh_s1: T_M2_mpy <0b11, 1, 0, 1, 0>;
2382 def M2_mpy_sat_hh_s0: T_M2_mpy <0b11, 1, 0, 0, 0>;
2384 def M2_mpy_sat_rnd_ll_s1: T_M2_mpy <0b00, 1, 1, 1, 0>;
2385 def M2_mpy_sat_rnd_ll_s0: T_M2_mpy <0b00, 1, 1, 0, 0>;
2386 def M2_mpy_sat_rnd_lh_s1: T_M2_mpy <0b01, 1, 1, 1, 0>;
2387 def M2_mpy_sat_rnd_lh_s0: T_M2_mpy <0b01, 1, 1, 0, 0>;
2388 def M2_mpy_sat_rnd_hl_s1: T_M2_mpy <0b10, 1, 1, 1, 0>;
2389 def M2_mpy_sat_rnd_hl_s0: T_M2_mpy <0b10, 1, 1, 0, 0>;
2390 def M2_mpy_sat_rnd_hh_s1: T_M2_mpy <0b11, 1, 1, 1, 0>;
2391 def M2_mpy_sat_rnd_hh_s0: T_M2_mpy <0b11, 1, 1, 0, 0>;
2394 //===----------------------------------------------------------------------===//
2396 // MPYS / Multipy signed/unsigned halfwords and add/subtract the
2397 // result from the accumulator.
2398 //Rx [-+]= mpy[u](Rs.[H|L],Rt.[H|L])[:<<1][:sat]
2399 //===----------------------------------------------------------------------===//
2401 let hasNewValue = 1, opNewValue = 0 in
2402 class T_M2_mpy_acc < bits<2> LHbits, bit isSat, bit isNac,
2403 bit hasShift, bit isUnsigned >
2404 : MInst_acc<(outs IntRegs:$Rx), (ins IntRegs:$dst2, IntRegs:$Rs, IntRegs:$Rt),
2405 "$Rx "#!if(isNac,"-= ","+= ")#!if(isUnsigned,"mpyu","mpy")
2406 #"($Rs."#!if(LHbits{1},"h","l")
2407 #", $Rt."#!if(LHbits{0},"h)","l)")
2408 #!if(hasShift,":<<1","")
2409 #!if(isSat,":sat",""),
2410 [], "$dst2 = $Rx", M_tc_3x_SLOT23 > {
2415 let IClass = 0b1110;
2416 let Inst{27-24} = 0b1110;
2417 let Inst{23} = hasShift;
2418 let Inst{22} = isUnsigned;
2419 let Inst{21} = isNac;
2420 let Inst{7} = isSat;
2421 let Inst{6-5} = LHbits;
2423 let Inst{20-16} = Rs;
2424 let Inst{12-8} = Rt;
2427 //Rx += mpy(Rs.[H|L],Rt.[H|L])[:<<1]
2428 def M2_mpy_acc_ll_s1: T_M2_mpy_acc <0b00, 0, 0, 1, 0>;
2429 def M2_mpy_acc_ll_s0: T_M2_mpy_acc <0b00, 0, 0, 0, 0>;
2430 def M2_mpy_acc_lh_s1: T_M2_mpy_acc <0b01, 0, 0, 1, 0>;
2431 def M2_mpy_acc_lh_s0: T_M2_mpy_acc <0b01, 0, 0, 0, 0>;
2432 def M2_mpy_acc_hl_s1: T_M2_mpy_acc <0b10, 0, 0, 1, 0>;
2433 def M2_mpy_acc_hl_s0: T_M2_mpy_acc <0b10, 0, 0, 0, 0>;
2434 def M2_mpy_acc_hh_s1: T_M2_mpy_acc <0b11, 0, 0, 1, 0>;
2435 def M2_mpy_acc_hh_s0: T_M2_mpy_acc <0b11, 0, 0, 0, 0>;
2437 //Rx += mpyu(Rs.[H|L],Rt.[H|L])[:<<1]
2438 def M2_mpyu_acc_ll_s1: T_M2_mpy_acc <0b00, 0, 0, 1, 1>;
2439 def M2_mpyu_acc_ll_s0: T_M2_mpy_acc <0b00, 0, 0, 0, 1>;
2440 def M2_mpyu_acc_lh_s1: T_M2_mpy_acc <0b01, 0, 0, 1, 1>;
2441 def M2_mpyu_acc_lh_s0: T_M2_mpy_acc <0b01, 0, 0, 0, 1>;
2442 def M2_mpyu_acc_hl_s1: T_M2_mpy_acc <0b10, 0, 0, 1, 1>;
2443 def M2_mpyu_acc_hl_s0: T_M2_mpy_acc <0b10, 0, 0, 0, 1>;
2444 def M2_mpyu_acc_hh_s1: T_M2_mpy_acc <0b11, 0, 0, 1, 1>;
2445 def M2_mpyu_acc_hh_s0: T_M2_mpy_acc <0b11, 0, 0, 0, 1>;
2447 //Rx -= mpy(Rs.[H|L],Rt.[H|L])[:<<1]
2448 def M2_mpy_nac_ll_s1: T_M2_mpy_acc <0b00, 0, 1, 1, 0>;
2449 def M2_mpy_nac_ll_s0: T_M2_mpy_acc <0b00, 0, 1, 0, 0>;
2450 def M2_mpy_nac_lh_s1: T_M2_mpy_acc <0b01, 0, 1, 1, 0>;
2451 def M2_mpy_nac_lh_s0: T_M2_mpy_acc <0b01, 0, 1, 0, 0>;
2452 def M2_mpy_nac_hl_s1: T_M2_mpy_acc <0b10, 0, 1, 1, 0>;
2453 def M2_mpy_nac_hl_s0: T_M2_mpy_acc <0b10, 0, 1, 0, 0>;
2454 def M2_mpy_nac_hh_s1: T_M2_mpy_acc <0b11, 0, 1, 1, 0>;
2455 def M2_mpy_nac_hh_s0: T_M2_mpy_acc <0b11, 0, 1, 0, 0>;
2457 //Rx -= mpyu(Rs.[H|L],Rt.[H|L])[:<<1]
2458 def M2_mpyu_nac_ll_s1: T_M2_mpy_acc <0b00, 0, 1, 1, 1>;
2459 def M2_mpyu_nac_ll_s0: T_M2_mpy_acc <0b00, 0, 1, 0, 1>;
2460 def M2_mpyu_nac_lh_s1: T_M2_mpy_acc <0b01, 0, 1, 1, 1>;
2461 def M2_mpyu_nac_lh_s0: T_M2_mpy_acc <0b01, 0, 1, 0, 1>;
2462 def M2_mpyu_nac_hl_s1: T_M2_mpy_acc <0b10, 0, 1, 1, 1>;
2463 def M2_mpyu_nac_hl_s0: T_M2_mpy_acc <0b10, 0, 1, 0, 1>;
2464 def M2_mpyu_nac_hh_s1: T_M2_mpy_acc <0b11, 0, 1, 1, 1>;
2465 def M2_mpyu_nac_hh_s0: T_M2_mpy_acc <0b11, 0, 1, 0, 1>;
2467 //Rx += mpy(Rs.[H|L],Rt.[H|L])[:<<1]:sat
2468 def M2_mpy_acc_sat_ll_s1: T_M2_mpy_acc <0b00, 1, 0, 1, 0>;
2469 def M2_mpy_acc_sat_ll_s0: T_M2_mpy_acc <0b00, 1, 0, 0, 0>;
2470 def M2_mpy_acc_sat_lh_s1: T_M2_mpy_acc <0b01, 1, 0, 1, 0>;
2471 def M2_mpy_acc_sat_lh_s0: T_M2_mpy_acc <0b01, 1, 0, 0, 0>;
2472 def M2_mpy_acc_sat_hl_s1: T_M2_mpy_acc <0b10, 1, 0, 1, 0>;
2473 def M2_mpy_acc_sat_hl_s0: T_M2_mpy_acc <0b10, 1, 0, 0, 0>;
2474 def M2_mpy_acc_sat_hh_s1: T_M2_mpy_acc <0b11, 1, 0, 1, 0>;
2475 def M2_mpy_acc_sat_hh_s0: T_M2_mpy_acc <0b11, 1, 0, 0, 0>;
2477 //Rx -= mpy(Rs.[H|L],Rt.[H|L])[:<<1]:sat
2478 def M2_mpy_nac_sat_ll_s1: T_M2_mpy_acc <0b00, 1, 1, 1, 0>;
2479 def M2_mpy_nac_sat_ll_s0: T_M2_mpy_acc <0b00, 1, 1, 0, 0>;
2480 def M2_mpy_nac_sat_lh_s1: T_M2_mpy_acc <0b01, 1, 1, 1, 0>;
2481 def M2_mpy_nac_sat_lh_s0: T_M2_mpy_acc <0b01, 1, 1, 0, 0>;
2482 def M2_mpy_nac_sat_hl_s1: T_M2_mpy_acc <0b10, 1, 1, 1, 0>;
2483 def M2_mpy_nac_sat_hl_s0: T_M2_mpy_acc <0b10, 1, 1, 0, 0>;
2484 def M2_mpy_nac_sat_hh_s1: T_M2_mpy_acc <0b11, 1, 1, 1, 0>;
2485 def M2_mpy_nac_sat_hh_s0: T_M2_mpy_acc <0b11, 1, 1, 0, 0>;
2487 //===----------------------------------------------------------------------===//
2489 // MPYS / Multipy signed/unsigned halfwords and add/subtract the
2490 // result from the 64-bit destination register.
2491 //Rxx [-+]= mpy[u](Rs.[H|L],Rt.[H|L])[:<<1][:sat]
2492 //===----------------------------------------------------------------------===//
2494 class T_M2_mpyd_acc < bits<2> LHbits, bit isNac, bit hasShift, bit isUnsigned>
2495 : MInst_acc<(outs DoubleRegs:$Rxx),
2496 (ins DoubleRegs:$dst2, IntRegs:$Rs, IntRegs:$Rt),
2497 "$Rxx "#!if(isNac,"-= ","+= ")#!if(isUnsigned,"mpyu","mpy")
2498 #"($Rs."#!if(LHbits{1},"h","l")
2499 #", $Rt."#!if(LHbits{0},"h)","l)")
2500 #!if(hasShift,":<<1",""),
2501 [], "$dst2 = $Rxx", M_tc_3x_SLOT23 > {
2506 let IClass = 0b1110;
2508 let Inst{27-24} = 0b0110;
2509 let Inst{23} = hasShift;
2510 let Inst{22} = isUnsigned;
2511 let Inst{21} = isNac;
2513 let Inst{6-5} = LHbits;
2514 let Inst{4-0} = Rxx;
2515 let Inst{20-16} = Rs;
2516 let Inst{12-8} = Rt;
2519 def M2_mpyd_acc_hh_s0: T_M2_mpyd_acc <0b11, 0, 0, 0>;
2520 def M2_mpyd_acc_hl_s0: T_M2_mpyd_acc <0b10, 0, 0, 0>;
2521 def M2_mpyd_acc_lh_s0: T_M2_mpyd_acc <0b01, 0, 0, 0>;
2522 def M2_mpyd_acc_ll_s0: T_M2_mpyd_acc <0b00, 0, 0, 0>;
2524 def M2_mpyd_acc_hh_s1: T_M2_mpyd_acc <0b11, 0, 1, 0>;
2525 def M2_mpyd_acc_hl_s1: T_M2_mpyd_acc <0b10, 0, 1, 0>;
2526 def M2_mpyd_acc_lh_s1: T_M2_mpyd_acc <0b01, 0, 1, 0>;
2527 def M2_mpyd_acc_ll_s1: T_M2_mpyd_acc <0b00, 0, 1, 0>;
2529 def M2_mpyd_nac_hh_s0: T_M2_mpyd_acc <0b11, 1, 0, 0>;
2530 def M2_mpyd_nac_hl_s0: T_M2_mpyd_acc <0b10, 1, 0, 0>;
2531 def M2_mpyd_nac_lh_s0: T_M2_mpyd_acc <0b01, 1, 0, 0>;
2532 def M2_mpyd_nac_ll_s0: T_M2_mpyd_acc <0b00, 1, 0, 0>;
2534 def M2_mpyd_nac_hh_s1: T_M2_mpyd_acc <0b11, 1, 1, 0>;
2535 def M2_mpyd_nac_hl_s1: T_M2_mpyd_acc <0b10, 1, 1, 0>;
2536 def M2_mpyd_nac_lh_s1: T_M2_mpyd_acc <0b01, 1, 1, 0>;
2537 def M2_mpyd_nac_ll_s1: T_M2_mpyd_acc <0b00, 1, 1, 0>;
2539 def M2_mpyud_acc_hh_s0: T_M2_mpyd_acc <0b11, 0, 0, 1>;
2540 def M2_mpyud_acc_hl_s0: T_M2_mpyd_acc <0b10, 0, 0, 1>;
2541 def M2_mpyud_acc_lh_s0: T_M2_mpyd_acc <0b01, 0, 0, 1>;
2542 def M2_mpyud_acc_ll_s0: T_M2_mpyd_acc <0b00, 0, 0, 1>;
2544 def M2_mpyud_acc_hh_s1: T_M2_mpyd_acc <0b11, 0, 1, 1>;
2545 def M2_mpyud_acc_hl_s1: T_M2_mpyd_acc <0b10, 0, 1, 1>;
2546 def M2_mpyud_acc_lh_s1: T_M2_mpyd_acc <0b01, 0, 1, 1>;
2547 def M2_mpyud_acc_ll_s1: T_M2_mpyd_acc <0b00, 0, 1, 1>;
2549 def M2_mpyud_nac_hh_s0: T_M2_mpyd_acc <0b11, 1, 0, 1>;
2550 def M2_mpyud_nac_hl_s0: T_M2_mpyd_acc <0b10, 1, 0, 1>;
2551 def M2_mpyud_nac_lh_s0: T_M2_mpyd_acc <0b01, 1, 0, 1>;
2552 def M2_mpyud_nac_ll_s0: T_M2_mpyd_acc <0b00, 1, 0, 1>;
2554 def M2_mpyud_nac_hh_s1: T_M2_mpyd_acc <0b11, 1, 1, 1>;
2555 def M2_mpyud_nac_hl_s1: T_M2_mpyd_acc <0b10, 1, 1, 1>;
2556 def M2_mpyud_nac_lh_s1: T_M2_mpyd_acc <0b01, 1, 1, 1>;
2557 def M2_mpyud_nac_ll_s1: T_M2_mpyd_acc <0b00, 1, 1, 1>;
2559 //===----------------------------------------------------------------------===//
2560 // Template Class -- Vector Multipy
2561 // Used for complex multiply real or imaginary, dual multiply and even halfwords
2562 //===----------------------------------------------------------------------===//
2563 class T_M2_vmpy < string opc, bits<3> MajOp, bits<3> MinOp, bit hasShift,
2564 bit isRnd, bit isSat >
2565 : MInst <(outs DoubleRegs:$Rdd), (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
2566 "$Rdd = "#opc#"($Rss, $Rtt)"#!if(hasShift,":<<1","")
2567 #!if(isRnd,":rnd","")
2568 #!if(isSat,":sat",""),
2574 let IClass = 0b1110;
2576 let Inst{27-24} = 0b1000;
2577 let Inst{23-21} = MajOp;
2578 let Inst{7-5} = MinOp;
2579 let Inst{4-0} = Rdd;
2580 let Inst{20-16} = Rss;
2581 let Inst{12-8} = Rtt;
2584 // Vector complex multiply imaginary: Rdd=vcmpyi(Rss,Rtt)[:<<1]:sat
2585 let Defs = [USR_OVF] in {
2586 def M2_vcmpy_s1_sat_i: T_M2_vmpy <"vcmpyi", 0b110, 0b110, 1, 0, 1>;
2587 def M2_vcmpy_s0_sat_i: T_M2_vmpy <"vcmpyi", 0b010, 0b110, 0, 0, 1>;
2589 // Vector complex multiply real: Rdd=vcmpyr(Rss,Rtt)[:<<1]:sat
2590 def M2_vcmpy_s1_sat_r: T_M2_vmpy <"vcmpyr", 0b101, 0b110, 1, 0, 1>;
2591 def M2_vcmpy_s0_sat_r: T_M2_vmpy <"vcmpyr", 0b001, 0b110, 0, 0, 1>;
2593 // Vector dual multiply: Rdd=vdmpy(Rss,Rtt)[:<<1]:sat
2594 def M2_vdmpys_s1: T_M2_vmpy <"vdmpy", 0b100, 0b100, 1, 0, 1>;
2595 def M2_vdmpys_s0: T_M2_vmpy <"vdmpy", 0b000, 0b100, 0, 0, 1>;
2597 // Vector multiply even halfwords: Rdd=vmpyeh(Rss,Rtt)[:<<1]:sat
2598 def M2_vmpy2es_s1: T_M2_vmpy <"vmpyeh", 0b100, 0b110, 1, 0, 1>;
2599 def M2_vmpy2es_s0: T_M2_vmpy <"vmpyeh", 0b000, 0b110, 0, 0, 1>;
2601 //Rdd=vmpywoh(Rss,Rtt)[:<<1][:rnd]:sat
2602 def M2_mmpyh_s0: T_M2_vmpy <"vmpywoh", 0b000, 0b111, 0, 0, 1>;
2603 def M2_mmpyh_s1: T_M2_vmpy <"vmpywoh", 0b100, 0b111, 1, 0, 1>;
2604 def M2_mmpyh_rs0: T_M2_vmpy <"vmpywoh", 0b001, 0b111, 0, 1, 1>;
2605 def M2_mmpyh_rs1: T_M2_vmpy <"vmpywoh", 0b101, 0b111, 1, 1, 1>;
2607 //Rdd=vmpyweh(Rss,Rtt)[:<<1][:rnd]:sat
2608 def M2_mmpyl_s0: T_M2_vmpy <"vmpyweh", 0b000, 0b101, 0, 0, 1>;
2609 def M2_mmpyl_s1: T_M2_vmpy <"vmpyweh", 0b100, 0b101, 1, 0, 1>;
2610 def M2_mmpyl_rs0: T_M2_vmpy <"vmpyweh", 0b001, 0b101, 0, 1, 1>;
2611 def M2_mmpyl_rs1: T_M2_vmpy <"vmpyweh", 0b101, 0b101, 1, 1, 1>;
2613 //Rdd=vmpywouh(Rss,Rtt)[:<<1][:rnd]:sat
2614 def M2_mmpyuh_s0: T_M2_vmpy <"vmpywouh", 0b010, 0b111, 0, 0, 1>;
2615 def M2_mmpyuh_s1: T_M2_vmpy <"vmpywouh", 0b110, 0b111, 1, 0, 1>;
2616 def M2_mmpyuh_rs0: T_M2_vmpy <"vmpywouh", 0b011, 0b111, 0, 1, 1>;
2617 def M2_mmpyuh_rs1: T_M2_vmpy <"vmpywouh", 0b111, 0b111, 1, 1, 1>;
2619 //Rdd=vmpyweuh(Rss,Rtt)[:<<1][:rnd]:sat
2620 def M2_mmpyul_s0: T_M2_vmpy <"vmpyweuh", 0b010, 0b101, 0, 0, 1>;
2621 def M2_mmpyul_s1: T_M2_vmpy <"vmpyweuh", 0b110, 0b101, 1, 0, 1>;
2622 def M2_mmpyul_rs0: T_M2_vmpy <"vmpyweuh", 0b011, 0b101, 0, 1, 1>;
2623 def M2_mmpyul_rs1: T_M2_vmpy <"vmpyweuh", 0b111, 0b101, 1, 1, 1>;
2626 let hasNewValue = 1, opNewValue = 0 in
2627 class T_MType_mpy <string mnemonic, bits<4> RegTyBits, RegisterClass RC,
2628 bits<3> MajOp, bits<3> MinOp, bit isSat = 0, bit isRnd = 0,
2629 string op2Suffix = "", bit isRaw = 0, bit isHi = 0 >
2630 : MInst <(outs IntRegs:$dst), (ins RC:$src1, RC:$src2),
2632 #"($src1, $src2"#op2Suffix#")"
2633 #!if(MajOp{2}, ":<<1", "")
2634 #!if(isRnd, ":rnd", "")
2635 #!if(isSat, ":sat", "")
2636 #!if(isRaw, !if(isHi, ":raw:hi", ":raw:lo"), ""), [] > {
2641 let IClass = 0b1110;
2643 let Inst{27-24} = RegTyBits;
2644 let Inst{23-21} = MajOp;
2645 let Inst{20-16} = src1;
2647 let Inst{12-8} = src2;
2648 let Inst{7-5} = MinOp;
2649 let Inst{4-0} = dst;
2652 class T_MType_vrcmpy <string mnemonic, bits<3> MajOp, bits<3> MinOp, bit isHi>
2653 : T_MType_mpy <mnemonic, 0b1001, DoubleRegs, MajOp, MinOp, 1, 1, "", 1, isHi>;
2655 class T_MType_dd <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2656 bit isSat = 0, bit isRnd = 0 >
2657 : T_MType_mpy <mnemonic, 0b1001, DoubleRegs, MajOp, MinOp, isSat, isRnd>;
2659 class T_MType_rr1 <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2660 bit isSat = 0, bit isRnd = 0 >
2661 : T_MType_mpy<mnemonic, 0b1101, IntRegs, MajOp, MinOp, isSat, isRnd>;
2663 class T_MType_rr2 <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2664 bit isSat = 0, bit isRnd = 0, string op2str = "" >
2665 : T_MType_mpy<mnemonic, 0b1101, IntRegs, MajOp, MinOp, isSat, isRnd, op2str>;
2667 def M2_vradduh : T_MType_dd <"vradduh", 0b000, 0b001, 0, 0>;
2668 def M2_vdmpyrs_s0 : T_MType_dd <"vdmpy", 0b000, 0b000, 1, 1>;
2669 def M2_vdmpyrs_s1 : T_MType_dd <"vdmpy", 0b100, 0b000, 1, 1>;
2671 let CextOpcode = "mpyi", InputType = "reg" in
2672 def M2_mpyi : T_MType_rr1 <"mpyi", 0b000, 0b000>, ImmRegRel;
2674 def M2_mpy_up : T_MType_rr1 <"mpy", 0b000, 0b001>;
2675 def M2_mpyu_up : T_MType_rr1 <"mpyu", 0b010, 0b001>;
2677 def M2_dpmpyss_rnd_s0 : T_MType_rr1 <"mpy", 0b001, 0b001, 0, 1>;
2679 def M2_vmpy2s_s0pack : T_MType_rr1 <"vmpyh", 0b001, 0b111, 1, 1>;
2680 def M2_vmpy2s_s1pack : T_MType_rr1 <"vmpyh", 0b101, 0b111, 1, 1>;
2682 def M2_hmmpyh_rs1 : T_MType_rr2 <"mpy", 0b101, 0b100, 1, 1, ".h">;
2683 def M2_hmmpyl_rs1 : T_MType_rr2 <"mpy", 0b111, 0b100, 1, 1, ".l">;
2685 def M2_cmpyrs_s0 : T_MType_rr2 <"cmpy", 0b001, 0b110, 1, 1>;
2686 def M2_cmpyrs_s1 : T_MType_rr2 <"cmpy", 0b101, 0b110, 1, 1>;
2687 def M2_cmpyrsc_s0 : T_MType_rr2 <"cmpy", 0b011, 0b110, 1, 1, "*">;
2688 def M2_cmpyrsc_s1 : T_MType_rr2 <"cmpy", 0b111, 0b110, 1, 1, "*">;
2691 def M2_vraddh : T_MType_dd <"vraddh", 0b001, 0b111, 0>;
2692 def M2_mpysu_up : T_MType_rr1 <"mpysu", 0b011, 0b001, 0>;
2693 def M2_mpy_up_s1 : T_MType_rr1 <"mpy", 0b101, 0b010, 0>;
2694 def M2_mpy_up_s1_sat : T_MType_rr1 <"mpy", 0b111, 0b000, 1>;
2696 def M2_hmmpyh_s1 : T_MType_rr2 <"mpy", 0b101, 0b000, 1, 0, ".h">;
2697 def M2_hmmpyl_s1 : T_MType_rr2 <"mpy", 0b101, 0b001, 1, 0, ".l">;
2699 def: Pat<(i32 (mul I32:$src1, I32:$src2)), (M2_mpyi I32:$src1, I32:$src2)>;
2700 def: Pat<(i32 (mulhs I32:$src1, I32:$src2)), (M2_mpy_up I32:$src1, I32:$src2)>;
2701 def: Pat<(i32 (mulhu I32:$src1, I32:$src2)), (M2_mpyu_up I32:$src1, I32:$src2)>;
2703 let hasNewValue = 1, opNewValue = 0 in
2704 class T_MType_mpy_ri <bit isNeg, Operand ImmOp, list<dag> pattern>
2705 : MInst < (outs IntRegs:$Rd), (ins IntRegs:$Rs, ImmOp:$u8),
2706 "$Rd ="#!if(isNeg, "- ", "+ ")#"mpyi($Rs, #$u8)" ,
2707 pattern, "", M_tc_3x_SLOT23> {
2712 let IClass = 0b1110;
2714 let Inst{27-24} = 0b0000;
2715 let Inst{23} = isNeg;
2718 let Inst{20-16} = Rs;
2719 let Inst{12-5} = u8;
2722 let isExtendable = 1, opExtentBits = 8, opExtendable = 2 in
2723 def M2_mpysip : T_MType_mpy_ri <0, u8Ext,
2724 [(set (i32 IntRegs:$Rd), (mul IntRegs:$Rs, u32ImmPred:$u8))]>;
2726 def M2_mpysin : T_MType_mpy_ri <1, u8Imm,
2727 [(set (i32 IntRegs:$Rd), (ineg (mul IntRegs:$Rs,
2730 // Assember mapped to M2_mpyi
2731 let isAsmParserOnly = 1 in
2732 def M2_mpyui : MInst<(outs IntRegs:$dst),
2733 (ins IntRegs:$src1, IntRegs:$src2),
2734 "$dst = mpyui($src1, $src2)">;
2737 // s9 is NOT the same as m9 - but it works.. so far.
2738 // Assembler maps to either Rd=+mpyi(Rs,#u8) or Rd=-mpyi(Rs,#u8)
2739 // depending on the value of m9. See Arch Spec.
2740 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 9,
2741 CextOpcode = "mpyi", InputType = "imm", hasNewValue = 1,
2742 isAsmParserOnly = 1 in
2743 def M2_mpysmi : MInst<(outs IntRegs:$dst), (ins IntRegs:$src1, s9Ext:$src2),
2744 "$dst = mpyi($src1, #$src2)",
2745 [(set (i32 IntRegs:$dst), (mul (i32 IntRegs:$src1),
2746 s32ImmPred:$src2))]>, ImmRegRel;
2748 let hasNewValue = 1, isExtendable = 1, opExtentBits = 8, opExtendable = 3,
2749 InputType = "imm" in
2750 class T_MType_acc_ri <string mnemonic, bits<3> MajOp, Operand ImmOp,
2751 list<dag> pattern = []>
2752 : MInst < (outs IntRegs:$dst), (ins IntRegs:$src1, IntRegs:$src2, ImmOp:$src3),
2753 "$dst "#mnemonic#"($src2, #$src3)",
2754 pattern, "$src1 = $dst", M_tc_2_SLOT23> {
2759 let IClass = 0b1110;
2761 let Inst{27-26} = 0b00;
2762 let Inst{25-23} = MajOp;
2763 let Inst{20-16} = src2;
2765 let Inst{12-5} = src3;
2766 let Inst{4-0} = dst;
2769 let InputType = "reg", hasNewValue = 1 in
2770 class T_MType_acc_rr <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2771 bit isSwap = 0, list<dag> pattern = [], bit hasNot = 0,
2772 bit isSat = 0, bit isShift = 0>
2773 : MInst < (outs IntRegs:$dst),
2774 (ins IntRegs:$src1, IntRegs:$src2, IntRegs:$src3),
2775 "$dst "#mnemonic#"($src2, "#!if(hasNot, "~$src3)","$src3)")
2776 #!if(isShift, ":<<1", "")
2777 #!if(isSat, ":sat", ""),
2778 pattern, "$src1 = $dst", M_tc_2_SLOT23 > {
2783 let IClass = 0b1110;
2785 let Inst{27-24} = 0b1111;
2786 let Inst{23-21} = MajOp;
2787 let Inst{20-16} = !if(isSwap, src3, src2);
2789 let Inst{12-8} = !if(isSwap, src2, src3);
2790 let Inst{7-5} = MinOp;
2791 let Inst{4-0} = dst;
2794 let CextOpcode = "MPYI_acc", Itinerary = M_tc_3x_SLOT23 in {
2795 def M2_macsip : T_MType_acc_ri <"+= mpyi", 0b010, u8Ext,
2796 [(set (i32 IntRegs:$dst),
2797 (add (mul IntRegs:$src2, u32ImmPred:$src3),
2798 IntRegs:$src1))]>, ImmRegRel;
2800 def M2_maci : T_MType_acc_rr <"+= mpyi", 0b000, 0b000, 0,
2801 [(set (i32 IntRegs:$dst),
2802 (add (mul IntRegs:$src2, IntRegs:$src3),
2803 IntRegs:$src1))]>, ImmRegRel;
2806 let CextOpcode = "ADD_acc" in {
2807 let isExtentSigned = 1 in
2808 def M2_accii : T_MType_acc_ri <"+= add", 0b100, s8Ext,
2809 [(set (i32 IntRegs:$dst),
2810 (add (add (i32 IntRegs:$src2), s32ImmPred:$src3),
2811 (i32 IntRegs:$src1)))]>, ImmRegRel;
2813 def M2_acci : T_MType_acc_rr <"+= add", 0b000, 0b001, 0,
2814 [(set (i32 IntRegs:$dst),
2815 (add (add (i32 IntRegs:$src2), (i32 IntRegs:$src3)),
2816 (i32 IntRegs:$src1)))]>, ImmRegRel;
2819 let CextOpcode = "SUB_acc" in {
2820 let isExtentSigned = 1 in
2821 def M2_naccii : T_MType_acc_ri <"-= add", 0b101, s8Ext>, ImmRegRel;
2823 def M2_nacci : T_MType_acc_rr <"-= add", 0b100, 0b001, 0>, ImmRegRel;
2826 let Itinerary = M_tc_3x_SLOT23 in
2827 def M2_macsin : T_MType_acc_ri <"-= mpyi", 0b011, u8Ext>;
2829 def M2_xor_xacc : T_MType_acc_rr < "^= xor", 0b100, 0b011, 0>;
2830 def M2_subacc : T_MType_acc_rr <"+= sub", 0b000, 0b011, 1>;
2832 class T_MType_acc_pat1 <InstHexagon MI, SDNode firstOp, SDNode secOp,
2834 : Pat <(secOp IntRegs:$src1, (firstOp IntRegs:$src2, ImmPred:$src3)),
2835 (MI IntRegs:$src1, IntRegs:$src2, ImmPred:$src3)>;
2837 class T_MType_acc_pat2 <InstHexagon MI, SDNode firstOp, SDNode secOp>
2838 : Pat <(i32 (secOp IntRegs:$src1, (firstOp IntRegs:$src2, IntRegs:$src3))),
2839 (MI IntRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2841 def : T_MType_acc_pat2 <M2_xor_xacc, xor, xor>;
2842 def : T_MType_acc_pat1 <M2_macsin, mul, sub, u32ImmPred>;
2844 def : T_MType_acc_pat1 <M2_naccii, add, sub, s32ImmPred>;
2845 def : T_MType_acc_pat2 <M2_nacci, add, sub>;
2847 //===----------------------------------------------------------------------===//
2848 // Template Class -- XType Vector Instructions
2849 //===----------------------------------------------------------------------===//
2850 class T_XTYPE_Vect < string opc, bits<3> MajOp, bits<3> MinOp, bit isConj >
2851 : MInst <(outs DoubleRegs:$Rdd), (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
2852 "$Rdd = "#opc#"($Rss, $Rtt"#!if(isConj,"*)",")"),
2858 let IClass = 0b1110;
2860 let Inst{27-24} = 0b1000;
2861 let Inst{23-21} = MajOp;
2862 let Inst{7-5} = MinOp;
2863 let Inst{4-0} = Rdd;
2864 let Inst{20-16} = Rss;
2865 let Inst{12-8} = Rtt;
2868 class T_XTYPE_Vect_acc < string opc, bits<3> MajOp, bits<3> MinOp, bit isConj >
2869 : MInst <(outs DoubleRegs:$Rdd),
2870 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, DoubleRegs:$Rtt),
2871 "$Rdd += "#opc#"($Rss, $Rtt"#!if(isConj,"*)",")"),
2872 [], "$dst2 = $Rdd",M_tc_3x_SLOT23 > {
2877 let IClass = 0b1110;
2879 let Inst{27-24} = 0b1010;
2880 let Inst{23-21} = MajOp;
2881 let Inst{7-5} = MinOp;
2882 let Inst{4-0} = Rdd;
2883 let Inst{20-16} = Rss;
2884 let Inst{12-8} = Rtt;
2887 class T_XTYPE_Vect_diff < bits<3> MajOp, string opc >
2888 : MInst <(outs DoubleRegs:$Rdd), (ins DoubleRegs:$Rtt, DoubleRegs:$Rss),
2889 "$Rdd = "#opc#"($Rtt, $Rss)",
2890 [], "",M_tc_2_SLOT23 > {
2895 let IClass = 0b1110;
2897 let Inst{27-24} = 0b1000;
2898 let Inst{23-21} = MajOp;
2899 let Inst{7-5} = 0b000;
2900 let Inst{4-0} = Rdd;
2901 let Inst{20-16} = Rss;
2902 let Inst{12-8} = Rtt;
2905 // Vector reduce add unsigned bytes: Rdd32=vrmpybu(Rss32,Rtt32)
2906 def A2_vraddub: T_XTYPE_Vect <"vraddub", 0b010, 0b001, 0>;
2907 def A2_vraddub_acc: T_XTYPE_Vect_acc <"vraddub", 0b010, 0b001, 0>;
2909 // Vector sum of absolute differences unsigned bytes: Rdd=vrsadub(Rss,Rtt)
2910 def A2_vrsadub: T_XTYPE_Vect <"vrsadub", 0b010, 0b010, 0>;
2911 def A2_vrsadub_acc: T_XTYPE_Vect_acc <"vrsadub", 0b010, 0b010, 0>;
2913 // Vector absolute difference: Rdd=vabsdiffh(Rtt,Rss)
2914 def M2_vabsdiffh: T_XTYPE_Vect_diff<0b011, "vabsdiffh">;
2916 // Vector absolute difference words: Rdd=vabsdiffw(Rtt,Rss)
2917 def M2_vabsdiffw: T_XTYPE_Vect_diff<0b001, "vabsdiffw">;
2919 // Vector reduce complex multiply real or imaginary:
2920 // Rdd[+]=vrcmpy[ir](Rss,Rtt[*])
2921 def M2_vrcmpyi_s0: T_XTYPE_Vect <"vrcmpyi", 0b000, 0b000, 0>;
2922 def M2_vrcmpyi_s0c: T_XTYPE_Vect <"vrcmpyi", 0b010, 0b000, 1>;
2923 def M2_vrcmaci_s0: T_XTYPE_Vect_acc <"vrcmpyi", 0b000, 0b000, 0>;
2924 def M2_vrcmaci_s0c: T_XTYPE_Vect_acc <"vrcmpyi", 0b010, 0b000, 1>;
2926 def M2_vrcmpyr_s0: T_XTYPE_Vect <"vrcmpyr", 0b000, 0b001, 0>;
2927 def M2_vrcmpyr_s0c: T_XTYPE_Vect <"vrcmpyr", 0b011, 0b001, 1>;
2928 def M2_vrcmacr_s0: T_XTYPE_Vect_acc <"vrcmpyr", 0b000, 0b001, 0>;
2929 def M2_vrcmacr_s0c: T_XTYPE_Vect_acc <"vrcmpyr", 0b011, 0b001, 1>;
2931 // Vector reduce halfwords:
2932 // Rdd[+]=vrmpyh(Rss,Rtt)
2933 def M2_vrmpy_s0: T_XTYPE_Vect <"vrmpyh", 0b000, 0b010, 0>;
2934 def M2_vrmac_s0: T_XTYPE_Vect_acc <"vrmpyh", 0b000, 0b010, 0>;
2936 //===----------------------------------------------------------------------===//
2937 // Template Class -- Vector Multipy with accumulation.
2938 // Used for complex multiply real or imaginary, dual multiply and even halfwords
2939 //===----------------------------------------------------------------------===//
2940 let Defs = [USR_OVF] in
2941 class T_M2_vmpy_acc_sat < string opc, bits<3> MajOp, bits<3> MinOp,
2942 bit hasShift, bit isRnd >
2943 : MInst <(outs DoubleRegs:$Rxx),
2944 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, DoubleRegs:$Rtt),
2945 "$Rxx += "#opc#"($Rss, $Rtt)"#!if(hasShift,":<<1","")
2946 #!if(isRnd,":rnd","")#":sat",
2947 [], "$dst2 = $Rxx",M_tc_3x_SLOT23 > {
2952 let IClass = 0b1110;
2954 let Inst{27-24} = 0b1010;
2955 let Inst{23-21} = MajOp;
2956 let Inst{7-5} = MinOp;
2957 let Inst{4-0} = Rxx;
2958 let Inst{20-16} = Rss;
2959 let Inst{12-8} = Rtt;
2962 class T_M2_vmpy_acc < string opc, bits<3> MajOp, bits<3> MinOp,
2963 bit hasShift, bit isRnd >
2964 : MInst <(outs DoubleRegs:$Rxx),
2965 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, DoubleRegs:$Rtt),
2966 "$Rxx += "#opc#"($Rss, $Rtt)"#!if(hasShift,":<<1","")
2967 #!if(isRnd,":rnd",""),
2968 [], "$dst2 = $Rxx",M_tc_3x_SLOT23 > {
2973 let IClass = 0b1110;
2975 let Inst{27-24} = 0b1010;
2976 let Inst{23-21} = MajOp;
2977 let Inst{7-5} = MinOp;
2978 let Inst{4-0} = Rxx;
2979 let Inst{20-16} = Rss;
2980 let Inst{12-8} = Rtt;
2983 // Vector multiply word by signed half with accumulation
2984 // Rxx+=vmpyw[eo]h(Rss,Rtt)[:<<1][:rnd]:sat
2985 def M2_mmacls_s1: T_M2_vmpy_acc_sat <"vmpyweh", 0b100, 0b101, 1, 0>;
2986 def M2_mmacls_s0: T_M2_vmpy_acc_sat <"vmpyweh", 0b000, 0b101, 0, 0>;
2987 def M2_mmacls_rs1: T_M2_vmpy_acc_sat <"vmpyweh", 0b101, 0b101, 1, 1>;
2988 def M2_mmacls_rs0: T_M2_vmpy_acc_sat <"vmpyweh", 0b001, 0b101, 0, 1>;
2990 def M2_mmachs_s1: T_M2_vmpy_acc_sat <"vmpywoh", 0b100, 0b111, 1, 0>;
2991 def M2_mmachs_s0: T_M2_vmpy_acc_sat <"vmpywoh", 0b000, 0b111, 0, 0>;
2992 def M2_mmachs_rs1: T_M2_vmpy_acc_sat <"vmpywoh", 0b101, 0b111, 1, 1>;
2993 def M2_mmachs_rs0: T_M2_vmpy_acc_sat <"vmpywoh", 0b001, 0b111, 0, 1>;
2995 // Vector multiply word by unsigned half with accumulation
2996 // Rxx+=vmpyw[eo]uh(Rss,Rtt)[:<<1][:rnd]:sat
2997 def M2_mmaculs_s1: T_M2_vmpy_acc_sat <"vmpyweuh", 0b110, 0b101, 1, 0>;
2998 def M2_mmaculs_s0: T_M2_vmpy_acc_sat <"vmpyweuh", 0b010, 0b101, 0, 0>;
2999 def M2_mmaculs_rs1: T_M2_vmpy_acc_sat <"vmpyweuh", 0b111, 0b101, 1, 1>;
3000 def M2_mmaculs_rs0: T_M2_vmpy_acc_sat <"vmpyweuh", 0b011, 0b101, 0, 1>;
3002 def M2_mmacuhs_s1: T_M2_vmpy_acc_sat <"vmpywouh", 0b110, 0b111, 1, 0>;
3003 def M2_mmacuhs_s0: T_M2_vmpy_acc_sat <"vmpywouh", 0b010, 0b111, 0, 0>;
3004 def M2_mmacuhs_rs1: T_M2_vmpy_acc_sat <"vmpywouh", 0b111, 0b111, 1, 1>;
3005 def M2_mmacuhs_rs0: T_M2_vmpy_acc_sat <"vmpywouh", 0b011, 0b111, 0, 1>;
3007 // Vector multiply even halfwords with accumulation
3008 // Rxx+=vmpyeh(Rss,Rtt)[:<<1][:sat]
3009 def M2_vmac2es: T_M2_vmpy_acc <"vmpyeh", 0b001, 0b010, 0, 0>;
3010 def M2_vmac2es_s1: T_M2_vmpy_acc_sat <"vmpyeh", 0b100, 0b110, 1, 0>;
3011 def M2_vmac2es_s0: T_M2_vmpy_acc_sat <"vmpyeh", 0b000, 0b110, 0, 0>;
3013 // Vector dual multiply with accumulation
3014 // Rxx+=vdmpy(Rss,Rtt)[:sat]
3015 def M2_vdmacs_s1: T_M2_vmpy_acc_sat <"vdmpy", 0b100, 0b100, 1, 0>;
3016 def M2_vdmacs_s0: T_M2_vmpy_acc_sat <"vdmpy", 0b000, 0b100, 0, 0>;
3018 // Vector complex multiply real or imaginary with accumulation
3019 // Rxx+=vcmpy[ir](Rss,Rtt):sat
3020 def M2_vcmac_s0_sat_r: T_M2_vmpy_acc_sat <"vcmpyr", 0b001, 0b100, 0, 0>;
3021 def M2_vcmac_s0_sat_i: T_M2_vmpy_acc_sat <"vcmpyi", 0b010, 0b100, 0, 0>;
3023 //===----------------------------------------------------------------------===//
3024 // Template Class -- Multiply signed/unsigned halfwords with and without
3025 // saturation and rounding
3026 //===----------------------------------------------------------------------===//
3027 class T_M2_mpyd < bits<2> LHbits, bit isRnd, bit hasShift, bit isUnsigned >
3028 : MInst < (outs DoubleRegs:$Rdd), (ins IntRegs:$Rs, IntRegs:$Rt),
3029 "$Rdd = "#!if(isUnsigned,"mpyu","mpy")#"($Rs."#!if(LHbits{1},"h","l")
3030 #", $Rt."#!if(LHbits{0},"h)","l)")
3031 #!if(hasShift,":<<1","")
3032 #!if(isRnd,":rnd",""),
3038 let IClass = 0b1110;
3040 let Inst{27-24} = 0b0100;
3041 let Inst{23} = hasShift;
3042 let Inst{22} = isUnsigned;
3043 let Inst{21} = isRnd;
3044 let Inst{6-5} = LHbits;
3045 let Inst{4-0} = Rdd;
3046 let Inst{20-16} = Rs;
3047 let Inst{12-8} = Rt;
3050 def M2_mpyd_hh_s0: T_M2_mpyd<0b11, 0, 0, 0>;
3051 def M2_mpyd_hl_s0: T_M2_mpyd<0b10, 0, 0, 0>;
3052 def M2_mpyd_lh_s0: T_M2_mpyd<0b01, 0, 0, 0>;
3053 def M2_mpyd_ll_s0: T_M2_mpyd<0b00, 0, 0, 0>;
3055 def M2_mpyd_hh_s1: T_M2_mpyd<0b11, 0, 1, 0>;
3056 def M2_mpyd_hl_s1: T_M2_mpyd<0b10, 0, 1, 0>;
3057 def M2_mpyd_lh_s1: T_M2_mpyd<0b01, 0, 1, 0>;
3058 def M2_mpyd_ll_s1: T_M2_mpyd<0b00, 0, 1, 0>;
3060 def M2_mpyd_rnd_hh_s0: T_M2_mpyd<0b11, 1, 0, 0>;
3061 def M2_mpyd_rnd_hl_s0: T_M2_mpyd<0b10, 1, 0, 0>;
3062 def M2_mpyd_rnd_lh_s0: T_M2_mpyd<0b01, 1, 0, 0>;
3063 def M2_mpyd_rnd_ll_s0: T_M2_mpyd<0b00, 1, 0, 0>;
3065 def M2_mpyd_rnd_hh_s1: T_M2_mpyd<0b11, 1, 1, 0>;
3066 def M2_mpyd_rnd_hl_s1: T_M2_mpyd<0b10, 1, 1, 0>;
3067 def M2_mpyd_rnd_lh_s1: T_M2_mpyd<0b01, 1, 1, 0>;
3068 def M2_mpyd_rnd_ll_s1: T_M2_mpyd<0b00, 1, 1, 0>;
3070 //Rdd=mpyu(Rs.[HL],Rt.[HL])[:<<1]
3071 def M2_mpyud_hh_s0: T_M2_mpyd<0b11, 0, 0, 1>;
3072 def M2_mpyud_hl_s0: T_M2_mpyd<0b10, 0, 0, 1>;
3073 def M2_mpyud_lh_s0: T_M2_mpyd<0b01, 0, 0, 1>;
3074 def M2_mpyud_ll_s0: T_M2_mpyd<0b00, 0, 0, 1>;
3076 def M2_mpyud_hh_s1: T_M2_mpyd<0b11, 0, 1, 1>;
3077 def M2_mpyud_hl_s1: T_M2_mpyd<0b10, 0, 1, 1>;
3078 def M2_mpyud_lh_s1: T_M2_mpyd<0b01, 0, 1, 1>;
3079 def M2_mpyud_ll_s1: T_M2_mpyd<0b00, 0, 1, 1>;
3081 //===----------------------------------------------------------------------===//
3082 // Template Class for xtype mpy:
3085 // multiply 32X32 and use full result
3086 //===----------------------------------------------------------------------===//
3087 let hasSideEffects = 0 in
3088 class T_XTYPE_mpy64 <string mnemonic, bits<3> MajOp, bits<3> MinOp,
3089 bit isSat, bit hasShift, bit isConj>
3090 : MInst <(outs DoubleRegs:$Rdd),
3091 (ins IntRegs:$Rs, IntRegs:$Rt),
3092 "$Rdd = "#mnemonic#"($Rs, $Rt"#!if(isConj,"*)",")")
3093 #!if(hasShift,":<<1","")
3094 #!if(isSat,":sat",""),
3100 let IClass = 0b1110;
3102 let Inst{27-24} = 0b0101;
3103 let Inst{23-21} = MajOp;
3104 let Inst{20-16} = Rs;
3105 let Inst{12-8} = Rt;
3106 let Inst{7-5} = MinOp;
3107 let Inst{4-0} = Rdd;
3110 //===----------------------------------------------------------------------===//
3111 // Template Class for xtype mpy with accumulation into 64-bit:
3114 // multiply 32X32 and use full result
3115 //===----------------------------------------------------------------------===//
3116 class T_XTYPE_mpy64_acc <string op1, string op2, bits<3> MajOp, bits<3> MinOp,
3117 bit isSat, bit hasShift, bit isConj>
3118 : MInst <(outs DoubleRegs:$Rxx),
3119 (ins DoubleRegs:$dst2, IntRegs:$Rs, IntRegs:$Rt),
3120 "$Rxx "#op2#"= "#op1#"($Rs, $Rt"#!if(isConj,"*)",")")
3121 #!if(hasShift,":<<1","")
3122 #!if(isSat,":sat",""),
3124 [] , "$dst2 = $Rxx" > {
3129 let IClass = 0b1110;
3131 let Inst{27-24} = 0b0111;
3132 let Inst{23-21} = MajOp;
3133 let Inst{20-16} = Rs;
3134 let Inst{12-8} = Rt;
3135 let Inst{7-5} = MinOp;
3136 let Inst{4-0} = Rxx;
3139 // MPY - Multiply and use full result
3140 // Rdd = mpy[u](Rs,Rt)
3141 def M2_dpmpyss_s0 : T_XTYPE_mpy64 < "mpy", 0b000, 0b000, 0, 0, 0>;
3142 def M2_dpmpyuu_s0 : T_XTYPE_mpy64 < "mpyu", 0b010, 0b000, 0, 0, 0>;
3144 // Rxx[+-]= mpy[u](Rs,Rt)
3145 def M2_dpmpyss_acc_s0 : T_XTYPE_mpy64_acc < "mpy", "+", 0b000, 0b000, 0, 0, 0>;
3146 def M2_dpmpyss_nac_s0 : T_XTYPE_mpy64_acc < "mpy", "-", 0b001, 0b000, 0, 0, 0>;
3147 def M2_dpmpyuu_acc_s0 : T_XTYPE_mpy64_acc < "mpyu", "+", 0b010, 0b000, 0, 0, 0>;
3148 def M2_dpmpyuu_nac_s0 : T_XTYPE_mpy64_acc < "mpyu", "-", 0b011, 0b000, 0, 0, 0>;
3150 // Complex multiply real or imaginary
3151 // Rxx=cmpy[ir](Rs,Rt)
3152 def M2_cmpyi_s0 : T_XTYPE_mpy64 < "cmpyi", 0b000, 0b001, 0, 0, 0>;
3153 def M2_cmpyr_s0 : T_XTYPE_mpy64 < "cmpyr", 0b000, 0b010, 0, 0, 0>;
3155 // Rxx+=cmpy[ir](Rs,Rt)
3156 def M2_cmaci_s0 : T_XTYPE_mpy64_acc < "cmpyi", "+", 0b000, 0b001, 0, 0, 0>;
3157 def M2_cmacr_s0 : T_XTYPE_mpy64_acc < "cmpyr", "+", 0b000, 0b010, 0, 0, 0>;
3160 // Rdd=cmpy(Rs,Rt)[:<<]:sat
3161 def M2_cmpys_s0 : T_XTYPE_mpy64 < "cmpy", 0b000, 0b110, 1, 0, 0>;
3162 def M2_cmpys_s1 : T_XTYPE_mpy64 < "cmpy", 0b100, 0b110, 1, 1, 0>;
3164 // Rdd=cmpy(Rs,Rt*)[:<<]:sat
3165 def M2_cmpysc_s0 : T_XTYPE_mpy64 < "cmpy", 0b010, 0b110, 1, 0, 1>;
3166 def M2_cmpysc_s1 : T_XTYPE_mpy64 < "cmpy", 0b110, 0b110, 1, 1, 1>;
3168 // Rxx[-+]=cmpy(Rs,Rt)[:<<1]:sat
3169 def M2_cmacs_s0 : T_XTYPE_mpy64_acc < "cmpy", "+", 0b000, 0b110, 1, 0, 0>;
3170 def M2_cnacs_s0 : T_XTYPE_mpy64_acc < "cmpy", "-", 0b000, 0b111, 1, 0, 0>;
3171 def M2_cmacs_s1 : T_XTYPE_mpy64_acc < "cmpy", "+", 0b100, 0b110, 1, 1, 0>;
3172 def M2_cnacs_s1 : T_XTYPE_mpy64_acc < "cmpy", "-", 0b100, 0b111, 1, 1, 0>;
3174 // Rxx[-+]=cmpy(Rs,Rt*)[:<<1]:sat
3175 def M2_cmacsc_s0 : T_XTYPE_mpy64_acc < "cmpy", "+", 0b010, 0b110, 1, 0, 1>;
3176 def M2_cnacsc_s0 : T_XTYPE_mpy64_acc < "cmpy", "-", 0b010, 0b111, 1, 0, 1>;
3177 def M2_cmacsc_s1 : T_XTYPE_mpy64_acc < "cmpy", "+", 0b110, 0b110, 1, 1, 1>;
3178 def M2_cnacsc_s1 : T_XTYPE_mpy64_acc < "cmpy", "-", 0b110, 0b111, 1, 1, 1>;
3180 // Vector multiply halfwords
3181 // Rdd=vmpyh(Rs,Rt)[:<<]:sat
3182 //let Defs = [USR_OVF] in {
3183 def M2_vmpy2s_s1 : T_XTYPE_mpy64 < "vmpyh", 0b100, 0b101, 1, 1, 0>;
3184 def M2_vmpy2s_s0 : T_XTYPE_mpy64 < "vmpyh", 0b000, 0b101, 1, 0, 0>;
3187 // Rxx+=vmpyh(Rs,Rt)[:<<1][:sat]
3188 def M2_vmac2 : T_XTYPE_mpy64_acc < "vmpyh", "+", 0b001, 0b001, 0, 0, 0>;
3189 def M2_vmac2s_s1 : T_XTYPE_mpy64_acc < "vmpyh", "+", 0b100, 0b101, 1, 1, 0>;
3190 def M2_vmac2s_s0 : T_XTYPE_mpy64_acc < "vmpyh", "+", 0b000, 0b101, 1, 0, 0>;
3192 def: Pat<(i64 (mul (i64 (anyext (i32 IntRegs:$src1))),
3193 (i64 (anyext (i32 IntRegs:$src2))))),
3194 (M2_dpmpyuu_s0 IntRegs:$src1, IntRegs:$src2)>;
3196 def: Pat<(i64 (mul (i64 (sext (i32 IntRegs:$src1))),
3197 (i64 (sext (i32 IntRegs:$src2))))),
3198 (M2_dpmpyss_s0 IntRegs:$src1, IntRegs:$src2)>;
3200 def: Pat<(i64 (mul (is_sext_i32:$src1),
3201 (is_sext_i32:$src2))),
3202 (M2_dpmpyss_s0 (LoReg DoubleRegs:$src1), (LoReg DoubleRegs:$src2))>;
3204 // Multiply and accumulate, use full result.
3205 // Rxx[+-]=mpy(Rs,Rt)
3207 def: Pat<(i64 (add (i64 DoubleRegs:$src1),
3208 (mul (i64 (sext (i32 IntRegs:$src2))),
3209 (i64 (sext (i32 IntRegs:$src3)))))),
3210 (M2_dpmpyss_acc_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
3212 def: Pat<(i64 (sub (i64 DoubleRegs:$src1),
3213 (mul (i64 (sext (i32 IntRegs:$src2))),
3214 (i64 (sext (i32 IntRegs:$src3)))))),
3215 (M2_dpmpyss_nac_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
3217 def: Pat<(i64 (add (i64 DoubleRegs:$src1),
3218 (mul (i64 (anyext (i32 IntRegs:$src2))),
3219 (i64 (anyext (i32 IntRegs:$src3)))))),
3220 (M2_dpmpyuu_acc_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
3222 def: Pat<(i64 (add (i64 DoubleRegs:$src1),
3223 (mul (i64 (zext (i32 IntRegs:$src2))),
3224 (i64 (zext (i32 IntRegs:$src3)))))),
3225 (M2_dpmpyuu_acc_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
3227 def: Pat<(i64 (sub (i64 DoubleRegs:$src1),
3228 (mul (i64 (anyext (i32 IntRegs:$src2))),
3229 (i64 (anyext (i32 IntRegs:$src3)))))),
3230 (M2_dpmpyuu_nac_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
3232 def: Pat<(i64 (sub (i64 DoubleRegs:$src1),
3233 (mul (i64 (zext (i32 IntRegs:$src2))),
3234 (i64 (zext (i32 IntRegs:$src3)))))),
3235 (M2_dpmpyuu_nac_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
3237 //===----------------------------------------------------------------------===//
3239 //===----------------------------------------------------------------------===//
3241 //===----------------------------------------------------------------------===//
3243 //===----------------------------------------------------------------------===//
3244 //===----------------------------------------------------------------------===//
3246 //===----------------------------------------------------------------------===//
3248 //===----------------------------------------------------------------------===//
3250 //===----------------------------------------------------------------------===//
3251 //===----------------------------------------------------------------------===//
3253 //===----------------------------------------------------------------------===//
3255 //===----------------------------------------------------------------------===//
3257 //===----------------------------------------------------------------------===//
3258 //===----------------------------------------------------------------------===//
3260 //===----------------------------------------------------------------------===//
3262 //===----------------------------------------------------------------------===//
3264 //===----------------------------------------------------------------------===//
3266 // Store doubleword.
3267 //===----------------------------------------------------------------------===//
3268 // Template class for non-predicated post increment stores with immediate offset
3269 //===----------------------------------------------------------------------===//
3270 let isPredicable = 1, hasSideEffects = 0, addrMode = PostInc in
3271 class T_store_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
3272 bits<4> MajOp, bit isHalf >
3273 : STInst <(outs IntRegs:$_dst_),
3274 (ins IntRegs:$src1, ImmOp:$offset, RC:$src2),
3275 mnemonic#"($src1++#$offset) = $src2"#!if(isHalf, ".h", ""),
3276 [], "$src1 = $_dst_" >,
3283 string ImmOpStr = !cast<string>(ImmOp);
3284 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
3285 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
3286 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
3287 /* s4_0Imm */ offset{3-0})));
3288 // Store upper-half and store doubleword cannot be NV.
3289 let isNVStorable = !if (!eq(ImmOpStr, "s4_3Imm"), 0, !if(isHalf,0,1));
3291 let IClass = 0b1010;
3293 let Inst{27-25} = 0b101;
3294 let Inst{24-21} = MajOp;
3295 let Inst{20-16} = src1;
3297 let Inst{12-8} = src2;
3299 let Inst{6-3} = offsetBits;
3303 //===----------------------------------------------------------------------===//
3304 // Template class for predicated post increment stores with immediate offset
3305 //===----------------------------------------------------------------------===//
3306 let isPredicated = 1, hasSideEffects = 0, addrMode = PostInc in
3307 class T_pstore_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
3308 bits<4> MajOp, bit isHalf, bit isPredNot, bit isPredNew>
3309 : STInst <(outs IntRegs:$_dst_),
3310 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$offset, RC:$src3),
3311 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
3312 ") ")#mnemonic#"($src2++#$offset) = $src3"#!if(isHalf, ".h", ""),
3313 [], "$src2 = $_dst_" >,
3321 string ImmOpStr = !cast<string>(ImmOp);
3322 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
3323 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
3324 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
3325 /* s4_0Imm */ offset{3-0})));
3327 // Store upper-half and store doubleword cannot be NV.
3328 let isNVStorable = !if (!eq(ImmOpStr, "s4_3Imm"), 0, !if(isHalf,0,1));
3329 let isPredicatedNew = isPredNew;
3330 let isPredicatedFalse = isPredNot;
3332 let IClass = 0b1010;
3334 let Inst{27-25} = 0b101;
3335 let Inst{24-21} = MajOp;
3336 let Inst{20-16} = src2;
3338 let Inst{12-8} = src3;
3339 let Inst{7} = isPredNew;
3340 let Inst{6-3} = offsetBits;
3341 let Inst{2} = isPredNot;
3342 let Inst{1-0} = src1;
3345 multiclass ST_PostInc<string mnemonic, string BaseOp, RegisterClass RC,
3346 Operand ImmOp, bits<4> MajOp, bit isHalf = 0 > {
3348 let BaseOpcode = "POST_"#BaseOp in {
3349 def S2_#NAME#_pi : T_store_pi <mnemonic, RC, ImmOp, MajOp, isHalf>;
3352 def S2_p#NAME#t_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp, isHalf, 0, 0>;
3353 def S2_p#NAME#f_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp, isHalf, 1, 0>;
3356 def S2_p#NAME#tnew_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp,
3358 def S2_p#NAME#fnew_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp,
3363 let accessSize = ByteAccess in
3364 defm storerb: ST_PostInc <"memb", "STrib", IntRegs, s4_0Imm, 0b1000>;
3366 let accessSize = HalfWordAccess in
3367 defm storerh: ST_PostInc <"memh", "STrih", IntRegs, s4_1Imm, 0b1010>;
3369 let accessSize = WordAccess in
3370 defm storeri: ST_PostInc <"memw", "STriw", IntRegs, s4_2Imm, 0b1100>;
3372 let accessSize = DoubleWordAccess in
3373 defm storerd: ST_PostInc <"memd", "STrid", DoubleRegs, s4_3Imm, 0b1110>;
3375 let accessSize = HalfWordAccess, isNVStorable = 0 in
3376 defm storerf: ST_PostInc <"memh", "STrih_H", IntRegs, s4_1Imm, 0b1011, 1>;
3378 class Storepi_pat<PatFrag Store, PatFrag Value, PatFrag Offset,
3380 : Pat<(Store Value:$src1, I32:$src2, Offset:$offset),
3381 (MI I32:$src2, imm:$offset, Value:$src1)>;
3383 def: Storepi_pat<post_truncsti8, I32, s4_0ImmPred, S2_storerb_pi>;
3384 def: Storepi_pat<post_truncsti16, I32, s4_1ImmPred, S2_storerh_pi>;
3385 def: Storepi_pat<post_store, I32, s4_2ImmPred, S2_storeri_pi>;
3386 def: Storepi_pat<post_store, I64, s4_3ImmPred, S2_storerd_pi>;
3388 //===----------------------------------------------------------------------===//
3389 // Template class for post increment stores with register offset.
3390 //===----------------------------------------------------------------------===//
3391 class T_store_pr <string mnemonic, RegisterClass RC, bits<3> MajOp,
3392 MemAccessSize AccessSz, bit isHalf = 0>
3393 : STInst <(outs IntRegs:$_dst_),
3394 (ins IntRegs:$src1, ModRegs:$src2, RC:$src3),
3395 mnemonic#"($src1++$src2) = $src3"#!if(isHalf, ".h", ""),
3396 [], "$src1 = $_dst_" > {
3400 let accessSize = AccessSz;
3402 // Store upper-half and store doubleword cannot be NV.
3403 let isNVStorable = !if(!eq(mnemonic,"memd"), 0, !if(isHalf,0,1));
3405 let IClass = 0b1010;
3407 let Inst{27-24} = 0b1101;
3408 let Inst{23-21} = MajOp;
3409 let Inst{20-16} = src1;
3410 let Inst{13} = src2;
3411 let Inst{12-8} = src3;
3415 def S2_storerb_pr : T_store_pr<"memb", IntRegs, 0b000, ByteAccess>;
3416 def S2_storerh_pr : T_store_pr<"memh", IntRegs, 0b010, HalfWordAccess>;
3417 def S2_storeri_pr : T_store_pr<"memw", IntRegs, 0b100, WordAccess>;
3418 def S2_storerd_pr : T_store_pr<"memd", DoubleRegs, 0b110, DoubleWordAccess>;
3419 def S2_storerf_pr : T_store_pr<"memh", IntRegs, 0b011, HalfWordAccess, 1>;
3421 let opExtendable = 1, isExtentSigned = 1, isPredicable = 1 in
3422 class T_store_io <string mnemonic, RegisterClass RC, Operand ImmOp,
3423 bits<3> MajOp, bit isH = 0>
3425 (ins IntRegs:$src1, ImmOp:$src2, RC:$src3),
3426 mnemonic#"($src1+#$src2) = $src3"#!if(isH,".h","")>,
3427 AddrModeRel, ImmRegRel {
3429 bits<14> src2; // Actual address offset
3431 bits<11> offsetBits; // Represents offset encoding
3433 string ImmOpStr = !cast<string>(ImmOp);
3435 let opExtentBits = !if (!eq(ImmOpStr, "s11_3Ext"), 14,
3436 !if (!eq(ImmOpStr, "s11_2Ext"), 13,
3437 !if (!eq(ImmOpStr, "s11_1Ext"), 12,
3438 /* s11_0Ext */ 11)));
3439 let offsetBits = !if (!eq(ImmOpStr, "s11_3Ext"), src2{13-3},
3440 !if (!eq(ImmOpStr, "s11_2Ext"), src2{12-2},
3441 !if (!eq(ImmOpStr, "s11_1Ext"), src2{11-1},
3442 /* s11_0Ext */ src2{10-0})));
3443 // Store upper-half and store doubleword cannot be NV.
3444 let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isH,0,1));
3445 let IClass = 0b1010;
3448 let Inst{26-25} = offsetBits{10-9};
3450 let Inst{23-21} = MajOp;
3451 let Inst{20-16} = src1;
3452 let Inst{13} = offsetBits{8};
3453 let Inst{12-8} = src3;
3454 let Inst{7-0} = offsetBits{7-0};
3457 let opExtendable = 2, isPredicated = 1 in
3458 class T_pstore_io <string mnemonic, RegisterClass RC, Operand ImmOp,
3459 bits<3>MajOp, bit PredNot, bit isPredNew, bit isH = 0>
3461 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$src3, RC:$src4),
3462 !if(PredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
3463 ") ")#mnemonic#"($src2+#$src3) = $src4"#!if(isH,".h",""),
3464 [],"",V2LDST_tc_st_SLOT01 >,
3465 AddrModeRel, ImmRegRel {
3468 bits<9> src3; // Actual address offset
3470 bits<6> offsetBits; // Represents offset encoding
3472 let isPredicatedNew = isPredNew;
3473 let isPredicatedFalse = PredNot;
3475 string ImmOpStr = !cast<string>(ImmOp);
3476 let opExtentBits = !if (!eq(ImmOpStr, "u6_3Ext"), 9,
3477 !if (!eq(ImmOpStr, "u6_2Ext"), 8,
3478 !if (!eq(ImmOpStr, "u6_1Ext"), 7,
3480 let offsetBits = !if (!eq(ImmOpStr, "u6_3Ext"), src3{8-3},
3481 !if (!eq(ImmOpStr, "u6_2Ext"), src3{7-2},
3482 !if (!eq(ImmOpStr, "u6_1Ext"), src3{6-1},
3483 /* u6_0Ext */ src3{5-0})));
3484 // Store upper-half and store doubleword cannot be NV.
3485 let isNVStorable = !if (!eq(mnemonic, "memd"), 0, !if(isH,0,1));
3487 let IClass = 0b0100;
3490 let Inst{26} = PredNot;
3491 let Inst{25} = isPredNew;
3493 let Inst{23-21} = MajOp;
3494 let Inst{20-16} = src2;
3495 let Inst{13} = offsetBits{5};
3496 let Inst{12-8} = src4;
3497 let Inst{7-3} = offsetBits{4-0};
3498 let Inst{1-0} = src1;
3501 let isExtendable = 1, hasSideEffects = 0 in
3502 multiclass ST_Idxd<string mnemonic, string CextOp, RegisterClass RC,
3503 Operand ImmOp, Operand predImmOp, bits<3> MajOp, bit isH = 0> {
3504 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
3505 def S2_#NAME#_io : T_store_io <mnemonic, RC, ImmOp, MajOp, isH>;
3508 def S2_p#NAME#t_io : T_pstore_io<mnemonic, RC, predImmOp, MajOp, 0, 0, isH>;
3509 def S2_p#NAME#f_io : T_pstore_io<mnemonic, RC, predImmOp, MajOp, 1, 0, isH>;
3512 def S4_p#NAME#tnew_io : T_pstore_io <mnemonic, RC, predImmOp,
3514 def S4_p#NAME#fnew_io : T_pstore_io <mnemonic, RC, predImmOp,
3519 let addrMode = BaseImmOffset, InputType = "imm" in {
3520 let accessSize = ByteAccess in
3521 defm storerb: ST_Idxd < "memb", "STrib", IntRegs, s11_0Ext, u6_0Ext, 0b000>;
3523 let accessSize = HalfWordAccess, opExtentAlign = 1 in
3524 defm storerh: ST_Idxd < "memh", "STrih", IntRegs, s11_1Ext, u6_1Ext, 0b010>;
3526 let accessSize = WordAccess, opExtentAlign = 2 in
3527 defm storeri: ST_Idxd < "memw", "STriw", IntRegs, s11_2Ext, u6_2Ext, 0b100>;
3529 let accessSize = DoubleWordAccess, isNVStorable = 0, opExtentAlign = 3 in
3530 defm storerd: ST_Idxd < "memd", "STrid", DoubleRegs, s11_3Ext,
3533 let accessSize = HalfWordAccess, opExtentAlign = 1 in
3534 defm storerf: ST_Idxd < "memh", "STrif", IntRegs, s11_1Ext,
3538 // Patterns for generating stores, where the address takes different forms:
3540 // - frameindex + offset,
3542 // - simple (base address without offset).
3543 // These would usually be used together (via Storex_pat defined below), but
3544 // in some cases one may want to apply different properties (such as
3545 // AddedComplexity) to the individual patterns.
3546 class Storex_fi_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
3547 : Pat<(Store Value:$Rs, AddrFI:$fi), (MI AddrFI:$fi, 0, Value:$Rs)>;
3548 multiclass Storex_fi_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
3550 def: Pat<(Store Value:$Rs, (add (i32 AddrFI:$fi), ImmPred:$Off)),
3551 (MI AddrFI:$fi, imm:$Off, Value:$Rs)>;
3552 def: Pat<(Store Value:$Rs, (orisadd (i32 AddrFI:$fi), ImmPred:$Off)),
3553 (MI AddrFI:$fi, imm:$Off, Value:$Rs)>;
3555 multiclass Storex_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
3557 def: Pat<(Store Value:$Rt, (add (i32 IntRegs:$Rs), ImmPred:$Off)),
3558 (MI IntRegs:$Rs, imm:$Off, Value:$Rt)>;
3559 def: Pat<(Store Value:$Rt, (orisadd (i32 IntRegs:$Rs), ImmPred:$Off)),
3560 (MI IntRegs:$Rs, imm:$Off, Value:$Rt)>;
3562 class Storex_simple_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
3563 : Pat<(Store Value:$Rt, (i32 IntRegs:$Rs)),
3564 (MI IntRegs:$Rs, 0, Value:$Rt)>;
3566 // Patterns for generating stores, where the address takes different forms,
3567 // and where the value being stored is transformed through the value modifier
3568 // ValueMod. The address forms are same as above.
3569 class Storexm_fi_pat<PatFrag Store, PatFrag Value, PatFrag ValueMod,
3571 : Pat<(Store Value:$Rs, AddrFI:$fi),
3572 (MI AddrFI:$fi, 0, (ValueMod Value:$Rs))>;
3573 multiclass Storexm_fi_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
3574 PatFrag ValueMod, InstHexagon MI> {
3575 def: Pat<(Store Value:$Rs, (add (i32 AddrFI:$fi), ImmPred:$Off)),
3576 (MI AddrFI:$fi, imm:$Off, (ValueMod Value:$Rs))>;
3577 def: Pat<(Store Value:$Rs, (orisadd (i32 AddrFI:$fi), ImmPred:$Off)),
3578 (MI AddrFI:$fi, imm:$Off, (ValueMod Value:$Rs))>;
3580 multiclass Storexm_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
3581 PatFrag ValueMod, InstHexagon MI> {
3582 def: Pat<(Store Value:$Rt, (add (i32 IntRegs:$Rs), ImmPred:$Off)),
3583 (MI IntRegs:$Rs, imm:$Off, (ValueMod Value:$Rt))>;
3584 def: Pat<(Store Value:$Rt, (orisadd (i32 IntRegs:$Rs), ImmPred:$Off)),
3585 (MI IntRegs:$Rs, imm:$Off, (ValueMod Value:$Rt))>;
3587 class Storexm_simple_pat<PatFrag Store, PatFrag Value, PatFrag ValueMod,
3589 : Pat<(Store Value:$Rt, (i32 IntRegs:$Rs)),
3590 (MI IntRegs:$Rs, 0, (ValueMod Value:$Rt))>;
3592 multiclass Storex_pat<PatFrag Store, PatFrag Value, PatLeaf ImmPred,
3594 def: Storex_fi_pat <Store, Value, MI>;
3595 defm: Storex_fi_add_pat <Store, Value, ImmPred, MI>;
3596 defm: Storex_add_pat <Store, Value, ImmPred, MI>;
3599 multiclass Storexm_pat<PatFrag Store, PatFrag Value, PatLeaf ImmPred,
3600 PatFrag ValueMod, InstHexagon MI> {
3601 def: Storexm_fi_pat <Store, Value, ValueMod, MI>;
3602 defm: Storexm_fi_add_pat <Store, Value, ImmPred, ValueMod, MI>;
3603 defm: Storexm_add_pat <Store, Value, ImmPred, ValueMod, MI>;
3606 // Regular stores in the DAG have two operands: value and address.
3607 // Atomic stores also have two, but they are reversed: address, value.
3608 // To use atomic stores with the patterns, they need to have their operands
3609 // swapped. This relies on the knowledge that the F.Fragment uses names
3611 class SwapSt<PatFrag F>
3612 : PatFrag<(ops node:$val, node:$ptr), F.Fragment, F.PredicateCode,
3613 F.OperandTransform>;
3615 let AddedComplexity = 20 in {
3616 defm: Storex_pat<truncstorei8, I32, s32_0ImmPred, S2_storerb_io>;
3617 defm: Storex_pat<truncstorei16, I32, s31_1ImmPred, S2_storerh_io>;
3618 defm: Storex_pat<store, I32, s30_2ImmPred, S2_storeri_io>;
3619 defm: Storex_pat<store, I64, s29_3ImmPred, S2_storerd_io>;
3621 defm: Storex_pat<SwapSt<atomic_store_8>, I32, s32_0ImmPred, S2_storerb_io>;
3622 defm: Storex_pat<SwapSt<atomic_store_16>, I32, s31_1ImmPred, S2_storerh_io>;
3623 defm: Storex_pat<SwapSt<atomic_store_32>, I32, s30_2ImmPred, S2_storeri_io>;
3624 defm: Storex_pat<SwapSt<atomic_store_64>, I64, s29_3ImmPred, S2_storerd_io>;
3627 // Simple patterns should be tried with the least priority.
3628 def: Storex_simple_pat<truncstorei8, I32, S2_storerb_io>;
3629 def: Storex_simple_pat<truncstorei16, I32, S2_storerh_io>;
3630 def: Storex_simple_pat<store, I32, S2_storeri_io>;
3631 def: Storex_simple_pat<store, I64, S2_storerd_io>;
3633 def: Storex_simple_pat<SwapSt<atomic_store_8>, I32, S2_storerb_io>;
3634 def: Storex_simple_pat<SwapSt<atomic_store_16>, I32, S2_storerh_io>;
3635 def: Storex_simple_pat<SwapSt<atomic_store_32>, I32, S2_storeri_io>;
3636 def: Storex_simple_pat<SwapSt<atomic_store_64>, I64, S2_storerd_io>;
3638 let AddedComplexity = 20 in {
3639 defm: Storexm_pat<truncstorei8, I64, s32_0ImmPred, LoReg, S2_storerb_io>;
3640 defm: Storexm_pat<truncstorei16, I64, s31_1ImmPred, LoReg, S2_storerh_io>;
3641 defm: Storexm_pat<truncstorei32, I64, s30_2ImmPred, LoReg, S2_storeri_io>;
3644 def: Storexm_simple_pat<truncstorei8, I64, LoReg, S2_storerb_io>;
3645 def: Storexm_simple_pat<truncstorei16, I64, LoReg, S2_storerh_io>;
3646 def: Storexm_simple_pat<truncstorei32, I64, LoReg, S2_storeri_io>;
3649 let isExtendable = 1, opExtendable = 1, isExtentSigned = 1, opExtentBits = 13,
3650 isCodeGenOnly = 1, isPseudo = 1, hasSideEffects = 0 in
3651 def STriw_pred : STInst<(outs),
3652 (ins IntRegs:$addr, s11_2Ext:$off, PredRegs:$src1),
3653 ".error \"should not emit\"", []>;
3655 let isExtendable = 1, opExtendable = 1, isExtentSigned = 1, opExtentBits = 13,
3656 isCodeGenOnly = 1, isPseudo = 1, hasSideEffects = 0 in
3657 def STriw_mod : STInst<(outs),
3658 (ins IntRegs:$addr, s11_2Ext:$off, ModRegs:$src1),
3659 ".error \"should not emit\"", []>;
3661 // S2_allocframe: Allocate stack frame.
3662 let Defs = [R29, R30], Uses = [R29, R31, R30],
3663 hasSideEffects = 0, accessSize = DoubleWordAccess in
3664 def S2_allocframe: ST0Inst <
3665 (outs), (ins u11_3Imm:$u11_3),
3666 "allocframe(#$u11_3)" > {
3669 let IClass = 0b1010;
3670 let Inst{27-16} = 0b000010011101;
3671 let Inst{13-11} = 0b000;
3672 let Inst{10-0} = u11_3{13-3};
3675 // S2_storer[bhwdf]_pci: Store byte/half/word/double.
3676 // S2_storer[bhwdf]_pci -> S2_storerbnew_pci
3677 let Uses = [CS], addrMode = PostInc in
3678 class T_store_pci <string mnemonic, RegisterClass RC,
3679 Operand Imm, bits<4>MajOp,
3680 MemAccessSize AlignSize, string RegSrc = "Rt">
3681 : STInst <(outs IntRegs:$_dst_),
3682 (ins IntRegs:$Rz, Imm:$offset, ModRegs:$Mu, RC:$Rt),
3683 #mnemonic#"($Rz ++ #$offset:circ($Mu)) = $"#RegSrc#"",
3690 let accessSize = AlignSize;
3691 let isNVStorable = !if(!eq(mnemonic,"memd"), 0,
3692 !if(!eq(RegSrc,"Rt.h"), 0, 1));
3694 let IClass = 0b1010;
3695 let Inst{27-25} = 0b100;
3696 let Inst{24-21} = MajOp;
3697 let Inst{20-16} = Rz;
3699 let Inst{12-8} = Rt;
3702 !if (!eq(!cast<string>(AlignSize), "DoubleWordAccess"), offset{6-3},
3703 !if (!eq(!cast<string>(AlignSize), "WordAccess"), offset{5-2},
3704 !if (!eq(!cast<string>(AlignSize), "HalfWordAccess"), offset{4-1},
3705 /* ByteAccess */ offset{3-0})));
3709 def S2_storerb_pci : T_store_pci<"memb", IntRegs, s4_0Imm, 0b1000,
3711 def S2_storerh_pci : T_store_pci<"memh", IntRegs, s4_1Imm, 0b1010,
3713 def S2_storerf_pci : T_store_pci<"memh", IntRegs, s4_1Imm, 0b1011,
3714 HalfWordAccess, "Rt.h">;
3715 def S2_storeri_pci : T_store_pci<"memw", IntRegs, s4_2Imm, 0b1100,
3717 def S2_storerd_pci : T_store_pci<"memd", DoubleRegs, s4_3Imm, 0b1110,
3720 let Uses = [CS], isNewValue = 1, mayStore = 1, isNVStore = 1, opNewValue = 4,
3721 addrMode = PostInc in
3722 class T_storenew_pci <string mnemonic, Operand Imm,
3723 bits<2>MajOp, MemAccessSize AlignSize>
3724 : NVInst < (outs IntRegs:$_dst_),
3725 (ins IntRegs:$Rz, Imm:$offset, ModRegs:$Mu, IntRegs:$Nt),
3726 #mnemonic#"($Rz ++ #$offset:circ($Mu)) = $Nt.new",
3734 let accessSize = AlignSize;
3736 let IClass = 0b1010;
3737 let Inst{27-21} = 0b1001101;
3738 let Inst{20-16} = Rz;
3740 let Inst{12-11} = MajOp;
3741 let Inst{10-8} = Nt;
3744 !if (!eq(!cast<string>(AlignSize), "WordAccess"), offset{5-2},
3745 !if (!eq(!cast<string>(AlignSize), "HalfWordAccess"), offset{4-1},
3746 /* ByteAccess */ offset{3-0}));
3750 def S2_storerbnew_pci : T_storenew_pci <"memb", s4_0Imm, 0b00, ByteAccess>;
3751 def S2_storerhnew_pci : T_storenew_pci <"memh", s4_1Imm, 0b01, HalfWordAccess>;
3752 def S2_storerinew_pci : T_storenew_pci <"memw", s4_2Imm, 0b10, WordAccess>;
3754 //===----------------------------------------------------------------------===//
3755 // Circular stores with auto-increment register
3756 //===----------------------------------------------------------------------===//
3757 let Uses = [CS], addrMode = PostInc in
3758 class T_store_pcr <string mnemonic, RegisterClass RC, bits<4>MajOp,
3759 MemAccessSize AlignSize, string RegSrc = "Rt">
3760 : STInst <(outs IntRegs:$_dst_),
3761 (ins IntRegs:$Rz, ModRegs:$Mu, RC:$Rt),
3762 #mnemonic#"($Rz ++ I:circ($Mu)) = $"#RegSrc#"",
3769 let accessSize = AlignSize;
3770 let isNVStorable = !if(!eq(mnemonic,"memd"), 0,
3771 !if(!eq(RegSrc,"Rt.h"), 0, 1));
3773 let IClass = 0b1010;
3774 let Inst{27-25} = 0b100;
3775 let Inst{24-21} = MajOp;
3776 let Inst{20-16} = Rz;
3778 let Inst{12-8} = Rt;
3783 def S2_storerb_pcr : T_store_pcr<"memb", IntRegs, 0b1000, ByteAccess>;
3784 def S2_storerh_pcr : T_store_pcr<"memh", IntRegs, 0b1010, HalfWordAccess>;
3785 def S2_storeri_pcr : T_store_pcr<"memw", IntRegs, 0b1100, WordAccess>;
3786 def S2_storerd_pcr : T_store_pcr<"memd", DoubleRegs, 0b1110, DoubleWordAccess>;
3787 def S2_storerf_pcr : T_store_pcr<"memh", IntRegs, 0b1011,
3788 HalfWordAccess, "Rt.h">;
3790 //===----------------------------------------------------------------------===//
3791 // Circular .new stores with auto-increment register
3792 //===----------------------------------------------------------------------===//
3793 let Uses = [CS], isNewValue = 1, mayStore = 1, isNVStore = 1, opNewValue = 3,
3794 addrMode = PostInc in
3795 class T_storenew_pcr <string mnemonic, bits<2>MajOp,
3796 MemAccessSize AlignSize>
3797 : NVInst <(outs IntRegs:$_dst_),
3798 (ins IntRegs:$Rz, ModRegs:$Mu, IntRegs:$Nt),
3799 #mnemonic#"($Rz ++ I:circ($Mu)) = $Nt.new" ,
3806 let accessSize = AlignSize;
3808 let IClass = 0b1010;
3809 let Inst{27-21} = 0b1001101;
3810 let Inst{20-16} = Rz;
3812 let Inst{12-11} = MajOp;
3813 let Inst{10-8} = Nt;
3818 def S2_storerbnew_pcr : T_storenew_pcr <"memb", 0b00, ByteAccess>;
3819 def S2_storerhnew_pcr : T_storenew_pcr <"memh", 0b01, HalfWordAccess>;
3820 def S2_storerinew_pcr : T_storenew_pcr <"memw", 0b10, WordAccess>;
3822 //===----------------------------------------------------------------------===//
3823 // Bit-reversed stores with auto-increment register
3824 //===----------------------------------------------------------------------===//
3825 let hasSideEffects = 0, addrMode = PostInc in
3826 class T_store_pbr<string mnemonic, RegisterClass RC,
3827 MemAccessSize addrSize, bits<3> majOp,
3830 <(outs IntRegs:$_dst_),
3831 (ins IntRegs:$Rz, ModRegs:$Mu, RC:$src),
3832 #mnemonic#"($Rz ++ $Mu:brev) = $src"#!if (!eq(isHalf, 1), ".h", ""),
3833 [], "$Rz = $_dst_" > {
3835 let accessSize = addrSize;
3841 let IClass = 0b1010;
3843 let Inst{27-24} = 0b1111;
3844 let Inst{23-21} = majOp;
3846 let Inst{20-16} = Rz;
3848 let Inst{12-8} = src;
3851 let isNVStorable = 1 in {
3852 let BaseOpcode = "S2_storerb_pbr" in
3853 def S2_storerb_pbr : T_store_pbr<"memb", IntRegs, ByteAccess,
3854 0b000>, NewValueRel;
3855 let BaseOpcode = "S2_storerh_pbr" in
3856 def S2_storerh_pbr : T_store_pbr<"memh", IntRegs, HalfWordAccess,
3857 0b010>, NewValueRel;
3858 let BaseOpcode = "S2_storeri_pbr" in
3859 def S2_storeri_pbr : T_store_pbr<"memw", IntRegs, WordAccess,
3860 0b100>, NewValueRel;
3863 def S2_storerf_pbr : T_store_pbr<"memh", IntRegs, HalfWordAccess, 0b011, 1>;
3864 def S2_storerd_pbr : T_store_pbr<"memd", DoubleRegs, DoubleWordAccess, 0b110>;
3866 //===----------------------------------------------------------------------===//
3867 // Bit-reversed .new stores with auto-increment register
3868 //===----------------------------------------------------------------------===//
3869 let isNewValue = 1, mayStore = 1, isNVStore = 1, opNewValue = 3,
3870 hasSideEffects = 0, addrMode = PostInc in
3871 class T_storenew_pbr<string mnemonic, MemAccessSize addrSize, bits<2> majOp>
3872 : NVInst <(outs IntRegs:$_dst_),
3873 (ins IntRegs:$Rz, ModRegs:$Mu, IntRegs:$Nt),
3874 #mnemonic#"($Rz ++ $Mu:brev) = $Nt.new", [],
3875 "$Rz = $_dst_">, NewValueRel {
3876 let accessSize = addrSize;
3881 let IClass = 0b1010;
3883 let Inst{27-21} = 0b1111101;
3884 let Inst{12-11} = majOp;
3886 let Inst{20-16} = Rz;
3888 let Inst{10-8} = Nt;
3891 let BaseOpcode = "S2_storerb_pbr" in
3892 def S2_storerbnew_pbr : T_storenew_pbr<"memb", ByteAccess, 0b00>;
3894 let BaseOpcode = "S2_storerh_pbr" in
3895 def S2_storerhnew_pbr : T_storenew_pbr<"memh", HalfWordAccess, 0b01>;
3897 let BaseOpcode = "S2_storeri_pbr" in
3898 def S2_storerinew_pbr : T_storenew_pbr<"memw", WordAccess, 0b10>;
3900 //===----------------------------------------------------------------------===//
3902 //===----------------------------------------------------------------------===//
3904 //===----------------------------------------------------------------------===//
3905 // Template class for S_2op instructions.
3906 //===----------------------------------------------------------------------===//
3907 let hasSideEffects = 0 in
3908 class T_S2op_1 <string mnemonic, bits<4> RegTyBits, RegisterClass RCOut,
3909 RegisterClass RCIn, bits<2> MajOp, bits<3> MinOp, bit isSat>
3910 : SInst <(outs RCOut:$dst), (ins RCIn:$src),
3911 "$dst = "#mnemonic#"($src)"#!if(isSat, ":sat", ""),
3912 [], "", S_2op_tc_1_SLOT23 > {
3916 let IClass = 0b1000;
3918 let Inst{27-24} = RegTyBits;
3919 let Inst{23-22} = MajOp;
3921 let Inst{20-16} = src;
3922 let Inst{7-5} = MinOp;
3923 let Inst{4-0} = dst;
3926 class T_S2op_1_di <string mnemonic, bits<2> MajOp, bits<3> MinOp>
3927 : T_S2op_1 <mnemonic, 0b0100, DoubleRegs, IntRegs, MajOp, MinOp, 0>;
3929 let hasNewValue = 1 in
3930 class T_S2op_1_id <string mnemonic, bits<2> MajOp, bits<3> MinOp, bit isSat = 0>
3931 : T_S2op_1 <mnemonic, 0b1000, IntRegs, DoubleRegs, MajOp, MinOp, isSat>;
3933 let hasNewValue = 1 in
3934 class T_S2op_1_ii <string mnemonic, bits<2> MajOp, bits<3> MinOp, bit isSat = 0>
3935 : T_S2op_1 <mnemonic, 0b1100, IntRegs, IntRegs, MajOp, MinOp, isSat>;
3937 // Vector sign/zero extend
3938 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
3939 def S2_vsxtbh : T_S2op_1_di <"vsxtbh", 0b00, 0b000>;
3940 def S2_vsxthw : T_S2op_1_di <"vsxthw", 0b00, 0b100>;
3941 def S2_vzxtbh : T_S2op_1_di <"vzxtbh", 0b00, 0b010>;
3942 def S2_vzxthw : T_S2op_1_di <"vzxthw", 0b00, 0b110>;
3945 // Vector splat bytes/halfwords
3946 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
3947 def S2_vsplatrb : T_S2op_1_ii <"vsplatb", 0b01, 0b111>;
3948 def S2_vsplatrh : T_S2op_1_di <"vsplath", 0b01, 0b010>;
3951 // Sign extend word to doubleword
3952 def A2_sxtw : T_S2op_1_di <"sxtw", 0b01, 0b000>;
3954 def: Pat <(i64 (sext I32:$src)), (A2_sxtw I32:$src)>;
3956 // Vector saturate and pack
3957 let Defs = [USR_OVF] in {
3958 def S2_svsathb : T_S2op_1_ii <"vsathb", 0b10, 0b000>;
3959 def S2_svsathub : T_S2op_1_ii <"vsathub", 0b10, 0b010>;
3960 def S2_vsathb : T_S2op_1_id <"vsathb", 0b00, 0b110>;
3961 def S2_vsathub : T_S2op_1_id <"vsathub", 0b00, 0b000>;
3962 def S2_vsatwh : T_S2op_1_id <"vsatwh", 0b00, 0b010>;
3963 def S2_vsatwuh : T_S2op_1_id <"vsatwuh", 0b00, 0b100>;
3967 def S2_vtrunohb : T_S2op_1_id <"vtrunohb", 0b10, 0b000>;
3968 def S2_vtrunehb : T_S2op_1_id <"vtrunehb", 0b10, 0b010>;
3970 // Swizzle the bytes of a word
3971 def A2_swiz : T_S2op_1_ii <"swiz", 0b10, 0b111>;
3974 let Defs = [USR_OVF] in {
3975 def A2_sat : T_S2op_1_id <"sat", 0b11, 0b000>;
3976 def A2_satb : T_S2op_1_ii <"satb", 0b11, 0b111>;
3977 def A2_satub : T_S2op_1_ii <"satub", 0b11, 0b110>;
3978 def A2_sath : T_S2op_1_ii <"sath", 0b11, 0b100>;
3979 def A2_satuh : T_S2op_1_ii <"satuh", 0b11, 0b101>;
3980 def A2_roundsat : T_S2op_1_id <"round", 0b11, 0b001, 0b1>;
3983 let Itinerary = S_2op_tc_2_SLOT23 in {
3984 // Vector round and pack
3985 def S2_vrndpackwh : T_S2op_1_id <"vrndwh", 0b10, 0b100>;
3987 let Defs = [USR_OVF] in
3988 def S2_vrndpackwhs : T_S2op_1_id <"vrndwh", 0b10, 0b110, 1>;
3991 def S2_brev : T_S2op_1_ii <"brev", 0b01, 0b110>;
3993 // Absolute value word
3994 def A2_abs : T_S2op_1_ii <"abs", 0b10, 0b100>;
3996 let Defs = [USR_OVF] in
3997 def A2_abssat : T_S2op_1_ii <"abs", 0b10, 0b101, 1>;
3999 // Negate with saturation
4000 let Defs = [USR_OVF] in
4001 def A2_negsat : T_S2op_1_ii <"neg", 0b10, 0b110, 1>;
4004 def: Pat<(i32 (select (i1 (setlt (i32 IntRegs:$src), 0)),
4005 (i32 (sub 0, (i32 IntRegs:$src))),
4006 (i32 IntRegs:$src))),
4007 (A2_abs IntRegs:$src)>;
4009 let AddedComplexity = 50 in
4010 def: Pat<(i32 (xor (add (sra (i32 IntRegs:$src), (i32 31)),
4011 (i32 IntRegs:$src)),
4012 (sra (i32 IntRegs:$src), (i32 31)))),
4013 (A2_abs IntRegs:$src)>;
4015 class T_S2op_2 <string mnemonic, bits<4> RegTyBits, RegisterClass RCOut,
4016 RegisterClass RCIn, bits<3> MajOp, bits<3> MinOp,
4017 bit isSat, bit isRnd, list<dag> pattern = []>
4018 : SInst <(outs RCOut:$dst),
4019 (ins RCIn:$src, u5Imm:$u5),
4020 "$dst = "#mnemonic#"($src, #$u5)"#!if(isSat, ":sat", "")
4021 #!if(isRnd, ":rnd", ""),
4022 pattern, "", S_2op_tc_2_SLOT23> {
4027 let IClass = 0b1000;
4029 let Inst{27-24} = RegTyBits;
4030 let Inst{23-21} = MajOp;
4031 let Inst{20-16} = src;
4033 let Inst{12-8} = u5;
4034 let Inst{7-5} = MinOp;
4035 let Inst{4-0} = dst;
4038 class T_S2op_2_di <string mnemonic, bits<3> MajOp, bits<3> MinOp>
4039 : T_S2op_2 <mnemonic, 0b1000, DoubleRegs, IntRegs, MajOp, MinOp, 0, 0>;
4041 let hasNewValue = 1 in
4042 class T_S2op_2_id <string mnemonic, bits<3> MajOp, bits<3> MinOp>
4043 : T_S2op_2 <mnemonic, 0b1000, IntRegs, DoubleRegs, MajOp, MinOp, 0, 0>;
4045 let hasNewValue = 1 in
4046 class T_S2op_2_ii <string mnemonic, bits<3> MajOp, bits<3> MinOp,
4047 bit isSat = 0, bit isRnd = 0, list<dag> pattern = []>
4048 : T_S2op_2 <mnemonic, 0b1100, IntRegs, IntRegs, MajOp, MinOp,
4049 isSat, isRnd, pattern>;
4051 class T_S2op_shift <string mnemonic, bits<3> MajOp, bits<3> MinOp, SDNode OpNd>
4052 : T_S2op_2_ii <mnemonic, MajOp, MinOp, 0, 0,
4053 [(set (i32 IntRegs:$dst), (OpNd (i32 IntRegs:$src),
4054 (u5ImmPred:$u5)))]>;
4056 // Vector arithmetic shift right by immediate with truncate and pack
4057 def S2_asr_i_svw_trun : T_S2op_2_id <"vasrw", 0b110, 0b010>;
4059 // Arithmetic/logical shift right/left by immediate
4060 let Itinerary = S_2op_tc_1_SLOT23 in {
4061 def S2_asr_i_r : T_S2op_shift <"asr", 0b000, 0b000, sra>;
4062 def S2_lsr_i_r : T_S2op_shift <"lsr", 0b000, 0b001, srl>;
4063 def S2_asl_i_r : T_S2op_shift <"asl", 0b000, 0b010, shl>;
4066 // Shift left by immediate with saturation
4067 let Defs = [USR_OVF] in
4068 def S2_asl_i_r_sat : T_S2op_2_ii <"asl", 0b010, 0b010, 1>;
4070 // Shift right with round
4071 def S2_asr_i_r_rnd : T_S2op_2_ii <"asr", 0b010, 0b000, 0, 1>;
4073 let isAsmParserOnly = 1 in
4074 def S2_asr_i_r_rnd_goodsyntax
4075 : SInst <(outs IntRegs:$dst), (ins IntRegs:$src, u5Imm:$u5),
4076 "$dst = asrrnd($src, #$u5)",
4077 [], "", S_2op_tc_1_SLOT23>;
4079 let isAsmParserOnly = 1 in
4080 def A2_not: ALU32_rr<(outs IntRegs:$dst),(ins IntRegs:$src),
4081 "$dst = not($src)">;
4083 def: Pat<(i32 (sra (i32 (add (i32 (sra I32:$src1, u5ImmPred:$src2)),
4086 (S2_asr_i_r_rnd IntRegs:$src1, u5ImmPred:$src2)>;
4088 class T_S2op_3<string opc, bits<2>MajOp, bits<3>minOp, bits<1> sat = 0>
4089 : SInst<(outs DoubleRegs:$Rdd), (ins DoubleRegs:$Rss),
4090 "$Rdd = "#opc#"($Rss)"#!if(!eq(sat, 1),":sat","")> {
4093 let IClass = 0b1000;
4094 let Inst{27-24} = 0;
4095 let Inst{23-22} = MajOp;
4096 let Inst{20-16} = Rss;
4097 let Inst{7-5} = minOp;
4098 let Inst{4-0} = Rdd;
4101 def A2_absp : T_S2op_3 <"abs", 0b10, 0b110>;
4102 def A2_negp : T_S2op_3 <"neg", 0b10, 0b101>;
4103 def A2_notp : T_S2op_3 <"not", 0b10, 0b100>;
4105 // Innterleave/deinterleave
4106 def S2_interleave : T_S2op_3 <"interleave", 0b11, 0b101>;
4107 def S2_deinterleave : T_S2op_3 <"deinterleave", 0b11, 0b100>;
4109 // Vector Complex conjugate
4110 def A2_vconj : T_S2op_3 <"vconj", 0b10, 0b111, 1>;
4112 // Vector saturate without pack
4113 def S2_vsathb_nopack : T_S2op_3 <"vsathb", 0b00, 0b111>;
4114 def S2_vsathub_nopack : T_S2op_3 <"vsathub", 0b00, 0b100>;
4115 def S2_vsatwh_nopack : T_S2op_3 <"vsatwh", 0b00, 0b110>;
4116 def S2_vsatwuh_nopack : T_S2op_3 <"vsatwuh", 0b00, 0b101>;
4118 // Vector absolute value halfwords with and without saturation
4119 // Rdd64=vabsh(Rss64)[:sat]
4120 def A2_vabsh : T_S2op_3 <"vabsh", 0b01, 0b100>;
4121 def A2_vabshsat : T_S2op_3 <"vabsh", 0b01, 0b101, 1>;
4123 // Vector absolute value words with and without saturation
4124 def A2_vabsw : T_S2op_3 <"vabsw", 0b01, 0b110>;
4125 def A2_vabswsat : T_S2op_3 <"vabsw", 0b01, 0b111, 1>;
4127 def : Pat<(not (i64 DoubleRegs:$src1)),
4128 (A2_notp DoubleRegs:$src1)>;
4130 //===----------------------------------------------------------------------===//
4132 //===----------------------------------------------------------------------===//
4135 let hasSideEffects = 0, hasNewValue = 1 in
4136 class T_COUNT_LEADING<string MnOp, bits<3> MajOp, bits<3> MinOp, bit Is32,
4138 : SInst<Out, Inp, "$Rd = "#MnOp#"($Rs)", [], "", S_2op_tc_1_SLOT23> {
4141 let IClass = 0b1000;
4143 let Inst{26} = Is32;
4144 let Inst{25-24} = 0b00;
4145 let Inst{23-21} = MajOp;
4146 let Inst{20-16} = Rs;
4147 let Inst{7-5} = MinOp;
4151 class T_COUNT_LEADING_32<string MnOp, bits<3> MajOp, bits<3> MinOp>
4152 : T_COUNT_LEADING<MnOp, MajOp, MinOp, 0b1,
4153 (outs IntRegs:$Rd), (ins IntRegs:$Rs)>;
4155 class T_COUNT_LEADING_64<string MnOp, bits<3> MajOp, bits<3> MinOp>
4156 : T_COUNT_LEADING<MnOp, MajOp, MinOp, 0b0,
4157 (outs IntRegs:$Rd), (ins DoubleRegs:$Rs)>;
4159 def S2_cl0 : T_COUNT_LEADING_32<"cl0", 0b000, 0b101>;
4160 def S2_cl1 : T_COUNT_LEADING_32<"cl1", 0b000, 0b110>;
4161 def S2_ct0 : T_COUNT_LEADING_32<"ct0", 0b010, 0b100>;
4162 def S2_ct1 : T_COUNT_LEADING_32<"ct1", 0b010, 0b101>;
4163 def S2_cl0p : T_COUNT_LEADING_64<"cl0", 0b010, 0b010>;
4164 def S2_cl1p : T_COUNT_LEADING_64<"cl1", 0b010, 0b100>;
4165 def S2_clb : T_COUNT_LEADING_32<"clb", 0b000, 0b100>;
4166 def S2_clbp : T_COUNT_LEADING_64<"clb", 0b010, 0b000>;
4167 def S2_clbnorm : T_COUNT_LEADING_32<"normamt", 0b000, 0b111>;
4169 // Count leading zeros.
4170 def: Pat<(i32 (ctlz I32:$Rs)), (S2_cl0 I32:$Rs)>;
4171 def: Pat<(i32 (trunc (ctlz I64:$Rss))), (S2_cl0p I64:$Rss)>;
4173 // Count trailing zeros: 32-bit.
4174 def: Pat<(i32 (cttz I32:$Rs)), (S2_ct0 I32:$Rs)>;
4176 // Count leading ones.
4177 def: Pat<(i32 (ctlz (not I32:$Rs))), (S2_cl1 I32:$Rs)>;
4178 def: Pat<(i32 (trunc (ctlz (not I64:$Rss)))), (S2_cl1p I64:$Rss)>;
4180 // Count trailing ones: 32-bit.
4181 def: Pat<(i32 (cttz (not I32:$Rs))), (S2_ct1 I32:$Rs)>;
4183 // The 64-bit counts leading/trailing are defined in HexagonInstrInfoV4.td.
4185 // Bit set/clear/toggle
4187 let hasSideEffects = 0, hasNewValue = 1 in
4188 class T_SCT_BIT_IMM<string MnOp, bits<3> MinOp>
4189 : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, u5Imm:$u5),
4190 "$Rd = "#MnOp#"($Rs, #$u5)", [], "", S_2op_tc_1_SLOT23> {
4194 let IClass = 0b1000;
4195 let Inst{27-21} = 0b1100110;
4196 let Inst{20-16} = Rs;
4198 let Inst{12-8} = u5;
4199 let Inst{7-5} = MinOp;
4203 let hasSideEffects = 0, hasNewValue = 1 in
4204 class T_SCT_BIT_REG<string MnOp, bits<2> MinOp>
4205 : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
4206 "$Rd = "#MnOp#"($Rs, $Rt)", [], "", S_3op_tc_1_SLOT23> {
4210 let IClass = 0b1100;
4211 let Inst{27-22} = 0b011010;
4212 let Inst{20-16} = Rs;
4213 let Inst{12-8} = Rt;
4214 let Inst{7-6} = MinOp;
4218 def S2_clrbit_i : T_SCT_BIT_IMM<"clrbit", 0b001>;
4219 def S2_setbit_i : T_SCT_BIT_IMM<"setbit", 0b000>;
4220 def S2_togglebit_i : T_SCT_BIT_IMM<"togglebit", 0b010>;
4221 def S2_clrbit_r : T_SCT_BIT_REG<"clrbit", 0b01>;
4222 def S2_setbit_r : T_SCT_BIT_REG<"setbit", 0b00>;
4223 def S2_togglebit_r : T_SCT_BIT_REG<"togglebit", 0b10>;
4225 def: Pat<(i32 (and (i32 IntRegs:$Rs), (not (shl 1, u5ImmPred:$u5)))),
4226 (S2_clrbit_i IntRegs:$Rs, u5ImmPred:$u5)>;
4227 def: Pat<(i32 (or (i32 IntRegs:$Rs), (shl 1, u5ImmPred:$u5))),
4228 (S2_setbit_i IntRegs:$Rs, u5ImmPred:$u5)>;
4229 def: Pat<(i32 (xor (i32 IntRegs:$Rs), (shl 1, u5ImmPred:$u5))),
4230 (S2_togglebit_i IntRegs:$Rs, u5ImmPred:$u5)>;
4231 def: Pat<(i32 (and (i32 IntRegs:$Rs), (not (shl 1, (i32 IntRegs:$Rt))))),
4232 (S2_clrbit_r IntRegs:$Rs, IntRegs:$Rt)>;
4233 def: Pat<(i32 (or (i32 IntRegs:$Rs), (shl 1, (i32 IntRegs:$Rt)))),
4234 (S2_setbit_r IntRegs:$Rs, IntRegs:$Rt)>;
4235 def: Pat<(i32 (xor (i32 IntRegs:$Rs), (shl 1, (i32 IntRegs:$Rt)))),
4236 (S2_togglebit_r IntRegs:$Rs, IntRegs:$Rt)>;
4240 let hasSideEffects = 0 in
4241 class T_TEST_BIT_IMM<string MnOp, bits<3> MajOp>
4242 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, u5Imm:$u5),
4243 "$Pd = "#MnOp#"($Rs, #$u5)",
4244 [], "", S_2op_tc_2early_SLOT23> {
4248 let IClass = 0b1000;
4249 let Inst{27-24} = 0b0101;
4250 let Inst{23-21} = MajOp;
4251 let Inst{20-16} = Rs;
4253 let Inst{12-8} = u5;
4257 let hasSideEffects = 0 in
4258 class T_TEST_BIT_REG<string MnOp, bit IsNeg>
4259 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
4260 "$Pd = "#MnOp#"($Rs, $Rt)",
4261 [], "", S_3op_tc_2early_SLOT23> {
4265 let IClass = 0b1100;
4266 let Inst{27-22} = 0b011100;
4267 let Inst{21} = IsNeg;
4268 let Inst{20-16} = Rs;
4269 let Inst{12-8} = Rt;
4273 def S2_tstbit_i : T_TEST_BIT_IMM<"tstbit", 0b000>;
4274 def S2_tstbit_r : T_TEST_BIT_REG<"tstbit", 0>;
4276 let AddedComplexity = 20 in { // Complexity greater than cmp reg-imm.
4277 def: Pat<(i1 (setne (and (shl 1, u5ImmPred:$u5), (i32 IntRegs:$Rs)), 0)),
4278 (S2_tstbit_i IntRegs:$Rs, u5ImmPred:$u5)>;
4279 def: Pat<(i1 (setne (and (shl 1, (i32 IntRegs:$Rt)), (i32 IntRegs:$Rs)), 0)),
4280 (S2_tstbit_r IntRegs:$Rs, IntRegs:$Rt)>;
4281 def: Pat<(i1 (trunc (i32 IntRegs:$Rs))),
4282 (S2_tstbit_i IntRegs:$Rs, 0)>;
4283 def: Pat<(i1 (trunc (i64 DoubleRegs:$Rs))),
4284 (S2_tstbit_i (LoReg DoubleRegs:$Rs), 0)>;
4287 let hasSideEffects = 0 in
4288 class T_TEST_BITS_IMM<string MnOp, bits<2> MajOp, bit IsNeg>
4289 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, u6Imm:$u6),
4290 "$Pd = "#MnOp#"($Rs, #$u6)",
4291 [], "", S_2op_tc_2early_SLOT23> {
4295 let IClass = 0b1000;
4296 let Inst{27-24} = 0b0101;
4297 let Inst{23-22} = MajOp;
4298 let Inst{21} = IsNeg;
4299 let Inst{20-16} = Rs;
4300 let Inst{13-8} = u6;
4304 let hasSideEffects = 0 in
4305 class T_TEST_BITS_REG<string MnOp, bits<2> MajOp, bit IsNeg>
4306 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
4307 "$Pd = "#MnOp#"($Rs, $Rt)",
4308 [], "", S_3op_tc_2early_SLOT23> {
4312 let IClass = 0b1100;
4313 let Inst{27-24} = 0b0111;
4314 let Inst{23-22} = MajOp;
4315 let Inst{21} = IsNeg;
4316 let Inst{20-16} = Rs;
4317 let Inst{12-8} = Rt;
4321 def C2_bitsclri : T_TEST_BITS_IMM<"bitsclr", 0b10, 0>;
4322 def C2_bitsclr : T_TEST_BITS_REG<"bitsclr", 0b10, 0>;
4323 def C2_bitsset : T_TEST_BITS_REG<"bitsset", 0b01, 0>;
4325 let AddedComplexity = 20 in { // Complexity greater than compare reg-imm.
4326 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), u6ImmPred:$u6), 0)),
4327 (C2_bitsclri IntRegs:$Rs, u6ImmPred:$u6)>;
4328 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)), 0)),
4329 (C2_bitsclr IntRegs:$Rs, IntRegs:$Rt)>;
4332 let AddedComplexity = 10 in // Complexity greater than compare reg-reg.
4333 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)), IntRegs:$Rt)),
4334 (C2_bitsset IntRegs:$Rs, IntRegs:$Rt)>;
4336 //===----------------------------------------------------------------------===//
4338 //===----------------------------------------------------------------------===//
4340 //===----------------------------------------------------------------------===//
4342 //===----------------------------------------------------------------------===//
4343 //===----------------------------------------------------------------------===//
4345 //===----------------------------------------------------------------------===//
4347 //===----------------------------------------------------------------------===//
4349 //===----------------------------------------------------------------------===//
4351 def: Pat<(or (or (shl (or (shl (i32 (extloadi8 (add (i32 IntRegs:$b), 3))),
4353 (i32 (zextloadi8 (add (i32 IntRegs:$b), 2)))),
4355 (shl (i32 (zextloadi8 (add (i32 IntRegs:$b), 1))), (i32 8))),
4356 (zextloadi8 (i32 IntRegs:$b))),
4357 (A2_swiz (L2_loadri_io IntRegs:$b, 0))>;
4359 //===----------------------------------------------------------------------===//
4361 //===----------------------------------------------------------------------===//
4363 //===----------------------------------------------------------------------===//
4365 //===----------------------------------------------------------------------===//
4367 // Predicate transfer.
4368 let hasSideEffects = 0, hasNewValue = 1 in
4369 def C2_tfrpr : SInst<(outs IntRegs:$Rd), (ins PredRegs:$Ps),
4370 "$Rd = $Ps", [], "", S_2op_tc_1_SLOT23> {
4374 let IClass = 0b1000;
4375 let Inst{27-24} = 0b1001;
4377 let Inst{17-16} = Ps;
4381 // Transfer general register to predicate.
4382 let hasSideEffects = 0 in
4383 def C2_tfrrp: SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs),
4384 "$Pd = $Rs", [], "", S_2op_tc_2early_SLOT23> {
4388 let IClass = 0b1000;
4389 let Inst{27-21} = 0b0101010;
4390 let Inst{20-16} = Rs;
4394 let hasSideEffects = 0, isCodeGenOnly = 1 in
4395 def C2_pxfer_map: SInst<(outs PredRegs:$dst), (ins PredRegs:$src),
4399 // Patterns for loads of i1:
4400 def: Pat<(i1 (load AddrFI:$fi)),
4401 (C2_tfrrp (L2_loadrub_io AddrFI:$fi, 0))>;
4402 def: Pat<(i1 (load (add (i32 IntRegs:$Rs), s32ImmPred:$Off))),
4403 (C2_tfrrp (L2_loadrub_io IntRegs:$Rs, imm:$Off))>;
4404 def: Pat<(i1 (load (i32 IntRegs:$Rs))),
4405 (C2_tfrrp (L2_loadrub_io IntRegs:$Rs, 0))>;
4407 def I1toI32: OutPatFrag<(ops node:$Rs),
4408 (C2_muxii (i1 $Rs), 1, 0)>;
4410 def I32toI1: OutPatFrag<(ops node:$Rs),
4411 (i1 (C2_tfrrp (i32 $Rs)))>;
4413 defm: Storexm_pat<store, I1, s32ImmPred, I1toI32, S2_storerb_io>;
4414 def: Storexm_simple_pat<store, I1, I1toI32, S2_storerb_io>;
4416 //===----------------------------------------------------------------------===//
4418 //===----------------------------------------------------------------------===//
4420 //===----------------------------------------------------------------------===//
4422 //===----------------------------------------------------------------------===//
4423 class S_2OpInstImm<string Mnemonic, bits<3>MajOp, bits<3>MinOp,
4424 Operand Imm, list<dag> pattern = [], bit isRnd = 0>
4425 : SInst<(outs DoubleRegs:$dst), (ins DoubleRegs:$src1, Imm:$src2),
4426 "$dst = "#Mnemonic#"($src1, #$src2)"#!if(isRnd, ":rnd", ""),
4430 let IClass = 0b1000;
4431 let Inst{27-24} = 0;
4432 let Inst{23-21} = MajOp;
4433 let Inst{20-16} = src1;
4434 let Inst{7-5} = MinOp;
4435 let Inst{4-0} = dst;
4438 class S_2OpInstImmI6<string Mnemonic, SDNode OpNode, bits<3>MinOp>
4439 : S_2OpInstImm<Mnemonic, 0b000, MinOp, u6Imm,
4440 [(set (i64 DoubleRegs:$dst), (OpNode (i64 DoubleRegs:$src1),
4441 u6ImmPred:$src2))]> {
4443 let Inst{13-8} = src2;
4446 // Shift by immediate.
4447 def S2_asr_i_p : S_2OpInstImmI6<"asr", sra, 0b000>;
4448 def S2_asl_i_p : S_2OpInstImmI6<"asl", shl, 0b010>;
4449 def S2_lsr_i_p : S_2OpInstImmI6<"lsr", srl, 0b001>;
4451 // Shift left by small amount and add.
4452 let AddedComplexity = 100, hasNewValue = 1, hasSideEffects = 0 in
4453 def S2_addasl_rrri: SInst <(outs IntRegs:$Rd),
4454 (ins IntRegs:$Rt, IntRegs:$Rs, u3Imm:$u3),
4455 "$Rd = addasl($Rt, $Rs, #$u3)" ,
4456 [(set (i32 IntRegs:$Rd), (add (i32 IntRegs:$Rt),
4457 (shl (i32 IntRegs:$Rs), u3ImmPred:$u3)))],
4458 "", S_3op_tc_2_SLOT23> {
4464 let IClass = 0b1100;
4466 let Inst{27-21} = 0b0100000;
4467 let Inst{20-16} = Rs;
4469 let Inst{12-8} = Rt;
4474 //===----------------------------------------------------------------------===//
4476 //===----------------------------------------------------------------------===//
4478 //===----------------------------------------------------------------------===//
4480 //===----------------------------------------------------------------------===//
4481 //===----------------------------------------------------------------------===//
4483 //===----------------------------------------------------------------------===//
4485 //===----------------------------------------------------------------------===//
4487 //===----------------------------------------------------------------------===//
4488 //===----------------------------------------------------------------------===//
4490 //===----------------------------------------------------------------------===//
4492 //===----------------------------------------------------------------------===//
4494 //===----------------------------------------------------------------------===//
4496 //===----------------------------------------------------------------------===//
4498 //===----------------------------------------------------------------------===//
4499 def HexagonBARRIER: SDNode<"HexagonISD::BARRIER", SDTNone, [SDNPHasChain]>;
4501 let hasSideEffects = 1, isSoloAX = 1 in
4502 def Y2_barrier : SYSInst<(outs), (ins),
4504 [(HexagonBARRIER)],"",ST_tc_st_SLOT0> {
4505 let Inst{31-28} = 0b1010;
4506 let Inst{27-21} = 0b1000000;
4509 //===----------------------------------------------------------------------===//
4511 //===----------------------------------------------------------------------===//
4513 // Generate frameindex addresses. The main reason for the offset operand is
4514 // that every instruction that is allowed to have frame index as an operand
4515 // will then have that operand followed by an immediate operand (the offset).
4516 // This simplifies the frame-index elimination code.
4518 let isMoveImm = 1, isAsCheapAsAMove = 1, isReMaterializable = 1,
4519 isPseudo = 1, isCodeGenOnly = 1, hasSideEffects = 0 in {
4520 def PS_fi : ALU32_ri<(outs IntRegs:$Rd),
4521 (ins IntRegs:$fi, s32Imm:$off), "">;
4522 def PS_fia : ALU32_ri<(outs IntRegs:$Rd),
4523 (ins IntRegs:$Rs, IntRegs:$fi, s32Imm:$off), "">;
4526 def: Pat<(orisadd (i32 AddrFI:$Rs), s32ImmPred:$off),
4527 (PS_fi (i32 AddrFI:$Rs), s32ImmPred:$off)>;
4529 //===----------------------------------------------------------------------===//
4531 //===----------------------------------------------------------------------===//
4533 let isExtendable = 1, isExtentSigned = 1, opExtentBits = 9, opExtentAlign = 2,
4534 opExtendable = 0, hasSideEffects = 0 in
4535 class LOOP_iBase<string mnemonic, Operand brOp, bit mustExtend = 0>
4536 : CRInst<(outs), (ins brOp:$offset, u10Imm:$src2),
4537 #mnemonic#"($offset, #$src2)",
4538 [], "" , CR_tc_3x_SLOT3> {
4542 let IClass = 0b0110;
4544 let Inst{27-22} = 0b100100;
4545 let Inst{21} = !if (!eq(mnemonic, "loop0"), 0b0, 0b1);
4546 let Inst{20-16} = src2{9-5};
4547 let Inst{12-8} = offset{8-4};
4548 let Inst{7-5} = src2{4-2};
4549 let Inst{4-3} = offset{3-2};
4550 let Inst{1-0} = src2{1-0};
4553 let isExtendable = 1, isExtentSigned = 1, opExtentBits = 9, opExtentAlign = 2,
4554 opExtendable = 0, hasSideEffects = 0 in
4555 class LOOP_rBase<string mnemonic, Operand brOp, bit mustExtend = 0>
4556 : CRInst<(outs), (ins brOp:$offset, IntRegs:$src2),
4557 #mnemonic#"($offset, $src2)",
4558 [], "" ,CR_tc_3x_SLOT3> {
4562 let IClass = 0b0110;
4564 let Inst{27-22} = 0b000000;
4565 let Inst{21} = !if (!eq(mnemonic, "loop0"), 0b0, 0b1);
4566 let Inst{20-16} = src2;
4567 let Inst{12-8} = offset{8-4};
4568 let Inst{4-3} = offset{3-2};
4571 multiclass LOOP_ri<string mnemonic> {
4572 def i : LOOP_iBase<mnemonic, brtarget>;
4573 def r : LOOP_rBase<mnemonic, brtarget>;
4575 let isCodeGenOnly = 1, isExtended = 1, opExtendable = 0 in {
4576 def iext: LOOP_iBase<mnemonic, brtargetExt, 1>;
4577 def rext: LOOP_rBase<mnemonic, brtargetExt, 1>;
4582 let Defs = [SA0, LC0, USR] in
4583 defm J2_loop0 : LOOP_ri<"loop0">;
4585 // Interestingly only loop0's appear to set usr.lpcfg
4586 let Defs = [SA1, LC1] in
4587 defm J2_loop1 : LOOP_ri<"loop1">;
4589 let isBranch = 1, isTerminator = 1, hasSideEffects = 0,
4590 Defs = [PC, LC0], Uses = [SA0, LC0] in {
4591 def ENDLOOP0 : Endloop<(outs), (ins brtarget:$offset),
4596 let isBranch = 1, isTerminator = 1, hasSideEffects = 0,
4597 Defs = [PC, LC1], Uses = [SA1, LC1] in {
4598 def ENDLOOP1 : Endloop<(outs), (ins brtarget:$offset),
4603 // Pipelined loop instructions, sp[123]loop0
4604 let Defs = [LC0, SA0, P3, USR], hasSideEffects = 0,
4605 isExtentSigned = 1, isExtendable = 1, opExtentBits = 9, opExtentAlign = 2,
4606 opExtendable = 0, isPredicateLate = 1 in
4607 class SPLOOP_iBase<string SP, bits<2> op>
4608 : CRInst <(outs), (ins brtarget:$r7_2, u10Imm:$U10),
4609 "p3 = sp"#SP#"loop0($r7_2, #$U10)" > {
4613 let IClass = 0b0110;
4615 let Inst{22-21} = op;
4616 let Inst{27-23} = 0b10011;
4617 let Inst{20-16} = U10{9-5};
4618 let Inst{12-8} = r7_2{8-4};
4619 let Inst{7-5} = U10{4-2};
4620 let Inst{4-3} = r7_2{3-2};
4621 let Inst{1-0} = U10{1-0};
4624 let Defs = [LC0, SA0, P3, USR], hasSideEffects = 0,
4625 isExtentSigned = 1, isExtendable = 1, opExtentBits = 9, opExtentAlign = 2,
4626 opExtendable = 0, isPredicateLate = 1 in
4627 class SPLOOP_rBase<string SP, bits<2> op>
4628 : CRInst <(outs), (ins brtarget:$r7_2, IntRegs:$Rs),
4629 "p3 = sp"#SP#"loop0($r7_2, $Rs)" > {
4633 let IClass = 0b0110;
4635 let Inst{22-21} = op;
4636 let Inst{27-23} = 0b00001;
4637 let Inst{20-16} = Rs;
4638 let Inst{12-8} = r7_2{8-4};
4639 let Inst{4-3} = r7_2{3-2};
4642 multiclass SPLOOP_ri<string mnemonic, bits<2> op> {
4643 def i : SPLOOP_iBase<mnemonic, op>;
4644 def r : SPLOOP_rBase<mnemonic, op>;
4647 defm J2_ploop1s : SPLOOP_ri<"1", 0b01>;
4648 defm J2_ploop2s : SPLOOP_ri<"2", 0b10>;
4649 defm J2_ploop3s : SPLOOP_ri<"3", 0b11>;
4651 // if (Rs[!>=<]=#0) jump:[t/nt]
4652 let Defs = [PC], isPredicated = 1, isBranch = 1, hasSideEffects = 0,
4653 hasSideEffects = 0 in
4654 class J2_jump_0_Base<string compare, bit isTak, bits<2> op>
4655 : CRInst <(outs), (ins IntRegs:$Rs, brtarget:$r13_2),
4656 "if ($Rs"#compare#"#0) jump"#!if(isTak, ":t", ":nt")#" $r13_2" > {
4660 let IClass = 0b0110;
4662 let Inst{27-24} = 0b0001;
4663 let Inst{23-22} = op;
4664 let Inst{12} = isTak;
4665 let Inst{21} = r13_2{14};
4666 let Inst{20-16} = Rs;
4667 let Inst{11-1} = r13_2{12-2};
4668 let Inst{13} = r13_2{13};
4671 multiclass J2_jump_compare_0<string compare, bits<2> op> {
4672 def NAME : J2_jump_0_Base<compare, 0, op>;
4673 def NAME#pt : J2_jump_0_Base<compare, 1, op>;
4676 defm J2_jumprz : J2_jump_compare_0<"!=", 0b00>;
4677 defm J2_jumprgtez : J2_jump_compare_0<">=", 0b01>;
4678 defm J2_jumprnz : J2_jump_compare_0<"==", 0b10>;
4679 defm J2_jumprltez : J2_jump_compare_0<"<=", 0b11>;
4681 // Transfer to/from Control/GPR Guest/GPR
4682 let hasSideEffects = 0 in
4683 class TFR_CR_RS_base<RegisterClass CTRC, RegisterClass RC, bit isDouble>
4684 : CRInst <(outs CTRC:$dst), (ins RC:$src),
4685 "$dst = $src", [], "", CR_tc_3x_SLOT3> {
4689 let IClass = 0b0110;
4691 let Inst{27-25} = 0b001;
4692 let Inst{24} = isDouble;
4693 let Inst{23-21} = 0b001;
4694 let Inst{20-16} = src;
4695 let Inst{4-0} = dst;
4698 def A2_tfrrcr : TFR_CR_RS_base<CtrRegs, IntRegs, 0b0>;
4699 def A4_tfrpcp : TFR_CR_RS_base<CtrRegs64, DoubleRegs, 0b1>;
4700 def : InstAlias<"m0 = $Rs", (A2_tfrrcr C6, IntRegs:$Rs)>;
4701 def : InstAlias<"m1 = $Rs", (A2_tfrrcr C7, IntRegs:$Rs)>;
4703 let hasSideEffects = 0 in
4704 class TFR_RD_CR_base<RegisterClass RC, RegisterClass CTRC, bit isSingle>
4705 : CRInst <(outs RC:$dst), (ins CTRC:$src),
4706 "$dst = $src", [], "", CR_tc_3x_SLOT3> {
4710 let IClass = 0b0110;
4712 let Inst{27-26} = 0b10;
4713 let Inst{25} = isSingle;
4714 let Inst{24-21} = 0b0000;
4715 let Inst{20-16} = src;
4716 let Inst{4-0} = dst;
4719 let hasNewValue = 1, opNewValue = 0 in
4720 def A2_tfrcrr : TFR_RD_CR_base<IntRegs, CtrRegs, 1>;
4721 def A4_tfrcpp : TFR_RD_CR_base<DoubleRegs, CtrRegs64, 0>;
4722 def : InstAlias<"$Rd = m0", (A2_tfrcrr IntRegs:$Rd, C6)>;
4723 def : InstAlias<"$Rd = m1", (A2_tfrcrr IntRegs:$Rd, C7)>;
4725 // Y4_trace: Send value to etm trace.
4726 let isSoloAX = 1, hasSideEffects = 0 in
4727 def Y4_trace: CRInst <(outs), (ins IntRegs:$Rs),
4731 let IClass = 0b0110;
4732 let Inst{27-21} = 0b0010010;
4733 let Inst{20-16} = Rs;
4736 // Support for generating global address.
4737 // Taken from X86InstrInfo.td.
4738 def SDTHexagonCONST32 : SDTypeProfile<1, 1, [SDTCisVT<0, i32>,
4741 def HexagonCONST32 : SDNode<"HexagonISD::CONST32", SDTHexagonCONST32>;
4742 def HexagonCONST32_GP : SDNode<"HexagonISD::CONST32_GP", SDTHexagonCONST32>;
4744 // HI/LO Instructions
4745 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0,
4746 hasNewValue = 1, opNewValue = 0 in
4747 class REG_IMMED<string RegHalf, bit Rs, bits<3> MajOp, bit MinOp>
4748 : ALU32_ri<(outs IntRegs:$dst),
4749 (ins u16Imm:$imm_value),
4750 "$dst"#RegHalf#" = $imm_value", []> {
4753 let IClass = 0b0111;
4756 let Inst{26-24} = MajOp;
4757 let Inst{21} = MinOp;
4758 let Inst{20-16} = dst;
4759 let Inst{23-22} = imm_value{15-14};
4760 let Inst{13-0} = imm_value{13-0};
4763 let isAsmParserOnly = 1 in {
4764 def LO : REG_IMMED<".l", 0b0, 0b001, 0b1>;
4765 def HI : REG_IMMED<".h", 0b0, 0b010, 0b1>;
4768 let isReMaterializable = 1, isMoveImm = 1, isAsmParserOnly = 1 in {
4769 def CONST32 : CONSTLDInst<(outs IntRegs:$Rd), (ins i32imm:$v),
4770 "$Rd = CONST32(#$v)", [(set I32:$Rd, imm:$v)]>;
4771 def CONST64 : CONSTLDInst<(outs DoubleRegs:$Rd), (ins i64imm:$v),
4772 "$Rd = CONST64(#$v)", [(set I64:$Rd, imm:$v)]>;
4775 // Map TLS addressses to A2_tfrsi.
4776 def: Pat<(HexagonCONST32 tglobaltlsaddr:$addr), (A2_tfrsi s16Ext:$addr)>;
4777 def: Pat<(HexagonCONST32 bbl:$label), (A2_tfrsi s16Ext:$label)>;
4779 let hasSideEffects = 0, isReMaterializable = 1, isPseudo = 1,
4780 isCodeGenOnly = 1 in
4781 def PS_true : SInst<(outs PredRegs:$dst), (ins), "",
4782 [(set (i1 PredRegs:$dst), 1)]>;
4784 let hasSideEffects = 0, isReMaterializable = 1, isPseudo = 1,
4785 isCodeGenOnly = 1 in
4786 def PS_false : SInst<(outs PredRegs:$dst), (ins), "",
4787 [(set (i1 PredRegs:$dst), 0)]>;
4789 // Pseudo instructions.
4790 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
4791 def SDT_SPCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>,
4792 SDTCisVT<1, i32> ]>;
4794 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
4795 [SDNPHasChain, SDNPOutGlue]>;
4796 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeqEnd,
4797 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
4799 def SDT_SPCall : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
4801 // For tailcalls a HexagonTCRet SDNode has 3 SDNode Properties - a chain,
4802 // Optional Flag and Variable Arguments.
4803 // Its 1 Operand has pointer type.
4804 def HexagonTCRet : SDNode<"HexagonISD::TC_RETURN", SDT_SPCall,
4805 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
4807 let Defs = [R29, R30], Uses = [R31, R30, R29], isPseudo = 1 in
4808 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
4809 ".error \"should not emit\" ",
4810 [(callseq_start timm:$amt)]>;
4812 let Defs = [R29, R30, R31], Uses = [R29], isPseudo = 1 in
4813 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
4814 ".error \"should not emit\" ",
4815 [(callseq_end timm:$amt1, timm:$amt2)]>;
4817 // Call subroutine indirectly.
4818 let Defs = VolatileV3.Regs in
4819 def J2_callr : JUMPR_MISC_CALLR<0, 1>;
4821 // Indirect tail-call.
4822 let isPseudo = 1, isCall = 1, isReturn = 1, isBarrier = 1, isPredicable = 0,
4823 isTerminator = 1, isCodeGenOnly = 1 in
4824 def PS_tailcall_r : T_JMPr;
4826 // Direct tail-calls.
4827 let isPseudo = 1, isCall = 1, isReturn = 1, isBarrier = 1, isPredicable = 0,
4828 isTerminator = 1, isCodeGenOnly = 1 in
4829 def PS_tailcall_i : JInst<(outs), (ins calltarget:$dst), "", []>;
4832 def: Pat<(HexagonTCRet tglobaladdr:$dst),
4833 (PS_tailcall_i tglobaladdr:$dst)>;
4834 def: Pat<(HexagonTCRet texternalsym:$dst),
4835 (PS_tailcall_i texternalsym:$dst)>;
4836 def: Pat<(HexagonTCRet I32:$dst),
4837 (PS_tailcall_r I32:$dst)>;
4839 // Map from r0 = and(r1, 65535) to r0 = zxth(r1)
4840 def: Pat<(and (i32 IntRegs:$src1), 65535),
4841 (A2_zxth IntRegs:$src1)>;
4843 // Map from r0 = and(r1, 255) to r0 = zxtb(r1).
4844 def: Pat<(and (i32 IntRegs:$src1), 255),
4845 (A2_zxtb IntRegs:$src1)>;
4847 // Map Add(p1, true) to p1 = not(p1).
4848 // Add(p1, false) should never be produced,
4849 // if it does, it got to be mapped to NOOP.
4850 def: Pat<(add (i1 PredRegs:$src1), -1),
4851 (C2_not PredRegs:$src1)>;
4853 // Map from p0 = pnot(p0); r0 = mux(p0, #i, #j) => r0 = mux(p0, #j, #i).
4854 def: Pat<(select (not (i1 PredRegs:$src1)), s8ImmPred:$src2, s32ImmPred:$src3),
4855 (C2_muxii PredRegs:$src1, s32ImmPred:$src3, s8ImmPred:$src2)>;
4857 // Map from p0 = pnot(p0); r0 = select(p0, #i, r1)
4858 // => r0 = C2_muxir(p0, r1, #i)
4859 def: Pat<(select (not (i1 PredRegs:$src1)), s32ImmPred:$src2,
4860 (i32 IntRegs:$src3)),
4861 (C2_muxir PredRegs:$src1, IntRegs:$src3, s32ImmPred:$src2)>;
4863 // Map from p0 = pnot(p0); r0 = mux(p0, r1, #i)
4864 // => r0 = C2_muxri (p0, #i, r1)
4865 def: Pat<(select (not (i1 PredRegs:$src1)), IntRegs:$src2, s32ImmPred:$src3),
4866 (C2_muxri PredRegs:$src1, s32ImmPred:$src3, IntRegs:$src2)>;
4868 // Map from p0 = pnot(p0); if (p0) jump => if (!p0) jump.
4869 def: Pat<(brcond (not (i1 PredRegs:$src1)), bb:$offset),
4870 (J2_jumpf PredRegs:$src1, bb:$offset)>;
4872 // Map from Rdd = sign_extend_inreg(Rss, i32) -> Rdd = A2_sxtw(Rss.lo).
4873 def: Pat<(i64 (sext_inreg (i64 DoubleRegs:$src1), i32)),
4874 (A2_sxtw (LoReg DoubleRegs:$src1))>;
4876 // Map from Rdd = sign_extend_inreg(Rss, i16) -> Rdd = A2_sxtw(A2_sxth(Rss.lo)).
4877 def: Pat<(i64 (sext_inreg (i64 DoubleRegs:$src1), i16)),
4878 (A2_sxtw (A2_sxth (LoReg DoubleRegs:$src1)))>;
4880 // Map from Rdd = sign_extend_inreg(Rss, i8) -> Rdd = A2_sxtw(A2_sxtb(Rss.lo)).
4881 def: Pat<(i64 (sext_inreg (i64 DoubleRegs:$src1), i8)),
4882 (A2_sxtw (A2_sxtb (LoReg DoubleRegs:$src1)))>;
4884 // We want to prevent emitting pnot's as much as possible.
4885 // Map brcond with an unsupported setcc to a J2_jumpf.
4886 def : Pat <(brcond (i1 (setne (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4888 (J2_jumpf (C2_cmpeq (i32 IntRegs:$src1), (i32 IntRegs:$src2)),
4891 def : Pat <(brcond (i1 (setne (i32 IntRegs:$src1), s10ImmPred:$src2)),
4893 (J2_jumpf (C2_cmpeqi (i32 IntRegs:$src1), s10ImmPred:$src2), bb:$offset)>;
4895 def: Pat<(brcond (i1 (setne (i1 PredRegs:$src1), (i1 -1))), bb:$offset),
4896 (J2_jumpf PredRegs:$src1, bb:$offset)>;
4898 def: Pat<(brcond (i1 (setne (i1 PredRegs:$src1), (i1 0))), bb:$offset),
4899 (J2_jumpt PredRegs:$src1, bb:$offset)>;
4901 // cmp.lt(Rs, Imm) -> !cmp.ge(Rs, Imm) -> !cmp.gt(Rs, Imm-1)
4902 def: Pat<(brcond (i1 (setlt (i32 IntRegs:$src1), s8ImmPred:$src2)), bb:$offset),
4903 (J2_jumpf (C2_cmpgti IntRegs:$src1, (DEC_CONST_SIGNED s8ImmPred:$src2)),
4906 // Map from a 64-bit select to an emulated 64-bit mux.
4907 // Hexagon does not support 64-bit MUXes; so emulate with combines.
4908 def: Pat<(select (i1 PredRegs:$src1), (i64 DoubleRegs:$src2),
4909 (i64 DoubleRegs:$src3)),
4910 (A2_combinew (C2_mux PredRegs:$src1, (HiReg DoubleRegs:$src2),
4911 (HiReg DoubleRegs:$src3)),
4912 (C2_mux PredRegs:$src1, (LoReg DoubleRegs:$src2),
4913 (LoReg DoubleRegs:$src3)))>;
4915 // Map from a 1-bit select to logical ops.
4916 // From LegalizeDAG.cpp: (B1 ? B2 : B3) <=> (B1 & B2)|(!B1&B3).
4917 def: Pat<(select (i1 PredRegs:$src1), (i1 PredRegs:$src2), (i1 PredRegs:$src3)),
4918 (C2_or (C2_and PredRegs:$src1, PredRegs:$src2),
4919 (C2_and (C2_not PredRegs:$src1), PredRegs:$src3))>;
4921 // Map for truncating from 64 immediates to 32 bit immediates.
4922 def: Pat<(i32 (trunc (i64 DoubleRegs:$src))),
4923 (LoReg DoubleRegs:$src)>;
4925 // Map for truncating from i64 immediates to i1 bit immediates.
4926 def: Pat<(i1 (trunc (i64 DoubleRegs:$src))),
4927 (C2_tfrrp (LoReg DoubleRegs:$src))>;
4929 // rs <= rt -> !(rs > rt).
4930 let AddedComplexity = 30 in
4931 def: Pat<(i1 (setle (i32 IntRegs:$src1), s32ImmPred:$src2)),
4932 (C2_not (C2_cmpgti IntRegs:$src1, s32ImmPred:$src2))>;
4934 // rs <= rt -> !(rs > rt).
4935 def : Pat<(i1 (setle (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4936 (i1 (C2_not (C2_cmpgt (i32 IntRegs:$src1), (i32 IntRegs:$src2))))>;
4938 // Rss <= Rtt -> !(Rss > Rtt).
4939 def: Pat<(i1 (setle (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4940 (C2_not (C2_cmpgtp DoubleRegs:$src1, DoubleRegs:$src2))>;
4942 // Map cmpne -> cmpeq.
4943 // Hexagon_TODO: We should improve on this.
4944 // rs != rt -> !(rs == rt).
4945 let AddedComplexity = 30 in
4946 def: Pat<(i1 (setne (i32 IntRegs:$src1), s32ImmPred:$src2)),
4947 (C2_not (C2_cmpeqi IntRegs:$src1, s32ImmPred:$src2))>;
4949 // Convert setne back to xor for hexagon since we compute w/ pred registers.
4950 def: Pat<(i1 (setne (i1 PredRegs:$src1), (i1 PredRegs:$src2))),
4951 (C2_xor PredRegs:$src1, PredRegs:$src2)>;
4953 // Map cmpne(Rss) -> !cmpew(Rss).
4954 // rs != rt -> !(rs == rt).
4955 def: Pat<(i1 (setne (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4956 (C2_not (C2_cmpeqp DoubleRegs:$src1, DoubleRegs:$src2))>;
4958 // Map cmpge(Rs, Rt) -> !(cmpgt(Rs, Rt).
4959 // rs >= rt -> !(rt > rs).
4960 def : Pat <(i1 (setge (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4961 (i1 (C2_not (i1 (C2_cmpgt (i32 IntRegs:$src2), (i32 IntRegs:$src1)))))>;
4963 // cmpge(Rs, Imm) -> cmpgt(Rs, Imm-1)
4964 let AddedComplexity = 30 in
4965 def: Pat<(i1 (setge (i32 IntRegs:$src1), s32ImmPred:$src2)),
4966 (C2_cmpgti IntRegs:$src1, (DEC_CONST_SIGNED s32ImmPred:$src2))>;
4968 // Map cmpge(Rss, Rtt) -> !cmpgt(Rtt, Rss).
4969 // rss >= rtt -> !(rtt > rss).
4970 def: Pat<(i1 (setge (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4971 (C2_not (C2_cmpgtp DoubleRegs:$src2, DoubleRegs:$src1))>;
4973 // Map cmplt(Rs, Imm) -> !cmpge(Rs, Imm).
4974 // !cmpge(Rs, Imm) -> !cmpgt(Rs, Imm-1).
4975 // rs < rt -> !(rs >= rt).
4976 let AddedComplexity = 30 in
4977 def: Pat<(i1 (setlt (i32 IntRegs:$src1), s32ImmPred:$src2)),
4978 (C2_not (C2_cmpgti IntRegs:$src1,
4979 (DEC_CONST_SIGNED s32ImmPred:$src2)))>;
4981 // Generate cmpgeu(Rs, #0) -> cmpeq(Rs, Rs)
4982 def: Pat<(i1 (setuge (i32 IntRegs:$src1), 0)),
4983 (C2_cmpeq IntRegs:$src1, IntRegs:$src1)>;
4985 // Generate cmpgeu(Rs, #u8) -> cmpgtu(Rs, #u8 -1)
4986 def: Pat<(i1 (setuge (i32 IntRegs:$src1), u32ImmPred:$src2)),
4987 (C2_cmpgtui IntRegs:$src1, (DEC_CONST_UNSIGNED u32ImmPred:$src2))>;
4989 // Generate cmpgtu(Rs, #u9)
4990 def: Pat<(i1 (setugt (i32 IntRegs:$src1), u32ImmPred:$src2)),
4991 (C2_cmpgtui IntRegs:$src1, u32ImmPred:$src2)>;
4993 // Map from Rs >= Rt -> !(Rt > Rs).
4994 // rs >= rt -> !(rt > rs).
4995 def: Pat<(i1 (setuge (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4996 (C2_not (C2_cmpgtup DoubleRegs:$src2, DoubleRegs:$src1))>;
4998 // Map from cmpleu(Rss, Rtt) -> !cmpgtu(Rss, Rtt-1).
4999 // Map from (Rs <= Rt) -> !(Rs > Rt).
5000 def: Pat<(i1 (setule (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
5001 (C2_not (C2_cmpgtup DoubleRegs:$src1, DoubleRegs:$src2))>;
5005 def: Pat<(i32 (sext (i1 PredRegs:$src1))),
5006 (C2_muxii PredRegs:$src1, -1, 0)>;
5009 def: Pat<(i64 (sext (i1 PredRegs:$src1))),
5010 (A2_combinew (A2_tfrsi -1), (C2_muxii PredRegs:$src1, -1, 0))>;
5014 def: Pat<(i32 (zext (i1 PredRegs:$src1))),
5015 (C2_muxii PredRegs:$src1, 1, 0)>;
5017 // Map from Rs = Pd to Pd = mux(Pd, #1, #0)
5018 def: Pat<(i32 (anyext (i1 PredRegs:$src1))),
5019 (C2_muxii PredRegs:$src1, 1, 0)>;
5021 // Map from Rss = Pd to Rdd = sxtw (mux(Pd, #1, #0))
5022 def: Pat<(i64 (anyext (i1 PredRegs:$src1))),
5023 (A2_sxtw (C2_muxii PredRegs:$src1, 1, 0))>;
5025 // Clear the sign bit in a 64-bit register.
5026 def ClearSign : OutPatFrag<(ops node:$Rss),
5027 (A2_combinew (S2_clrbit_i (HiReg $Rss), 31), (LoReg $Rss))>;
5029 def MulHU : OutPatFrag<(ops node:$Rss, node:$Rtt),
5035 (S2_lsr_i_p (M2_dpmpyuu_s0 (LoReg $Rss), (LoReg $Rtt)), 32),
5038 (A2_combinew (A2_tfrsi 0),
5039 (LoReg (M2_dpmpyuu_s0 (LoReg $Rss), (HiReg $Rtt))))),
5043 (S2_lsr_i_p (M2_dpmpyuu_s0 (LoReg $Rss), (HiReg $Rtt)), 32))>;
5045 // Multiply 64-bit unsigned and use upper result.
5046 def : Pat <(mulhu I64:$Rss, I64:$Rtt), (MulHU $Rss, $Rtt)>;
5048 // Multiply 64-bit signed and use upper result.
5050 // For two signed 64-bit integers A and B, let A' and B' denote A and B
5051 // with the sign bit cleared. Then A = -2^63*s(A) + A', where s(A) is the
5052 // sign bit of A (and identically for B). With this notation, the signed
5053 // product A*B can be written as:
5054 // AB = (-2^63 s(A) + A') * (-2^63 s(B) + B')
5055 // = 2^126 s(A)s(B) - 2^63 [s(A)B'+s(B)A'] + A'B'
5056 // = 2^126 s(A)s(B) + 2^63 [s(A)B'+s(B)A'] + A'B' - 2*2^63 [s(A)B'+s(B)A']
5057 // = (unsigned product AB) - 2^64 [s(A)B'+s(B)A']
5059 def : Pat <(mulhs I64:$Rss, I64:$Rtt),
5063 (A2_andp (S2_asr_i_p $Rss, 63), (ClearSign $Rtt)),
5064 (A2_andp (S2_asr_i_p $Rtt, 63), (ClearSign $Rss))))>;
5066 // Hexagon specific ISD nodes.
5067 def SDTHexagonALLOCA : SDTypeProfile<1, 2,
5068 [SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
5069 def HexagonALLOCA : SDNode<"HexagonISD::ALLOCA", SDTHexagonALLOCA,
5072 // The reason for the custom inserter is to record all ALLOCA instructions
5073 // in MachineFunctionInfo.
5074 let Defs = [R29], isCodeGenOnly = 1, isPseudo = 1, hasSideEffects = 1 in
5075 def PS_alloca: ALU32Inst<(outs IntRegs:$Rd),
5076 (ins IntRegs:$Rs, u32Imm:$A), "",
5077 [(set (i32 IntRegs:$Rd),
5078 (HexagonALLOCA (i32 IntRegs:$Rs), (i32 imm:$A)))]>;
5080 let isCodeGenOnly = 1, isPseudo = 1, Uses = [R30], hasSideEffects = 0 in
5081 def PS_aligna : ALU32Inst<(outs IntRegs:$Rd), (ins u32Imm:$A), "", []>;
5083 def HexagonJT: SDNode<"HexagonISD::JT", SDTIntUnaryOp>;
5084 def HexagonCP: SDNode<"HexagonISD::CP", SDTIntUnaryOp>;
5086 def: Pat<(HexagonJT tjumptable:$dst), (A2_tfrsi s16Ext:$dst)>;
5087 def: Pat<(HexagonCP tconstpool:$dst), (A2_tfrsi s16Ext:$dst)>;
5091 //===----------------------------------------------------------------------===//
5093 // Shift by immediate/register and accumulate/logical
5094 //===----------------------------------------------------------------------===//
5096 // Rx[+-&|]=asr(Rs,#u5)
5097 // Rx[+-&|^]=lsr(Rs,#u5)
5098 // Rx[+-&|^]=asl(Rs,#u5)
5100 let hasNewValue = 1, opNewValue = 0 in
5101 class T_shift_imm_acc_r <string opc1, string opc2, SDNode OpNode1,
5102 SDNode OpNode2, bits<3> majOp, bits<2> minOp>
5103 : SInst_acc<(outs IntRegs:$Rx),
5104 (ins IntRegs:$src1, IntRegs:$Rs, u5Imm:$u5),
5105 "$Rx "#opc2#opc1#"($Rs, #$u5)",
5106 [(set (i32 IntRegs:$Rx),
5107 (OpNode2 (i32 IntRegs:$src1),
5108 (OpNode1 (i32 IntRegs:$Rs), u5ImmPred:$u5)))],
5109 "$src1 = $Rx", S_2op_tc_2_SLOT23> {
5114 let IClass = 0b1000;
5116 let Inst{27-24} = 0b1110;
5117 let Inst{23-22} = majOp{2-1};
5119 let Inst{7} = majOp{0};
5120 let Inst{6-5} = minOp;
5122 let Inst{20-16} = Rs;
5123 let Inst{12-8} = u5;
5126 // Rx[+-&|]=asr(Rs,Rt)
5127 // Rx[+-&|^]=lsr(Rs,Rt)
5128 // Rx[+-&|^]=asl(Rs,Rt)
5130 let hasNewValue = 1, opNewValue = 0 in
5131 class T_shift_reg_acc_r <string opc1, string opc2, SDNode OpNode1,
5132 SDNode OpNode2, bits<2> majOp, bits<2> minOp>
5133 : SInst_acc<(outs IntRegs:$Rx),
5134 (ins IntRegs:$src1, IntRegs:$Rs, IntRegs:$Rt),
5135 "$Rx "#opc2#opc1#"($Rs, $Rt)",
5136 [(set (i32 IntRegs:$Rx),
5137 (OpNode2 (i32 IntRegs:$src1),
5138 (OpNode1 (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))],
5139 "$src1 = $Rx", S_3op_tc_2_SLOT23 > {
5144 let IClass = 0b1100;
5146 let Inst{27-24} = 0b1100;
5147 let Inst{23-22} = majOp;
5148 let Inst{7-6} = minOp;
5150 let Inst{20-16} = Rs;
5151 let Inst{12-8} = Rt;
5154 // Rxx[+-&|]=asr(Rss,#u6)
5155 // Rxx[+-&|^]=lsr(Rss,#u6)
5156 // Rxx[+-&|^]=asl(Rss,#u6)
5158 class T_shift_imm_acc_p <string opc1, string opc2, SDNode OpNode1,
5159 SDNode OpNode2, bits<3> majOp, bits<2> minOp>
5160 : SInst_acc<(outs DoubleRegs:$Rxx),
5161 (ins DoubleRegs:$src1, DoubleRegs:$Rss, u6Imm:$u6),
5162 "$Rxx "#opc2#opc1#"($Rss, #$u6)",
5163 [(set (i64 DoubleRegs:$Rxx),
5164 (OpNode2 (i64 DoubleRegs:$src1),
5165 (OpNode1 (i64 DoubleRegs:$Rss), u6ImmPred:$u6)))],
5166 "$src1 = $Rxx", S_2op_tc_2_SLOT23> {
5171 let IClass = 0b1000;
5173 let Inst{27-24} = 0b0010;
5174 let Inst{23-22} = majOp{2-1};
5175 let Inst{7} = majOp{0};
5176 let Inst{6-5} = minOp;
5177 let Inst{4-0} = Rxx;
5178 let Inst{20-16} = Rss;
5179 let Inst{13-8} = u6;
5183 // Rxx[+-&|]=asr(Rss,Rt)
5184 // Rxx[+-&|^]=lsr(Rss,Rt)
5185 // Rxx[+-&|^]=asl(Rss,Rt)
5186 // Rxx[+-&|^]=lsl(Rss,Rt)
5188 class T_shift_reg_acc_p <string opc1, string opc2, SDNode OpNode1,
5189 SDNode OpNode2, bits<3> majOp, bits<2> minOp>
5190 : SInst_acc<(outs DoubleRegs:$Rxx),
5191 (ins DoubleRegs:$src1, DoubleRegs:$Rss, IntRegs:$Rt),
5192 "$Rxx "#opc2#opc1#"($Rss, $Rt)",
5193 [(set (i64 DoubleRegs:$Rxx),
5194 (OpNode2 (i64 DoubleRegs:$src1),
5195 (OpNode1 (i64 DoubleRegs:$Rss), (i32 IntRegs:$Rt))))],
5196 "$src1 = $Rxx", S_3op_tc_2_SLOT23> {
5201 let IClass = 0b1100;
5203 let Inst{27-24} = 0b1011;
5204 let Inst{23-21} = majOp;
5205 let Inst{20-16} = Rss;
5206 let Inst{12-8} = Rt;
5207 let Inst{7-6} = minOp;
5208 let Inst{4-0} = Rxx;
5211 //===----------------------------------------------------------------------===//
5212 // Multi-class for the shift instructions with logical/arithmetic operators.
5213 //===----------------------------------------------------------------------===//
5215 multiclass xtype_imm_base<string OpcStr1, string OpcStr2, SDNode OpNode1,
5216 SDNode OpNode2, bits<3> majOp, bits<2> minOp > {
5217 def _i_r#NAME : T_shift_imm_acc_r< OpcStr1, OpcStr2, OpNode1,
5218 OpNode2, majOp, minOp >;
5219 def _i_p#NAME : T_shift_imm_acc_p< OpcStr1, OpcStr2, OpNode1,
5220 OpNode2, majOp, minOp >;
5223 multiclass xtype_imm_acc<string opc1, SDNode OpNode, bits<2>minOp> {
5224 let AddedComplexity = 100 in
5225 defm _acc : xtype_imm_base< opc1, "+= ", OpNode, add, 0b001, minOp>;
5227 defm _nac : xtype_imm_base< opc1, "-= ", OpNode, sub, 0b000, minOp>;
5228 defm _and : xtype_imm_base< opc1, "&= ", OpNode, and, 0b010, minOp>;
5229 defm _or : xtype_imm_base< opc1, "|= ", OpNode, or, 0b011, minOp>;
5232 multiclass xtype_xor_imm_acc<string opc1, SDNode OpNode, bits<2>minOp> {
5233 let AddedComplexity = 100 in
5234 defm _xacc : xtype_imm_base< opc1, "^= ", OpNode, xor, 0b100, minOp>;
5237 defm S2_asr : xtype_imm_acc<"asr", sra, 0b00>;
5239 defm S2_lsr : xtype_imm_acc<"lsr", srl, 0b01>,
5240 xtype_xor_imm_acc<"lsr", srl, 0b01>;
5242 defm S2_asl : xtype_imm_acc<"asl", shl, 0b10>,
5243 xtype_xor_imm_acc<"asl", shl, 0b10>;
5245 multiclass xtype_reg_acc_r<string opc1, SDNode OpNode, bits<2>minOp> {
5246 let AddedComplexity = 100 in
5247 def _acc : T_shift_reg_acc_r <opc1, "+= ", OpNode, add, 0b11, minOp>;
5249 def _nac : T_shift_reg_acc_r <opc1, "-= ", OpNode, sub, 0b10, minOp>;
5250 def _and : T_shift_reg_acc_r <opc1, "&= ", OpNode, and, 0b01, minOp>;
5251 def _or : T_shift_reg_acc_r <opc1, "|= ", OpNode, or, 0b00, minOp>;
5254 multiclass xtype_reg_acc_p<string opc1, SDNode OpNode, bits<2>minOp> {
5255 let AddedComplexity = 100 in
5256 def _acc : T_shift_reg_acc_p <opc1, "+= ", OpNode, add, 0b110, minOp>;
5258 def _nac : T_shift_reg_acc_p <opc1, "-= ", OpNode, sub, 0b100, minOp>;
5259 def _and : T_shift_reg_acc_p <opc1, "&= ", OpNode, and, 0b010, minOp>;
5260 def _or : T_shift_reg_acc_p <opc1, "|= ", OpNode, or, 0b000, minOp>;
5261 def _xor : T_shift_reg_acc_p <opc1, "^= ", OpNode, xor, 0b011, minOp>;
5264 multiclass xtype_reg_acc<string OpcStr, SDNode OpNode, bits<2> minOp > {
5265 defm _r_r : xtype_reg_acc_r <OpcStr, OpNode, minOp>;
5266 defm _r_p : xtype_reg_acc_p <OpcStr, OpNode, minOp>;
5269 defm S2_asl : xtype_reg_acc<"asl", shl, 0b10>;
5270 defm S2_asr : xtype_reg_acc<"asr", sra, 0b00>;
5271 defm S2_lsr : xtype_reg_acc<"lsr", srl, 0b01>;
5272 defm S2_lsl : xtype_reg_acc<"lsl", shl, 0b11>;
5274 //===----------------------------------------------------------------------===//
5275 let hasSideEffects = 0 in
5276 class T_S3op_1 <string mnemonic, RegisterClass RC, bits<2> MajOp, bits<3> MinOp,
5277 bit SwapOps, bit isSat = 0, bit isRnd = 0, bit hasShift = 0>
5278 : SInst <(outs RC:$dst),
5279 (ins DoubleRegs:$src1, DoubleRegs:$src2),
5280 "$dst = "#mnemonic#"($src1, $src2)"#!if(isRnd, ":rnd", "")
5281 #!if(hasShift,":>>1","")
5282 #!if(isSat, ":sat", ""),
5283 [], "", S_3op_tc_2_SLOT23 > {
5288 let IClass = 0b1100;
5290 let Inst{27-24} = 0b0001;
5291 let Inst{23-22} = MajOp;
5292 let Inst{20-16} = !if (SwapOps, src2, src1);
5293 let Inst{12-8} = !if (SwapOps, src1, src2);
5294 let Inst{7-5} = MinOp;
5295 let Inst{4-0} = dst;
5298 class T_S3op_64 <string mnemonic, bits<2> MajOp, bits<3> MinOp, bit SwapOps,
5299 bit isSat = 0, bit isRnd = 0, bit hasShift = 0 >
5300 : T_S3op_1 <mnemonic, DoubleRegs, MajOp, MinOp, SwapOps,
5301 isSat, isRnd, hasShift>;
5303 let Itinerary = S_3op_tc_1_SLOT23 in {
5304 def S2_shuffeb : T_S3op_64 < "shuffeb", 0b00, 0b010, 0>;
5305 def S2_shuffeh : T_S3op_64 < "shuffeh", 0b00, 0b110, 0>;
5306 def S2_shuffob : T_S3op_64 < "shuffob", 0b00, 0b100, 1>;
5307 def S2_shuffoh : T_S3op_64 < "shuffoh", 0b10, 0b000, 1>;
5309 def S2_vtrunewh : T_S3op_64 < "vtrunewh", 0b10, 0b010, 0>;
5310 def S2_vtrunowh : T_S3op_64 < "vtrunowh", 0b10, 0b100, 0>;
5313 def S2_lfsp : T_S3op_64 < "lfs", 0b10, 0b110, 0>;
5315 let hasSideEffects = 0 in
5316 class T_S3op_2 <string mnemonic, bits<3> MajOp, bit SwapOps>
5317 : SInst < (outs DoubleRegs:$Rdd),
5318 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt, PredRegs:$Pu),
5319 "$Rdd = "#mnemonic#"($Rss, $Rtt, $Pu)",
5320 [], "", S_3op_tc_1_SLOT23 > {
5326 let IClass = 0b1100;
5328 let Inst{27-24} = 0b0010;
5329 let Inst{23-21} = MajOp;
5330 let Inst{20-16} = !if (SwapOps, Rtt, Rss);
5331 let Inst{12-8} = !if (SwapOps, Rss, Rtt);
5333 let Inst{4-0} = Rdd;
5336 def S2_valignrb : T_S3op_2 < "valignb", 0b000, 1>;
5337 def S2_vsplicerb : T_S3op_2 < "vspliceb", 0b100, 0>;
5339 //===----------------------------------------------------------------------===//
5340 // Template class used by vector shift, vector rotate, vector neg,
5341 // 32-bit shift, 64-bit shifts, etc.
5342 //===----------------------------------------------------------------------===//
5344 let hasSideEffects = 0 in
5345 class T_S3op_3 <string mnemonic, RegisterClass RC, bits<2> MajOp,
5346 bits<2> MinOp, bit isSat = 0, list<dag> pattern = [] >
5347 : SInst <(outs RC:$dst),
5348 (ins RC:$src1, IntRegs:$src2),
5349 "$dst = "#mnemonic#"($src1, $src2)"#!if(isSat, ":sat", ""),
5350 pattern, "", S_3op_tc_1_SLOT23> {
5355 let IClass = 0b1100;
5357 let Inst{27-24} = !if(!eq(!cast<string>(RC), "IntRegs"), 0b0110, 0b0011);
5358 let Inst{23-22} = MajOp;
5359 let Inst{20-16} = src1;
5360 let Inst{12-8} = src2;
5361 let Inst{7-6} = MinOp;
5362 let Inst{4-0} = dst;
5365 let hasNewValue = 1 in
5366 class T_S3op_shift32 <string mnemonic, SDNode OpNode, bits<2> MinOp>
5367 : T_S3op_3 <mnemonic, IntRegs, 0b01, MinOp, 0,
5368 [(set (i32 IntRegs:$dst), (OpNode (i32 IntRegs:$src1),
5369 (i32 IntRegs:$src2)))]>;
5371 let hasNewValue = 1, Itinerary = S_3op_tc_2_SLOT23 in
5372 class T_S3op_shift32_Sat <string mnemonic, bits<2> MinOp>
5373 : T_S3op_3 <mnemonic, IntRegs, 0b00, MinOp, 1, []>;
5376 class T_S3op_shift64 <string mnemonic, SDNode OpNode, bits<2> MinOp>
5377 : T_S3op_3 <mnemonic, DoubleRegs, 0b10, MinOp, 0,
5378 [(set (i64 DoubleRegs:$dst), (OpNode (i64 DoubleRegs:$src1),
5379 (i32 IntRegs:$src2)))]>;
5382 class T_S3op_shiftVect <string mnemonic, bits<2> MajOp, bits<2> MinOp>
5383 : T_S3op_3 <mnemonic, DoubleRegs, MajOp, MinOp, 0, []>;
5386 // Shift by register
5387 // Rdd=[asr|lsr|asl|lsl](Rss,Rt)
5389 def S2_asr_r_p : T_S3op_shift64 < "asr", sra, 0b00>;
5390 def S2_lsr_r_p : T_S3op_shift64 < "lsr", srl, 0b01>;
5391 def S2_asl_r_p : T_S3op_shift64 < "asl", shl, 0b10>;
5392 def S2_lsl_r_p : T_S3op_shift64 < "lsl", shl, 0b11>;
5394 // Rd=[asr|lsr|asl|lsl](Rs,Rt)
5396 def S2_asr_r_r : T_S3op_shift32<"asr", sra, 0b00>;
5397 def S2_lsr_r_r : T_S3op_shift32<"lsr", srl, 0b01>;
5398 def S2_asl_r_r : T_S3op_shift32<"asl", shl, 0b10>;
5399 def S2_lsl_r_r : T_S3op_shift32<"lsl", shl, 0b11>;
5401 // Shift by register with saturation
5402 // Rd=asr(Rs,Rt):sat
5403 // Rd=asl(Rs,Rt):sat
5405 let Defs = [USR_OVF] in {
5406 def S2_asr_r_r_sat : T_S3op_shift32_Sat<"asr", 0b00>;
5407 def S2_asl_r_r_sat : T_S3op_shift32_Sat<"asl", 0b10>;
5410 let hasNewValue = 1, hasSideEffects = 0 in
5411 class T_S3op_8 <string opc, bits<3> MinOp, bit isSat, bit isRnd, bit hasShift, bit hasSplat = 0>
5412 : SInst < (outs IntRegs:$Rd),
5413 (ins DoubleRegs:$Rss, IntRegs:$Rt),
5414 "$Rd = "#opc#"($Rss, $Rt"#!if(hasSplat, "*", "")#")"
5415 #!if(hasShift, ":<<1", "")
5416 #!if(isRnd, ":rnd", "")
5417 #!if(isSat, ":sat", ""),
5418 [], "", S_3op_tc_1_SLOT23 > {
5423 let IClass = 0b1100;
5425 let Inst{27-24} = 0b0101;
5426 let Inst{20-16} = Rss;
5427 let Inst{12-8} = Rt;
5428 let Inst{7-5} = MinOp;
5432 def S2_asr_r_svw_trun : T_S3op_8<"vasrw", 0b010, 0, 0, 0>;
5434 let Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23 in
5435 def S2_vcrotate : T_S3op_shiftVect < "vcrotate", 0b11, 0b00>;
5437 let hasSideEffects = 0 in
5438 class T_S3op_7 <string mnemonic, bit MajOp >
5439 : SInst <(outs DoubleRegs:$Rdd),
5440 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt, u3Imm:$u3),
5441 "$Rdd = "#mnemonic#"($Rss, $Rtt, #$u3)" ,
5442 [], "", S_3op_tc_1_SLOT23 > {
5448 let IClass = 0b1100;
5450 let Inst{27-24} = 0b0000;
5451 let Inst{23} = MajOp;
5452 let Inst{20-16} = !if(MajOp, Rss, Rtt);
5453 let Inst{12-8} = !if(MajOp, Rtt, Rss);
5455 let Inst{4-0} = Rdd;
5458 def S2_valignib : T_S3op_7 < "valignb", 0>;
5459 def S2_vspliceib : T_S3op_7 < "vspliceb", 1>;
5461 //===----------------------------------------------------------------------===//
5462 // Template class for 'insert bitfield' instructions
5463 //===----------------------------------------------------------------------===//
5464 let hasSideEffects = 0 in
5465 class T_S3op_insert <string mnemonic, RegisterClass RC>
5466 : SInst <(outs RC:$dst),
5467 (ins RC:$src1, RC:$src2, DoubleRegs:$src3),
5468 "$dst = "#mnemonic#"($src2, $src3)" ,
5469 [], "$src1 = $dst", S_3op_tc_1_SLOT23 > {
5474 let IClass = 0b1100;
5476 let Inst{27-26} = 0b10;
5477 let Inst{25-24} = !if(!eq(!cast<string>(RC), "IntRegs"), 0b00, 0b10);
5479 let Inst{20-16} = src2;
5480 let Inst{12-8} = src3;
5481 let Inst{4-0} = dst;
5484 let hasSideEffects = 0 in
5485 class T_S2op_insert <bits<4> RegTyBits, RegisterClass RC, Operand ImmOp>
5486 : SInst <(outs RC:$dst), (ins RC:$dst2, RC:$src1, ImmOp:$src2, ImmOp:$src3),
5487 "$dst = insert($src1, #$src2, #$src3)",
5488 [], "$dst2 = $dst", S_2op_tc_2_SLOT23> {
5495 string ImmOpStr = !cast<string>(ImmOp);
5497 let bit23 = !if (!eq(ImmOpStr, "u6Imm"), src3{5}, 0);
5498 let bit13 = !if (!eq(ImmOpStr, "u6Imm"), src2{5}, 0);
5500 let IClass = 0b1000;
5502 let Inst{27-24} = RegTyBits;
5503 let Inst{23} = bit23;
5504 let Inst{22-21} = src3{4-3};
5505 let Inst{20-16} = src1;
5506 let Inst{13} = bit13;
5507 let Inst{12-8} = src2{4-0};
5508 let Inst{7-5} = src3{2-0};
5509 let Inst{4-0} = dst;
5512 // Rx=insert(Rs,Rtt)
5513 // Rx=insert(Rs,#u5,#U5)
5514 let hasNewValue = 1 in {
5515 def S2_insert_rp : T_S3op_insert <"insert", IntRegs>;
5516 def S2_insert : T_S2op_insert <0b1111, IntRegs, u5Imm>;
5519 // Rxx=insert(Rss,Rtt)
5520 // Rxx=insert(Rss,#u6,#U6)
5521 def S2_insertp_rp : T_S3op_insert<"insert", DoubleRegs>;
5522 def S2_insertp : T_S2op_insert <0b0011, DoubleRegs, u6Imm>;
5525 def SDTHexagonINSERT:
5526 SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
5527 SDTCisInt<0>, SDTCisVT<3, i32>, SDTCisVT<4, i32>]>;
5528 def SDTHexagonINSERTRP:
5529 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
5530 SDTCisInt<0>, SDTCisVT<3, i64>]>;
5532 def HexagonINSERT : SDNode<"HexagonISD::INSERT", SDTHexagonINSERT>;
5533 def HexagonINSERTRP : SDNode<"HexagonISD::INSERTRP", SDTHexagonINSERTRP>;
5535 def: Pat<(HexagonINSERT I32:$Rs, I32:$Rt, u5ImmPred:$u1, u5ImmPred:$u2),
5536 (S2_insert I32:$Rs, I32:$Rt, u5ImmPred:$u1, u5ImmPred:$u2)>;
5537 def: Pat<(HexagonINSERT I64:$Rs, I64:$Rt, u6ImmPred:$u1, u6ImmPred:$u2),
5538 (S2_insertp I64:$Rs, I64:$Rt, u6ImmPred:$u1, u6ImmPred:$u2)>;
5539 def: Pat<(HexagonINSERTRP I32:$Rs, I32:$Rt, I64:$Ru),
5540 (S2_insert_rp I32:$Rs, I32:$Rt, I64:$Ru)>;
5541 def: Pat<(HexagonINSERTRP I64:$Rs, I64:$Rt, I64:$Ru),
5542 (S2_insertp_rp I64:$Rs, I64:$Rt, I64:$Ru)>;
5544 let AddedComplexity = 100 in
5545 def: Pat<(or (or (shl (HexagonINSERT (i32 (zextloadi8 (add I32:$b, 2))),
5546 (i32 (extloadi8 (add I32:$b, 3))),
5549 (shl (i32 (zextloadi8 (add I32:$b, 1))), (i32 8))),
5550 (zextloadi8 I32:$b)),
5551 (A2_swiz (L2_loadri_io I32:$b, 0))>;
5554 //===----------------------------------------------------------------------===//
5555 // Template class for 'extract bitfield' instructions
5556 //===----------------------------------------------------------------------===//
5557 let hasNewValue = 1, hasSideEffects = 0 in
5558 class T_S3op_extract <string mnemonic, bits<2> MinOp>
5559 : SInst <(outs IntRegs:$Rd), (ins IntRegs:$Rs, DoubleRegs:$Rtt),
5560 "$Rd = "#mnemonic#"($Rs, $Rtt)",
5561 [], "", S_3op_tc_2_SLOT23 > {
5566 let IClass = 0b1100;
5568 let Inst{27-22} = 0b100100;
5569 let Inst{20-16} = Rs;
5570 let Inst{12-8} = Rtt;
5571 let Inst{7-6} = MinOp;
5575 let hasSideEffects = 0 in
5576 class T_S2op_extract <string mnemonic, bits<4> RegTyBits,
5577 RegisterClass RC, Operand ImmOp>
5578 : SInst <(outs RC:$dst), (ins RC:$src1, ImmOp:$src2, ImmOp:$src3),
5579 "$dst = "#mnemonic#"($src1, #$src2, #$src3)",
5580 [], "", S_2op_tc_2_SLOT23> {
5587 string ImmOpStr = !cast<string>(ImmOp);
5589 let bit23 = !if (!eq(ImmOpStr, "u6Imm"), src3{5},
5590 !if (!eq(mnemonic, "extractu"), 0, 1));
5592 let bit13 = !if (!eq(ImmOpStr, "u6Imm"), src2{5}, 0);
5594 let IClass = 0b1000;
5596 let Inst{27-24} = RegTyBits;
5597 let Inst{23} = bit23;
5598 let Inst{22-21} = src3{4-3};
5599 let Inst{20-16} = src1;
5600 let Inst{13} = bit13;
5601 let Inst{12-8} = src2{4-0};
5602 let Inst{7-5} = src3{2-0};
5603 let Inst{4-0} = dst;
5608 // Rdd=extractu(Rss,Rtt)
5609 // Rdd=extractu(Rss,#u6,#U6)
5610 def S2_extractup_rp : T_S3op_64 < "extractu", 0b00, 0b000, 0>;
5611 def S2_extractup : T_S2op_extract <"extractu", 0b0001, DoubleRegs, u6Imm>;
5613 // Rd=extractu(Rs,Rtt)
5614 // Rd=extractu(Rs,#u5,#U5)
5615 let hasNewValue = 1 in {
5616 def S2_extractu_rp : T_S3op_extract<"extractu", 0b00>;
5617 def S2_extractu : T_S2op_extract <"extractu", 0b1101, IntRegs, u5Imm>;
5620 def SDTHexagonEXTRACTU:
5621 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<1>,
5622 SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
5623 def SDTHexagonEXTRACTURP:
5624 SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<1>,
5627 def HexagonEXTRACTU : SDNode<"HexagonISD::EXTRACTU", SDTHexagonEXTRACTU>;
5628 def HexagonEXTRACTURP : SDNode<"HexagonISD::EXTRACTURP", SDTHexagonEXTRACTURP>;
5630 def: Pat<(HexagonEXTRACTU I32:$src1, u5ImmPred:$src2, u5ImmPred:$src3),
5631 (S2_extractu I32:$src1, u5ImmPred:$src2, u5ImmPred:$src3)>;
5632 def: Pat<(HexagonEXTRACTU I64:$src1, u6ImmPred:$src2, u6ImmPred:$src3),
5633 (S2_extractup I64:$src1, u6ImmPred:$src2, u6ImmPred:$src3)>;
5634 def: Pat<(HexagonEXTRACTURP I32:$src1, I64:$src2),
5635 (S2_extractu_rp I32:$src1, I64:$src2)>;
5636 def: Pat<(HexagonEXTRACTURP I64:$src1, I64:$src2),
5637 (S2_extractup_rp I64:$src1, I64:$src2)>;
5639 // Change the sign of the immediate for Rd=-mpyi(Rs,#u8)
5640 def: Pat<(mul (i32 IntRegs:$src1), (ineg n8ImmPred:$src2)),
5641 (M2_mpysin IntRegs:$src1, u8ImmPred:$src2)>;
5643 //===----------------------------------------------------------------------===//
5644 // :raw for of tableindx[bdhw] insns
5645 //===----------------------------------------------------------------------===//
5647 let hasSideEffects = 0, hasNewValue = 1, opNewValue = 0 in
5648 class tableidxRaw<string OpStr, bits<2>MinOp>
5649 : SInst <(outs IntRegs:$Rx),
5650 (ins IntRegs:$_dst_, IntRegs:$Rs, u4Imm:$u4, s6Imm:$S6),
5651 "$Rx = "#OpStr#"($Rs, #$u4, #$S6):raw",
5652 [], "$Rx = $_dst_" > {
5658 let IClass = 0b1000;
5660 let Inst{27-24} = 0b0111;
5661 let Inst{23-22} = MinOp;
5662 let Inst{21} = u4{3};
5663 let Inst{20-16} = Rs;
5664 let Inst{13-8} = S6;
5665 let Inst{7-5} = u4{2-0};
5669 def S2_tableidxb : tableidxRaw<"tableidxb", 0b00>;
5670 def S2_tableidxh : tableidxRaw<"tableidxh", 0b01>;
5671 def S2_tableidxw : tableidxRaw<"tableidxw", 0b10>;
5672 def S2_tableidxd : tableidxRaw<"tableidxd", 0b11>;
5674 //===----------------------------------------------------------------------===//
5675 // Template class for 'table index' instructions which are assembler mapped
5676 // to their :raw format.
5677 //===----------------------------------------------------------------------===//
5679 class tableidx_goodsyntax <string mnemonic>
5680 : SInst <(outs IntRegs:$Rx),
5681 (ins IntRegs:$_dst_, IntRegs:$Rs, u4Imm:$u4, u5Imm:$u5),
5682 "$Rx = "#mnemonic#"($Rs, #$u4, #$u5)",
5683 [], "$Rx = $_dst_" >;
5685 def S2_tableidxb_goodsyntax : tableidx_goodsyntax<"tableidxb">;
5686 def S2_tableidxh_goodsyntax : tableidx_goodsyntax<"tableidxh">;
5687 def S2_tableidxw_goodsyntax : tableidx_goodsyntax<"tableidxw">;
5688 def S2_tableidxd_goodsyntax : tableidx_goodsyntax<"tableidxd">;
5690 //===----------------------------------------------------------------------===//
5691 // V3 Instructions +
5692 //===----------------------------------------------------------------------===//
5694 include "HexagonInstrInfoV3.td"
5696 //===----------------------------------------------------------------------===//
5697 // V3 Instructions -
5698 //===----------------------------------------------------------------------===//
5700 //===----------------------------------------------------------------------===//
5701 // V4 Instructions +
5702 //===----------------------------------------------------------------------===//
5704 include "HexagonInstrInfoV4.td"
5706 //===----------------------------------------------------------------------===//
5707 // V4 Instructions -
5708 //===----------------------------------------------------------------------===//
5710 //===----------------------------------------------------------------------===//
5711 // V5 Instructions +
5712 //===----------------------------------------------------------------------===//
5714 include "HexagonInstrInfoV5.td"
5716 //===----------------------------------------------------------------------===//
5717 // V5 Instructions -
5718 //===----------------------------------------------------------------------===//
5720 //===----------------------------------------------------------------------===//
5721 // V60 Instructions +
5722 //===----------------------------------------------------------------------===//
5724 include "HexagonInstrInfoV60.td"
5726 //===----------------------------------------------------------------------===//
5727 // V60 Instructions -
5728 //===----------------------------------------------------------------------===//
5730 //===----------------------------------------------------------------------===//
5731 // ALU32/64/Vector +
5732 //===----------------------------------------------------------------------===///
5734 include "HexagonInstrInfoVector.td"
5736 include "HexagonInstrAlias.td"
5737 include "HexagonSystemInst.td"