xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
1*bdd1243dSDimitry Andric//===-- RISCVInstrInfoXTHead.td ----------------------------*- tablegen -*-===//
2*bdd1243dSDimitry Andric//
3*bdd1243dSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*bdd1243dSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
5*bdd1243dSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*bdd1243dSDimitry Andric//
7*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
8*bdd1243dSDimitry Andric//
9*bdd1243dSDimitry Andric// This file describes the vendor extensions defined by T-Head of Alibaba.
10*bdd1243dSDimitry Andric//
11*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
12*bdd1243dSDimitry Andric
13*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
14*bdd1243dSDimitry Andric// Instruction class templates
15*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
16*bdd1243dSDimitry Andricclass THInstVdotVV<bits<6> funct6, RISCVVFormat opv, dag outs, dag ins,
17*bdd1243dSDimitry Andric                   string opcodestr, string argstr>
18*bdd1243dSDimitry Andric    : RVInstVV<funct6, opv, outs, ins, opcodestr, argstr> {
19*bdd1243dSDimitry Andric  let Inst{26} = 0;
20*bdd1243dSDimitry Andric  let Opcode = OPC_CUSTOM_0.Value;
21*bdd1243dSDimitry Andric  let DecoderNamespace = "THeadV";
22*bdd1243dSDimitry Andric}
23*bdd1243dSDimitry Andric
24*bdd1243dSDimitry Andricclass THInstVdotVX<bits<6> funct6, RISCVVFormat opv, dag outs, dag ins,
25*bdd1243dSDimitry Andric                   string opcodestr, string argstr>
26*bdd1243dSDimitry Andric    : RVInstVX<funct6, opv, outs, ins, opcodestr, argstr> {
27*bdd1243dSDimitry Andric  let Inst{26} = 1;
28*bdd1243dSDimitry Andric  let Opcode = OPC_CUSTOM_0.Value;
29*bdd1243dSDimitry Andric  let DecoderNamespace = "THeadV";
30*bdd1243dSDimitry Andric}
31*bdd1243dSDimitry Andric
32*bdd1243dSDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
33*bdd1243dSDimitry Andric// op vd, vs1, vs2, vm (reverse the order of vs1 and vs2)
34*bdd1243dSDimitry Andricclass THVdotALUrVV<bits<6> funct6, RISCVVFormat opv, string opcodestr>
35*bdd1243dSDimitry Andric    : THInstVdotVV<funct6, opv, (outs VR:$vd),
36*bdd1243dSDimitry Andric                   (ins VR:$vs1, VR:$vs2, VMaskOp:$vm),
37*bdd1243dSDimitry Andric                   opcodestr, "$vd, $vs1, $vs2$vm">;
38*bdd1243dSDimitry Andric
39*bdd1243dSDimitry Andric// op vd, rs1, vs2, vm (reverse the order of rs1 and vs2)
40*bdd1243dSDimitry Andricclass THVdotALUrVX<bits<6> funct6, RISCVVFormat opv, string opcodestr>
41*bdd1243dSDimitry Andric    : THInstVdotVX<funct6, opv, (outs VR:$vd),
42*bdd1243dSDimitry Andric                   (ins GPR:$rs1, VR:$vs2, VMaskOp:$vm),
43*bdd1243dSDimitry Andric                   opcodestr, "$vd, $rs1, $vs2$vm">;
44*bdd1243dSDimitry Andric} // hasSideEffects = 0, mayLoad = 0, mayStore = 0
45*bdd1243dSDimitry Andric
46*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
47*bdd1243dSDimitry Andric// Combination of instruction classes.
48*bdd1243dSDimitry Andric// Use these multiclasses to define instructions more easily.
49*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
50*bdd1243dSDimitry Andricmulticlass THVdotVMAQA_VX<string opcodestr, bits<6> funct6> {
51*bdd1243dSDimitry Andric  def _VX : THVdotALUrVX<funct6, OPMVX, opcodestr # ".vx">;
52*bdd1243dSDimitry Andric}
53*bdd1243dSDimitry Andric
54*bdd1243dSDimitry Andricmulticlass THVdotVMAQA<string opcodestr, bits<6> funct6> {
55*bdd1243dSDimitry Andric  def _VV   : THVdotALUrVV<funct6, OPMVX, opcodestr # ".vv">;
56*bdd1243dSDimitry Andric  defm ""   : THVdotVMAQA_VX<opcodestr, funct6>;
57*bdd1243dSDimitry Andric}
58*bdd1243dSDimitry Andric
59*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
60*bdd1243dSDimitry Andric// Instructions
61*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
62*bdd1243dSDimitry Andriclet Predicates = [HasVendorXTHeadVdot],
63*bdd1243dSDimitry Andric    Constraints = "@earlyclobber $vd",
64*bdd1243dSDimitry Andric    RVVConstraint = WidenV in {
65*bdd1243dSDimitry Andricdefm THVdotVMAQA      : THVdotVMAQA<"th.vmaqa",     0b100000>;
66*bdd1243dSDimitry Andricdefm THVdotVMAQAU     : THVdotVMAQA<"th.vmaqau",    0b100010>;
67*bdd1243dSDimitry Andricdefm THVdotVMAQASU    : THVdotVMAQA<"th.vmaqasu",   0b100100>;
68*bdd1243dSDimitry Andricdefm THVdotVMAQAUS    : THVdotVMAQA_VX<"th.vmaqaus",0b100110>;
69*bdd1243dSDimitry Andric}
70*bdd1243dSDimitry Andric
71*bdd1243dSDimitry Andric// Associate LMUL with tablegen records of register classes.
72*bdd1243dSDimitry Andricdef THVdotV_M1  : LMULInfo<0b000,  8,   VR, VR,   VR,   VR,   VR, "M1">;
73*bdd1243dSDimitry Andricdef THVdotV_M2  : LMULInfo<0b001, 16, VRM2, VRM2, VR,   VR,   VR, "M2">;
74*bdd1243dSDimitry Andricdef THVdotV_M4  : LMULInfo<0b010, 32, VRM4, VRM4, VRM2, VR,   VR, "M4">;
75*bdd1243dSDimitry Andricdef THVdotV_M8  : LMULInfo<0b011, 64, VRM8, VRM8, VRM4, VRM2, VR, "M8">;
76*bdd1243dSDimitry Andric
77*bdd1243dSDimitry Andricdefvar MxListTHVdot = [V_MF2, THVdotV_M1, THVdotV_M2, THVdotV_M4, THVdotV_M8];
78*bdd1243dSDimitry Andric
79*bdd1243dSDimitry Andricdefset list<VTypeInfoToWide> AllQuadWidenableInt8NoVLMulVectors = {
80*bdd1243dSDimitry Andric  def : VTypeInfoToWide<VI8MF2,  VI32MF2>;
81*bdd1243dSDimitry Andric  def : VTypeInfoToWide<VI8M1,   VI32M1>;
82*bdd1243dSDimitry Andric  def : VTypeInfoToWide<VI8M2,   VI32M2>;
83*bdd1243dSDimitry Andric  def : VTypeInfoToWide<VI8M4,   VI32M4>;
84*bdd1243dSDimitry Andric  def : VTypeInfoToWide<VI8M8,   VI32M8>;
85*bdd1243dSDimitry Andric}
86*bdd1243dSDimitry Andric
87*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
88*bdd1243dSDimitry Andric// Combination of instruction classes.
89*bdd1243dSDimitry Andric// Use these multiclasses to define instructions more easily.
90*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
91*bdd1243dSDimitry Andricmulticlass VPseudoVMAQA_VV_VX {
92*bdd1243dSDimitry Andric  foreach m = MxListTHVdot in {
93*bdd1243dSDimitry Andric    defm "" : VPseudoTernaryW_VV<m>;
94*bdd1243dSDimitry Andric    defm "" : VPseudoTernaryW_VX<m>;
95*bdd1243dSDimitry Andric  }
96*bdd1243dSDimitry Andric}
97*bdd1243dSDimitry Andric
98*bdd1243dSDimitry Andricmulticlass VPseudoVMAQA_VX {
99*bdd1243dSDimitry Andric  foreach m = MxListTHVdot in {
100*bdd1243dSDimitry Andric    defm "" : VPseudoTernaryW_VX<m>;
101*bdd1243dSDimitry Andric  }
102*bdd1243dSDimitry Andric}
103*bdd1243dSDimitry Andric
104*bdd1243dSDimitry Andricmulticlass VPatTernaryVMAQA_VV<string intrinsic, string instruction,
105*bdd1243dSDimitry Andric                               list<VTypeInfoToWide> vtilist> {
106*bdd1243dSDimitry Andric  foreach vtiToWti = vtilist in {
107*bdd1243dSDimitry Andric    defvar vti = vtiToWti.Vti;
108*bdd1243dSDimitry Andric    defvar wti = vtiToWti.Wti;
109*bdd1243dSDimitry Andric    defm : VPatTernaryWithPolicy<intrinsic, instruction, "VV",
110*bdd1243dSDimitry Andric                                 wti.Vector, vti.Vector, vti.Vector,
111*bdd1243dSDimitry Andric                                 vti.Mask, wti.Log2SEW, vti.LMul,
112*bdd1243dSDimitry Andric                                 wti.RegClass, vti.RegClass, vti.RegClass>;
113*bdd1243dSDimitry Andric  }
114*bdd1243dSDimitry Andric}
115*bdd1243dSDimitry Andric
116*bdd1243dSDimitry Andricmulticlass VPatTernaryVMAQA_VX<string intrinsic, string instruction,
117*bdd1243dSDimitry Andric                               list<VTypeInfoToWide> vtilist> {
118*bdd1243dSDimitry Andric  foreach vtiToWti = vtilist in {
119*bdd1243dSDimitry Andric    defvar vti = vtiToWti.Vti;
120*bdd1243dSDimitry Andric    defvar wti = vtiToWti.Wti;
121*bdd1243dSDimitry Andric    defm : VPatTernaryWithPolicy<intrinsic, instruction,
122*bdd1243dSDimitry Andric                                 "V"#vti.ScalarSuffix,
123*bdd1243dSDimitry Andric                                 wti.Vector, vti.Scalar, vti.Vector,
124*bdd1243dSDimitry Andric                                 vti.Mask, wti.Log2SEW, vti.LMul,
125*bdd1243dSDimitry Andric                                 wti.RegClass, vti.ScalarRegClass, vti.RegClass>;
126*bdd1243dSDimitry Andric  }
127*bdd1243dSDimitry Andric}
128*bdd1243dSDimitry Andric
129*bdd1243dSDimitry Andricmulticlass VPatTernaryVMAQA_VV_VX<string intrinsic, string instruction,
130*bdd1243dSDimitry Andric                                  list<VTypeInfoToWide> vtilist>
131*bdd1243dSDimitry Andric    : VPatTernaryVMAQA_VV<intrinsic, instruction, vtilist>,
132*bdd1243dSDimitry Andric      VPatTernaryVMAQA_VX<intrinsic, instruction, vtilist>;
133*bdd1243dSDimitry Andric
134*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
135*bdd1243dSDimitry Andric// Pseudo-instructions and codegen patterns
136*bdd1243dSDimitry Andric//===----------------------------------------------------------------------===//
137*bdd1243dSDimitry Andricdefm PseudoTHVdotVMAQA      : VPseudoVMAQA_VV_VX;
138*bdd1243dSDimitry Andricdefm PseudoTHVdotVMAQAU     : VPseudoVMAQA_VV_VX;
139*bdd1243dSDimitry Andricdefm PseudoTHVdotVMAQASU    : VPseudoVMAQA_VV_VX;
140*bdd1243dSDimitry Andricdefm PseudoTHVdotVMAQAUS    : VPseudoVMAQA_VX;
141*bdd1243dSDimitry Andric
142*bdd1243dSDimitry Andriclet Predicates = [HasVendorXTHeadVdot] in {
143*bdd1243dSDimitry Andricdefm : VPatTernaryVMAQA_VV_VX<"int_riscv_th_vmaqa",  "PseudoTHVdotVMAQA",  AllQuadWidenableInt8NoVLMulVectors>;
144*bdd1243dSDimitry Andricdefm : VPatTernaryVMAQA_VV_VX<"int_riscv_th_vmaqau", "PseudoTHVdotVMAQAU", AllQuadWidenableInt8NoVLMulVectors>;
145*bdd1243dSDimitry Andricdefm : VPatTernaryVMAQA_VV_VX<"int_riscv_th_vmaqasu","PseudoTHVdotVMAQASU",AllQuadWidenableInt8NoVLMulVectors>;
146*bdd1243dSDimitry Andricdefm : VPatTernaryVMAQA_VX<"int_riscv_th_vmaqaus",   "PseudoTHVdotVMAQAUS",AllQuadWidenableInt8NoVLMulVectors>;
147*bdd1243dSDimitry Andric}
148