aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm16/lib/Target/RISCV/RISCVInstrInfoZk.td
blob: 0ebe3b173ea430800a987d283f240cc95227f9dd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//===- RISCVInstrInfoZk.td - RISC-V 'Zk' instructions ------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file describes the RISC-V instructions from the standard 'Zk',
// Scalar Cryptography Instructions extension, version 1.0.
//
//===----------------------------------------------------------------------===//

//===----------------------------------------------------------------------===//
// Operand and SDNode transformation definitions.
//===----------------------------------------------------------------------===//

def RnumArg : AsmOperandClass {
  let Name = "RnumArg";
  let RenderMethod = "addImmOperands";
  let DiagnosticType = "InvalidRnumArg";
}

def rnum : Operand<i32>, TImmLeaf<i32, [{return (Imm >= 0 && Imm <= 10);}]> {
  let ParserMatchClass = RnumArg;
  let EncoderMethod = "getImmOpValue";
  let DecoderMethod = "decodeUImmOperand<4>";
  let OperandType = "OPERAND_RVKRNUM";
  let OperandNamespace = "RISCVOp";
}

def byteselect : Operand<i8>, TImmLeaf<i8, [{return isUInt<2>(Imm);}]> {
  let ParserMatchClass = UImmAsmOperand<2>;
  let DecoderMethod = "decodeUImmOperand<2>";
  let OperandType = "OPERAND_UIMM2";
  let OperandNamespace = "RISCVOp";
}

//===----------------------------------------------------------------------===//
// Instruction class templates
//===----------------------------------------------------------------------===//
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
class RVKUnary<bits<12> imm12_in, bits<3> funct3, string opcodestr>
    : RVInstI<funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1),
              opcodestr, "$rd, $rs1">{
  let imm12 = imm12_in;
}

let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
class RVKByteSelect<bits<5> funct5, string opcodestr>
    : RVInstR<{0b00, funct5}, 0b000, OPC_OP, (outs GPR:$rd),
              (ins GPR:$rs1, GPR:$rs2, byteselect:$bs),
              opcodestr, "$rd, $rs1, $rs2, $bs">{
  bits<2> bs;
  let Inst{31-30} = bs;
}

let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
class RVKUnary_rnum<bits<7> funct7, bits<3> funct3, string opcodestr>
    : RVInstI<funct3, OPC_OP_IMM, (outs GPR:$rd), (ins GPR:$rs1, rnum:$rnum),
              opcodestr, "$rd, $rs1, $rnum">{
    bits<4> rnum;
    let Inst{31-25} = funct7;
    let Inst{24} = 1;
    let Inst{23-20} = rnum;
}

//===----------------------------------------------------------------------===//
// Instructions
//===----------------------------------------------------------------------===//
let Predicates = [HasStdExtZknd, IsRV32] in {
def AES32DSI  : RVKByteSelect<0b10101, "aes32dsi">;
def AES32DSMI : RVKByteSelect<0b10111, "aes32dsmi">;
} // Predicates = [HasStdExtZknd, IsRV32]

let Predicates = [HasStdExtZknd, IsRV64] in {
def AES64DS  : ALU_rr<0b0011101, 0b000, "aes64ds">;
def AES64DSM : ALU_rr<0b0011111, 0b000, "aes64dsm">;

def AES64IM  : RVKUnary<0b001100000000, 0b001, "aes64im">;
} // Predicates = [HasStdExtZknd, IsRV64]

let Predicates = [HasStdExtZkndOrZkne, IsRV64] in {
def AES64KS2  : ALU_rr<0b0111111, 0b000, "aes64ks2">;

def AES64KS1I : RVKUnary_rnum<0b0011000, 0b001, "aes64ks1i">;
} // Predicates = [HasStdExtZkndOrZkne, IsRV64]

let Predicates = [HasStdExtZkne, IsRV32] in {
def AES32ESI  : RVKByteSelect<0b10001, "aes32esi">;
def AES32ESMI : RVKByteSelect<0b10011, "aes32esmi">;
} // Predicates = [HasStdExtZkne, IsRV32]

let Predicates = [HasStdExtZkne, IsRV64] in {
def AES64ES   : ALU_rr<0b0011001, 0b000, "aes64es">;
def AES64ESM  : ALU_rr<0b0011011, 0b000, "aes64esm">;
} // Predicates = [HasStdExtZkne, IsRV64]

let Predicates = [HasStdExtZknh], IsSignExtendingOpW = 1 in {
def SHA256SIG0 : RVKUnary<0b000100000010, 0b001, "sha256sig0">;
def SHA256SIG1 : RVKUnary<0b000100000011, 0b001, "sha256sig1">;
def SHA256SUM0 : RVKUnary<0b000100000000, 0b001, "sha256sum0">;
def SHA256SUM1 : RVKUnary<0b000100000001, 0b001, "sha256sum1">;
} // Predicates = [HasStdExtZknh]

let Predicates = [HasStdExtZknh, IsRV32] in {
def SHA512SIG0H : ALU_rr<0b0101110, 0b000, "sha512sig0h">;
def SHA512SIG0L : ALU_rr<0b0101010, 0b000, "sha512sig0l">;
def SHA512SIG1H : ALU_rr<0b0101111, 0b000, "sha512sig1h">;
def SHA512SIG1L : ALU_rr<0b0101011, 0b000, "sha512sig1l">;
def SHA512SUM0R : ALU_rr<0b0101000, 0b000, "sha512sum0r">;
def SHA512SUM1R : ALU_rr<0b0101001, 0b000, "sha512sum1r">;
} // [HasStdExtZknh, IsRV32]

