xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVInstrFormats.td (revision 700637cbb5e582861067a11aaca4d053546871d2)
1//===-- RISCVInstrFormats.td - RISC-V Instruction Formats --*- tablegen -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8
9//===----------------------------------------------------------------------===//
10//
11//  These instruction format definitions are structured to match the
12//  description in the RISC-V User-Level ISA specification as closely as
13//  possible. For instance, the specification describes instructions with the
14//  MSB (31st bit) on the left and the LSB (0th bit) on the right. This is
15//  reflected in the order of parameters to each instruction class.
16//
17//  One area of divergence is in the description of immediates. The
18//  specification describes immediate encoding in terms of bit-slicing
19//  operations on the logical value represented. The immediate argument to
20//  these instruction formats instead represents the bit sequence that will be
21//  inserted into the instruction. e.g. although JAL's immediate is logically
22//  a 21-bit value (where the LSB is always zero), we describe it as an imm20
23//  to match how it is encoded.
24//
25//===----------------------------------------------------------------------===//
26
27// Format specifies the encoding used by the instruction. This is used by
28// RISCVMCCodeEmitter to determine which form of fixup to use. These
29// definitions must be kept in-sync with RISCVBaseInfo.h.
30class InstFormat<bits<5> val> {
31  bits<5> Value = val;
32}
33def InstFormatPseudo        : InstFormat<0>;
34def InstFormatR             : InstFormat<1>;
35def InstFormatR4            : InstFormat<2>;
36def InstFormatI             : InstFormat<3>;
37def InstFormatS             : InstFormat<4>;
38def InstFormatB             : InstFormat<5>;
39def InstFormatU             : InstFormat<6>;
40def InstFormatJ             : InstFormat<7>;
41def InstFormatCR            : InstFormat<8>;
42def InstFormatCI            : InstFormat<9>;
43def InstFormatCSS           : InstFormat<10>;
44def InstFormatCIW           : InstFormat<11>;
45def InstFormatCL            : InstFormat<12>;
46def InstFormatCS            : InstFormat<13>;
47def InstFormatCA            : InstFormat<14>;
48def InstFormatCB            : InstFormat<15>;
49def InstFormatCJ            : InstFormat<16>;
50def InstFormatCU            : InstFormat<17>;
51def InstFormatCLB           : InstFormat<18>;
52def InstFormatCLH           : InstFormat<19>;
53def InstFormatCSB           : InstFormat<20>;
54def InstFormatCSH           : InstFormat<21>;
55def InstFormatQC_EAI        : InstFormat<22>;
56def InstFormatQC_EI         : InstFormat<23>;
57def InstFormatQC_EB         : InstFormat<24>;
58def InstFormatQC_EJ         : InstFormat<25>;
59def InstFormatQC_ES         : InstFormat<26>;
60def InstFormatNDS_BRANCH_10 : InstFormat<27>;
61def InstFormatOther         : InstFormat<31>;
62
63
64class RISCVVConstraint<bits<3> val> {
65  bits<3> Value = val;
66}
67def NoConstraint  : RISCVVConstraint<0b000>;
68def VS2Constraint : RISCVVConstraint<0b001>;
69def VS1Constraint : RISCVVConstraint<0b010>;
70def VMConstraint  : RISCVVConstraint<0b100>;
71
72// Illegal instructions:
73//
74// * The destination vector register group for a masked vector instruction
75// cannot overlap the source mask register (v0), unless the destination vector
76// register is being written with a mask value (e.g., comparisons) or the
77// scalar result of a reduction.
78//
79// * Widening: The destination EEW is greater than the source EEW, the source
80// EMUL is at least 1. The destination vector register group cannot overlap
81// with the source vector register groups besides the highest-numbered part of
82// the destination register group.
83//
84// * Narrowing: The destination EEW is smaller than the source EEW. The
85// destination vector register group cannot overlap with the source vector
86// register groups besides the lowest-numbered part of the source register
87// group.
88//
89// * vmsbf.m/vmsif.m/vmsof.m: The destination register cannot overlap the
90// source register and, if masked, cannot overlap the mask register ('v0').
91//
92// * viota: The destination register cannot overlap the source register and,
93// if masked, cannot overlap the mask register ('v0').
94//
95// * v[f]slide[1]up: The destination vector register group for vslideup cannot
96// overlap the source vector register group.
97//
98// * vrgather: The destination vector register group cannot overlap with the
99// source vector register groups.
100//
101// * vcompress: The destination vector register group cannot overlap the
102// source vector register group or the source mask register
103def WidenVNoMask : RISCVVConstraint<!or(VS2Constraint.Value,
104                                        VS1Constraint.Value)>;
105def WidenV       : RISCVVConstraint<!or(VS2Constraint.Value,
106                                        VS1Constraint.Value,
107                                        VMConstraint.Value)>;
108def WidenW       : RISCVVConstraint<!or(VS1Constraint.Value,
109                                        VMConstraint.Value)>;
110def WidenCvt     : RISCVVConstraint<!or(VS2Constraint.Value,
111                                        VMConstraint.Value)>;
112def Iota         : RISCVVConstraint<!or(VS2Constraint.Value,
113                                        VMConstraint.Value)>;
114def SlideUp      : RISCVVConstraint<!or(VS2Constraint.Value,
115                                        VMConstraint.Value)>;
116def Vrgather     : RISCVVConstraint<!or(VS2Constraint.Value,
117                                        VS1Constraint.Value,
118                                        VMConstraint.Value)>;
119def Vcompress    : RISCVVConstraint<!or(VS2Constraint.Value,
120                                        VS1Constraint.Value)>;
121def Sha2Constraint : RISCVVConstraint<!or(VS2Constraint.Value,
122                                          VS1Constraint.Value)>;
123
124// The following opcode names match those given in Table 19.1 in the
125// RISC-V User-level ISA specification ("RISC-V base opcode map").
126class RISCVOpcode<string name, bits<7> val> {
127  string Name = name;
128  bits<7> Value = val;
129}
130def RISCVOpcodesList : GenericTable {
131  let FilterClass = "RISCVOpcode";
132  let Fields = [
133    "Name", "Value"
134  ];
135  let PrimaryKey = [ "Value" ];
136  let PrimaryKeyName = "lookupRISCVOpcodeByValue";
137}
138def lookupRISCVOpcodeByName : SearchIndex {
139  let Table = RISCVOpcodesList;
140  let Key = [ "Name" ];
141}
142def OPC_LOAD      : RISCVOpcode<"LOAD",      0b0000011>;
143def OPC_LOAD_FP   : RISCVOpcode<"LOAD_FP",   0b0000111>;
144def OPC_CUSTOM_0  : RISCVOpcode<"CUSTOM_0",  0b0001011>;
145def OPC_MISC_MEM  : RISCVOpcode<"MISC_MEM",  0b0001111>;
146def OPC_OP_IMM    : RISCVOpcode<"OP_IMM",    0b0010011>;
147def OPC_AUIPC     : RISCVOpcode<"AUIPC",     0b0010111>;
148def OPC_OP_IMM_32 : RISCVOpcode<"OP_IMM_32", 0b0011011>;
149def OPC_STORE     : RISCVOpcode<"STORE",     0b0100011>;
150def OPC_STORE_FP  : RISCVOpcode<"STORE_FP",  0b0100111>;
151def OPC_CUSTOM_1  : RISCVOpcode<"CUSTOM_1",  0b0101011>;
152def OPC_AMO       : RISCVOpcode<"AMO",       0b0101111>;
153def OPC_OP        : RISCVOpcode<"OP",        0b0110011>;
154def OPC_LUI       : RISCVOpcode<"LUI",       0b0110111>;
155def OPC_OP_32     : RISCVOpcode<"OP_32",     0b0111011>;
156def OPC_MADD      : RISCVOpcode<"MADD",      0b1000011>;
157def OPC_MSUB      : RISCVOpcode<"MSUB",      0b1000111>;
158def OPC_NMSUB     : RISCVOpcode<"NMSUB",     0b1001011>;
159def OPC_NMADD     : RISCVOpcode<"NMADD",     0b1001111>;
160def OPC_OP_FP     : RISCVOpcode<"OP_FP",     0b1010011>;
161def OPC_OP_V      : RISCVOpcode<"OP_V",      0b1010111>;
162def OPC_CUSTOM_2  : RISCVOpcode<"CUSTOM_2",  0b1011011>;
163def OPC_BRANCH    : RISCVOpcode<"BRANCH",    0b1100011>;
164def OPC_JALR      : RISCVOpcode<"JALR",      0b1100111>;
165def OPC_JAL       : RISCVOpcode<"JAL",       0b1101111>;
166def OPC_SYSTEM    : RISCVOpcode<"SYSTEM",    0b1110011>;
167def OPC_OP_VE     : RISCVOpcode<"OP_VE",     0b1110111>;
168def OPC_CUSTOM_3  : RISCVOpcode<"CUSTOM_3",  0b1111011>;
169
170class EltDeps<bit vl, bit mask> {
171  bit VL = vl;
172  bit Mask = mask;
173}
174
175def EltDepsNone      : EltDeps<vl=0, mask=0>;
176def EltDepsVL        : EltDeps<vl=1, mask=0>;
177def EltDepsVLMask    : EltDeps<vl=1, mask=1>;
178
179class EEW <bits<2> val> {
180  bits<2> Value = val;
181}
182def EEW1     : EEW<0>;
183def EEWSEWx1 : EEW<1>;
184def EEWSEWx2 : EEW<2>;
185def EEWSEWx4 : EEW<3>;
186
187class RVInstCommon<dag outs, dag ins, string opcodestr, string argstr,
188                   list<dag> pattern, InstFormat format> : Instruction {
189  let Namespace = "RISCV";
190
191  dag OutOperandList = outs;
192  dag InOperandList = ins;
193  let AsmString = opcodestr # !if(!empty(argstr), "", "\t" # argstr);
194  let Pattern = pattern;
195
196  let TSFlags{4-0} = format.Value;
197
198  // Defaults
199  RISCVVConstraint RVVConstraint = NoConstraint;
200  let TSFlags{7-5} = RVVConstraint.Value;
201
202  bits<3> VLMul = 0;
203  let TSFlags{10-8} = VLMul;
204
205  bit IsTiedPseudo = 0;
206  let TSFlags{11} = IsTiedPseudo;
207
208  bit HasSEWOp = 0;
209  let TSFlags{12} = HasSEWOp;
210
211  bit HasVLOp = 0;
212  let TSFlags{13} = HasVLOp;
213
214  bit HasVecPolicyOp = 0;
215  let TSFlags{14} = HasVecPolicyOp;
216
217  bit IsRVVWideningReduction = 0;
218  let TSFlags{15} = IsRVVWideningReduction;
219
220  bit UsesMaskPolicy = 0;
221  let TSFlags{16} = UsesMaskPolicy;
222
223  // Indicates that the result can be considered sign extended from bit 31. Some
224  // instructions with this flag aren't W instructions, but are either sign
225  // extended from a smaller size, always outputs a small integer, or put zeros
226  // in bits 63:31. Used by the SExtWRemoval pass.
227  bit IsSignExtendingOpW = 0;
228  let TSFlags{17} = IsSignExtendingOpW;
229
230  bit HasRoundModeOp = 0;
231  let TSFlags{18} =  HasRoundModeOp;
232
233  // This is only valid when HasRoundModeOp is set to 1. HasRoundModeOp is set
234  // to 1 for vector fixed-point or floating-point intrinsics. This bit is
235  // processed under pass 'RISCVInsertReadWriteCSR' pass to distinguish between
236  // fixed-point / floating-point instructions and emit appropriate read/write
237  // to the correct CSR.
238  bit UsesVXRM = 0;
239  let TSFlags{19} =  UsesVXRM;
240
241  // Indicates whether these instructions can partially overlap between source
242  // registers and destination registers according to the vector spec.
243  // 0 -> not a vector pseudo
244  // 1 -> default value for vector pseudos. not widening or narrowing.
245  // 2 -> narrowing case
246  // 3 -> widening case
247  bits<2> TargetOverlapConstraintType = 0;
248  let TSFlags{21-20} = TargetOverlapConstraintType;
249
250  // Most vector instructions are elementwise, but some may depend on the value
251  // of VL (e.g. vslide1down.vx), and others may depend on the VL and mask
252  // (e.g. vredsum.vs, viota.m). Mark these instructions so that peepholes avoid
253  // changing their VL and/or mask.
254  EltDeps ElementsDependOn = EltDepsNone;
255  let TSFlags{22} = ElementsDependOn.VL;
256  let TSFlags{23} = ElementsDependOn.Mask;
257
258  // Indicates the EEW of a vector instruction's destination operand.
259  EEW DestEEW = EEWSEWx1;
260  let TSFlags{25-24} = DestEEW.Value;
261}
262
263class RVInst<dag outs, dag ins, string opcodestr, string argstr,
264             list<dag> pattern, InstFormat format>
265    : RVInstCommon<outs, ins, opcodestr, argstr, pattern, format> {
266  field bits<32> Inst;
267  // SoftFail is a field the disassembler can use to provide a way for
268  // instructions to not match without killing the whole decode process. It is
269  // mainly used for ARM, but Tablegen expects this field to exist or it fails
270  // to build the decode table.
271  field bits<32> SoftFail = 0;
272  let Size = 4;
273}
274
275class RVInst48<dag outs, dag ins, string opcodestr, string argstr,
276               list<dag> pattern, InstFormat format>
277    : RVInstCommon<outs, ins, opcodestr, argstr, pattern, format> {
278  field bits<48> Inst;
279  field bits<48> SoftFail = 0;
280  let Size = 6;
281}
282
283class RVInst64<dag outs, dag ins, string opcodestr, string argstr,
284               list<dag> pattern, InstFormat format>
285    : RVInstCommon<outs, ins, opcodestr, argstr, pattern, format> {
286  field bits<64> Inst;
287  field bits<64> SoftFail = 0;
288  let Size = 8;
289}
290
291// Pseudo instructions
292class Pseudo<dag outs, dag ins, list<dag> pattern, string opcodestr = "", string argstr = "">
293    : RVInstCommon<outs, ins, opcodestr, argstr, pattern, InstFormatPseudo> {
294  let isPseudo = 1;
295  let isCodeGenOnly = 1;
296  let Size = 4;
297}
298
299class PseudoQuietFCMP<DAGOperand Ty>
300    : Pseudo<(outs GPR:$rd), (ins Ty:$rs1, Ty:$rs2), []> {
301  let hasSideEffects = 1;
302  let mayLoad = 0;
303  let mayStore = 0;
304}
305
306// Pseudo load instructions.
307class PseudoLoad<string opcodestr, DAGOperand rdty = GPR>
308    : Pseudo<(outs rdty:$rd), (ins bare_symbol:$addr), [], opcodestr, "$rd, $addr"> {
309  let hasSideEffects = 0;
310  let mayLoad = 1;
311  let mayStore = 0;
312  let isCodeGenOnly = 0;
313  let isAsmParserOnly = 1;
314}
315
316class PseudoFloatLoad<string opcodestr, RegisterClass rdty>
317    : Pseudo<(outs GPR:$tmp, rdty:$rd), (ins bare_symbol:$addr), [], opcodestr, "$rd, $addr, $tmp"> {
318  let hasSideEffects = 0;
319  let mayLoad = 1;
320  let mayStore = 0;
321  let isCodeGenOnly = 0;
322  let isAsmParserOnly = 1;
323}
324
325// Pseudo store instructions.
326class PseudoStore<string opcodestr, DAGOperand rsty = GPR>
327    : Pseudo<(outs GPR:$tmp), (ins rsty:$rs, bare_symbol:$addr), [], opcodestr, "$rs, $addr, $tmp"> {
328  let hasSideEffects = 0;
329  let mayLoad = 0;
330  let mayStore = 1;
331  let isCodeGenOnly = 0;
332  let isAsmParserOnly = 1;
333}
334
335// Instruction formats are listed in the order they appear in the RISC-V
336// instruction set manual (R, R4, I, S, B, U, J).
337
338// Common base class for R format instructions. Bits {31-25} should be set by
339// the subclasses.
340class RVInstRBase<bits<3> funct3, RISCVOpcode opcode, dag outs,
341                  dag ins, string opcodestr, string argstr>
342    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatR> {
343  bits<5> rs2;
344  bits<5> rs1;
345  bits<5> rd;
346
347  let Inst{24-20} = rs2;
348  let Inst{19-15} = rs1;
349  let Inst{14-12} = funct3;
350  let Inst{11-7} = rd;
351  let Inst{6-0} = opcode.Value;
352}
353
354class RVInstR<bits<7> funct7, bits<3> funct3, RISCVOpcode opcode, dag outs,
355              dag ins, string opcodestr, string argstr>
356    : RVInstRBase<funct3, opcode, outs, ins, opcodestr, argstr> {
357  let Inst{31-25} = funct7;
358}
359
360class RVInstRAtomic<bits<5> funct5, bit aq, bit rl, bits<3> funct3,
361                    RISCVOpcode opcode, dag outs, dag ins, string opcodestr,
362                    string argstr>
363    : RVInstRBase<funct3, opcode, outs, ins, opcodestr, argstr> {
364  let Inst{31-27} = funct5;
365  let Inst{26} = aq;
366  let Inst{25} = rl;
367}
368
369class RVInstRFrm<bits<7> funct7, RISCVOpcode opcode, dag outs, dag ins,
370                 string opcodestr, string argstr>
371    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatR> {
372  bits<5> rs2;
373  bits<5> rs1;
374  bits<3> frm;
375  bits<5> rd;
376
377  let Inst{31-25} = funct7;
378  let Inst{24-20} = rs2;
379  let Inst{19-15} = rs1;
380  let Inst{14-12} = frm;
381  let Inst{11-7} = rd;
382  let Inst{6-0} = opcode.Value;
383}
384
385class RVInstR4<bits<2> funct2, bits<3> funct3, RISCVOpcode opcode, dag outs,
386               dag ins, string opcodestr, string argstr>
387    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatR4> {
388  bits<5> rs3;
389  bits<5> rs2;
390  bits<5> rs1;
391  bits<5> rd;
392
393  let Inst{31-27} = rs3;
394  let Inst{26-25} = funct2;
395  let Inst{24-20} = rs2;
396  let Inst{19-15} = rs1;
397  let Inst{14-12} = funct3;
398  let Inst{11-7} = rd;
399  let Inst{6-0} = opcode.Value;
400}
401
402class RVInstR4Frm<bits<2> funct2, RISCVOpcode opcode, dag outs, dag ins,
403                  string opcodestr, string argstr>
404    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatR4> {
405  bits<5> rs3;
406  bits<5> rs2;
407  bits<5> rs1;
408  bits<3> frm;
409  bits<5> rd;
410
411  let Inst{31-27} = rs3;
412  let Inst{26-25} = funct2;
413  let Inst{24-20} = rs2;
414  let Inst{19-15} = rs1;
415  let Inst{14-12} = frm;
416  let Inst{11-7} = rd;
417  let Inst{6-0} = opcode.Value;
418}
419
420// Common base class for I format instructions. Bits {31-20} should be set by
421// the subclasses.
422class RVInstIBase<bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
423                  string opcodestr, string argstr>
424    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> {
425  bits<5> rs1;
426  bits<5> rd;
427
428  let Inst{19-15} = rs1;
429  let Inst{14-12} = funct3;
430  let Inst{11-7} = rd;
431  let Inst{6-0} = opcode.Value;
432}
433
434class RVInstI<bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
435              string opcodestr, string argstr>
436    : RVInstIBase<funct3, opcode, outs, ins, opcodestr, argstr> {
437  bits<12> imm12;
438
439  let Inst{31-20} = imm12;
440}
441
442class RVInstIShift<bits<5> imm11_7, bits<3> funct3, RISCVOpcode opcode,
443                   dag outs, dag ins, string opcodestr, string argstr>
444    : RVInstIBase<funct3, opcode, outs, ins, opcodestr, argstr> {
445  bits<6> shamt;
446
447  let Inst{31-27} = imm11_7;
448  let Inst{26} = 0;
449  let Inst{25-20} = shamt;
450}
451
452class RVInstIShiftW<bits<7> imm11_5, bits<3> funct3, RISCVOpcode opcode,
453                    dag outs, dag ins, string opcodestr, string argstr>
454    : RVInstIBase<funct3, opcode, outs, ins, opcodestr, argstr> {
455  bits<5> shamt;
456
457  let Inst{31-25} = imm11_5;
458  let Inst{24-20} = shamt;
459}
460
461class RVInstIUnary<bits<12> imm12, bits<3> funct3, RISCVOpcode opcode,
462                   dag outs, dag ins, string opcodestr, string argstr>
463    : RVInstIBase<funct3, opcode, outs, ins, opcodestr, argstr> {
464  let Inst{31-20} = imm12;
465}
466
467class RVInstS<bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
468              string opcodestr, string argstr>
469    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatS> {
470  bits<12> imm12;
471  bits<5> rs2;
472  bits<5> rs1;
473
474  let Inst{31-25} = imm12{11-5};
475  let Inst{24-20} = rs2;
476  let Inst{19-15} = rs1;
477  let Inst{14-12} = funct3;
478  let Inst{11-7} = imm12{4-0};
479  let Inst{6-0} = opcode.Value;
480}
481
482class RVInstB<bits<3> funct3, RISCVOpcode opcode, dag outs, dag ins,
483              string opcodestr, string argstr>
484    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatB> {
485  bits<12> imm12;
486  bits<5> rs2;
487  bits<5> rs1;
488
489  let Inst{31} = imm12{11};
490  let Inst{30-25} = imm12{9-4};
491  let Inst{24-20} = rs2;
492  let Inst{19-15} = rs1;
493  let Inst{14-12} = funct3;
494  let Inst{11-8} = imm12{3-0};
495  let Inst{7} = imm12{10};
496  let Inst{6-0} = opcode.Value;
497}
498
499class RVInstU<RISCVOpcode opcode, dag outs, dag ins, string opcodestr,
500              string argstr>
501    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatU> {
502  bits<20> imm20;
503  bits<5> rd;
504
505  let Inst{31-12} = imm20;
506  let Inst{11-7} = rd;
507  let Inst{6-0} = opcode.Value;
508}
509
510class RVInstJ<RISCVOpcode opcode, dag outs, dag ins, string opcodestr,
511              string argstr>
512    : RVInst<outs, ins, opcodestr, argstr, [], InstFormatJ> {
513  bits<20> imm20;
514  bits<5> rd;
515
516  let Inst{31} = imm20{19};
517  let Inst{30-21} = imm20{9-0};
518  let Inst{20} = imm20{10};
519  let Inst{19-12} = imm20{18-11};
520  let Inst{11-7} = rd;
521  let Inst{6-0} = opcode.Value;
522}
523
524//===----------------------------------------------------------------------===//
525// Instruction classes for .insn directives
526//===----------------------------------------------------------------------===//
527
528class DirectiveInsnR<dag outs, dag ins, string argstr>
529  : RVInst<outs, ins, "", "", [], InstFormatR> {
530  bits<7> opcode;
531  bits<7> funct7;
532  bits<3> funct3;
533
534  bits<5> rs2;
535  bits<5> rs1;
536  bits<5> rd;
537
538  let Inst{31-25} = funct7;
539  let Inst{24-20} = rs2;
540  let Inst{19-15} = rs1;
541  let Inst{14-12} = funct3;
542  let Inst{11-7} = rd;
543  let Inst{6-0} = opcode;
544
545  let AsmString = ".insn r " # argstr;
546}
547
548class DirectiveInsnR4<dag outs, dag ins, string argstr>
549  : RVInst<outs, ins, "", "", [], InstFormatR4> {
550  bits<7> opcode;
551  bits<2> funct2;
552  bits<3> funct3;
553
554  bits<5> rs3;
555  bits<5> rs2;
556  bits<5> rs1;
557  bits<5> rd;
558
559  let Inst{31-27} = rs3;
560  let Inst{26-25} = funct2;
561  let Inst{24-20} = rs2;
562  let Inst{19-15} = rs1;
563  let Inst{14-12} = funct3;
564  let Inst{11-7} = rd;
565  let Inst{6-0} = opcode;
566
567  let AsmString = ".insn r4 " # argstr;
568}
569
570class DirectiveInsnI<dag outs, dag ins, string argstr>
571  : RVInst<outs, ins, "", "", [], InstFormatI> {
572  bits<7> opcode;
573  bits<3> funct3;
574
575  bits<12> imm12;
576  bits<5> rs1;
577  bits<5> rd;
578
579  let Inst{31-20} = imm12;
580  let Inst{19-15} = rs1;
581  let Inst{14-12} = funct3;
582  let Inst{11-7} = rd;
583  let Inst{6-0} = opcode;
584
585  let AsmString = ".insn i " # argstr;
586}
587
588class DirectiveInsnS<dag outs, dag ins, string argstr>
589  : RVInst<outs, ins, "", "", [], InstFormatS> {
590  bits<7> opcode;
591  bits<3> funct3;
592
593  bits<12> imm12;
594  bits<5> rs2;
595  bits<5> rs1;
596
597  let Inst{31-25} = imm12{11-5};
598  let Inst{24-20} = rs2;
599  let Inst{19-15} = rs1;
600  let Inst{14-12} = funct3;
601  let Inst{11-7} = imm12{4-0};
602  let Inst{6-0} = opcode;
603
604  let AsmString = ".insn s " # argstr;
605}
606
607class DirectiveInsnB<dag outs, dag ins, string argstr>
608  : RVInst<outs, ins, "", "", [], InstFormatB> {
609  bits<7> opcode;
610  bits<3> funct3;
611
612  bits<12> imm12;
613  bits<5> rs2;
614  bits<5> rs1;
615
616  let Inst{31} = imm12{11};
617  let Inst{30-25} = imm12{9-4};
618  let Inst{24-20} = rs2;
619  let Inst{19-15} = rs1;
620  let Inst{14-12} = funct3;
621  let Inst{11-8} = imm12{3-0};
622  let Inst{7} = imm12{10};
623  let Inst{6-0} = opcode;
624
625  let AsmString = ".insn b " # argstr;
626}
627
628class DirectiveInsnU<dag outs, dag ins, string argstr>
629  : RVInst<outs, ins, "", "", [], InstFormatU> {
630  bits<7> opcode;
631
632  bits<20> imm20;
633  bits<5> rd;
634
635  let Inst{31-12} = imm20;
636  let Inst{11-7} = rd;
637  let Inst{6-0} = opcode;
638
639  let AsmString = ".insn u " # argstr;
640}
641
642class DirectiveInsnJ<dag outs, dag ins, string argstr>
643  : RVInst<outs, ins, "", "", [], InstFormatJ> {
644  bits<7> opcode;
645
646  bits<20> imm20;
647  bits<5> rd;
648
649  let Inst{31-12} = imm20;
650  let Inst{11-7} = rd;
651  let Inst{6-0} = opcode;
652
653  let AsmString = ".insn j " # argstr;
654}
655