1*0fca6ea1SDimitry Andric//===-- RISCVInstrInfoXwch.td ------------------------------*- tablegen -*-===// 2*0fca6ea1SDimitry Andric// 3*0fca6ea1SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0fca6ea1SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 5*0fca6ea1SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0fca6ea1SDimitry Andric// 7*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 8*0fca6ea1SDimitry Andric// 9*0fca6ea1SDimitry Andric// This file describes the vendor extension(s) defined by WCH. 10*0fca6ea1SDimitry Andric// 11*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 12*0fca6ea1SDimitry Andric 13*0fca6ea1SDimitry Andricclass QKStackInst<bits<2> funct2, dag outs, dag ins, 14*0fca6ea1SDimitry Andric string opcodestr, string argstr> 15*0fca6ea1SDimitry Andric : RVInst16<outs, ins, opcodestr, argstr, [], InstFormatOther> { 16*0fca6ea1SDimitry Andric bits<3> rd_rs2; 17*0fca6ea1SDimitry Andric 18*0fca6ea1SDimitry Andric let Inst{15-11} = 0b10000; 19*0fca6ea1SDimitry Andric let Inst{6-5} = funct2; 20*0fca6ea1SDimitry Andric let Inst{4-2} = rd_rs2; 21*0fca6ea1SDimitry Andric let Inst{1-0} = 0b00; 22*0fca6ea1SDimitry Andric} 23*0fca6ea1SDimitry Andric 24*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 25*0fca6ea1SDimitry Andric// Operand definitions. 26*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 27*0fca6ea1SDimitry Andric 28*0fca6ea1SDimitry Andricdef uimm4_with_predicate : RISCVUImmLeafOp<4> { 29*0fca6ea1SDimitry Andric let MCOperandPredicate = [{ 30*0fca6ea1SDimitry Andric int64_t Imm; 31*0fca6ea1SDimitry Andric if (!MCOp.evaluateAsConstantImm(Imm)) 32*0fca6ea1SDimitry Andric return false; 33*0fca6ea1SDimitry Andric return isUInt<4>(Imm); 34*0fca6ea1SDimitry Andric }]; 35*0fca6ea1SDimitry Andric} 36*0fca6ea1SDimitry Andric 37*0fca6ea1SDimitry Andricdef uimm5_with_predicate : RISCVUImmLeafOp<5> { 38*0fca6ea1SDimitry Andric let MCOperandPredicate = [{ 39*0fca6ea1SDimitry Andric int64_t Imm; 40*0fca6ea1SDimitry Andric if (!MCOp.evaluateAsConstantImm(Imm)) 41*0fca6ea1SDimitry Andric return false; 42*0fca6ea1SDimitry Andric return isUInt<5>(Imm); 43*0fca6ea1SDimitry Andric }]; 44*0fca6ea1SDimitry Andric} 45*0fca6ea1SDimitry Andric 46*0fca6ea1SDimitry Andric// A 5-bit unsigned immediate where the least significant bit is zero. 47*0fca6ea1SDimitry Andricdef uimm5_lsb0 : RISCVOp, 48*0fca6ea1SDimitry Andric ImmLeaf<XLenVT, [{return isShiftedUInt<4, 1>(Imm);}]> { 49*0fca6ea1SDimitry Andric let ParserMatchClass = UImmAsmOperand<5, "Lsb0">; 50*0fca6ea1SDimitry Andric let EncoderMethod = "getImmOpValue"; 51*0fca6ea1SDimitry Andric let DecoderMethod = "decodeUImmOperand<5>"; 52*0fca6ea1SDimitry Andric let OperandType = "OPERAND_UIMM5_LSB0"; 53*0fca6ea1SDimitry Andric let MCOperandPredicate = [{ 54*0fca6ea1SDimitry Andric int64_t Imm; 55*0fca6ea1SDimitry Andric if (!MCOp.evaluateAsConstantImm(Imm)) 56*0fca6ea1SDimitry Andric return false; 57*0fca6ea1SDimitry Andric return isShiftedUInt<4, 1>(Imm); 58*0fca6ea1SDimitry Andric }]; 59*0fca6ea1SDimitry Andric} 60*0fca6ea1SDimitry Andric 61*0fca6ea1SDimitry Andric// A 6-bit unsigned immediate where the least significant bit is zero. 62*0fca6ea1SDimitry Andricdef uimm6_lsb0 : RISCVOp, 63*0fca6ea1SDimitry Andric ImmLeaf<XLenVT, [{return isShiftedUInt<5, 1>(Imm);}]> { 64*0fca6ea1SDimitry Andric let ParserMatchClass = UImmAsmOperand<6, "Lsb0">; 65*0fca6ea1SDimitry Andric let EncoderMethod = "getImmOpValue"; 66*0fca6ea1SDimitry Andric let DecoderMethod = "decodeUImmOperand<6>"; 67*0fca6ea1SDimitry Andric let OperandType = "OPERAND_UIMM6_LSB0"; 68*0fca6ea1SDimitry Andric let MCOperandPredicate = [{ 69*0fca6ea1SDimitry Andric int64_t Imm; 70*0fca6ea1SDimitry Andric if (!MCOp.evaluateAsConstantImm(Imm)) 71*0fca6ea1SDimitry Andric return false; 72*0fca6ea1SDimitry Andric return isShiftedUInt<5, 1>(Imm); 73*0fca6ea1SDimitry Andric }]; 74*0fca6ea1SDimitry Andric} 75*0fca6ea1SDimitry Andric 76*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 77*0fca6ea1SDimitry Andric// Instructions 78*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 79*0fca6ea1SDimitry Andriclet Predicates = [HasVendorXwchc], DecoderNamespace = "Xwchc" in { 80*0fca6ea1SDimitry Andric 81*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 1, mayStore = 0 in 82*0fca6ea1SDimitry Andricdef QK_C_LBU : RVInst16CL<0b001, 0b00, (outs GPRC:$rd), 83*0fca6ea1SDimitry Andric (ins GPRCMem:$rs1, uimm5_with_predicate:$imm), 84*0fca6ea1SDimitry Andric "qk.c.lbu", "$rd, ${imm}(${rs1})">, 85*0fca6ea1SDimitry Andric Sched<[WriteLDB, ReadMemBase]> { 86*0fca6ea1SDimitry Andric bits<5> imm; 87*0fca6ea1SDimitry Andric let Inst{12} = imm{0}; 88*0fca6ea1SDimitry Andric let Inst{11-10} = imm{4-3}; 89*0fca6ea1SDimitry Andric let Inst{6-5} = imm{2-1}; 90*0fca6ea1SDimitry Andric} 91*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 1 in 92*0fca6ea1SDimitry Andricdef QK_C_SB : RVInst16CS<0b101, 0b00, (outs), 93*0fca6ea1SDimitry Andric (ins GPRC:$rs2, GPRCMem:$rs1, 94*0fca6ea1SDimitry Andric uimm5_with_predicate:$imm), 95*0fca6ea1SDimitry Andric "qk.c.sb", "$rs2, ${imm}(${rs1})">, 96*0fca6ea1SDimitry Andric Sched<[WriteSTB, ReadStoreData, ReadMemBase]> { 97*0fca6ea1SDimitry Andric bits<5> imm; 98*0fca6ea1SDimitry Andric let Inst{12} = imm{0}; 99*0fca6ea1SDimitry Andric let Inst{11-10} = imm{4-3}; 100*0fca6ea1SDimitry Andric let Inst{6-5} = imm{2-1}; 101*0fca6ea1SDimitry Andric} 102*0fca6ea1SDimitry Andric 103*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 1, mayStore = 0 in 104*0fca6ea1SDimitry Andricdef QK_C_LHU : RVInst16CL<0b001, 0b10, (outs GPRC:$rd), 105*0fca6ea1SDimitry Andric (ins GPRCMem:$rs1, uimm6_lsb0:$imm), 106*0fca6ea1SDimitry Andric "qk.c.lhu", "$rd, ${imm}(${rs1})">, 107*0fca6ea1SDimitry Andric Sched<[WriteLDH, ReadMemBase]> { 108*0fca6ea1SDimitry Andric bits<6> imm; 109*0fca6ea1SDimitry Andric let Inst{12-10} = imm{5-3}; 110*0fca6ea1SDimitry Andric let Inst{6-5} = imm{2-1}; 111*0fca6ea1SDimitry Andric} 112*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 1 in 113*0fca6ea1SDimitry Andricdef QK_C_SH : RVInst16CS<0b101, 0b10, (outs), 114*0fca6ea1SDimitry Andric (ins GPRC:$rs2, GPRCMem:$rs1, uimm6_lsb0:$imm), 115*0fca6ea1SDimitry Andric "qk.c.sh", "$rs2, ${imm}(${rs1})">, 116*0fca6ea1SDimitry Andric Sched<[WriteSTH, ReadStoreData, ReadMemBase]> { 117*0fca6ea1SDimitry Andric bits<6> imm; 118*0fca6ea1SDimitry Andric let Inst{12-10} = imm{5-3}; 119*0fca6ea1SDimitry Andric let Inst{6-5} = imm{2-1}; 120*0fca6ea1SDimitry Andric} 121*0fca6ea1SDimitry Andric 122*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 1, mayStore = 0 in 123*0fca6ea1SDimitry Andricdef QK_C_LBUSP : QKStackInst<0b00, (outs GPRC:$rd_rs2), 124*0fca6ea1SDimitry Andric (ins SPMem:$rs1, uimm4_with_predicate:$imm), 125*0fca6ea1SDimitry Andric "qk.c.lbusp", "$rd_rs2, ${imm}(${rs1})">, 126*0fca6ea1SDimitry Andric Sched<[WriteLDB, ReadMemBase]> { 127*0fca6ea1SDimitry Andric bits<4> imm; 128*0fca6ea1SDimitry Andric let Inst{10-7} = imm; 129*0fca6ea1SDimitry Andric} 130*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 1 in 131*0fca6ea1SDimitry Andricdef QK_C_SBSP : QKStackInst<0b10, (outs), 132*0fca6ea1SDimitry Andric (ins GPRC:$rd_rs2, SPMem:$rs1, 133*0fca6ea1SDimitry Andric uimm4_with_predicate:$imm), 134*0fca6ea1SDimitry Andric "qk.c.sbsp", "$rd_rs2, ${imm}(${rs1})">, 135*0fca6ea1SDimitry Andric Sched<[WriteSTB, ReadStoreData, ReadMemBase]> { 136*0fca6ea1SDimitry Andric bits<4> imm; 137*0fca6ea1SDimitry Andric let Inst{10-7} = imm; 138*0fca6ea1SDimitry Andric} 139*0fca6ea1SDimitry Andric 140*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 1, mayStore = 0 in 141*0fca6ea1SDimitry Andricdef QK_C_LHUSP : QKStackInst<0b01, (outs GPRC:$rd_rs2), 142*0fca6ea1SDimitry Andric (ins SPMem:$rs1, uimm5_lsb0:$imm), 143*0fca6ea1SDimitry Andric "qk.c.lhusp", "$rd_rs2, ${imm}(${rs1})">, 144*0fca6ea1SDimitry Andric Sched<[WriteLDH, ReadMemBase]> { 145*0fca6ea1SDimitry Andric bits<5> imm; 146*0fca6ea1SDimitry Andric let Inst{10-8} = imm{3-1}; 147*0fca6ea1SDimitry Andric let Inst{7} = imm{4}; 148*0fca6ea1SDimitry Andric} 149*0fca6ea1SDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 1 in 150*0fca6ea1SDimitry Andricdef QK_C_SHSP : QKStackInst<0b11, (outs), 151*0fca6ea1SDimitry Andric (ins GPRC:$rd_rs2, SPMem:$rs1, uimm5_lsb0:$imm), 152*0fca6ea1SDimitry Andric "qk.c.shsp", "$rd_rs2, ${imm}(${rs1})">, 153*0fca6ea1SDimitry Andric Sched<[WriteSTH, ReadStoreData, ReadMemBase]> { 154*0fca6ea1SDimitry Andric bits<5> imm; 155*0fca6ea1SDimitry Andric let Inst{10-8} = imm{3-1}; 156*0fca6ea1SDimitry Andric let Inst{7} = imm{4}; 157*0fca6ea1SDimitry Andric} 158*0fca6ea1SDimitry Andric 159*0fca6ea1SDimitry Andric} // Predicates = [HasVendorXwchc], DecoderNamespace = "Xwchc" 160*0fca6ea1SDimitry Andric 161*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 162*0fca6ea1SDimitry Andric// Assembler Pseudo Instructions 163*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 164*0fca6ea1SDimitry Andric 165*0fca6ea1SDimitry Andriclet EmitPriority = 0 in { 166*0fca6ea1SDimitry Andriclet Predicates = [HasVendorXwchc] in { 167*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.lbu $rd, (${rs1})", (QK_C_LBU GPRC:$rd, GPRCMem:$rs1, 0)>; 168*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.sb $rs2, (${rs1})", (QK_C_SB GPRC:$rs2, GPRCMem:$rs1, 0)>; 169*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.lhu $rd, (${rs1})", (QK_C_LHU GPRC:$rd, GPRCMem:$rs1, 0)>; 170*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.sh $rs2, (${rs1})", (QK_C_SH GPRC:$rs2, GPRCMem:$rs1, 0)>; 171*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.lbusp $rd, (${rs1})", (QK_C_LBUSP GPRC:$rd, SPMem:$rs1, 0)>; 172*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.sbsp $rs2, (${rs1})", (QK_C_SBSP GPRC:$rs2, SPMem:$rs1, 0)>; 173*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.lhusp $rd, (${rs1})", (QK_C_LHUSP GPRC:$rd, SPMem:$rs1, 0)>; 174*0fca6ea1SDimitry Andricdef : InstAlias<"qk.c.shsp $rs2, (${rs1})", (QK_C_SHSP GPRC:$rs2, SPMem:$rs1, 0)>; 175*0fca6ea1SDimitry Andric} 176*0fca6ea1SDimitry Andric} 177*0fca6ea1SDimitry Andric 178*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===/ 179*0fca6ea1SDimitry Andric// Compress Instruction tablegen backend. 180*0fca6ea1SDimitry Andric//===----------------------------------------------------------------------===// 181*0fca6ea1SDimitry Andric 182*0fca6ea1SDimitry Andriclet Predicates = [HasVendorXwchc] in { 183*0fca6ea1SDimitry Andricdef : CompressPat<(LBU GPRC:$rd, GPRCMem:$rs1, uimm5_with_predicate:$imm), 184*0fca6ea1SDimitry Andric (QK_C_LBU GPRC:$rd, GPRCMem:$rs1, uimm5_with_predicate:$imm)>; 185*0fca6ea1SDimitry Andricdef : CompressPat<(SB GPRC:$rs2, GPRCMem:$rs1, uimm5_with_predicate:$imm), 186*0fca6ea1SDimitry Andric (QK_C_SB GPRC:$rs2, GPRCMem:$rs1, uimm5_with_predicate:$imm)>; 187*0fca6ea1SDimitry Andricdef : CompressPat<(LHU GPRC:$rd, GPRCMem:$rs1, uimm6_lsb0:$imm), 188*0fca6ea1SDimitry Andric (QK_C_LHU GPRC:$rd, GPRCMem:$rs1, uimm6_lsb0:$imm)>; 189*0fca6ea1SDimitry Andricdef : CompressPat<(SH GPRC:$rs2, GPRCMem:$rs1, uimm6_lsb0:$imm), 190*0fca6ea1SDimitry Andric (QK_C_SH GPRC:$rs2, GPRCMem:$rs1, uimm6_lsb0:$imm)>; 191*0fca6ea1SDimitry Andricdef : CompressPat<(LBU GPRC:$rd, SPMem:$rs1, uimm4_with_predicate:$imm), 192*0fca6ea1SDimitry Andric (QK_C_LBUSP GPRC:$rd, SPMem:$rs1, uimm4_with_predicate:$imm)>; 193*0fca6ea1SDimitry Andricdef : CompressPat<(SB GPRC:$rs2, SPMem:$rs1, uimm4_with_predicate:$imm), 194*0fca6ea1SDimitry Andric (QK_C_SBSP GPRC:$rs2, SPMem:$rs1, uimm4_with_predicate:$imm)>; 195*0fca6ea1SDimitry Andricdef : CompressPat<(LHU GPRC:$rd, SPMem:$rs1, uimm5_lsb0:$imm), 196*0fca6ea1SDimitry Andric (QK_C_LHUSP GPRC:$rd, SPMem:$rs1, uimm5_lsb0:$imm)>; 197*0fca6ea1SDimitry Andricdef : CompressPat<(SH GPRC:$rs2, SPMem:$rs1, uimm5_lsb0:$imm), 198*0fca6ea1SDimitry Andric (QK_C_SHSP GPRC:$rs2, SPMem:$rs1, uimm5_lsb0:$imm)>; 199*0fca6ea1SDimitry Andric} 200