let Predicates = [HasStdExtZknh, IsRV64] in {
def SHA512SIG0 : RVKUnary<0b000100000110, 0b001, "sha512sig0">;
def SHA512SIG1 : RVKUnary<0b000100000111, 0b001, "sha512sig1">;
def SHA512SUM0 : RVKUnary<0b000100000100, 0b001, "sha512sum0">;
def SHA512SUM1 : RVKUnary<0b000100000101, 0b001, "sha512sum1">;
} // Predicates = [HasStdExtZknh, IsRV64]

let Predicates = [HasStdExtZksed] in {
def SM4ED : RVKByteSelect<0b11000, "sm4ed">;
def SM4KS : RVKByteSelect<0b11010, "sm4ks">;
} // Predicates = [HasStdExtZksed]

let Predicates = [HasStdExtZksh] in {
def SM3P0 : RVKUnary<0b000100001000, 0b001, "sm3p0">;
def SM3P1 : RVKUnary<0b000100001001, 0b001, "sm3p1">;
} // Predicates = [HasStdExtZksh]

//===----------------------------------------------------------------------===//
// Codegen patterns
//===----------------------------------------------------------------------===//

class PatGprGprByteSelect<SDPatternOperator OpNode, RVInst Inst>
    : Pat<(OpNode GPR:$rs1, GPR:$rs2, i8:$imm),
          (Inst GPR:$rs1, GPR:$rs2, byteselect:$imm)>;

// Zknd
let Predicates = [HasStdExtZknd, IsRV32] in {
def : PatGprGprByteSelect<int_riscv_aes32dsi, AES32DSI>;
def : PatGprGprByteSelect<int_riscv_aes32dsmi, AES32DSMI>;
} // Predicates = [HasStdExtZknd, IsRV32]

let Predicates = [HasStdExtZknd, IsRV64] in {
def : PatGprGpr<int_riscv_aes64ds, AES64DS>;
def : PatGprGpr<int_riscv_aes64dsm, AES64DSM>;
def : PatGpr<int_riscv_aes64im, AES64IM>;
} // Predicates = [HasStdExtZknd, IsRV64]

let Predicates = [HasStdExtZkndOrZkne, IsRV64] in {
def : PatGprGpr<int_riscv_aes64ks2, AES64KS2>;
def : Pat<(int_riscv_aes64ks1i GPR:$rs1, i32:$rnum),
          (AES64KS1I GPR:$rs1, rnum:$rnum)>;
} // Predicates = [HasStdExtZkndOrZkne, IsRV64]

// Zkne
let Predicates = [HasStdExtZkne, IsRV32] in {
def : PatGprGprByteSelect<int_riscv_aes32esi, AES32ESI>;
def : PatGprGprByteSelect<int_riscv_aes32esmi, AES32ESMI>;
} // Predicates = [HasStdExtZkne, IsRV32]

let Predicates = [HasStdExtZkne, IsRV64] in {
def : PatGprGpr<int_riscv_aes64es, AES64ES>;
def : PatGprGpr<int_riscv_aes64esm, AES64ESM>;
} // Predicates = [HasStdExtZkne, IsRV64]

// Zknh
let Predicates = [HasStdExtZknh] in {
def : PatGpr<int_riscv_sha256sig0, SHA256SIG0>;
def : PatGpr<int_riscv_sha256sig1, SHA256SIG1>;
def : PatGpr<int_riscv_sha256sum0, SHA256SUM0>;
def : PatGpr<int_riscv_sha256sum1, SHA256SUM1>;
} // Predicates = [HasStdExtZknh]

let Predicates = [HasStdExtZknh, IsRV32] in {
def : PatGprGpr<int_riscv_sha512sig0l, SHA512SIG0L>;
def : PatGprGpr<int_riscv_sha512sig0h, SHA512SIG0H>;
def : PatGprGpr<int_riscv_sha512sig1l, SHA512SIG1L>;
def : PatGprGpr<int_riscv_sha512sig1h, SHA512SIG1H>;
def : PatGprGpr<int_riscv_sha512sum0r, SHA512SUM0R>;
def : PatGprGpr<int_riscv_sha512sum1r, SHA512SUM1R>;
} // Predicates = [HasStdExtZknh, IsRV32]

let Predicates = [HasStdExtZknh, IsRV64] in {
def : PatGpr<int_riscv_sha512sig0, SHA512SIG0>;
def : PatGpr<int_riscv_sha512sig1, SHA512SIG1>;
def : PatGpr<int_riscv_sha512sum0, SHA512SUM0>;
def : PatGpr<int_riscv_sha512sum1, SHA512SUM1>;
} // Predicates = [HasStdExtZknh, IsRV64]

// Zksed
let Predicates = [HasStdExtZksed] in {
def : PatGprGprByteSelect<int_riscv_sm4ks, SM4KS>;
def : PatGprGprByteSelect<int_riscv_sm4ed, SM4ED>;
} // Predicates = [HasStdExtZksed]

// Zksh
let Predicates = [HasStdExtZksh] in {
def : PatGpr<int_riscv_sm3p0, SM3P0>;
def : PatGpr<int_riscv_sm3p1, SM3P1>;
} // Predicates = [HasStdExtZksh]