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