1 //===-- VOPInstructions.td - Vector Instruction Defintions ----------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // dummies for outer let
12 bit isConvertibleToThreeAddress;
14 bit isReMaterializable;
16 bit VOPAsmPrefer32Bit;
17 Predicate SubtargetPredicate;
19 string DisableEncoding;
20 list<SchedReadWrite> SchedRW;
25 class VOP <string opName> {
26 string OpName = opName;
29 class VOPAnyCommon <dag outs, dag ins, string asm, list<dag> pattern> :
30 InstSI <outs, ins, asm, pattern> {
34 let hasSideEffects = 0;
35 let UseNamedOperandTable = 1;
40 class VOP_Pseudo <string opName, string suffix, VOPProfile P, dag outs, dag ins,
41 string asm, list<dag> pattern> :
42 InstSI <outs, ins, asm, pattern>,
44 SIMCInstr <opName#suffix, SIEncodingFamily.NONE>,
45 MnemonicAlias<opName#suffix, opName> {
48 let isCodeGenOnly = 1;
49 let UseNamedOperandTable = 1;
51 string Mnemonic = opName;
57 class VOP3Common <dag outs, dag ins, string asm = "",
58 list<dag> pattern = [], bit HasMods = 0,
60 VOPAnyCommon <outs, ins, asm, pattern> {
62 // Using complex patterns gives VOP3 patterns a very high complexity rating,
63 // but standalone patterns are almost always preferred, so we need to adjust the
64 // priority lower. The goal is to use a high number to reduce complexity to
65 // zero (or less than zero).
66 let AddedComplexity = -1000;
70 let AsmVariantName = AMDGPUAsmVariants.VOP3;
71 let AsmMatchConverter = !if(!eq(HasMods,1), "cvtVOP3", "");
73 let isCodeGenOnly = 0;
77 // Because SGPRs may be allowed if there are multiple operands, we
78 // need a post-isel hook to insert copies in order to avoid
79 // violating constant bus requirements.
80 let hasPostISelHook = 1;
83 class VOP3_Pseudo <string opName, VOPProfile P, list<dag> pattern = [],
84 bit VOP3Only = 0, bit isVOP3P = 0, bit isVop3OpSel = 0> :
85 VOP_Pseudo <opName, "_e64", P, P.Outs64,
88 !if(!and(isVOP3P, P.IsPacked), P.InsVOP3P, P.Ins64)),
91 let VOP3_OPSEL = isVop3OpSel;
92 let IsPacked = P.IsPacked;
94 let AsmOperands = !if(isVop3OpSel,
96 !if(!and(isVOP3P, P.IsPacked), P.AsmVOP3P, P.Asm64));
101 let hasSideEffects = 0;
103 // Because SGPRs may be allowed if there are multiple operands, we
104 // need a post-isel hook to insert copies in order to avoid
105 // violating constant bus requirements.
106 let hasPostISelHook = 1;
108 // Using complex patterns gives VOP3 patterns a very high complexity rating,
109 // but standalone patterns are almost always preferred, so we need to adjust the
110 // priority lower. The goal is to use a high number to reduce complexity to
111 // zero (or less than zero).
112 let AddedComplexity = -1000;
116 let FPClamp = P.HasFPClamp;
117 let IntClamp = P.HasIntClamp;
118 let ClampLo = P.HasClampLo;
119 let ClampHi = P.HasClampHi;
123 let AsmVariantName = AMDGPUAsmVariants.VOP3;
124 let AsmMatchConverter =
127 !if(!or(P.HasModifiers, !or(P.HasOMod, P.HasIntClamp)),
132 class VOP3P_Pseudo <string opName, VOPProfile P, list<dag> pattern = []> :
133 VOP3_Pseudo<opName, P, pattern, 1, 1> {
137 class VOP3_Real <VOP_Pseudo ps, int EncodingFamily> :
138 InstSI <ps.OutOperandList, ps.InOperandList, ps.Mnemonic # ps.AsmOperands, []>,
139 SIMCInstr <ps.PseudoInstr, EncodingFamily> {
142 let isCodeGenOnly = 0;
143 let UseNamedOperandTable = 1;
145 let Constraints = ps.Constraints;
146 let DisableEncoding = ps.DisableEncoding;
148 // copy relevant pseudo op flags
149 let SubtargetPredicate = ps.SubtargetPredicate;
150 let AsmMatchConverter = ps.AsmMatchConverter;
151 let AsmVariantName = ps.AsmVariantName;
152 let Constraints = ps.Constraints;
153 let DisableEncoding = ps.DisableEncoding;
154 let TSFlags = ps.TSFlags;
155 let UseNamedOperandTable = ps.UseNamedOperandTable;
159 VOPProfile Pfl = ps.Pfl;
162 // XXX - Is there any reason to distingusih this from regular VOP3
164 class VOP3P_Real<VOP_Pseudo ps, int EncodingFamily> :
165 VOP3_Real<ps, EncodingFamily>;
167 class VOP3a<VOPProfile P> : Enc64 {
168 bits<4> src0_modifiers;
170 bits<3> src1_modifiers;
172 bits<3> src2_modifiers;
177 let Inst{8} = !if(P.HasSrc0Mods, src0_modifiers{1}, 0);
178 let Inst{9} = !if(P.HasSrc1Mods, src1_modifiers{1}, 0);
179 let Inst{10} = !if(P.HasSrc2Mods, src2_modifiers{1}, 0);
181 let Inst{31-26} = 0x34; //encoding
182 let Inst{40-32} = !if(P.HasSrc0, src0, 0);
183 let Inst{49-41} = !if(P.HasSrc1, src1, 0);
184 let Inst{58-50} = !if(P.HasSrc2, src2, 0);
185 let Inst{60-59} = !if(P.HasOMod, omod, 0);
186 let Inst{61} = !if(P.HasSrc0Mods, src0_modifiers{0}, 0);
187 let Inst{62} = !if(P.HasSrc1Mods, src1_modifiers{0}, 0);
188 let Inst{63} = !if(P.HasSrc2Mods, src2_modifiers{0}, 0);
191 class VOP3a_si <bits<9> op, VOPProfile P> : VOP3a<P> {
192 let Inst{25-17} = op;
193 let Inst{11} = !if(P.HasClamp, clamp{0}, 0);
196 class VOP3a_vi <bits<10> op, VOPProfile P> : VOP3a<P> {
197 let Inst{25-16} = op;
198 let Inst{15} = !if(P.HasClamp, clamp{0}, 0);
201 class VOP3e_si <bits<9> op, VOPProfile P> : VOP3a_si <op, P> {
203 let Inst{7-0} = !if(P.EmitDst, vdst{7-0}, 0);
206 class VOP3e_vi <bits<10> op, VOPProfile P> : VOP3a_vi <op, P> {
208 let Inst{7-0} = !if(P.EmitDst, vdst{7-0}, 0);
211 class VOP3OpSel_gfx9 <bits<10> op, VOPProfile P> : VOP3e_vi <op, P> {
212 let Inst{11} = !if(P.HasSrc0, src0_modifiers{2}, 0);
213 let Inst{12} = !if(P.HasSrc1, src1_modifiers{2}, 0);
214 let Inst{13} = !if(P.HasSrc2, src2_modifiers{2}, 0);
215 let Inst{14} = !if(P.HasDst, src0_modifiers{3}, 0);
218 // NB: For V_INTERP* opcodes, src0 is encoded as src1 and vice versa
219 class VOP3Interp_vi <bits<10> op, VOPProfile P> : VOP3e_vi <op, P> {
224 let Inst{8} = 0; // No modifiers for src0
227 let Inst{9} = !if(P.HasSrc0Mods, src0_modifiers{1}, 0);
228 let Inst{62} = !if(P.HasSrc0Mods, src0_modifiers{0}, 0);
230 let Inst{37-32} = attr;
231 let Inst{39-38} = attrchan;
232 let Inst{40} = !if(P.HasHigh, high, 0);
234 let Inst{49-41} = src0;
237 class VOP3be <VOPProfile P> : Enc64 {
239 bits<2> src0_modifiers;
241 bits<2> src1_modifiers;
243 bits<2> src2_modifiers;
248 let Inst{7-0} = vdst;
249 let Inst{14-8} = sdst;
250 let Inst{31-26} = 0x34; //encoding
251 let Inst{40-32} = !if(P.HasSrc0, src0, 0);
252 let Inst{49-41} = !if(P.HasSrc1, src1, 0);
253 let Inst{58-50} = !if(P.HasSrc2, src2, 0);
254 let Inst{60-59} = !if(P.HasOMod, omod, 0);
255 let Inst{61} = !if(P.HasSrc0Mods, src0_modifiers{0}, 0);
256 let Inst{62} = !if(P.HasSrc1Mods, src1_modifiers{0}, 0);
257 let Inst{63} = !if(P.HasSrc2Mods, src2_modifiers{0}, 0);
260 class VOP3Pe <bits<10> op, VOPProfile P> : Enc64 {
262 // neg, neg_hi, op_sel put in srcN_modifiers
263 bits<4> src0_modifiers;
265 bits<4> src1_modifiers;
267 bits<4> src2_modifiers;
271 let Inst{7-0} = vdst;
272 let Inst{8} = !if(P.HasSrc0Mods, src0_modifiers{1}, 0); // neg_hi src0
273 let Inst{9} = !if(P.HasSrc1Mods, src1_modifiers{1}, 0); // neg_hi src1
274 let Inst{10} = !if(P.HasSrc2Mods, src2_modifiers{1}, 0); // neg_hi src2
276 let Inst{11} = !if(!and(P.HasSrc0, P.HasOpSel), src0_modifiers{2}, 0); // op_sel(0)
277 let Inst{12} = !if(!and(P.HasSrc1, P.HasOpSel), src1_modifiers{2}, 0); // op_sel(1)
278 let Inst{13} = !if(!and(P.HasSrc2, P.HasOpSel), src2_modifiers{2}, 0); // op_sel(2)
280 let Inst{14} = !if(!and(P.HasSrc2, P.HasOpSel), src2_modifiers{3}, 0); // op_sel_hi(2)
282 let Inst{15} = !if(P.HasClamp, clamp{0}, 0);
284 let Inst{25-16} = op;
285 let Inst{31-26} = 0x34; //encoding
286 let Inst{40-32} = !if(P.HasSrc0, src0, 0);
287 let Inst{49-41} = !if(P.HasSrc1, src1, 0);
288 let Inst{58-50} = !if(P.HasSrc2, src2, 0);
289 let Inst{59} = !if(!and(P.HasSrc0, P.HasOpSel), src0_modifiers{3}, 0); // op_sel_hi(0)
290 let Inst{60} = !if(!and(P.HasSrc1, P.HasOpSel), src1_modifiers{3}, 0); // op_sel_hi(1)
291 let Inst{61} = !if(P.HasSrc0Mods, src0_modifiers{0}, 0); // neg (lo)
292 let Inst{62} = !if(P.HasSrc1Mods, src1_modifiers{0}, 0); // neg (lo)
293 let Inst{63} = !if(P.HasSrc2Mods, src2_modifiers{0}, 0); // neg (lo)
296 class VOP3be_si <bits<9> op, VOPProfile P> : VOP3be<P> {
297 let Inst{25-17} = op;
300 class VOP3be_vi <bits<10> op, VOPProfile P> : VOP3be<P> {
302 let Inst{25-16} = op;
303 let Inst{15} = !if(P.HasClamp, clamp{0}, 0);
319 int UNUSED_PRESERVE = 2;
322 class VOP_SDWAe<VOPProfile P> : Enc64 {
325 bits<2> src0_modifiers; // float: {abs,neg}, int {sext}
327 bits<2> src1_modifiers;
332 let Inst{39-32} = !if(P.HasSrc0, src0{7-0}, 0);
333 let Inst{42-40} = !if(P.EmitDst, dst_sel{2-0}, 0);
334 let Inst{44-43} = !if(P.EmitDst, dst_unused{1-0}, 0);
335 let Inst{45} = !if(P.HasSDWAClamp, clamp{0}, 0);
336 let Inst{50-48} = !if(P.HasSrc0, src0_sel{2-0}, 0);
337 let Inst{51} = !if(P.HasSrc0IntMods, src0_modifiers{0}, 0);
338 let Inst{53-52} = !if(P.HasSrc0FloatMods, src0_modifiers{1-0}, 0);
339 let Inst{58-56} = !if(P.HasSrc1, src1_sel{2-0}, 0);
340 let Inst{59} = !if(P.HasSrc1IntMods, src1_modifiers{0}, 0);
341 let Inst{61-60} = !if(P.HasSrc1FloatMods, src1_modifiers{1-0}, 0);
344 // GFX9 adds two features to SDWA:
345 // 1. Add 3 fields to the SDWA microcode word: S0, S1 and OMOD.
346 // a. S0 and S1 indicate that source 0 and 1 respectively are SGPRs rather
347 // than VGPRs (at most 1 can be an SGPR);
348 // b. OMOD is the standard output modifier (result *2, *4, /2)
349 // 2. Add a new version of the SDWA microcode word for VOPC: SDWAB. This
350 // replaces OMOD and the dest fields with SD and SDST (SGPR destination)
352 // a. When SD=1, the SDST is used as the destination for the compare result;
353 // b. When SD=0, VCC is used.
355 // In GFX9, V_MAC_F16, V_MAC_F32 opcodes cannot be used with SDWA
357 // gfx9 SDWA basic encoding
358 class VOP_SDWA9e<VOPProfile P> : Enc64 {
359 bits<9> src0; // {src0_sgpr{0}, src0{7-0}}
361 bits<2> src0_modifiers; // float: {abs,neg}, int {sext}
363 bits<2> src1_modifiers;
366 let Inst{39-32} = !if(P.HasSrc0, src0{7-0}, 0);
367 let Inst{50-48} = !if(P.HasSrc0, src0_sel{2-0}, 0);
368 let Inst{51} = !if(P.HasSrc0IntMods, src0_modifiers{0}, 0);
369 let Inst{53-52} = !if(P.HasSrc0FloatMods, src0_modifiers{1-0}, 0);
370 let Inst{55} = !if(P.HasSrc0, src0{8}, 0);
371 let Inst{58-56} = !if(P.HasSrc1, src1_sel{2-0}, 0);
372 let Inst{59} = !if(P.HasSrc1IntMods, src1_modifiers{0}, 0);
373 let Inst{61-60} = !if(P.HasSrc1FloatMods, src1_modifiers{1-0}, 0);
374 let Inst{63} = 0; // src1_sgpr - should be specified in subclass
378 class VOP_SDWA9Ae<VOPProfile P> : VOP_SDWA9e<P> {
384 let Inst{42-40} = !if(P.EmitDst, dst_sel{2-0}, 0);
385 let Inst{44-43} = !if(P.EmitDst, dst_unused{1-0}, 0);
386 let Inst{45} = !if(P.HasSDWAClamp, clamp{0}, 0);
387 let Inst{47-46} = !if(P.HasSDWAOMod, omod{1-0}, 0);
391 class VOP_SDWA9Be<VOPProfile P> : VOP_SDWA9e<P> {
392 bits<8> sdst; // {vcc_sdst{0}, sdst{6-0}}
394 let Inst{46-40} = !if(P.EmitDst, sdst{6-0}, 0);
395 let Inst{47} = !if(P.EmitDst, sdst{7}, 0);
398 class VOP_SDWA_Pseudo <string opName, VOPProfile P, list<dag> pattern=[]> :
399 InstSI <P.OutsSDWA, P.InsSDWA, "", pattern>,
401 SIMCInstr <opName#"_sdwa", SIEncodingFamily.NONE>,
402 MnemonicAlias <opName#"_sdwa", opName> {
405 let isCodeGenOnly = 1;
406 let UseNamedOperandTable = 1;
408 string Mnemonic = opName;
409 string AsmOperands = P.AsmSDWA;
410 string AsmOperands9 = P.AsmSDWA9;
415 let hasSideEffects = 0;
421 let SubtargetPredicate = !if(P.HasExtSDWA, HasSDWA, DisableInst);
422 let AssemblerPredicate = !if(P.HasExtSDWA, HasSDWA, DisableInst);
423 let AsmVariantName = !if(P.HasExtSDWA, AMDGPUAsmVariants.SDWA,
424 AMDGPUAsmVariants.Disable);
425 let DecoderNamespace = "SDWA";
430 class VOP_SDWA_Real <VOP_SDWA_Pseudo ps> :
431 InstSI <ps.OutOperandList, ps.InOperandList, ps.Mnemonic # ps.AsmOperands, []>,
432 SIMCInstr <ps.PseudoInstr, SIEncodingFamily.SDWA> {
435 let isCodeGenOnly = 0;
439 let SchedRW = ps.SchedRW;
440 let hasSideEffects = ps.hasSideEffects;
442 let Constraints = ps.Constraints;
443 let DisableEncoding = ps.DisableEncoding;
445 // Copy relevant pseudo op flags
446 let SubtargetPredicate = ps.SubtargetPredicate;
447 let AssemblerPredicate = ps.AssemblerPredicate;
448 let AsmMatchConverter = ps.AsmMatchConverter;
449 let AsmVariantName = ps.AsmVariantName;
450 let UseNamedOperandTable = ps.UseNamedOperandTable;
451 let DecoderNamespace = ps.DecoderNamespace;
452 let Constraints = ps.Constraints;
453 let DisableEncoding = ps.DisableEncoding;
454 let TSFlags = ps.TSFlags;
457 class VOP_SDWA9_Real <VOP_SDWA_Pseudo ps> :
458 InstSI <ps.OutOperandList, ps.InOperandList, ps.Mnemonic # ps.AsmOperands9, []>,
459 SIMCInstr <ps.PseudoInstr, SIEncodingFamily.SDWA9> {
462 let isCodeGenOnly = 0;
466 let SchedRW = ps.SchedRW;
467 let hasSideEffects = ps.hasSideEffects;
469 let Constraints = ps.Constraints;
470 let DisableEncoding = ps.DisableEncoding;
472 let SubtargetPredicate = !if(ps.Pfl.HasExtSDWA9, HasSDWA9, DisableInst);
473 let AssemblerPredicate = !if(ps.Pfl.HasExtSDWA9, HasSDWA9, DisableInst);
474 let AsmVariantName = !if(ps.Pfl.HasExtSDWA9, AMDGPUAsmVariants.SDWA9,
475 AMDGPUAsmVariants.Disable);
476 let DecoderNamespace = "SDWA9";
478 // Copy relevant pseudo op flags
479 let AsmMatchConverter = ps.AsmMatchConverter;
480 let UseNamedOperandTable = ps.UseNamedOperandTable;
481 let Constraints = ps.Constraints;
482 let DisableEncoding = ps.DisableEncoding;
483 let TSFlags = ps.TSFlags;
486 class VOP_DPPe<VOPProfile P> : Enc64 {
487 bits<2> src0_modifiers;
489 bits<2> src1_modifiers;
495 let Inst{39-32} = !if(P.HasSrc0, src0{7-0}, 0);
496 let Inst{48-40} = dpp_ctrl;
497 let Inst{51} = bound_ctrl;
498 let Inst{52} = !if(P.HasSrc0Mods, src0_modifiers{0}, 0); // src0_neg
499 let Inst{53} = !if(P.HasSrc0Mods, src0_modifiers{1}, 0); // src0_abs
500 let Inst{54} = !if(P.HasSrc1Mods, src1_modifiers{0}, 0); // src1_neg
501 let Inst{55} = !if(P.HasSrc1Mods, src1_modifiers{1}, 0); // src1_abs
502 let Inst{59-56} = bank_mask;
503 let Inst{63-60} = row_mask;
506 class VOP_DPP_Pseudo <string OpName, VOPProfile P, list<dag> pattern=[]> :
507 InstSI <P.OutsDPP, P.InsDPP, OpName#P.AsmDPP, pattern>,
509 SIMCInstr <OpName#"_dpp", SIEncodingFamily.NONE>,
510 MnemonicAlias <OpName#"_dpp", OpName> {
513 let isCodeGenOnly = 1;
517 let hasSideEffects = 0;
518 let UseNamedOperandTable = 1;
524 let isConvergent = 1;
526 string Mnemonic = OpName;
527 string AsmOperands = P.AsmDPP;
529 let AsmMatchConverter = !if(!eq(P.HasModifiers,1), "cvtDPP", "");
530 let SubtargetPredicate = HasDPP;
531 let AssemblerPredicate = !if(P.HasExtDPP, HasDPP, DisableInst);
532 let AsmVariantName = !if(P.HasExtDPP, AMDGPUAsmVariants.DPP,
533 AMDGPUAsmVariants.Disable);
534 let Constraints = !if(P.NumSrcArgs, "$old = $vdst", "");
535 let DisableEncoding = !if(P.NumSrcArgs, "$old", "");
536 let DecoderNamespace = "DPP";
541 class VOP_DPP_Real <VOP_DPP_Pseudo ps, int EncodingFamily> :
542 InstSI <ps.OutOperandList, ps.InOperandList, ps.Mnemonic # ps.AsmOperands, []>,
543 SIMCInstr <ps.PseudoInstr, EncodingFamily> {
546 let isCodeGenOnly = 0;
550 let SchedRW = ps.SchedRW;
551 let hasSideEffects = ps.hasSideEffects;
553 let Constraints = ps.Constraints;
554 let DisableEncoding = ps.DisableEncoding;
556 // Copy relevant pseudo op flags
557 let isConvergent = ps.isConvergent;
558 let SubtargetPredicate = ps.SubtargetPredicate;
559 let AssemblerPredicate = ps.AssemblerPredicate;
560 let AsmMatchConverter = ps.AsmMatchConverter;
561 let AsmVariantName = ps.AsmVariantName;
562 let UseNamedOperandTable = ps.UseNamedOperandTable;
563 let DecoderNamespace = ps.DecoderNamespace;
564 let Constraints = ps.Constraints;
565 let DisableEncoding = ps.DisableEncoding;
566 let TSFlags = ps.TSFlags;
569 class getNumNodeArgs<SDPatternOperator Op> {
570 SDNode N = !cast<SDNode>(Op);
571 SDTypeProfile TP = N.TypeProfile;
572 int ret = TP.NumOperands;
576 class getDivergentFrag<SDPatternOperator Op> {
578 int NumSrcArgs = getNumNodeArgs<Op>.ret;
579 PatFrag ret = PatFrag <
580 !if(!eq(NumSrcArgs, 1),
582 !if(!eq(NumSrcArgs, 2),
583 (ops node:$src0, node:$src1),
584 (ops node:$src0, node:$src1, node:$src2))),
585 !if(!eq(NumSrcArgs, 1),
587 !if(!eq(NumSrcArgs, 2),
589 (Op $src0, $src1, $src2))),
590 [{ return N->isDivergent(); }]
594 class VOPPatGen<SDPatternOperator Op, VOPProfile P> {
596 PatFrag Operator = getDivergentFrag < Op >.ret;
598 dag Ins = !foreach(tmp, P.Ins32, !subst(ins, Operator,
599 !subst(P.Src0RC32, P.Src0VT,
600 !subst(P.Src1RC32, P.Src1VT, tmp))));
603 dag Outs = !foreach(tmp, P.Outs32, !subst(outs, set,
604 !subst(P.DstRC, P.DstVT, tmp)));
606 list<dag> ret = [!con(Outs, (set Ins))];
609 class VOPPatOrNull<SDPatternOperator Op, VOPProfile P> {
610 list<dag> ret = !if(!ne(P.NeedPatGen,PatGenMode.NoPattern), VOPPatGen<Op, P>.ret, []);
613 class DivergentFragOrOp<SDPatternOperator Op, VOPProfile P> {
614 SDPatternOperator ret = !if(!eq(P.NeedPatGen,PatGenMode.Pattern),
615 !if(!isa<SDNode>(Op), getDivergentFrag<Op>.ret, Op), Op);
618 include "VOPCInstructions.td"
619 include "VOP1Instructions.td"
620 include "VOP2Instructions.td"
621 include "VOP3Instructions.td"
622 include "VOP3PInstructions.td"