blob: 117c86c0bd5169a8adc56b08a530beedb5b4dc5f [file] [log] [blame]
Alex Bradbury9f6aec42017-12-07 12:50:32 +00001//===-- RISCVInstrFormatsC.td - RISCV C Instruction Formats --*- tablegen -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the RISC-V C extension instruction formats.
11//
12//===----------------------------------------------------------------------===//
13
14class RVInst16<dag outs, dag ins, string opcodestr, string argstr,
15 list<dag> pattern, InstFormat format>
16 : Instruction {
17 field bits<16> Inst;
18 // SoftFail is a field the disassembler can use to provide a way for
19 // instructions to not match without killing the whole decode process. It is
20 // mainly used for ARM, but Tablegen expects this field to exist or it fails
21 // to build the decode table.
22 field bits<16> SoftFail = 0;
23 let Size = 2;
24
25 bits<2> Opcode = 0;
26
27 let Namespace = "RISCV";
28
29 dag OutOperandList = outs;
30 dag InOperandList = ins;
31 let AsmString = opcodestr # "\t" # argstr;
32 let Pattern = pattern;
33
34 let TSFlags{4-0} = format.Value;
35}
36
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.
40class RVInst16CI<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
41 string opcodestr, string argstr>
42 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCI> {
43 bits<10> imm;
44 bits<5> rd;
45 bits<5> rs1;
46
47 let Inst{15-13} = funct3;
48 let Inst{12} = imm{5};
49 let Inst{11-7} = rd;
50 let Inst{1-0} = opcode;
51}
52
53// The immediate value encoding differs for each instruction, so each subclass
54// is responsible for setting the appropriate bits in the Inst field.
55// The bits Inst{12-7} must be set for each instruction.
56class RVInst16CSS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
57 string opcodestr, string argstr>
58 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCSS> {
59 bits<10> imm;
60 bits<5> rs2;
61 bits<5> rs1;
62
63 let Inst{15-13} = funct3;
64 let Inst{6-2} = rs2;
65 let Inst{1-0} = opcode;
66}
67
68// The immediate value encoding differs for each instruction, so each subclass
69// is responsible for setting the appropriate bits in the Inst field.
70// The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
71class RVInst16CL<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
72 string opcodestr, string argstr>
73 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCL> {
74 bits<3> rd;
75 bits<3> rs1;
76
77 let Inst{15-13} = funct3;
78 let Inst{9-7} = rs1;
79 let Inst{4-2} = rd;
80 let Inst{1-0} = opcode;
81}
82
83// The immediate value encoding differs for each instruction, so each subclass
84// is responsible for setting the appropriate bits in the Inst field.
85// The bits Inst{12-10} and Inst{6-5} must be set for each instruction.
86class RVInst16CS<bits<3> funct3, bits<2> opcode, dag outs, dag ins,
87 string opcodestr, string argstr>
88 : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCS> {
89 bits<3> rs2;
90 bits<3> rs1;
91
92 let Inst{15-13} = funct3;
93 let Inst{9-7} = rs1;
94 let Inst{4-2} = rs2;
95 let Inst{1-0} = opcode;
96}