1 //===-- RISCVInstrFormatsC.td - RISC-V C Instruction Formats -*- tablegen -*-=//
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
7 //===----------------------------------------------------------------------===//
9 // This file describes the RISC-V C extension instruction formats.
11 //===----------------------------------------------------------------------===//
13 class RVInst16<dag outs, dag ins, string opcodestr, string argstr,
14 list<dag> pattern, InstFormat format>
15 : RVInstCommon<outs, ins, opcodestr, argstr, pattern, format> {
17 // SoftFail is a field the disassembler can use to provide a way for
18 // instructions to not match without killing the whole decode process. It is
19 // mainly used for ARM, but Tablegen expects this field to exist or it fails
20 // to build the decode table.
21 field bits<16> SoftFail = 0;
25 class RVInst16CR<bits<4> funct4, bits<2> opcode, dag outs, dag ins,
26 string opcodestr, string argstr>
27 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCR> {
31 let Inst{15-12} = funct4;
34 let Inst{1-0} = opcode;
37 // The immediate value encoding differs for each instruction, so each subclass
38 // is responsible for setting the appropriate bits in the Inst field.
39 // The bits Inst{6-2} must be set for each instruction.
40 class RVInst16CI<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
41 string opcodestr, string argstr>
42 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCI> {
46 let Inst{15-13} = funct3;
47 let Inst{12} = imm{5};
49 let Inst{1-0} = opcode;
52 // The immediate value encoding differs for each instruction, so each subclass
53 // is responsible for setting the appropriate bits in the Inst field.
54 // The bits Inst{12-7} must be set for each instruction.
55 class RVInst16CSS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
56 string opcodestr, string argstr>
57 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCSS> {
62 let Inst{15-13} = funct3;
64 let Inst{1-0} = opcode;
67 class RVInst16CIW<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
68 string opcodestr, string argstr>
69 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCIW> {
73 let Inst{15-13} = funct3;
75 let Inst{1-0} = opcode;
78 // The immediate value encoding differs for each instruction, so each subclass
79 // is responsible for setting the appropriate bits in the Inst field.
80 // The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
81 class RVInst16CL<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
82 string opcodestr, string argstr>
83 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCL> {
87 let Inst{15-13} = funct3;
90 let Inst{1-0} = opcode;
93 // The immediate value encoding differs for each instruction, so each subclass
94 // is responsible for setting the appropriate bits in the Inst field.
95 // The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
96 class RVInst16CS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
97 string opcodestr, string argstr>
98 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCS> {
102 let Inst{15-13} = funct3;
105 let Inst{1-0} = opcode;
108 class RVInst16CA<bits<6> funct6, bits<2> funct2, bits<2> opcode, dag outs,
109 dag ins, string opcodestr, string argstr>
110 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCA> {
114 let Inst{15-10} = funct6;
116 let Inst{6-5} = funct2;
118 let Inst{1-0} = opcode;
121 class RVInst16CB<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
122 string opcodestr, string argstr>
123 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCB> {
127 let Inst{15-13} = funct3;
129 let Inst{1-0} = opcode;
132 class RVInst16CJ<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
133 string opcodestr, string argstr>
134 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCJ> {
137 let Inst{15-13} = funct3;
138 let Inst{12} = offset{10};
139 let Inst{11} = offset{3};
140 let Inst{10-9} = offset{8-7};
141 let Inst{8} = offset{9};
142 let Inst{7} = offset{5};
143 let Inst{6} = offset{6};
144 let Inst{5-3} = offset{2-0};
145 let Inst{2} = offset{4};
146 let Inst{1-0} = opcode;
149 class RVInst16CU<bits<6> funct6, bits<5> funct5, bits<2> opcode, dag outs,
150 dag ins, string opcodestr, string argstr>
151 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCU>{
154 let Inst{15-10} = funct6;
156 let Inst{6-2} = funct5;
157 let Inst{1-0} = opcode;
160 // The immediate value encoding differs for each instruction, so each subclass
161 // is responsible for setting the appropriate bits in the Inst field.
162 // The bits Inst{6-5} must be set for each instruction.
163 class RVInst16CLB<bits<6> funct6, bits<2> opcode, dag outs, dag ins,
164 string opcodestr, string argstr>
165 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCLB> {
169 let Inst{15-10} = funct6;
172 let Inst{1-0} = opcode;
175 // The immediate value encoding differs for each instruction, so each subclass
176 // is responsible for setting the appropriate bits in the Inst field.
177 // The bits Inst{5} must be set for each instruction.
178 class RVInst16CLH<bits<6> funct6, bit funct1, bits<2> opcode, dag outs,
179 dag ins, string opcodestr, string argstr>
180 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCLH> {
184 let Inst{15-10} = funct6;
186 let Inst{6} = funct1;
188 let Inst{1-0} = opcode;
191 // The immediate value encoding differs for each instruction, so each subclass
192 // is responsible for setting the appropriate bits in the Inst field.
193 // The bits Inst{6-5} must be set for each instruction.
194 class RVInst16CSB<bits<6> funct6, bits<2> opcode, dag outs, dag ins,
195 string opcodestr, string argstr>
196 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCSB> {
200 let Inst{15-10} = funct6;
203 let Inst{1-0} = opcode;
206 // The immediate value encoding differs for each instruction, so each subclass
207 // is responsible for setting the appropriate bits in the Inst field.
208 // The bits Inst{5} must be set for each instruction.
209 class RVInst16CSH<bits<6> funct6, bit funct1, bits<2> opcode, dag outs,
210 dag ins, string opcodestr, string argstr>
211 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCSH> {
215 let Inst{15-10} = funct6;
217 let Inst{6} = funct1;
219 let Inst{1-0} = opcode;
222 //===----------------------------------------------------------------------===//
223 // Instruction classes for .insn directives
224 //===----------------------------------------------------------------------===//
226 class DirectiveInsnCR<dag outs, dag ins, string argstr>
227 : RVInst16<outs, ins, "", "", [], InstFormatCR> {
234 let Inst{15-12} = funct4;
237 let Inst{1-0} = opcode;
239 let AsmString = ".insn cr " # argstr;
242 class DirectiveInsnCI<dag outs, dag ins, string argstr>
243 : RVInst16<outs, ins, "", "", [], InstFormatCI> {
250 let Inst{15-13} = funct3;
251 let Inst{12} = imm6{5};
253 let Inst{6-2} = imm6{4-0};
254 let Inst{1-0} = opcode;
256 let AsmString = ".insn ci " # argstr;
259 class DirectiveInsnCIW<dag outs, dag ins, string argstr>
260 : RVInst16<outs, ins, "", "", [], InstFormatCIW> {
267 let Inst{15-13} = funct3;
268 let Inst{12-5} = imm8;
270 let Inst{1-0} = opcode;
272 let AsmString = ".insn ciw " # argstr;
275 class DirectiveInsnCSS<dag outs, dag ins, string argstr>
276 : RVInst16<outs, ins, "", "", [], InstFormatCSS> {
283 let Inst{15-13} = funct3;
284 let Inst{12-7} = imm6;
286 let Inst{1-0} = opcode;
288 let AsmString = ".insn css " # argstr;
291 class DirectiveInsnCL<dag outs, dag ins, string argstr>
292 : RVInst16<outs, ins, "", "", [], InstFormatCL> {
300 let Inst{15-13} = funct3;
301 let Inst{12-10} = imm5{4-2};
303 let Inst{6-5} = imm5{1-0};
305 let Inst{1-0} = opcode;
307 let AsmString = ".insn cl " # argstr;
310 class DirectiveInsnCS<dag outs, dag ins, string argstr>
311 : RVInst16<outs, ins, "", "", [], InstFormatCS> {
319 let Inst{15-13} = funct3;
320 let Inst{12-10} = imm5{4-2};
322 let Inst{6-5} = imm5{1-0};
324 let Inst{1-0} = opcode;
326 let AsmString = ".insn cs " # argstr;
329 class DirectiveInsnCA<dag outs, dag ins, string argstr>
330 : RVInst16<outs, ins, "", "", [], InstFormatCA> {
338 let Inst{15-10} = funct6;
340 let Inst{6-5} = funct2;
342 let Inst{1-0} = opcode;
344 let AsmString = ".insn ca " # argstr;
347 class DirectiveInsnCB<dag outs, dag ins, string argstr>
348 : RVInst16<outs, ins, "", "", [], InstFormatCB> {
355 let Inst{15-13} = funct3;
356 let Inst{12} = imm8{7};
357 let Inst{11-10} = imm8{3-2};
359 let Inst{6-5} = imm8{6-5};
360 let Inst{4-3} = imm8{1-0};
361 let Inst{2} = imm8{4};
362 let Inst{1-0} = opcode;
364 let AsmString = ".insn cb " # argstr;
367 class DirectiveInsnCJ<dag outs, dag ins, string argstr>
368 : RVInst16<outs, ins, "", "", [], InstFormatCJ> {
374 let Inst{15-13} = funct3;
375 let Inst{12} = imm11{10};
376 let Inst{11} = imm11{3};
377 let Inst{10-9} = imm11{8-7};
378 let Inst{8} = imm11{9};
379 let Inst{7} = imm11{5};
380 let Inst{6} = imm11{6};
381 let Inst{5-3} = imm11{2-0};
382 let Inst{2} = imm11{4};
383 let Inst{1-0} = opcode;
385 let AsmString = ".insn cj " # argstr;