xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVInstrInfoZk.td (revision 5956d97f4b3204318ceb6aa9c77bd0bc6ea87a41)
1//===- RISCVInstrInfoZk.td - RISC-V 'Zk' 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 RISC-V instructions from the standard 'Zk',
10// Scalar Cryptography Instructions extension, version 1.0.
11//
12//===----------------------------------------------------------------------===//
13
14//===----------------------------------------------------------------------===//
15// Operand and SDNode transformation definitions.
16//===----------------------------------------------------------------------===//
17
18def RnumArg : AsmOperandClass {
19  let Name = "RnumArg";
20  let RenderMethod = "addImmOperands";
21  let DiagnosticType = "InvalidRnumArg";
22}
23
24def rnum : Operand<i32>, TImmLeaf<i32, [{return (Imm >= 0 && Imm <= 10);}]> {
25  let ParserMatchClass = RnumArg;
26  let EncoderMethod = "getImmOpValue";
27  let DecoderMethod = "decodeUImmOperand<4>";
28  let OperandType = "OPERAND_RVKRNUM";
29  let OperandNamespace = "RISCVOp";
30}
31
32def byteselect : Operand<i8>, TImmLeaf<i8, [{return isUInt<2>(Imm);}]> {
33  let ParserMatchClass = UImmAsmOperand<2>;
34  let DecoderMethod = "decodeUImmOperand<2>";
35  let OperandType = "OPERAND_UIMM2";
36  let OperandNamespace = "RISCVOp";
37}
38
39//===----------------------------------------------------------------------===//
40// Instruction class templates
41//===----------------------------------------------------------------------===//
42let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
43class RVKUnary<bits<12> imm12_in, bits<3> funct3, string opcodestr>
44    : RVInstI<funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1),
45              opcodestr, "$rd, $rs1">{
46  let imm12 = imm12_in;
47}
48
49let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
50class RVKByteSelect<bits<5> funct5, string opcodestr>
51    : RVInstR<{0b00, funct5}, 0b000, OPC_OP, (outs GPR:$rd),
52              (ins GPR:$rs1, GPR:$rs2, byteselect:$bs),
53              opcodestr, "$rd, $rs1, $rs2, $bs">{
54  bits<2> bs;
55  let Inst{31-30} = bs;
56}
57
58let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
59class RVKUnary_rnum<bits<7> funct7, bits<3> funct3, string opcodestr>
60    : RVInstI<funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1, rnum:$rnum),
61              opcodestr, "$rd, $rs1, $rnum">{
62    bits<4> rnum;
63    let Inst{31-25} = funct7;
64    let Inst{24} = 1;
65    let Inst{23-20} = rnum;
66}
67
68//===----------------------------------------------------------------------===//
69// Instructions
70//===----------------------------------------------------------------------===//
71let Predicates = [HasStdExtZknd, IsRV32] in {
72def AES32DSI  : RVKByteSelect<0b10101, "aes32dsi">;
73def AES32DSMI : RVKByteSelect<0b10111, "aes32dsmi">;
74} // Predicates = [HasStdExtZknd, IsRV32]
75
76let Predicates = [HasStdExtZknd, IsRV64] in {
77def AES64DS  : ALU_rr<0b0011101, 0b000, "aes64ds">;
78def AES64DSM : ALU_rr<0b0011111, 0b000, "aes64dsm">;
79
80def AES64IM  : RVKUnary<0b001100000000, 0b001, "aes64im">;
81} // Predicates = [HasStdExtZknd, IsRV64]
82
83let Predicates = [HasStdExtZkndOrZkne, IsRV64] in {
84def AES64KS2  : ALU_rr<0b0111111, 0b000, "aes64ks2">;
85
86def AES64KS1I : RVKUnary_rnum<0b0011000, 0b001, "aes64ks1i">;
87} // Predicates = [HasStdExtZkndOrZkne, IsRV64]
88
89let Predicates = [HasStdExtZkne, IsRV32] in {
90def AES32ESI  : RVKByteSelect<0b10001, "aes32esi">;
91def AES32ESMI : RVKByteSelect<0b10011, "aes32esmi">;
92} // Predicates = [HasStdExtZkne, IsRV32]
93
94let Predicates = [HasStdExtZkne, IsRV64] in {
95def AES64ES   : ALU_rr<0b0011001, 0b000, "aes64es">;
96def AES64ESM  : ALU_rr<0b0011011, 0b000, "aes64esm">;
97} // Predicates = [HasStdExtZkne, IsRV64]
98
99let Predicates = [HasStdExtZknh] in {
100def SHA256SIG0 : RVKUnary<0b000100000010, 0b001, "sha256sig0">;
101def SHA256SIG1 : RVKUnary<0b000100000011, 0b001, "sha256sig1">;
102def SHA256SUM0 : RVKUnary<0b000100000000, 0b001, "sha256sum0">;
103def SHA256SUM1 : RVKUnary<0b000100000001, 0b001, "sha256sum1">;
104} // Predicates = [HasStdExtZknh]
105
106let Predicates = [HasStdExtZknh, IsRV32] in {
107def SHA512SIG0H : ALU_rr<0b0101110, 0b000, "sha512sig0h">;
108def SHA512SIG0L : ALU_rr<0b0101010, 0b000, "sha512sig0l">;
109def SHA512SIG1H : ALU_rr<0b0101111, 0b000, "sha512sig1h">;
110def SHA512SIG1L : ALU_rr<0b0101011, 0b000, "sha512sig1l">;
111def SHA512SUM0R : ALU_rr<0b0101000, 0b000, "sha512sum0r">;
112def SHA512SUM1R : ALU_rr<0b0101001, 0b000, "sha512sum1r">;
113} // [HasStdExtZknh, IsRV32]
114
115let Predicates = [HasStdExtZknh, IsRV64] in {
116def SHA512SIG0 : RVKUnary<0b000100000110, 0b001, "sha512sig0">;
117def SHA512SIG1 : RVKUnary<0b000100000111, 0b001, "sha512sig1">;
118def SHA512SUM0 : RVKUnary<0b000100000100, 0b001, "sha512sum0">;
119def SHA512SUM1 : RVKUnary<0b000100000101, 0b001, "sha512sum1">;
120} // Predicates = [HasStdExtZknh, IsRV64]
121
122let Predicates = [HasStdExtZksed] in {
123def SM4ED : RVKByteSelect<0b11000, "sm4ed">;
124def SM4KS : RVKByteSelect<0b11010, "sm4ks">;
125} // Predicates = [HasStdExtZksed]
126
127let Predicates = [HasStdExtZksh] in {
128def SM3P0 : RVKUnary<0b000100001000, 0b001, "sm3p0">;
129def SM3P1 : RVKUnary<0b000100001001, 0b001, "sm3p1">;
130} // Predicates = [HasStdExtZksh]
131
132//===----------------------------------------------------------------------===//
133// Codegen patterns
134//===----------------------------------------------------------------------===//
135
136class PatGprGprByteSelect<SDPatternOperator OpNode, RVInst Inst>
137    : Pat<(OpNode GPR:$rs1, GPR:$rs2, i8:$imm),
138          (Inst GPR:$rs1, GPR:$rs2, byteselect:$imm)>;
139
140// Zknd
141let Predicates = [HasStdExtZknd, IsRV32] in {
142def : PatGprGprByteSelect<int_riscv_aes32dsi, AES32DSI>;
143def : PatGprGprByteSelect<int_riscv_aes32dsmi, AES32DSMI>;
144} // Predicates = [HasStdExtZknd, IsRV32]
145
146let Predicates = [HasStdExtZknd, IsRV64] in {
147def : PatGprGpr<int_riscv_aes64ds, AES64DS>;
148def : PatGprGpr<int_riscv_aes64dsm, AES64DSM>;
149def : PatGpr<int_riscv_aes64im, AES64IM>;
150} // Predicates = [HasStdExtZknd, IsRV64]
151
152let Predicates = [HasStdExtZkndOrZkne, IsRV64] in {
153def : PatGprGpr<int_riscv_aes64ks2, AES64KS2>;
154def : Pat<(int_riscv_aes64ks1i GPR:$rs1, i32:$rnum),
155          (AES64KS1I GPR:$rs1, rnum:$rnum)>;
156} // Predicates = [HasStdExtZkndOrZkne, IsRV64]
157
158// Zkne
159let Predicates = [HasStdExtZkne, IsRV32] in {
160def : PatGprGprByteSelect<int_riscv_aes32esi, AES32ESI>;
161def : PatGprGprByteSelect<int_riscv_aes32esmi, AES32ESMI>;
162} // Predicates = [HasStdExtZkne, IsRV32]
163
164let Predicates = [HasStdExtZkne, IsRV64] in {
165def : PatGprGpr<int_riscv_aes64es, AES64ES>;
166def : PatGprGpr<int_riscv_aes64esm, AES64ESM>;
167} // Predicates = [HasStdExtZkne, IsRV64]
168
169// Zknh
170let Predicates = [HasStdExtZknh] in {
171def : PatGpr<int_riscv_sha256sig0, SHA256SIG0>;
172def : PatGpr<int_riscv_sha256sig1, SHA256SIG1>;
173def : PatGpr<int_riscv_sha256sum0, SHA256SUM0>;
174def : PatGpr<int_riscv_sha256sum1, SHA256SUM1>;
175} // Predicates = [HasStdExtZknh]
176
177let Predicates = [HasStdExtZknh, IsRV32] in {
178def : PatGprGpr<int_riscv_sha512sig0l, SHA512SIG0L>;
179def : PatGprGpr<int_riscv_sha512sig0h, SHA512SIG0H>;
180def : PatGprGpr<int_riscv_sha512sig1l, SHA512SIG1L>;
181def : PatGprGpr<int_riscv_sha512sig1h, SHA512SIG1H>;
182def : PatGprGpr<int_riscv_sha512sum0r, SHA512SUM0R>;
183def : PatGprGpr<int_riscv_sha512sum1r, SHA512SUM1R>;
184} // Predicates = [HasStdExtZknh, IsRV32]
185
186let Predicates = [HasStdExtZknh, IsRV64] in {
187def : PatGpr<int_riscv_sha512sig0, SHA512SIG0>;
188def : PatGpr<int_riscv_sha512sig1, SHA512SIG1>;
189def : PatGpr<int_riscv_sha512sum0, SHA512SUM0>;
190def : PatGpr<int_riscv_sha512sum1, SHA512SUM1>;
191} // Predicates = [HasStdExtZknh, IsRV64]
192
193// Zksed
194let Predicates = [HasStdExtZksed] in {
195def : PatGprGprByteSelect<int_riscv_sm4ks, SM4KS>;
196def : PatGprGprByteSelect<int_riscv_sm4ed, SM4ED>;
197} // Predicates = [HasStdExtZksed]
198
199// Zksh
200let Predicates = [HasStdExtZksh] in {
201def : PatGpr<int_riscv_sm3p0, SM3P0>;
202def : PatGpr<int_riscv_sm3p1, SM3P1>;
203} // Predicates = [HasStdExtZksh]
204