xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/VINTERPInstructions.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
181ad6265SDimitry Andric//===-- VINTERPInstructions.td - VINTERP Instruction Definitions ----------===//
281ad6265SDimitry Andric//
381ad6265SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric//
781ad6265SDimitry Andric//===----------------------------------------------------------------------===//
881ad6265SDimitry Andric
981ad6265SDimitry Andric//===----------------------------------------------------------------------===//
1081ad6265SDimitry Andric// VINTERP encoding
1181ad6265SDimitry Andric//===----------------------------------------------------------------------===//
1281ad6265SDimitry Andric
135f757f3fSDimitry Andricclass VINTERPe <VOPProfile P> : Enc64 {
1481ad6265SDimitry Andric  bits<8> vdst;
1581ad6265SDimitry Andric  bits<4> src0_modifiers;
1681ad6265SDimitry Andric  bits<9> src0;
1781ad6265SDimitry Andric  bits<3> src1_modifiers;
1881ad6265SDimitry Andric  bits<9> src1;
1981ad6265SDimitry Andric  bits<3> src2_modifiers;
2081ad6265SDimitry Andric  bits<9> src2;
2181ad6265SDimitry Andric  bits<1> clamp;
2281ad6265SDimitry Andric  bits<3> waitexp;
2381ad6265SDimitry Andric
2481ad6265SDimitry Andric  let Inst{31-26} = 0x33; // VOP3P encoding
2581ad6265SDimitry Andric  let Inst{25-24} = 0x1; // VINTERP sub-encoding
2681ad6265SDimitry Andric
2781ad6265SDimitry Andric  let Inst{7-0}   = vdst;
2881ad6265SDimitry Andric  let Inst{10-8}  = waitexp;
2981ad6265SDimitry Andric  let Inst{11}    = !if(P.HasOpSel, src0_modifiers{2}, 0); // op_sel(0)
3081ad6265SDimitry Andric  let Inst{12}    = !if(P.HasOpSel, src1_modifiers{2}, 0); // op_sel(1)
3181ad6265SDimitry Andric  let Inst{13}    = !if(P.HasOpSel, src2_modifiers{2}, 0); // op_sel(2)
3281ad6265SDimitry Andric  let Inst{14}    = !if(P.HasOpSel, src0_modifiers{3}, 0); // op_sel(3)
3381ad6265SDimitry Andric  let Inst{15}    = clamp;
3481ad6265SDimitry Andric  let Inst{40-32} = src0;
3581ad6265SDimitry Andric  let Inst{49-41} = src1;
3681ad6265SDimitry Andric  let Inst{58-50} = src2;
3781ad6265SDimitry Andric  let Inst{61}    = src0_modifiers{0}; // neg(0)
3881ad6265SDimitry Andric  let Inst{62}    = src1_modifiers{0}; // neg(1)
3981ad6265SDimitry Andric  let Inst{63}    = src2_modifiers{0}; // neg(2)
4081ad6265SDimitry Andric}
4181ad6265SDimitry Andric
425f757f3fSDimitry Andricclass VINTERPe_gfx11 <bits<7> op, VOPProfile P> : VINTERPe<P> {
435f757f3fSDimitry Andric  let Inst{22-16} = op;
445f757f3fSDimitry Andric}
455f757f3fSDimitry Andric
465f757f3fSDimitry Andricclass VINTERPe_gfx12 <bits<7> op, VOPProfile P> : VINTERPe<P> {
475f757f3fSDimitry Andric  let Inst{20-16} = op{4-0};
485f757f3fSDimitry Andric}
495f757f3fSDimitry Andric
5081ad6265SDimitry Andric//===----------------------------------------------------------------------===//
5181ad6265SDimitry Andric// VOP3 VINTERP
5281ad6265SDimitry Andric//===----------------------------------------------------------------------===//
5381ad6265SDimitry Andric
5481ad6265SDimitry Andricclass VINTERP_Pseudo <string OpName, VOPProfile P, list<dag> pattern = []> :
5581ad6265SDimitry Andric  VOP3_Pseudo<OpName, P, pattern, 0, 0> {
5681ad6265SDimitry Andric  let AsmMatchConverter = "cvtVINTERP";
5781ad6265SDimitry Andric  let mayRaiseFPException = 0;
5881ad6265SDimitry Andric
5981ad6265SDimitry Andric  let VOP3_OPSEL = 1;
6081ad6265SDimitry Andric  let VINTERP = 1;
6181ad6265SDimitry Andric}
6281ad6265SDimitry Andric
6381ad6265SDimitry Andricclass VINTERP_Real <VOP_Pseudo ps, int EncodingFamily> :
6481ad6265SDimitry Andric  VOP3_Real <ps, EncodingFamily> {
6581ad6265SDimitry Andric  let VINTERP = 1;
6681ad6265SDimitry Andric}
6781ad6265SDimitry Andric
6881ad6265SDimitry Andricdef VOP3_VINTERP_F32 : VOPProfile<[f32, f32, f32, f32]> {
6981ad6265SDimitry Andric  let HasOpSel = 0;
7081ad6265SDimitry Andric  let HasModifiers = 1;
7181ad6265SDimitry Andric
72bdd1243dSDimitry Andric  let Src0Mod = FPVRegInputMods;
73bdd1243dSDimitry Andric  let Src1Mod = FPVRegInputMods;
74bdd1243dSDimitry Andric  let Src2Mod = FPVRegInputMods;
75bdd1243dSDimitry Andric
7681ad6265SDimitry Andric  let Outs64 = (outs VGPR_32:$vdst);
7781ad6265SDimitry Andric  let Ins64 = (ins Src0Mod:$src0_modifiers, VRegSrc_32:$src0,
7881ad6265SDimitry Andric                   Src1Mod:$src1_modifiers, VRegSrc_32:$src1,
7981ad6265SDimitry Andric                   Src2Mod:$src2_modifiers, VRegSrc_32:$src2,
80*0fca6ea1SDimitry Andric                   Clamp:$clamp,
81*0fca6ea1SDimitry Andric                   WaitEXP:$waitexp);
8281ad6265SDimitry Andric
8381ad6265SDimitry Andric  let Asm64 = " $vdst, $src0_modifiers, $src1_modifiers, $src2_modifiers$clamp$waitexp";
8481ad6265SDimitry Andric}
8581ad6265SDimitry Andric
8681ad6265SDimitry Andricclass VOP3_VINTERP_F16 <list<ValueType> ArgVT> : VOPProfile<ArgVT> {
8781ad6265SDimitry Andric  let HasOpSel = 1;
8881ad6265SDimitry Andric  let HasModifiers = 1;
8981ad6265SDimitry Andric
90bdd1243dSDimitry Andric  let Src0Mod = FPVRegInputMods;
91bdd1243dSDimitry Andric  let Src1Mod = FPVRegInputMods;
92bdd1243dSDimitry Andric  let Src2Mod = FPVRegInputMods;
93bdd1243dSDimitry Andric
9481ad6265SDimitry Andric  let Outs64 = (outs VGPR_32:$vdst);
9581ad6265SDimitry Andric  let Ins64 = (ins Src0Mod:$src0_modifiers, VRegSrc_32:$src0,
9681ad6265SDimitry Andric                   Src1Mod:$src1_modifiers, VRegSrc_32:$src1,
9781ad6265SDimitry Andric                   Src2Mod:$src2_modifiers, VRegSrc_32:$src2,
98*0fca6ea1SDimitry Andric                   Clamp:$clamp, op_sel0:$op_sel,
99*0fca6ea1SDimitry Andric                   WaitEXP:$waitexp);
10081ad6265SDimitry Andric
10181ad6265SDimitry Andric  let Asm64 = " $vdst, $src0_modifiers, $src1_modifiers, $src2_modifiers$clamp$op_sel$waitexp";
10281ad6265SDimitry Andric}
10381ad6265SDimitry Andric
10481ad6265SDimitry Andric//===----------------------------------------------------------------------===//
10581ad6265SDimitry Andric// VINTERP Pseudo Instructions
10681ad6265SDimitry Andric//===----------------------------------------------------------------------===//
10781ad6265SDimitry Andric
108*0fca6ea1SDimitry Andriclet SubtargetPredicate = HasVINTERPEncoding in {
10981ad6265SDimitry Andric
11081ad6265SDimitry Andriclet Uses = [M0, EXEC, MODE] in {
11181ad6265SDimitry Andricdef V_INTERP_P10_F32_inreg : VINTERP_Pseudo <"v_interp_p10_f32", VOP3_VINTERP_F32>;
11281ad6265SDimitry Andricdef V_INTERP_P2_F32_inreg : VINTERP_Pseudo <"v_interp_p2_f32", VOP3_VINTERP_F32>;
11381ad6265SDimitry Andricdef V_INTERP_P10_F16_F32_inreg :
11481ad6265SDimitry Andric  VINTERP_Pseudo <"v_interp_p10_f16_f32", VOP3_VINTERP_F16<[f32, f32, f32, f32]>>;
11581ad6265SDimitry Andricdef V_INTERP_P2_F16_F32_inreg :
11681ad6265SDimitry Andric  VINTERP_Pseudo <"v_interp_p2_f16_f32", VOP3_VINTERP_F16<[f16, f32, f32, f32]>>;
11781ad6265SDimitry Andric} // Uses = [M0, EXEC, MODE]
11881ad6265SDimitry Andric
11981ad6265SDimitry Andriclet Uses = [M0, EXEC] in {
12081ad6265SDimitry Andricdef V_INTERP_P10_RTZ_F16_F32_inreg :
12181ad6265SDimitry Andric  VINTERP_Pseudo <"v_interp_p10_rtz_f16_f32", VOP3_VINTERP_F16<[f32, f32, f32, f32]>>;
12281ad6265SDimitry Andricdef V_INTERP_P2_RTZ_F16_F32_inreg :
12381ad6265SDimitry Andric  VINTERP_Pseudo <"v_interp_p2_rtz_f16_f32", VOP3_VINTERP_F16<[f16, f32, f32, f32]>>;
12481ad6265SDimitry Andric} // Uses = [M0, EXEC]
12581ad6265SDimitry Andric
126*0fca6ea1SDimitry Andric} // SubtargetPredicate = HasVINTERPEncoding.
12781ad6265SDimitry Andric
12881ad6265SDimitry Andricclass VInterpF32Pat <SDPatternOperator op, Instruction inst> : GCNPat <
12981ad6265SDimitry Andric   (f32 (op
13081ad6265SDimitry Andric      (VINTERPMods f32:$src0, i32:$src0_modifiers),
13181ad6265SDimitry Andric      (VINTERPMods f32:$src1, i32:$src1_modifiers),
13281ad6265SDimitry Andric      (VINTERPMods f32:$src2, i32:$src2_modifiers))),
13381ad6265SDimitry Andric    (inst $src0_modifiers, $src0,
13481ad6265SDimitry Andric          $src1_modifiers, $src1,
13581ad6265SDimitry Andric          $src2_modifiers, $src2,
13681ad6265SDimitry Andric          0, /* clamp */
13781ad6265SDimitry Andric          7) /* wait_exp */
13881ad6265SDimitry Andric>;
13981ad6265SDimitry Andric
14081ad6265SDimitry Andricdef VINTERP_OPSEL {
14181ad6265SDimitry Andric  int LOW = 0;
14281ad6265SDimitry Andric  int HIGH = 0xa;
14381ad6265SDimitry Andric}
14481ad6265SDimitry Andric
14581ad6265SDimitry Andricclass VInterpF16Pat <SDPatternOperator op, Instruction inst,
14681ad6265SDimitry Andric                     ValueType dst_type, bit high,
14781ad6265SDimitry Andric                     list<ComplexPattern> pat> : GCNPat <
14881ad6265SDimitry Andric   (dst_type (op
14981ad6265SDimitry Andric      (pat[0] f32:$src0, i32:$src0_modifiers),
15081ad6265SDimitry Andric      (pat[1] f32:$src1, i32:$src1_modifiers),
15181ad6265SDimitry Andric      (pat[2] f32:$src2, i32:$src2_modifiers),
15281ad6265SDimitry Andric      !if(high, (i1 -1), (i1 0)))),
15381ad6265SDimitry Andric    (inst $src0_modifiers, $src0,
15481ad6265SDimitry Andric          $src1_modifiers, $src1,
15581ad6265SDimitry Andric          $src2_modifiers, $src2,
15681ad6265SDimitry Andric          0, /* clamp */
15781ad6265SDimitry Andric          /* op_sel = 0 */
15881ad6265SDimitry Andric          7) /* wait_exp */
15981ad6265SDimitry Andric>;
16081ad6265SDimitry Andric
16181ad6265SDimitry Andricmulticlass VInterpF16Pat <SDPatternOperator op, Instruction inst,
16281ad6265SDimitry Andric                          ValueType dst_type, list<ComplexPattern> high_pat> {
16381ad6265SDimitry Andric  def : VInterpF16Pat<op, inst, dst_type, 0,
16481ad6265SDimitry Andric                      [VINTERPMods, VINTERPMods, VINTERPMods]>;
16581ad6265SDimitry Andric  def : VInterpF16Pat<op, inst, dst_type, 1, high_pat>;
16681ad6265SDimitry Andric}
16781ad6265SDimitry Andric
16881ad6265SDimitry Andricdef : VInterpF32Pat<int_amdgcn_interp_inreg_p10, V_INTERP_P10_F32_inreg>;
16981ad6265SDimitry Andricdef : VInterpF32Pat<int_amdgcn_interp_inreg_p2, V_INTERP_P2_F32_inreg>;
17081ad6265SDimitry Andricdefm : VInterpF16Pat<int_amdgcn_interp_inreg_p10_f16,
17181ad6265SDimitry Andric                     V_INTERP_P10_F16_F32_inreg, f32,
17281ad6265SDimitry Andric                     [VINTERPModsHi, VINTERPMods, VINTERPModsHi]>;
17381ad6265SDimitry Andricdefm : VInterpF16Pat<int_amdgcn_interp_inreg_p2_f16,
17481ad6265SDimitry Andric                     V_INTERP_P2_F16_F32_inreg, f16,
17581ad6265SDimitry Andric                     [VINTERPModsHi, VINTERPMods, VINTERPMods]>;
176*0fca6ea1SDimitry Andricdefm : VInterpF16Pat<int_amdgcn_interp_p10_rtz_f16,
177*0fca6ea1SDimitry Andric                     V_INTERP_P10_RTZ_F16_F32_inreg, f32,
178*0fca6ea1SDimitry Andric                     [VINTERPModsHi, VINTERPMods, VINTERPModsHi]>;
179*0fca6ea1SDimitry Andricdefm : VInterpF16Pat<int_amdgcn_interp_p2_rtz_f16,
180*0fca6ea1SDimitry Andric                     V_INTERP_P2_RTZ_F16_F32_inreg, f16,
181*0fca6ea1SDimitry Andric                     [VINTERPModsHi, VINTERPMods, VINTERPMods]>;
18281ad6265SDimitry Andric
18381ad6265SDimitry Andric//===----------------------------------------------------------------------===//
18481ad6265SDimitry Andric// VINTERP Real Instructions
18581ad6265SDimitry Andric//===----------------------------------------------------------------------===//
18681ad6265SDimitry Andric
18781ad6265SDimitry Andricmulticlass VINTERP_Real_gfx11 <bits<7> op> {
1885f757f3fSDimitry Andric  let AssemblerPredicate = isGFX11Only, DecoderNamespace = "GFX11" in {
18981ad6265SDimitry Andric    def _gfx11 :
19081ad6265SDimitry Andric      VINTERP_Real<!cast<VOP3_Pseudo>(NAME), SIEncodingFamily.GFX11>,
19181ad6265SDimitry Andric      VINTERPe_gfx11<op, !cast<VOP3_Pseudo>(NAME).Pfl>;
19281ad6265SDimitry Andric  }
19381ad6265SDimitry Andric}
19481ad6265SDimitry Andric
1955f757f3fSDimitry Andricmulticlass VINTERP_Real_gfx12 <bits<7> op> {
1965f757f3fSDimitry Andric  let AssemblerPredicate = isGFX12Only, DecoderNamespace = "GFX12" in {
1975f757f3fSDimitry Andric    def _gfx12 :
1985f757f3fSDimitry Andric      VINTERP_Real<!cast<VOP3_Pseudo>(NAME), SIEncodingFamily.GFX12>,
1995f757f3fSDimitry Andric      VINTERPe_gfx12<op, !cast<VOP3_Pseudo>(NAME).Pfl>;
2005f757f3fSDimitry Andric  }
2015f757f3fSDimitry Andric}
2025f757f3fSDimitry Andric
2035f757f3fSDimitry Andricmulticlass VINTERP_Real_gfx11_gfx12 <bits<7> op> :
2045f757f3fSDimitry Andric  VINTERP_Real_gfx11<op>, VINTERP_Real_gfx12<op>;
2055f757f3fSDimitry Andric
2065f757f3fSDimitry Andricdefm V_INTERP_P10_F32_inreg : VINTERP_Real_gfx11_gfx12<0x000>;
2075f757f3fSDimitry Andricdefm V_INTERP_P2_F32_inreg : VINTERP_Real_gfx11_gfx12<0x001>;
2085f757f3fSDimitry Andricdefm V_INTERP_P10_F16_F32_inreg : VINTERP_Real_gfx11_gfx12<0x002>;
2095f757f3fSDimitry Andricdefm V_INTERP_P2_F16_F32_inreg : VINTERP_Real_gfx11_gfx12<0x003>;
2105f757f3fSDimitry Andricdefm V_INTERP_P10_RTZ_F16_F32_inreg : VINTERP_Real_gfx11_gfx12<0x004>;
2115f757f3fSDimitry Andricdefm V_INTERP_P2_RTZ_F16_F32_inreg : VINTERP_Real_gfx11_gfx12<0x005>;
212