1*09467b48Spatrick//===-- RISCVInstrFormatsC.td - RISCV C Instruction Formats --*- tablegen -*-=// 2*09467b48Spatrick// 3*09467b48Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*09467b48Spatrick// See https://llvm.org/LICENSE.txt for license information. 5*09467b48Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*09467b48Spatrick// 7*09467b48Spatrick//===----------------------------------------------------------------------===// 8*09467b48Spatrick// 9*09467b48Spatrick// This file describes the RISC-V C extension instruction formats. 10*09467b48Spatrick// 11*09467b48Spatrick//===----------------------------------------------------------------------===// 12*09467b48Spatrick 13*09467b48Spatrickclass RVInst16<dag outs, dag ins, string opcodestr, string argstr, 14*09467b48Spatrick list<dag> pattern, InstFormat format> 15*09467b48Spatrick : Instruction { 16*09467b48Spatrick field bits<16> Inst; 17*09467b48Spatrick // SoftFail is a field the disassembler can use to provide a way for 18*09467b48Spatrick // instructions to not match without killing the whole decode process. It is 19*09467b48Spatrick // mainly used for ARM, but Tablegen expects this field to exist or it fails 20*09467b48Spatrick // to build the decode table. 21*09467b48Spatrick field bits<16> SoftFail = 0; 22*09467b48Spatrick let Size = 2; 23*09467b48Spatrick 24*09467b48Spatrick bits<2> Opcode = 0; 25*09467b48Spatrick 26*09467b48Spatrick let Namespace = "RISCV"; 27*09467b48Spatrick 28*09467b48Spatrick dag OutOperandList = outs; 29*09467b48Spatrick dag InOperandList = ins; 30*09467b48Spatrick let AsmString = opcodestr # "\t" # argstr; 31*09467b48Spatrick let Pattern = pattern; 32*09467b48Spatrick 33*09467b48Spatrick let TSFlags{4-0} = format.Value; 34*09467b48Spatrick} 35*09467b48Spatrick 36*09467b48Spatrickclass RVInst16CR<bits<4> funct4, bits<2> opcode, dag outs, dag ins, 37*09467b48Spatrick string opcodestr, string argstr> 38*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCR> { 39*09467b48Spatrick bits<5> rs1; 40*09467b48Spatrick bits<5> rs2; 41*09467b48Spatrick 42*09467b48Spatrick let Inst{15-12} = funct4; 43*09467b48Spatrick let Inst{11-7} = rs1; 44*09467b48Spatrick let Inst{6-2} = rs2; 45*09467b48Spatrick let Inst{1-0} = opcode; 46*09467b48Spatrick} 47*09467b48Spatrick 48*09467b48Spatrick// The immediate value encoding differs for each instruction, so each subclass 49*09467b48Spatrick// is responsible for setting the appropriate bits in the Inst field. 50*09467b48Spatrick// The bits Inst{6-2} must be set for each instruction. 51*09467b48Spatrickclass RVInst16CI<bits<3> funct3, bits<2> opcode, dag outs, dag ins, 52*09467b48Spatrick string opcodestr, string argstr> 53*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCI> { 54*09467b48Spatrick bits<10> imm; 55*09467b48Spatrick bits<5> rd; 56*09467b48Spatrick bits<5> rs1; 57*09467b48Spatrick 58*09467b48Spatrick let Inst{15-13} = funct3; 59*09467b48Spatrick let Inst{12} = imm{5}; 60*09467b48Spatrick let Inst{11-7} = rd; 61*09467b48Spatrick let Inst{1-0} = opcode; 62*09467b48Spatrick} 63*09467b48Spatrick 64*09467b48Spatrick// The immediate value encoding differs for each instruction, so each subclass 65*09467b48Spatrick// is responsible for setting the appropriate bits in the Inst field. 66*09467b48Spatrick// The bits Inst{12-7} must be set for each instruction. 67*09467b48Spatrickclass RVInst16CSS<bits<3> funct3, bits<2> opcode, dag outs, dag ins, 68*09467b48Spatrick string opcodestr, string argstr> 69*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCSS> { 70*09467b48Spatrick bits<10> imm; 71*09467b48Spatrick bits<5> rs2; 72*09467b48Spatrick bits<5> rs1; 73*09467b48Spatrick 74*09467b48Spatrick let Inst{15-13} = funct3; 75*09467b48Spatrick let Inst{6-2} = rs2; 76*09467b48Spatrick let Inst{1-0} = opcode; 77*09467b48Spatrick} 78*09467b48Spatrick 79*09467b48Spatrickclass RVInst16CIW<bits<3> funct3, bits<2> opcode, dag outs, dag ins, 80*09467b48Spatrick string opcodestr, string argstr> 81*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCIW> { 82*09467b48Spatrick bits<10> imm; 83*09467b48Spatrick bits<3> rd; 84*09467b48Spatrick 85*09467b48Spatrick let Inst{15-13} = funct3; 86*09467b48Spatrick let Inst{4-2} = rd; 87*09467b48Spatrick let Inst{1-0} = opcode; 88*09467b48Spatrick} 89*09467b48Spatrick 90*09467b48Spatrick// The immediate value encoding differs for each instruction, so each subclass 91*09467b48Spatrick// is responsible for setting the appropriate bits in the Inst field. 92*09467b48Spatrick// The bits Inst{12-10} and Inst{6-5} must be set for each instruction. 93*09467b48Spatrickclass RVInst16CL<bits<3> funct3, bits<2> opcode, dag outs, dag ins, 94*09467b48Spatrick string opcodestr, string argstr> 95*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCL> { 96*09467b48Spatrick bits<3> rd; 97*09467b48Spatrick bits<3> rs1; 98*09467b48Spatrick 99*09467b48Spatrick let Inst{15-13} = funct3; 100*09467b48Spatrick let Inst{9-7} = rs1; 101*09467b48Spatrick let Inst{4-2} = rd; 102*09467b48Spatrick let Inst{1-0} = opcode; 103*09467b48Spatrick} 104*09467b48Spatrick 105*09467b48Spatrick// The immediate value encoding differs for each instruction, so each subclass 106*09467b48Spatrick// is responsible for setting the appropriate bits in the Inst field. 107*09467b48Spatrick// The bits Inst{12-10} and Inst{6-5} must be set for each instruction. 108*09467b48Spatrickclass RVInst16CS<bits<3> funct3, bits<2> opcode, dag outs, dag ins, 109*09467b48Spatrick string opcodestr, string argstr> 110*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCS> { 111*09467b48Spatrick bits<3> rs2; 112*09467b48Spatrick bits<3> rs1; 113*09467b48Spatrick 114*09467b48Spatrick let Inst{15-13} = funct3; 115*09467b48Spatrick let Inst{9-7} = rs1; 116*09467b48Spatrick let Inst{4-2} = rs2; 117*09467b48Spatrick let Inst{1-0} = opcode; 118*09467b48Spatrick} 119*09467b48Spatrick 120*09467b48Spatrickclass RVInst16CA<bits<6> funct6, bits<2> funct2, bits<2> opcode, dag outs, 121*09467b48Spatrick dag ins, string opcodestr, string argstr> 122*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCA> { 123*09467b48Spatrick bits<3> rs2; 124*09467b48Spatrick bits<3> rs1; 125*09467b48Spatrick 126*09467b48Spatrick let Inst{15-10} = funct6; 127*09467b48Spatrick let Inst{9-7} = rs1; 128*09467b48Spatrick let Inst{6-5} = funct2; 129*09467b48Spatrick let Inst{4-2} = rs2; 130*09467b48Spatrick let Inst{1-0} = opcode; 131*09467b48Spatrick} 132*09467b48Spatrick 133*09467b48Spatrickclass RVInst16CB<bits<3> funct3, bits<2> opcode, dag outs, dag ins, 134*09467b48Spatrick string opcodestr, string argstr> 135*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCB> { 136*09467b48Spatrick bits<9> imm; 137*09467b48Spatrick bits<3> rs1; 138*09467b48Spatrick 139*09467b48Spatrick let Inst{15-13} = funct3; 140*09467b48Spatrick let Inst{9-7} = rs1; 141*09467b48Spatrick let Inst{1-0} = opcode; 142*09467b48Spatrick} 143*09467b48Spatrick 144*09467b48Spatrickclass RVInst16CJ<bits<3> funct3, bits<2> opcode, dag outs, dag ins, 145*09467b48Spatrick string opcodestr, string argstr> 146*09467b48Spatrick : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatCJ> { 147*09467b48Spatrick bits<11> offset; 148*09467b48Spatrick 149*09467b48Spatrick let Inst{15-13} = funct3; 150*09467b48Spatrick let Inst{12} = offset{10}; 151*09467b48Spatrick let Inst{11} = offset{3}; 152*09467b48Spatrick let Inst{10-9} = offset{8-7}; 153*09467b48Spatrick let Inst{8} = offset{9}; 154*09467b48Spatrick let Inst{7} = offset{5}; 155*09467b48Spatrick let Inst{6} = offset{6}; 156*09467b48Spatrick let Inst{5-3} = offset{2-0}; 157*09467b48Spatrick let Inst{2} = offset{4}; 158*09467b48Spatrick let Inst{1-0} = opcode; 159*09467b48Spatrick} 160