xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1//===-- RISCVInstrInfoXCV.td - CORE-V instructions ---------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file describes the vendor extensions defined by Core-V extensions.
10//
11//===----------------------------------------------------------------------===//
12
13let DecoderNamespace = "XCVbitmanip" in {
14  class CVInstBitManipRII<bits<2> funct2, bits<3> funct3, dag outs, dag ins,
15                      string opcodestr, string argstr>
16      : RVInstIBase<funct3, OPC_CUSTOM_2, outs, ins, opcodestr, argstr> {
17    bits<5> is3;
18    bits<5> is2;
19    let Inst{31-30} = funct2;
20    let Inst{29-25} = is3;
21    let Inst{24-20} = is2;
22  }
23
24  class CVBitManipRII<bits<2> funct2, bits<3> funct3, string opcodestr,
25                      Operand i3type = uimm5>
26      : CVInstBitManipRII<funct2, funct3, (outs GPR:$rd),
27                          (ins GPR:$rs1, i3type:$is3, uimm5:$is2),
28                          opcodestr, "$rd, $rs1, $is3, $is2">;
29
30  class CVBitManipRR<bits<7> funct7, string opcodestr>
31      : RVInstR<funct7, 0b011, OPC_CUSTOM_1, (outs GPR:$rd),
32                (ins GPR:$rs1, GPR:$rs2), opcodestr, "$rd, $rs1, $rs2">;
33
34  class CVBitManipR<bits<7> funct7, string opcodestr>
35      : RVInstR<funct7, 0b011, OPC_CUSTOM_1, (outs GPR:$rd),
36                (ins GPR:$rs1), opcodestr, "$rd, $rs1"> {
37    let rs2 = 0b00000;
38  }
39}
40
41let Predicates = [HasVendorXCVbitmanip, IsRV32],
42    hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
43  def CV_EXTRACT : CVBitManipRII<0b00, 0b000, "cv.extract">;
44  def CV_EXTRACTU : CVBitManipRII<0b01, 0b000, "cv.extractu">;
45
46  def CV_BCLR : CVBitManipRII<0b00, 0b001, "cv.bclr">;
47  def CV_BSET : CVBitManipRII<0b01, 0b001, "cv.bset">;
48  def CV_BITREV : CVBitManipRII<0b11, 0b001, "cv.bitrev", uimm2>;
49
50  def CV_EXTRACTR : CVBitManipRR<0b0011000, "cv.extractr">;
51  def CV_EXTRACTUR : CVBitManipRR<0b0011001, "cv.extractur">;
52
53  let Constraints = "$rd = $rd_wb" in {
54    def CV_INSERT : CVInstBitManipRII<0b10, 0b000, (outs GPR:$rd_wb),
55                             (ins GPR:$rd, GPR:$rs1, uimm5:$is3, uimm5:$is2),
56                             "cv.insert", "$rd, $rs1, $is3, $is2">;
57    def CV_INSERTR : RVInstR<0b0011010, 0b011, OPC_CUSTOM_1, (outs GPR:$rd_wb),
58                             (ins GPR:$rd, GPR:$rs1, GPR:$rs2),
59                             "cv.insertr", "$rd, $rs1, $rs2">;
60  }
61
62  def CV_BCLRR : CVBitManipRR<0b0011100, "cv.bclrr">;
63  def CV_BSETR : CVBitManipRR<0b0011101, "cv.bsetr">;
64
65  def CV_ROR : CVBitManipRR<0b0100000, "cv.ror">;
66  def CV_FF1 : CVBitManipR<0b0100001, "cv.ff1">;
67  def CV_FL1 : CVBitManipR<0b0100010, "cv.fl1">;
68  def CV_CLB : CVBitManipR<0b0100011, "cv.clb">;
69  def CV_CNT : CVBitManipR<0b0100100, "cv.cnt">;
70}
71
72class CVInstMac<bits<7> funct7, bits<3> funct3, string opcodestr>
73    : RVInstR<funct7, funct3, OPC_CUSTOM_1,
74              (outs GPR:$rd_wb), (ins GPR:$rd, GPR:$rs1, GPR:$rs2),
75              opcodestr, "$rd, $rs1, $rs2"> {
76  let DecoderNamespace = "XCVmac";
77}
78
79class CVInstMacMulN<bits<2> funct2, bits<3> funct3, dag outs, dag ins,
80                    string opcodestr>
81    : RVInstRBase<funct3, OPC_CUSTOM_2, outs, ins, opcodestr,
82                  "$rd, $rs1, $rs2, $imm5"> {
83  bits<5> imm5;
84
85  let Inst{31-30} = funct2;
86  let Inst{29-25} = imm5;
87  let DecoderNamespace = "XCVmac";
88}
89
90class CVInstMacN<bits<2> funct2, bits<3> funct3, string opcodestr>
91    : CVInstMacMulN<funct2, funct3, (outs GPR:$rd_wb),
92                    (ins GPR:$rd, GPR:$rs1, GPR:$rs2, uimm5:$imm5), opcodestr>;
93
94class CVInstMulN<bits<2> funct2, bits<3> funct3, string opcodestr>
95    : CVInstMacMulN<funct2, funct3, (outs GPR:$rd),
96                    (ins GPR:$rs1, GPR:$rs2, uimm5:$imm5), opcodestr>;
97
98let Predicates = [HasVendorXCVmac, IsRV32], hasSideEffects = 0, mayLoad = 0,
99    mayStore = 0, Constraints = "$rd = $rd_wb" in {
100  // 32x32 bit macs
101  def CV_MAC      : CVInstMac<0b1001000, 0b011, "cv.mac">,
102                    Sched<[]>;
103  def CV_MSU      : CVInstMac<0b1001001, 0b011, "cv.msu">,
104                    Sched<[]>;
105
106  // Signed 16x16 bit macs with imm
107  def CV_MACSN    : CVInstMacN<0b00, 0b110, "cv.macsn">,
108                    Sched<[]>;
109  def CV_MACHHSN  : CVInstMacN<0b01, 0b110, "cv.machhsn">,
110                    Sched<[]>;
111  def CV_MACSRN   : CVInstMacN<0b10, 0b110, "cv.macsrn">,
112                    Sched<[]>;
113  def CV_MACHHSRN : CVInstMacN<0b11, 0b110, "cv.machhsrn">,
114                    Sched<[]>;
115
116  // Unsigned 16x16 bit macs with imm
117  def CV_MACUN    : CVInstMacN<0b00, 0b111, "cv.macun">,
118                    Sched<[]>;
119  def CV_MACHHUN  : CVInstMacN<0b01, 0b111, "cv.machhun">,
120                    Sched<[]>;
121  def CV_MACURN   : CVInstMacN<0b10, 0b111, "cv.macurn">,
122                    Sched<[]>;
123  def CV_MACHHURN : CVInstMacN<0b11, 0b111, "cv.machhurn">,
124                    Sched<[]>;
125} // Predicates = [HasVendorXCVmac, IsRV32], hasSideEffects = 0, mayLoad = 0...
126
127let Predicates = [HasVendorXCVmac, IsRV32], hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
128  // Signed 16x16 bit muls with imm
129  def CV_MULSN    : CVInstMulN<0b00, 0b100, "cv.mulsn">,
130                    Sched<[]>;
131  def CV_MULHHSN  : CVInstMulN<0b01, 0b100, "cv.mulhhsn">,
132                    Sched<[]>;
133  def CV_MULSRN   : CVInstMulN<0b10, 0b100, "cv.mulsrn">,
134                    Sched<[]>;
135  def CV_MULHHSRN : CVInstMulN<0b11, 0b100, "cv.mulhhsrn">,
136                    Sched<[]>;
137
138  // Unsigned 16x16 bit muls with imm
139  def CV_MULUN    : CVInstMulN<0b00, 0b101, "cv.mulun">,
140                    Sched<[]>;
141  def CV_MULHHUN  : CVInstMulN<0b01, 0b101, "cv.mulhhun">,
142                    Sched<[]>;
143  def CV_MULURN   : CVInstMulN<0b10, 0b101, "cv.mulurn">,
144                    Sched<[]>;
145  def CV_MULHHURN : CVInstMulN<0b11, 0b101, "cv.mulhhurn">,
146                    Sched<[]>;
147} // Predicates = [HasVendorXCVmac, IsRV32], hasSideEffects = 0, mayLoad = 0...
148
149let Predicates = [HasVendorXCVmac, IsRV32] in {
150  // Xcvmac Pseudo Instructions
151  // Signed 16x16 bit muls
152  def : InstAlias<"cv.muls $rd1, $rs1, $rs2",
153                  (CV_MULSN GPR:$rd1,   GPR:$rs1, GPR:$rs2, 0)>;
154  def : InstAlias<"cv.mulhhs $rd1, $rs1, $rs2",
155                  (CV_MULHHSN GPR:$rd1, GPR:$rs1, GPR:$rs2, 0)>;
156
157  // Unsigned 16x16 bit muls
158  def : InstAlias<"cv.mulu $rd1, $rs1, $rs2",
159                  (CV_MULUN GPR:$rd1,   GPR:$rs1, GPR:$rs2, 0)>;
160  def : InstAlias<"cv.mulhhu $rd1, $rs1, $rs2",
161                  (CV_MULHHUN GPR:$rd1, GPR:$rs1, GPR:$rs2, 0)>;
162} // Predicates = [HasVendorXCVmac, IsRV32]
163
164let DecoderNamespace = "XCValu" in {
165  class CVInstAluRRI<bits<2> funct2, bits<3> funct3, string opcodestr>
166      : RVInstRBase<funct3, OPC_CUSTOM_2, (outs GPR:$rd),
167                    (ins GPR:$rs1, GPR:$rs2, uimm5:$imm5), opcodestr,
168                    "$rd, $rs1, $rs2, $imm5"> {
169    bits<5> imm5;
170
171    let Inst{31-30} = funct2;
172    let Inst{29-25} = imm5;
173  }
174
175  class CVInstAluRR<bits<7> funct7, bits<3> funct3, string opcodestr>
176    : RVInstR<funct7, funct3, OPC_CUSTOM_1, (outs GPR:$rd),
177              (ins GPR:$rs1, GPR:$rs2), opcodestr, "$rd, $rs1, $rs2">;
178
179  class CVInstAluRRNR<bits<7> funct7, bits<3> funct3, string opcodestr>
180    : RVInstR<funct7, funct3, OPC_CUSTOM_1, (outs GPR:$rd_wb),
181              (ins GPR:$rd, GPR:$rs1, GPR:$rs2), opcodestr, "$rd, $rs1, $rs2">;
182
183  class CVInstAluRI<bits<7> funct7, bits<3> funct3, string opcodestr>
184      : RVInstIBase<funct3, OPC_CUSTOM_1, (outs GPR:$rd),
185                    (ins GPR:$rs1, uimm5:$imm5), opcodestr,
186                    "$rd, $rs1, $imm5"> {
187    bits<5> imm5;
188
189    let Inst{31-25} = funct7;
190    let Inst{24-20} = imm5;
191  }
192
193  class CVInstAluR<bits<7> funct7, bits<3> funct3, string opcodestr>
194    : RVInstR<funct7, funct3, OPC_CUSTOM_1, (outs GPR:$rd), (ins GPR:$rs1),
195              opcodestr, "$rd, $rs1"> {
196     let rs2 = 0b00000;
197  }
198
199} // DecoderNamespace = "XCValu"
200
201let Predicates = [HasVendorXCValu, IsRV32],
202  hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
203  // General ALU Operations
204  def CV_ABS    : CVInstAluR<0b0101000, 0b011, "cv.abs">,
205                  Sched<[]>;
206  def CV_SLET   : CVInstAluRR<0b0101001, 0b011, "cv.slet">,
207                  Sched<[]>;
208  def CV_SLETU  : CVInstAluRR<0b0101010, 0b011, "cv.sletu">,
209                  Sched<[]>;
210  def CV_MIN    : CVInstAluRR<0b0101011, 0b011, "cv.min">,
211                  Sched<[]>;
212  def CV_MINU   : CVInstAluRR<0b0101100, 0b011, "cv.minu">,
213                  Sched<[]>;
214  def CV_MAX    : CVInstAluRR<0b0101101, 0b011, "cv.max">,
215                  Sched<[]>;
216  def CV_MAXU   : CVInstAluRR<0b0101110, 0b011, "cv.maxu">,
217                  Sched<[]>;
218  def CV_EXTHS  : CVInstAluR<0b0110000, 0b011, "cv.exths">,
219                  Sched<[]>;
220  def CV_EXTHZ  : CVInstAluR<0b0110001, 0b011, "cv.exthz">,
221                  Sched<[]>;
222  def CV_EXTBS  : CVInstAluR<0b0110010, 0b011, "cv.extbs">,
223                  Sched<[]>;
224  def CV_EXTBZ  : CVInstAluR<0b0110011, 0b011, "cv.extbz">,
225                  Sched<[]>;
226
227  def CV_CLIP   : CVInstAluRI<0b0111000, 0b011, "cv.clip">,
228                  Sched<[]>;
229  def CV_CLIPU  : CVInstAluRI<0b0111001, 0b011, "cv.clipu">,
230                  Sched<[]>;
231  def CV_CLIPR  : CVInstAluRR<0b0111010, 0b011, "cv.clipr">,
232                  Sched<[]>;
233  def CV_CLIPUR : CVInstAluRR<0b0111011, 0b011, "cv.clipur">,
234                  Sched<[]>;
235
236  def CV_ADDN   : CVInstAluRRI<0b00, 0b010, "cv.addn">,
237                  Sched<[]>;
238  def CV_ADDUN  : CVInstAluRRI<0b01, 0b010, "cv.addun">,
239                  Sched<[]>;
240  def CV_ADDRN  : CVInstAluRRI<0b10, 0b010, "cv.addrn">,
241                  Sched<[]>;
242  def CV_ADDURN : CVInstAluRRI<0b11, 0b010, "cv.addurn">,
243                  Sched<[]>;
244  def CV_SUBN   : CVInstAluRRI<0b00, 0b011, "cv.subn">,
245                  Sched<[]>;
246  def CV_SUBUN  : CVInstAluRRI<0b01, 0b011, "cv.subun">,
247                  Sched<[]>;
248  def CV_SUBRN  : CVInstAluRRI<0b10, 0b011, "cv.subrn">,
249                  Sched<[]>;
250  def CV_SUBURN : CVInstAluRRI<0b11, 0b011, "cv.suburn">,
251                  Sched<[]>;
252} // Predicates = [HasVendorXCValu, IsRV32],
253  //   hasSideEffects = 0, mayLoad = 0, mayStore = 0
254
255let Predicates = [HasVendorXCValu, IsRV32],
256  hasSideEffects = 0, mayLoad = 0, mayStore = 0,
257  Constraints = "$rd = $rd_wb" in {
258  def CV_ADDNR   : CVInstAluRRNR<0b1000000, 0b011, "cv.addnr">,
259                   Sched<[]>;
260  def CV_ADDUNR  : CVInstAluRRNR<0b1000001, 0b011, "cv.addunr">,
261                   Sched<[]>;
262  def CV_ADDRNR  : CVInstAluRRNR<0b1000010, 0b011, "cv.addrnr">,
263                   Sched<[]>;
264  def CV_ADDURNR : CVInstAluRRNR<0b1000011, 0b011, "cv.addurnr">,
265                   Sched<[]>;
266  def CV_SUBNR   : CVInstAluRRNR<0b1000100, 0b011, "cv.subnr">,
267                   Sched<[]>;
268  def CV_SUBUNR  : CVInstAluRRNR<0b1000101, 0b011, "cv.subunr">,
269                   Sched<[]>;
270  def CV_SUBRNR  : CVInstAluRRNR<0b1000110, 0b011, "cv.subrnr">,
271                   Sched<[]>;
272  def CV_SUBURNR : CVInstAluRRNR<0b1000111, 0b011, "cv.suburnr">,
273                   Sched<[]>;
274
275} // Predicates = [HasVendorXCValu, IsRV32],
276  //   hasSideEffects = 0, mayLoad = 0, mayStore = 0,
277  //   Constraints = "$rd = $rd_wb"
278
279
280class CVInstSIMDRR<bits<5> funct5, bit F, bit funct1, bits<3> funct3,
281                   RISCVOpcode opcode, dag outs,
282                   dag ins, string opcodestr, string argstr>
283    : RVInstRBase<funct3, opcode, outs, ins, opcodestr, argstr> {
284  let Inst{31-27} = funct5;
285  let Inst{26} = F;
286  let Inst{25} = funct1;
287  let DecoderNamespace = "XCVsimd";
288}
289
290class CVInstSIMDRI<bits<5> funct5, bit F, bits<3> funct3, RISCVOpcode opcode,
291                   dag outs, dag ins, string opcodestr, string argstr>
292    : RVInstIBase<funct3, opcode, outs, ins, opcodestr, argstr> {
293  bits<6> imm6;
294
295  let Inst{31-27} = funct5;
296  let Inst{26} = F;
297  let Inst{25} = imm6{0}; // funct1 unused
298  let Inst{24-20} = imm6{5-1};
299  let DecoderNamespace = "XCVsimd";
300}
301
302class CVSIMDRR<bits<5> funct5, bit F, bit funct1, bits<3> funct3,
303               string opcodestr>
304    : CVInstSIMDRR<funct5, F, funct1, funct3, OPC_CUSTOM_3, (outs GPR:$rd),
305              (ins GPR:$rs1, GPR:$rs2), opcodestr, "$rd, $rs1, $rs2">;
306
307class CVSIMDRRWb<bits<5> funct5, bit F, bit funct1, bits<3> funct3,
308                 string opcodestr>
309    : CVInstSIMDRR<funct5, F, funct1, funct3, OPC_CUSTOM_3, (outs GPR:$rd_wb),
310              (ins GPR:$rd, GPR:$rs1, GPR:$rs2), opcodestr, "$rd, $rs1, $rs2"> {
311  let Constraints = "$rd = $rd_wb";
312}
313
314class CVSIMDRI<bits<5> funct5, bit F, bits<3> funct3, string opcodestr>
315    : CVInstSIMDRI<funct5, F, funct3, OPC_CUSTOM_3, (outs GPR:$rd),
316              (ins GPR:$rs1, simm6:$imm6), opcodestr, "$rd, $rs1, $imm6">;
317
318class CVSIMDRIWb<bits<5> funct5, bit F, bits<3> funct3, string opcodestr>
319    : CVInstSIMDRI<funct5, F, funct3, OPC_CUSTOM_3,
320                   (outs GPR:$rd_wb), (ins GPR:$rd, GPR:$rs1, simm6:$imm6),
321                   opcodestr, "$rd, $rs1, $imm6"> {
322  let Constraints = "$rd = $rd_wb";
323}
324
325class CVSIMDRU<bits<5> funct5, bit F, bits<3> funct3, string opcodestr,
326               Operand immtype = uimm6>
327    : CVInstSIMDRI<funct5, F, funct3, OPC_CUSTOM_3,
328                   (outs GPR:$rd), (ins GPR:$rs1, immtype:$imm6),
329                   opcodestr, "$rd, $rs1, $imm6">;
330
331class CVSIMDRUWb<bits<5> funct5, bit F, bits<3> funct3, string opcodestr>
332    : CVInstSIMDRI<funct5, F, funct3, OPC_CUSTOM_3,
333                   (outs GPR:$rd_wb),
334                   (ins GPR:$rd, GPR:$rs1, uimm6:$imm6),
335                   opcodestr, "$rd, $rs1, $imm6"> {
336  let Constraints = "$rd = $rd_wb";
337}
338
339class CVSIMDR<bits<5> funct5, bit F, bit funct1, bits<3> funct3,
340              string opcodestr>
341    : CVInstSIMDRR<funct5, F, funct1, funct3, OPC_CUSTOM_3, (outs GPR:$rd),
342                  (ins GPR:$rs1), opcodestr, "$rd, $rs1"> {
343  let rs2 = 0b00000;
344}
345
346multiclass CVSIMDBinarySigned<bits<5> funct5, bit F, bit funct1, string mnemonic> {
347  def CV_ # NAME # _H : CVSIMDRR<funct5, F, funct1, 0b000, "cv." # mnemonic # ".h">;
348  def CV_ # NAME # _B : CVSIMDRR<funct5, F, funct1, 0b001, "cv." # mnemonic # ".b">;
349  def CV_ # NAME # _SC_H : CVSIMDRR<funct5, F, funct1, 0b100, "cv." # mnemonic # ".sc.h">;
350  def CV_ # NAME # _SC_B : CVSIMDRR<funct5, F, funct1, 0b101, "cv." # mnemonic # ".sc.b">;
351  def CV_ # NAME # _SCI_H : CVSIMDRI<funct5, F, 0b110, "cv." # mnemonic # ".sci.h">;
352  def CV_ # NAME # _SCI_B : CVSIMDRI<funct5, F, 0b111, "cv." # mnemonic # ".sci.b">;
353}
354
355multiclass CVSIMDBinaryUnsigned<bits<5> funct5, bit F, bit funct1, string mnemonic> {
356  def CV_ # NAME # _H : CVSIMDRR<funct5, F, funct1, 0b000, "cv." # mnemonic # ".h">;
357  def CV_ # NAME # _B : CVSIMDRR<funct5, F, funct1, 0b001, "cv." # mnemonic # ".b">;
358  def CV_ # NAME # _SC_H : CVSIMDRR<funct5, F, funct1, 0b100, "cv." # mnemonic # ".sc.h">;
359  def CV_ # NAME # _SC_B : CVSIMDRR<funct5, F, funct1, 0b101, "cv." # mnemonic # ".sc.b">;
360  def CV_ # NAME # _SCI_H : CVSIMDRU<funct5, F, 0b110, "cv." # mnemonic # ".sci.h">;
361  def CV_ # NAME # _SCI_B : CVSIMDRU<funct5, F, 0b111, "cv." # mnemonic # ".sci.b">;
362}
363
364multiclass CVSIMDShift<bits<5> funct5, bit F, bit funct1, string mnemonic> {
365  def CV_ # NAME # _H : CVSIMDRR<funct5, F, funct1, 0b000, "cv." # mnemonic # ".h">;
366  def CV_ # NAME # _B : CVSIMDRR<funct5, F, funct1, 0b001, "cv." # mnemonic # ".b">;
367  def CV_ # NAME # _SC_H : CVSIMDRR<funct5, F, funct1, 0b100, "cv." # mnemonic # ".sc.h">;
368  def CV_ # NAME # _SC_B : CVSIMDRR<funct5, F, funct1, 0b101, "cv." # mnemonic # ".sc.b">;
369  def CV_ # NAME # _SCI_H : CVSIMDRU<funct5, F, 0b110, "cv." # mnemonic # ".sci.h", uimm4>;
370  def CV_ # NAME # _SCI_B : CVSIMDRU<funct5, F, 0b111, "cv." # mnemonic # ".sci.b", uimm3>;
371}
372
373multiclass CVSIMDBinarySignedWb<bits<5> funct5, bit F, bit funct1, string mnemonic> {
374  def CV_ # NAME # _H : CVSIMDRRWb<funct5, F, funct1, 0b000, "cv." # mnemonic # ".h">;
375  def CV_ # NAME # _B : CVSIMDRRWb<funct5, F, funct1, 0b001, "cv." # mnemonic # ".b">;
376  def CV_ # NAME # _SC_H : CVSIMDRRWb<funct5, F, funct1, 0b100, "cv." # mnemonic # ".sc.h">;
377  def CV_ # NAME # _SC_B : CVSIMDRRWb<funct5, F, funct1, 0b101, "cv." # mnemonic # ".sc.b">;
378  def CV_ # NAME # _SCI_H : CVSIMDRIWb<funct5, F, 0b110, "cv." # mnemonic # ".sci.h">;
379  def CV_ # NAME # _SCI_B : CVSIMDRIWb<funct5, F, 0b111, "cv." # mnemonic # ".sci.b">;
380}
381
382multiclass CVSIMDBinaryUnsignedWb<bits<5> funct5, bit F, bit funct1, string mnemonic> {
383  def CV_ # NAME # _H : CVSIMDRRWb<funct5, F, funct1, 0b000, "cv." # mnemonic # ".h">;
384  def CV_ # NAME # _B : CVSIMDRRWb<funct5, F, funct1, 0b001, "cv." # mnemonic # ".b">;
385  def CV_ # NAME # _SC_H : CVSIMDRRWb<funct5, F, funct1, 0b100, "cv." # mnemonic # ".sc.h">;
386  def CV_ # NAME # _SC_B : CVSIMDRRWb<funct5, F, funct1, 0b101, "cv." # mnemonic # ".sc.b">;
387  def CV_ # NAME # _SCI_H : CVSIMDRUWb<funct5, F, 0b110, "cv." # mnemonic # ".sci.h">;
388  def CV_ # NAME # _SCI_B : CVSIMDRUWb<funct5, F, 0b111, "cv." # mnemonic # ".sci.b">;
389}
390
391
392let Predicates = [HasVendorXCVsimd, IsRV32],
393    hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
394  defm ADD :    CVSIMDBinarySigned<0b00000, 0, 0, "add">;
395  defm SUB :    CVSIMDBinarySigned<0b00001, 0, 0, "sub">;
396  defm AVG :    CVSIMDBinarySigned<0b00010, 0, 0, "avg">;
397  defm AVGU : CVSIMDBinaryUnsigned<0b00011, 0, 0, "avgu">;
398  defm MIN :    CVSIMDBinarySigned<0b00100, 0, 0, "min">;
399  defm MINU : CVSIMDBinaryUnsigned<0b00101, 0, 0, "minu">;
400  defm MAX :    CVSIMDBinarySigned<0b00110, 0, 0, "max">;
401  defm MAXU : CVSIMDBinaryUnsigned<0b00111, 0, 0, "maxu">;
402  defm SRL :           CVSIMDShift<0b01000, 0, 0, "srl">;
403  defm SRA :           CVSIMDShift<0b01001, 0, 0, "sra">;
404  defm SLL :           CVSIMDShift<0b01010, 0, 0, "sll">;
405  defm OR :     CVSIMDBinarySigned<0b01011, 0, 0, "or">;
406  defm XOR :    CVSIMDBinarySigned<0b01100, 0, 0, "xor">;
407  defm AND :    CVSIMDBinarySigned<0b01101, 0, 0, "and">;
408
409  def CV_ABS_H :    CVSIMDR<0b01110, 0, 0, 0b000, "cv.abs.h">;
410  def CV_ABS_B :    CVSIMDR<0b01110, 0, 0, 0b001, "cv.abs.b">;
411
412  // 0b01111xx: UNDEF
413
414  defm DOTUP :   CVSIMDBinaryUnsigned<0b10000, 0, 0, "dotup">;
415  defm DOTUSP :  CVSIMDBinarySigned<0b10001, 0, 0, "dotusp">;
416  defm DOTSP :   CVSIMDBinarySigned<0b10010, 0, 0, "dotsp">;
417  defm SDOTUP :  CVSIMDBinaryUnsignedWb<0b10011, 0, 0, "sdotup">;
418  defm SDOTUSP : CVSIMDBinarySignedWb<0b10100, 0, 0, "sdotusp">;
419  defm SDOTSP :  CVSIMDBinarySignedWb<0b10101, 0, 0, "sdotsp">;
420
421  // 0b10110xx: UNDEF
422
423  def CV_EXTRACT_H :    CVSIMDRU<0b10111, 0, 0b000, "cv.extract.h">;
424  def CV_EXTRACT_B :    CVSIMDRU<0b10111, 0, 0b001, "cv.extract.b">;
425  def CV_EXTRACTU_H :   CVSIMDRU<0b10111, 0, 0b010, "cv.extractu.h">;
426  def CV_EXTRACTU_B :   CVSIMDRU<0b10111, 0, 0b011, "cv.extractu.b">;
427  def CV_INSERT_H :     CVSIMDRUWb<0b10111, 0, 0b100, "cv.insert.h">;
428  def CV_INSERT_B :     CVSIMDRUWb<0b10111, 0, 0b101, "cv.insert.b">;
429
430  def CV_SHUFFLE_H :    CVSIMDRR<0b11000, 0, 0, 0b000, "cv.shuffle.h">;
431  def CV_SHUFFLE_B :    CVSIMDRR<0b11000, 0, 0, 0b001, "cv.shuffle.b">;
432  def CV_SHUFFLE_SCI_H :   CVSIMDRU<0b11000, 0, 0b110, "cv.shuffle.sci.h">;
433  def CV_SHUFFLEI0_SCI_B : CVSIMDRU<0b11000, 0, 0b111, "cv.shufflei0.sci.b">;
434
435  def CV_SHUFFLEI1_SCI_B : CVSIMDRU<0b11001, 0, 0b111, "cv.shufflei1.sci.b">;
436
437  def CV_SHUFFLEI2_SCI_B : CVSIMDRU<0b11010, 0, 0b111, "cv.shufflei2.sci.b">;
438
439  def CV_SHUFFLEI3_SCI_B : CVSIMDRU<0b11011, 0, 0b111, "cv.shufflei3.sci.b">;
440
441  def CV_SHUFFLE2_H :    CVSIMDRRWb<0b11100, 0, 0, 0b000, "cv.shuffle2.h">;
442  def CV_SHUFFLE2_B :    CVSIMDRRWb<0b11100, 0, 0, 0b001, "cv.shuffle2.b">;
443
444  // 0b11101xx: UNDEF
445
446  def CV_PACK :      CVSIMDRR<0b11110, 0, 0, 0b000, "cv.pack">;
447  def CV_PACK_H :    CVSIMDRR<0b11110, 0, 1, 0b000, "cv.pack.h">;
448
449  def CV_PACKHI_B : CVSIMDRRWb<0b11111, 0, 1, 0b001, "cv.packhi.b">;
450  def CV_PACKLO_B : CVSIMDRRWb<0b11111, 0, 0, 0b001, "cv.packlo.b">;
451
452  defm CMPEQ :  CVSIMDBinarySigned<0b00000, 1, 0, "cmpeq">;
453  defm CMPNE :  CVSIMDBinarySigned<0b00001, 1, 0, "cmpne">;
454  defm CMPGT :  CVSIMDBinarySigned<0b00010, 1, 0, "cmpgt">;
455  defm CMPGE :  CVSIMDBinarySigned<0b00011, 1, 0, "cmpge">;
456  defm CMPLT :  CVSIMDBinarySigned<0b00100, 1, 0, "cmplt">;
457  defm CMPLE :  CVSIMDBinarySigned<0b00101, 1, 0, "cmple">;
458  defm CMPGTU : CVSIMDBinaryUnsigned<0b00110, 1, 0, "cmpgtu">;
459  defm CMPGEU : CVSIMDBinaryUnsigned<0b00111, 1, 0, "cmpgeu">;
460  defm CMPLTU : CVSIMDBinaryUnsigned<0b01000, 1, 0, "cmpltu">;
461  defm CMPLEU : CVSIMDBinaryUnsigned<0b01001, 1, 0, "cmpleu">;
462
463  def CV_CPLXMUL_R :      CVSIMDRRWb<0b01010, 1, 0, 0b000, "cv.cplxmul.r">;
464  def CV_CPLXMUL_I :      CVSIMDRRWb<0b01010, 1, 1, 0b000, "cv.cplxmul.i">;
465  def CV_CPLXMUL_R_DIV2 : CVSIMDRRWb<0b01010, 1, 0, 0b010, "cv.cplxmul.r.div2">;
466  def CV_CPLXMUL_I_DIV2 : CVSIMDRRWb<0b01010, 1, 1, 0b010, "cv.cplxmul.i.div2">;
467  def CV_CPLXMUL_R_DIV4 : CVSIMDRRWb<0b01010, 1, 0, 0b100, "cv.cplxmul.r.div4">;
468  def CV_CPLXMUL_I_DIV4 : CVSIMDRRWb<0b01010, 1, 1, 0b100, "cv.cplxmul.i.div4">;
469  def CV_CPLXMUL_R_DIV8 : CVSIMDRRWb<0b01010, 1, 0, 0b110, "cv.cplxmul.r.div8">;
470  def CV_CPLXMUL_I_DIV8 : CVSIMDRRWb<0b01010, 1, 1, 0b110, "cv.cplxmul.i.div8">;
471
472  def CV_CPLXCONJ :    CVSIMDR<0b01011, 1, 0, 0b000, "cv.cplxconj">;
473
474  // 0b01011xx: UNDEF
475
476  def CV_SUBROTMJ :      CVSIMDRR<0b01100, 1, 0, 0b000, "cv.subrotmj">;
477  def CV_SUBROTMJ_DIV2 : CVSIMDRR<0b01100, 1, 0, 0b010, "cv.subrotmj.div2">;
478  def CV_SUBROTMJ_DIV4 : CVSIMDRR<0b01100, 1, 0, 0b100, "cv.subrotmj.div4">;
479  def CV_SUBROTMJ_DIV8 : CVSIMDRR<0b01100, 1, 0, 0b110, "cv.subrotmj.div8">;
480
481  def CV_ADD_DIV2 :    CVSIMDRR<0b01101, 1, 0, 0b010, "cv.add.div2">;
482  def CV_ADD_DIV4 :    CVSIMDRR<0b01101, 1, 0, 0b100, "cv.add.div4">;
483  def CV_ADD_DIV8 :    CVSIMDRR<0b01101, 1, 0, 0b110, "cv.add.div8">;
484
485  def CV_SUB_DIV2 :    CVSIMDRR<0b01110, 1, 0, 0b010, "cv.sub.div2">;
486  def CV_SUB_DIV4 :    CVSIMDRR<0b01110, 1, 0, 0b100, "cv.sub.div4">;
487  def CV_SUB_DIV8 :    CVSIMDRR<0b01110, 1, 0, 0b110, "cv.sub.div8">;
488}
489
490class CVInstImmBranch<bits<3> funct3, dag outs, dag ins,
491                      string opcodestr, string argstr>
492    : RVInstB<funct3, OPC_CUSTOM_0, outs, ins, opcodestr, argstr> {
493  bits<5> imm5;
494  let rs2 = imm5;
495  let DecoderNamespace = "XCVbi";
496}
497
498let Predicates = [HasVendorXCVbi, IsRV32], hasSideEffects = 0, mayLoad = 0,
499    mayStore = 0, isBranch = 1, isTerminator = 1 in {
500  // Immediate branching operations
501  def CV_BEQIMM : CVInstImmBranch<0b110, (outs),
502        (ins GPR:$rs1, simm5:$imm5, simm13_lsb0:$imm12),
503        "cv.beqimm", "$rs1, $imm5, $imm12">, Sched<[]>;
504  def CV_BNEIMM : CVInstImmBranch<0b111, (outs),
505        (ins GPR:$rs1, simm5:$imm5, simm13_lsb0:$imm12),
506        "cv.bneimm", "$rs1, $imm5, $imm12">, Sched<[]>;
507}
508
509def CVrrAsmOperand : AsmOperandClass {
510  let Name = "RegReg";
511  let ParserMethod = "parseRegReg";
512  let DiagnosticType = "InvalidRegReg";
513}
514
515def CVrr : Operand<i32>,
516           ComplexPattern<i32, 2, "SelectAddrRegReg",[]> {
517   let ParserMatchClass = CVrrAsmOperand;
518   let EncoderMethod =  "getRegReg";
519   let DecoderMethod = "decodeRegReg";
520   let PrintMethod = "printRegReg";
521   let MIOperandInfo = (ops GPR:$base, GPR:$offset);
522}
523
524class CVLoad_ri_inc<bits<3> funct3, string opcodestr>
525    : RVInstI<funct3, OPC_CUSTOM_0, (outs GPR:$rd, GPR:$rs1_wb), (ins GPRMem:$rs1, simm12:$imm12),
526              opcodestr, "$rd, (${rs1}), ${imm12}"> {
527  let Constraints = "$rs1_wb = $rs1";
528  let DecoderNamespace = "XCVmem";
529}
530
531class CVLoad_rr_inc<bits<7> funct7, bits<3> funct3, string opcodestr>
532    : RVInstR<funct7, funct3, OPC_CUSTOM_1, (outs GPR:$rd, GPR:$rs1_wb), (ins GPRMem:$rs1, GPR:$rs2),
533              opcodestr, "$rd, (${rs1}), ${rs2}"> {
534  let Constraints = "$rs1_wb = $rs1";
535  let DecoderNamespace = "XCVmem";
536}
537
538class CVLoad_rr<bits<7> funct7, bits<3> funct3, string opcodestr>
539    : RVInstR<funct7, funct3, OPC_CUSTOM_1, (outs GPR:$rd), (ins CVrr:$cvrr),
540              opcodestr, "$rd, $cvrr"> {
541  bits<5> rd;
542  bits<10> cvrr;
543
544  let Inst{31-25} = funct7;
545  let Inst{24-20} = cvrr{4-0};
546  let Inst{19-15} = cvrr{9-5};
547  let Inst{14-12} = funct3;
548  let Inst{11-7} = rd;
549  let DecoderNamespace = "XCVmem";
550}
551
552let Predicates = [HasVendorXCVmem, IsRV32], hasSideEffects = 0,
553                 mayLoad = 1, mayStore = 0, Constraints = "$rs1_wb = $rs1" in {
554  // Register-Immediate load with post-increment
555  def CV_LB_ri_inc  : CVLoad_ri_inc<0b000, "cv.lb">;
556  def CV_LBU_ri_inc : CVLoad_ri_inc<0b100, "cv.lbu">;
557  def CV_LH_ri_inc  : CVLoad_ri_inc<0b001, "cv.lh">;
558  def CV_LHU_ri_inc : CVLoad_ri_inc<0b101, "cv.lhu">;
559  def CV_LW_ri_inc  : CVLoad_ri_inc<0b010, "cv.lw">;
560
561  // Register-Register load with post-increment
562  def CV_LB_rr_inc  : CVLoad_rr_inc<0b0000000, 0b011, "cv.lb">;
563  def CV_LBU_rr_inc : CVLoad_rr_inc<0b0001000, 0b011, "cv.lbu">;
564  def CV_LH_rr_inc  : CVLoad_rr_inc<0b0000001, 0b011, "cv.lh">;
565  def CV_LHU_rr_inc : CVLoad_rr_inc<0b0001001, 0b011, "cv.lhu">;
566  def CV_LW_rr_inc  : CVLoad_rr_inc<0b0000010, 0b011, "cv.lw">;
567}
568
569let Predicates = [HasVendorXCVmem, IsRV32], hasSideEffects = 0,
570                 mayLoad = 1, mayStore = 0 in {
571  // Register-Register load
572  def CV_LB_rr  : CVLoad_rr<0b0000100, 0b011, "cv.lb">;
573  def CV_LBU_rr : CVLoad_rr<0b0001100, 0b011, "cv.lbu">;
574  def CV_LH_rr  : CVLoad_rr<0b0000101, 0b011, "cv.lh">;
575  def CV_LHU_rr : CVLoad_rr<0b0001101, 0b011, "cv.lhu">;
576  def CV_LW_rr  : CVLoad_rr<0b0000110, 0b011, "cv.lw">;
577}
578
579class CVStore_ri_inc<bits<3> funct3, string opcodestr>
580    : RVInstS<funct3, OPC_CUSTOM_1, (outs GPR:$rs1_wb),
581              (ins GPR:$rs2, GPR:$rs1, simm12:$imm12),
582              opcodestr, "$rs2, (${rs1}), ${imm12}"> {
583  let Constraints = "$rs1_wb = $rs1";
584  let DecoderNamespace = "XCVmem";
585}
586
587class CVStore_rr_inc<bits<3> funct3, bits<7> funct7, dag outs, dag ins,
588                     string opcodestr, string argstr>
589    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatOther> {
590  bits<5> rs3;
591  bits<5> rs2;
592  bits<5> rs1;
593
594  let Inst{31-25} = funct7;
595  let Inst{24-20} = rs2;
596  let Inst{19-15} = rs1;
597  let Inst{14-12} = funct3;
598  let Inst{11-7} = rs3;
599  let Inst{6-0} = OPC_CUSTOM_1.Value;
600  let DecoderNamespace = "XCVmem";
601}
602
603
604class CVStore_rr<bits<3> funct3, bits<7> funct7, dag outs, dag ins,
605                     string opcodestr, string argstr>
606    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatOther> {
607  bits<5> rs2;
608  bits<10> cvrr;
609
610  let Inst{31-25} = funct7;
611  let Inst{24-20} = rs2;
612  let Inst{19-15} = cvrr{9-5};
613  let Inst{14-12} = funct3;
614  let Inst{11-7} = cvrr{4-0};
615  let Inst{6-0} = OPC_CUSTOM_1.Value;
616  let DecoderNamespace = "XCVmem";
617}
618
619let Predicates = [HasVendorXCVmem, IsRV32], hasSideEffects = 0,
620                 mayLoad = 0, mayStore = 1, Constraints = "$rs1_wb = $rs1" in {
621  // Register-Immediate store with post-increment
622  def CV_SB_ri_inc : CVStore_ri_inc<0b000, "cv.sb">;
623  def CV_SH_ri_inc : CVStore_ri_inc<0b001, "cv.sh">;
624  def CV_SW_ri_inc : CVStore_ri_inc<0b010, "cv.sw">;
625
626  // Register-Register store with post-increment
627  def CV_SB_rr_inc : CVStore_rr_inc<0b011, 0b0010000,
628                     (outs GPR:$rs1_wb), (ins GPR:$rs2, GPR:$rs1, GPR:$rs3),
629                      "cv.sb", "$rs2, (${rs1}), ${rs3}">;
630  def CV_SH_rr_inc : CVStore_rr_inc<0b011, 0b0010001,
631                     (outs GPR:$rs1_wb), (ins GPR:$rs2, GPR:$rs1, GPR:$rs3),
632                      "cv.sh", "$rs2, (${rs1}), ${rs3}">;
633  def CV_SW_rr_inc : CVStore_rr_inc<0b011, 0b0010010,
634                     (outs GPR:$rs1_wb), (ins GPR:$rs2, GPR:$rs1, GPR:$rs3),
635                      "cv.sw", "$rs2, (${rs1}), ${rs3}">;
636}
637
638
639let Predicates = [HasVendorXCVmem, IsRV32], hasSideEffects = 0,
640                  mayLoad = 0, mayStore = 1 in {
641  // Register-Register store
642  def CV_SB_rr : CVStore_rr<0b011, 0b0010100,
643                 (outs), (ins GPR:$rs2, CVrr:$cvrr),
644                 "cv.sb", "$rs2, $cvrr">;
645  def CV_SH_rr : CVStore_rr<0b011, 0b0010101,
646                 (outs), (ins GPR:$rs2, CVrr:$cvrr),
647                 "cv.sh", "$rs2, $cvrr">;
648  def CV_SW_rr : CVStore_rr<0b011, 0b0010110,
649                 (outs), (ins GPR:$rs2, CVrr:$cvrr),
650                 "cv.sw", "$rs2, $cvrr">;
651}
652
653let DecoderNamespace = "XCVelw" in
654class CVLoad_ri<bits<3> funct3, string opcodestr>
655    : RVInstI<funct3, OPC_CUSTOM_0, (outs GPR:$rd),
656      (ins GPRMem:$rs1, simm12:$imm12), opcodestr, "$rd, ${imm12}(${rs1})">;
657
658let Predicates = [HasVendorXCVelw, IsRV32], hasSideEffects = 0,
659    mayLoad = 1, mayStore = 0 in {
660  // Event load
661  def CV_ELW : CVLoad_ri<0b011, "cv.elw">;
662}
663
664//===----------------------------------------------------------------------===//
665// Patterns for load & store operations
666//===----------------------------------------------------------------------===//
667class CVLdrrPat<PatFrag LoadOp, RVInst Inst>
668    : Pat<(XLenVT (LoadOp CVrr:$regreg)),
669          (Inst CVrr:$regreg)>;
670
671class CVStriPat<PatFrag StoreOp, RVInst Inst>
672    : Pat<(StoreOp (XLenVT GPR:$rs2), GPR:$rs1, simm12:$imm12),
673          (Inst GPR:$rs2, GPR:$rs1, simm12:$imm12)>;
674
675class CVStrriPat<PatFrag StoreOp, RVInst Inst>
676    : Pat<(StoreOp (XLenVT GPR:$rs2), GPR:$rs1, GPR:$rs3),
677          (Inst GPR:$rs2, GPR:$rs1, GPR:$rs3)>;
678
679class CVStrrPat<PatFrag StoreOp, RVInst Inst>
680    : Pat<(StoreOp (XLenVT GPR:$rs2), CVrr:$regreg),
681          (Inst GPR:$rs2, CVrr:$regreg)>;
682
683let Predicates = [HasVendorXCVmem, IsRV32], AddedComplexity = 1 in {
684  def : CVLdrrPat<sextloadi8, CV_LB_rr>;
685  def : CVLdrrPat<zextloadi8, CV_LBU_rr>;
686  def : CVLdrrPat<extloadi8, CV_LBU_rr>;
687  def : CVLdrrPat<sextloadi16, CV_LH_rr>;
688  def : CVLdrrPat<zextloadi16, CV_LHU_rr>;
689  def : CVLdrrPat<extloadi16, CV_LHU_rr>;
690  def : CVLdrrPat<load, CV_LW_rr>;
691
692  def : CVStriPat<post_truncsti8, CV_SB_ri_inc>;
693  def : CVStriPat<post_truncsti16, CV_SH_ri_inc>;
694  def : CVStriPat<post_store, CV_SW_ri_inc>;
695
696  def : CVStrriPat<post_truncsti8, CV_SB_rr_inc>;
697  def : CVStrriPat<post_truncsti16, CV_SH_ri_inc>;
698  def : CVStrriPat<post_store, CV_SW_rr_inc>;
699
700  def : CVStrrPat<truncstorei8, CV_SB_rr>;
701  def : CVStrrPat<truncstorei16, CV_SH_rr>;
702  def : CVStrrPat<store, CV_SW_rr>;
703}
704
705def cv_tuimm2 : TImmLeaf<XLenVT, [{return isUInt<2>(Imm);}]>;
706def cv_tuimm5 : TImmLeaf<XLenVT, [{return isUInt<5>(Imm);}]>;
707def cv_uimm10 : ImmLeaf<XLenVT, [{return isUInt<10>(Imm);}]>;
708
709def CV_LO5: SDNodeXForm<imm, [{
710  return CurDAG->getTargetConstant(N->getZExtValue() & 0x1f, SDLoc(N),
711                                   N->getValueType(0));
712}]>;
713
714def CV_HI5: SDNodeXForm<imm, [{
715  return CurDAG->getTargetConstant(N->getZExtValue() >> 5, SDLoc(N),
716                                   N->getValueType(0));
717}]>;
718
719def powerOf2Minus1 : ImmLeaf<XLenVT, [{ return isPowerOf2_32(Imm+1); }]>;
720def trailing1sPlus1 : SDNodeXForm<imm, [{
721  return CurDAG->getTargetConstant(
722                          llvm::countr_one(N->getZExtValue()) + 1,
723                          SDLoc(N), N->getValueType(0));
724}]>;
725
726multiclass PatCoreVBitManip<Intrinsic intr> {
727  def : PatGprGpr<intr, !cast<RVInst>("CV_" # NAME # "R")>;
728  def : Pat<(intr GPR:$rs1, cv_uimm10:$imm),
729            (!cast<RVInst>("CV_" # NAME)
730             GPR:$rs1, (CV_HI5 cv_uimm10:$imm), (CV_LO5 cv_uimm10:$imm))>;
731}
732
733let Predicates = [HasVendorXCVbitmanip, IsRV32] in {
734  defm EXTRACT : PatCoreVBitManip<int_riscv_cv_bitmanip_extract>;
735  defm EXTRACTU : PatCoreVBitManip<int_riscv_cv_bitmanip_extractu>;
736  defm BCLR : PatCoreVBitManip<int_riscv_cv_bitmanip_bclr>;
737  defm BSET : PatCoreVBitManip<int_riscv_cv_bitmanip_bset>;
738
739  def : Pat<(int_riscv_cv_bitmanip_insert GPR:$rs1, GPR:$rs2, GPR:$rd),
740            (CV_INSERTR GPR:$rd, GPR:$rs1, GPR:$rs2)>;
741  def : Pat<(int_riscv_cv_bitmanip_insert GPR:$rs1, cv_uimm10:$imm, GPR:$rd),
742            (CV_INSERT GPR:$rd, GPR:$rs1, (CV_HI5 cv_uimm10:$imm),
743                                          (CV_LO5 cv_uimm10:$imm))>;
744
745  def : PatGpr<cttz, CV_FF1>;
746  def : PatGpr<ctlz, CV_FL1>;
747  def : PatGpr<int_riscv_cv_bitmanip_clb, CV_CLB>;
748  def : PatGpr<ctpop, CV_CNT>;
749
750  def : PatGprGpr<rotr, CV_ROR>;
751
752  def : Pat<(int_riscv_cv_bitmanip_bitrev GPR:$rs1, cv_tuimm5:$pts,
753             cv_tuimm2:$radix),
754            (CV_BITREV GPR:$rs1, cv_tuimm2:$radix, cv_tuimm5:$pts)>;
755  def : Pat<(bitreverse (XLenVT GPR:$rs)), (CV_BITREV GPR:$rs, 0, 0)>;
756}
757
758class PatCoreVAluGpr<string intr, string asm> :
759  PatGpr<!cast<Intrinsic>("int_riscv_cv_alu_" # intr),
760            !cast<RVInst>("CV_" # asm)>;
761class PatCoreVAluGprGpr <string intr, string asm> :
762  PatGprGpr<!cast<Intrinsic>("int_riscv_cv_alu_" # intr),
763               !cast<RVInst>("CV_" # asm)>;
764
765multiclass PatCoreVAluGprImm<Intrinsic intr> {
766  def : PatGprGpr<intr, !cast<RVInst>("CV_" # NAME # "R")>;
767  def : Pat<(intr (XLenVT GPR:$rs1), powerOf2Minus1:$upperBound),
768            (!cast<RVInst>("CV_" # NAME) GPR:$rs1,
769            (trailing1sPlus1 imm:$upperBound))>;
770}
771
772multiclass PatCoreVAluGprGprImm<Intrinsic intr> {
773  def : Pat<(intr GPR:$rs1, GPR:$rs2, GPR:$rs3),
774            (!cast<RVInst>("CV_" # NAME # "R") GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
775  def : Pat<(intr GPR:$rs1, GPR:$rs2, uimm5:$imm),
776            (!cast<RVInst>("CV_" # NAME) GPR:$rs1, GPR:$rs2, uimm5:$imm)>;
777}
778
779let Predicates = [HasVendorXCValu, IsRV32], AddedComplexity = 1 in {
780  def : PatGpr<abs, CV_ABS>;
781  def : PatGprGpr<setle, CV_SLET>;
782  def : PatGprGpr<setule, CV_SLETU>;
783  def : PatGprGpr<smin, CV_MIN>;
784  def : PatGprGpr<umin, CV_MINU>;
785  def : PatGprGpr<smax, CV_MAX>;
786  def : PatGprGpr<umax, CV_MAXU>;
787
788  def : Pat<(sext_inreg (XLenVT GPR:$rs1), i16), (CV_EXTHS GPR:$rs1)>;
789  def : Pat<(sext_inreg (XLenVT GPR:$rs1), i8), (CV_EXTBS GPR:$rs1)>;
790  def : Pat<(and (XLenVT GPR:$rs1), 0xffff), (CV_EXTHZ GPR:$rs1)>;
791
792  defm CLIP   : PatCoreVAluGprImm<int_riscv_cv_alu_clip>;
793  defm CLIPU  : PatCoreVAluGprImm<int_riscv_cv_alu_clipu>;
794  defm ADDN   : PatCoreVAluGprGprImm<int_riscv_cv_alu_addn>;
795  defm ADDUN  : PatCoreVAluGprGprImm<int_riscv_cv_alu_addun>;
796  defm ADDRN  : PatCoreVAluGprGprImm<int_riscv_cv_alu_addrn>;
797  defm ADDURN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addurn>;
798  defm SUBN   : PatCoreVAluGprGprImm<int_riscv_cv_alu_subn>;
799  defm SUBUN  : PatCoreVAluGprGprImm<int_riscv_cv_alu_subun>;
800  defm SUBRN  : PatCoreVAluGprGprImm<int_riscv_cv_alu_subrn>;
801  defm SUBURN : PatCoreVAluGprGprImm<int_riscv_cv_alu_suburn>;
802} // Predicates = [HasVendorXCValu, IsRV32]
803
804//===----------------------------------------------------------------------===//
805// Patterns for immediate branching operations
806//===----------------------------------------------------------------------===//
807
808let Predicates = [HasVendorXCVbi, IsRV32], AddedComplexity = 2 in {
809  def : Pat<(riscv_brcc GPR:$rs1, simm5:$imm5, SETEQ, bb:$imm12),
810            (CV_BEQIMM GPR:$rs1, simm5:$imm5, simm13_lsb0:$imm12)>;
811  def : Pat<(riscv_brcc GPR:$rs1, simm5:$imm5, SETNE, bb:$imm12),
812            (CV_BNEIMM GPR:$rs1, simm5:$imm5, simm13_lsb0:$imm12)>;
813
814  let usesCustomInserter = 1 in
815  def Select_GPR_Using_CC_Imm : Pseudo<(outs GPR:$dst),
816                             (ins GPR:$lhs, simm5:$imm5, ixlenimm:$cc,
817                              GPR:$truev, GPR:$falsev), []>;
818
819
820  class Selectbi<CondCode Cond>
821      : Pat<(riscv_selectcc_frag:$cc (i32 GPR:$lhs), simm5:$Constant, Cond,
822                                     (i32 GPR:$truev), GPR:$falsev),
823            (Select_GPR_Using_CC_Imm GPR:$lhs, simm5:$Constant,
824             (IntCCtoRISCVCC $cc), GPR:$truev, GPR:$falsev)>;
825
826  def : Selectbi<SETEQ>;
827  def : Selectbi<SETNE>;
828}
829
830class PatCoreVMacGprGprGpr <string intr, string asm>
831  : Pat<(!cast<Intrinsic>("int_riscv_cv_mac_" # intr) GPR:$rs1, GPR:$rs2, GPR:$rd),
832        (!cast<RVInst>("CV_" # asm) GPR:$rd, GPR:$rs1, GPR:$rs2)>;
833class PatCoreVMacGprGprGprUimm5 <string intr, string asm>
834  : Pat<(!cast<Intrinsic>("int_riscv_cv_mac_" # intr) GPR:$rs1, GPR:$rs2, GPR:$rd, cv_tuimm5:$imm5),
835        (!cast<RVInst>("CV_" # asm) GPR:$rd, GPR:$rs1, GPR:$rs2, cv_tuimm5:$imm5)>;
836class PatCoreVMacGprGprUimm5 <string intr, string asm>
837  : Pat<(!cast<Intrinsic>("int_riscv_cv_mac_" # intr) GPR:$rs1, GPR:$rs2, cv_tuimm5:$imm5),
838        (!cast<RVInst>("CV_" # asm) GPR:$rs1, GPR:$rs2, cv_tuimm5:$imm5)>;
839
840let Predicates = [HasVendorXCVmac] in {
841  def : PatCoreVMacGprGprGpr<"mac", "MAC">;
842  def : PatCoreVMacGprGprGpr<"msu", "MSU">;
843
844  def : PatCoreVMacGprGprUimm5<"muluN", "MULUN">;
845  def : PatCoreVMacGprGprUimm5<"mulhhuN", "MULHHUN">;
846  def : PatCoreVMacGprGprUimm5<"mulsN", "MULSN">;
847  def : PatCoreVMacGprGprUimm5<"mulhhsN", "MULHHSN">;
848  def : PatCoreVMacGprGprUimm5<"muluRN", "MULURN">;
849  def : PatCoreVMacGprGprUimm5<"mulhhuRN", "MULHHURN">;
850  def : PatCoreVMacGprGprUimm5<"mulsRN", "MULSRN">;
851  def : PatCoreVMacGprGprUimm5<"mulhhsRN", "MULHHSRN">;
852
853  def : PatCoreVMacGprGprGprUimm5<"macuN", "MACUN">;
854  def : PatCoreVMacGprGprGprUimm5<"machhuN", "MACHHUN">;
855  def : PatCoreVMacGprGprGprUimm5<"macsN", "MACSN">;
856  def : PatCoreVMacGprGprGprUimm5<"machhsN", "MACHHSN">;
857  def : PatCoreVMacGprGprGprUimm5<"macuRN", "MACURN">;
858  def : PatCoreVMacGprGprGprUimm5<"machhuRN", "MACHHURN">;
859  def : PatCoreVMacGprGprGprUimm5<"macsRN", "MACSRN">;
860  def : PatCoreVMacGprGprGprUimm5<"machhsRN", "MACHHSRN">;
861}
862