1 //===- LoongArchInstrFormats.td - LoongArch Instr. 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 //===----------------------------------------------------------------------===//
10 // Describe LoongArch instructions format
12 // opcode - operation code.
13 // rd - destination register operand.
14 // r{j/k} - source register operand.
15 // immN - immediate data operand.
17 //===----------------------------------------------------------------------===//
19 class LAInst<dag outs, dag ins, string opcstr, string opnstr,
20 list<dag> pattern = []>
23 // SoftFail is a field the disassembler can use to provide a way for
24 // instructions to not match without killing the whole decode process. It is
25 // mainly used for ARM, but Tablegen expects this field to exist or it fails
26 // to build the decode table.
27 field bits<32> SoftFail = 0;
29 let Namespace = "LoongArch";
31 let OutOperandList = outs;
32 let InOperandList = ins;
33 let AsmString = opcstr # "\t" # opnstr;
34 let Pattern = pattern;
37 // Pseudo instructions
38 class Pseudo<dag outs, dag ins, list<dag> pattern = [], string opcstr = "",
40 : LAInst<outs, ins, opcstr, opnstr, pattern> {
42 let isCodeGenOnly = 1;
45 class deriveInsnMnemonic<string name> {
46 string ret = !tolower(!subst("@", "_", !subst("_", ".", !subst("__", "@", name))));
51 class Fmt2R<bits<32> op, dag outs, dag ins, string opnstr,
52 list<dag> pattern = []>
53 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
63 // <opcode | rk | rj | rd>
64 class Fmt3R<bits<32> op, dag outs, dag ins, string opnstr,
65 list<dag> pattern = []>
66 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
78 // <opcode | I2 | rk | rj | rd>
79 class Fmt3RI2<bits<32> op, dag outs, dag ins, string opnstr,
80 list<dag> pattern = []>
81 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
88 let Inst{16-15} = imm2;
95 // <opcode | I3 | rk | rj | rd>
96 class Fmt3RI3<bits<32> op, dag outs, dag ins, string opnstr,
97 list<dag> pattern = []>
98 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
105 let Inst{17-15} = imm3;
106 let Inst{14-10} = rk;
112 // <opcode | I5 | rj | rd>
113 class Fmt2RI5<bits<32> op, dag outs, dag ins, string opnstr,
114 list<dag> pattern = []>
115 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
121 let Inst{14-10} = imm5;
127 // <opcode | I6 | rj | rd>
128 class Fmt2RI6<bits<32> op, dag outs, dag ins, string opnstr,
129 list<dag> pattern = []>
130 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
136 let Inst{15-10} = imm6;
142 // <opcode | I8 | rj | rd>
143 class Fmt2RI8<bits<32> op, dag outs, dag ins, string opnstr,
144 list<dag> pattern = []>
145 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
151 let Inst{17-10} = imm8;
157 // <opcode | I12 | rj | rd>
158 class Fmt2RI12<bits<32> op, dag outs, dag ins, string opnstr,
159 list<dag> pattern = []>
160 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
166 let Inst{21-10} = imm12;
172 // <opcode | I14 | rj | rd>
173 class Fmt2RI14<bits<32> op, dag outs, dag ins, string opnstr,
174 list<dag> pattern = []>
175 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
181 let Inst{23-10} = imm14;
187 // <opcode | I16 | rj | rd>
188 class Fmt2RI16<bits<32> op, dag outs, dag ins, string opnstr,
189 list<dag> pattern = []>
190 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
196 let Inst{25-10} = imm16;
202 // <opcode | I20 | rd>
203 class Fmt1RI20<bits<32> op, dag outs, dag ins, string opnstr,
204 list<dag> pattern = []>
205 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
210 let Inst{24-5} = imm20;
215 // <opcode | I21[15:0] | rj | I21[20:16]>
216 class Fmt1RI21<bits<32> op, dag outs, dag ins, string opnstr,
217 list<dag> pattern = []>
218 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
223 let Inst{25-10} = imm21{15-0};
225 let Inst{4-0} = imm21{20-16};
230 class FmtI15<bits<32> op, dag outs, dag ins, string opnstr,
231 list<dag> pattern = []>
232 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
236 let Inst{14-0} = imm15;
240 // <opcode | I26[15:0] | I26[25:16]>
241 class FmtI26<bits<32> op, dag outs, dag ins, string opnstr,
242 list<dag> pattern = []>
243 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
247 let Inst{25-10} = imm26{15-0};
248 let Inst{9-0} = imm26{25-16};
252 // <opcode | msbw | lsbw | rj | rd>
253 class FmtBSTR_W<bits<32> op, dag outs, dag ins, string opnstr,
254 list<dag> pattern = []>
255 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
262 let Inst{20-16} = msbw;
263 let Inst{14-10} = lsbw;
269 // <opcode | msbd | lsbd | rj | rd>
270 class FmtBSTR_D<bits<32> op, dag outs, dag ins, string opnstr,
271 list<dag> pattern = []>
272 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
279 let Inst{21-16} = msbd;
280 let Inst{15-10} = lsbd;
286 // <opcode | rk | rj>
287 class FmtASRT<bits<32> op, dag outs, dag ins, string opnstr,
288 list<dag> pattern = []>
289 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
294 let Inst{14-10} = rk;
299 // < 0b0010101011 | I12 | rj | I5>
300 class FmtPRELD<dag outs, dag ins, string opnstr, list<dag> pattern = []>
301 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
306 let Inst{31-22} = 0b0010101011;
307 let Inst{21-10} = imm12;
309 let Inst{4-0} = imm5;
313 // < 0b00111000001011000 | rk | rj | I5>
314 class FmtPRELDX<dag outs, dag ins, string opnstr, list<dag> pattern = []>
315 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
320 let Inst{31-15} = 0b00111000001011000;
321 let Inst{14-10} = rk;
323 let Inst{4-0} = imm5;
327 // <opcode | csr_num | rd>
328 class FmtCSR<bits<32> op, dag outs, dag ins, string opnstr,
329 list<dag> pattern = []>
330 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
335 let Inst{23-10} = csr_num;
340 // <opcode | csr_num | rj | rd>
341 class FmtCSRXCHG<bits<32> op, dag outs, dag ins, string opnstr,
342 list<dag> pattern = []>
343 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
349 let Inst{23-10} = csr_num;
355 // <0b0000011000 | I12 | rj | I5>
356 class FmtCACOP<dag outs, dag ins, string opnstr, list<dag> pattern = []>
357 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
362 let Inst{31-22} = 0b0000011000;
363 let Inst{21-10} = imm12;
370 class FmtI32<bits<32> op, list<dag> pattern = []>
371 : LAInst<(outs), (ins), deriveInsnMnemonic<NAME>.ret, "", pattern> {
376 // <0b00000110010010011 | rk | rj | I5>
377 class FmtINVTLB<dag outs, dag ins, string opnstr, list<dag> pattern = []>
378 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
383 let Inst{31-15} = 0b00000110010010011;
384 let Inst{14-10} = rk;
390 // <0b00000110010001 | seq | rj | 00000>
391 class FmtLDPTE<dag outs, dag ins, string opnstr, list<dag> pattern = []>
392 : LAInst<outs, ins, deriveInsnMnemonic<NAME>.ret, opnstr, pattern> {
396 let Inst{31-18} = 0b00000110010001;
397 let Inst{17-10} = seq;
399 let Inst{4-0} = 0b00000;