1 //===-- RISCVInstrFormatsC.td - RISCV 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>
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;
26 let Namespace = "RISCV";
28 dag OutOperandList = outs;
29 dag InOperandList = ins;
30 let AsmString = opcodestr # "\t" # argstr;
31 let Pattern = pattern;
33 let TSFlags{4-0} = format.Value;
36 class RVInst16CR<bits<4> funct4, bits<2> opcode, dag outs, dag ins,
37 string opcodestr, string argstr>
38 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCR> {
42 let Inst{15-12} = funct4;
45 let Inst{1-0} = opcode;
48 // The immediate value encoding differs for each instruction, so each subclass
49 // is responsible for setting the appropriate bits in the Inst field.
50 // The bits Inst{6-2} must be set for each instruction.
51 class RVInst16CI<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
52 string opcodestr, string argstr>
53 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCI> {
58 let Inst{15-13} = funct3;
59 let Inst{12} = imm{5};
61 let Inst{1-0} = opcode;
64 // The immediate value encoding differs for each instruction, so each subclass
65 // is responsible for setting the appropriate bits in the Inst field.
66 // The bits Inst{12-7} must be set for each instruction.
67 class RVInst16CSS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
68 string opcodestr, string argstr>
69 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCSS> {
74 let Inst{15-13} = funct3;
76 let Inst{1-0} = opcode;
79 class RVInst16CIW<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
80 string opcodestr, string argstr>
81 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCIW> {
85 let Inst{15-13} = funct3;
87 let Inst{1-0} = opcode;
90 // The immediate value encoding differs for each instruction, so each subclass
91 // is responsible for setting the appropriate bits in the Inst field.
92 // The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
93 class RVInst16CL<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
94 string opcodestr, string argstr>
95 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCL> {
99 let Inst{15-13} = funct3;
102 let Inst{1-0} = opcode;
105 // The immediate value encoding differs for each instruction, so each subclass
106 // is responsible for setting the appropriate bits in the Inst field.
107 // The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
108 class RVInst16CS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
109 string opcodestr, string argstr>
110 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCS> {
114 let Inst{15-13} = funct3;
117 let Inst{1-0} = opcode;
120 class RVInst16CA<bits<6> funct6, bits<2> funct2, bits<2> opcode, dag outs,
121 dag ins, string opcodestr, string argstr>
122 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCA> {
126 let Inst{15-10} = funct6;
128 let Inst{6-5} = funct2;
130 let Inst{1-0} = opcode;
133 class RVInst16CB<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
134 string opcodestr, string argstr>
135 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCB> {
139 let Inst{15-13} = funct3;
141 let Inst{1-0} = opcode;
144 class RVInst16CJ<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
145 string opcodestr, string argstr>
146 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCJ> {
149 let Inst{15-13} = funct3;
150 let Inst{12} = offset{10};
151 let Inst{11} = offset{3};
152 let Inst{10-9} = offset{8-7};
153 let Inst{8} = offset{9};
154 let Inst{7} = offset{5};
155 let Inst{6} = offset{6};
156 let Inst{5-3} = offset{2-0};
157 let Inst{2} = offset{4};
158 let Inst{1-0} = opcode;