blob: 3fab7122f6f1a51a8c2089d2e8aead9eb3f0a18e [file] [log] [blame]
Alex Bradbury24d9b132016-11-01 23:40:28 +00001//===-- RISCVInstrFormats.td - RISCV 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//===----------------------------------------------------------------------===//
11//
12// These instruction format definitions are structured to match the
13// description in the RISC-V User-Level ISA specification as closely as
14// possible. For instance, the specification describes instructions with the
15// MSB (31st bit) on the left and the LSB (0th bit) on the right. This is
16// reflected in the order of parameters to each instruction class.
17//
18// One area of divergence is in the description of immediates. The
19// specification describes immediate encoding in terms of bit-slicing
20// operations on the logical value represented. The immediate argument to
21// these instruction formats instead represents the bit sequence that will be
22// inserted into the instruction. e.g. although JAL's immediate is logically
23// a 21-bit value (where the LSB is always zero), we describe it as an imm20
24// to match how it is encoded.
25//
26//===----------------------------------------------------------------------===//
27
28class RISCVInst<dag outs, dag ins, string asmstr, list<dag> pattern>
29 : Instruction {
30 field bits<32> Inst;
31 let Size = 4;
32
33 bits<7> Opcode = 0;
34
35 let Inst{6-0} = Opcode;
36
37 let Namespace = "RISCV";
38
39 dag OutOperandList = outs;
40 dag InOperandList = ins;
41 let AsmString = asmstr;
42 let Pattern = pattern;
43}
44
45// Pseudo instructions
46class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
Alex Bradbury6be16fb2017-02-14 05:17:23 +000047 : RISCVInst<outs, ins, "", pattern> {
Alex Bradbury24d9b132016-11-01 23:40:28 +000048 let isPseudo = 1;
Alex Bradbury6be16fb2017-02-14 05:17:23 +000049 let isCodeGenOnly = 1;
Alex Bradbury24d9b132016-11-01 23:40:28 +000050}
51
52class FR<bits<7> funct7, bits<3> funct3, bits<7> opcode, dag outs, dag ins,
53 string asmstr, list<dag> pattern> : RISCVInst<outs, ins, asmstr, pattern>
54{
55 bits<5> rs2;
56 bits<5> rs1;
57 bits<5> rd;
58
59 let Inst{31-25} = funct7;
60 let Inst{24-20} = rs2;
61 let Inst{19-15} = rs1;
62 let Inst{14-12} = funct3;
63 let Inst{11-7} = rd;
64 let Opcode = opcode;
65}
66
67class FI<bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
68 : RISCVInst<outs, ins, asmstr, pattern>
69{
70 bits<12> imm12;
71 bits<5> rs1;
72 bits<5> rd;
73
74 let Inst{31-20} = imm12;
75 let Inst{19-15} = rs1;
76 let Inst{14-12} = funct3;
77 let Inst{11-7} = rd;
78 let Opcode = opcode;
79}
80
81class FI32Shift<bit arithshift, bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
82 : RISCVInst<outs, ins, asmstr, pattern>
83{
84 bits<5> shamt;
85 bits<5> rs1;
86 bits<5> rd;
87
88 let Inst{31} = 0;
89 let Inst{30} = arithshift;
90 let Inst{29-25} = 0;
91 let Inst{24-20} = shamt;
92 let Inst{19-15} = rs1;
93 let Inst{14-12} = funct3;
94 let Inst{11-7} = rd;
95 let Opcode = opcode;
96}
97
98class FS<bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
99 : RISCVInst<outs, ins, asmstr, pattern>
100{
101 bits<12> imm12;
102 bits<5> rs2;
103 bits<5> rs1;
104
105 let Inst{31-25} = imm12{11-5};
106 let Inst{24-20} = rs2;
107 let Inst{19-15} = rs1;
108 let Inst{14-12} = funct3;
109 let Inst{11-7} = imm12{4-0};
110 let Opcode = opcode;
111}
112
113class FSB<bits<3> funct3, bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
114 : RISCVInst<outs, ins, asmstr, pattern>
115{
116 bits<12> imm12;
117 bits<5> rs2;
118 bits<5> rs1;
119
120 let Inst{31} = imm12{11};
121 let Inst{30-25} = imm12{9-4};
122 let Inst{24-20} = rs2;
123 let Inst{19-15} = rs1;
124 let Inst{14-12} = funct3;
125 let Inst{11-8} = imm12{3-0};
126 let Inst{7} = imm12{10};
127 let Opcode = opcode;
128}
129
130class FU<bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
131 : RISCVInst<outs, ins, asmstr, pattern>
132{
133 bits<20> imm20;
134 bits<5> rd;
135
136 let Inst{31-12} = imm20;
137 let Inst{11-7} = rd;
138 let Opcode = opcode;
139}
140
141class FUJ<bits<7> opcode, dag outs, dag ins, string asmstr, list<dag> pattern>
142 : RISCVInst<outs, ins, asmstr, pattern>
143{
144 bits<20> imm20;
145 bits<5> rd;
146
147 let Inst{31} = imm20{19};
148 let Inst{30-21} = imm20{9-0};
149 let Inst{20} = imm20{10};
150 let Inst{19-12} = imm20{18-11};
151 let Inst{11-7} = rd;
152 let Opcode = opcode;
153}