1*700637cbSDimitry Andric//===-- RISCVInstrInfoXMips.td -----------------------------*- tablegen -*-===// 2*700637cbSDimitry Andric// 3*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 5*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*700637cbSDimitry Andric// 7*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 8*700637cbSDimitry Andric// 9*700637cbSDimitry Andric// This file describes the vendor extensions defined by MIPS. 10*700637cbSDimitry Andric// 11*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 12*700637cbSDimitry Andric 13*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 14*700637cbSDimitry Andric// Operand definitions. 15*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 16*700637cbSDimitry Andric 17*700637cbSDimitry Andric// A 7-bit unsigned immediate where the least significant three bits are zero. 18*700637cbSDimitry Andricdef uimm7_lsb000 : RISCVOp, 19*700637cbSDimitry Andric ImmLeaf<XLenVT, [{return isShiftedUInt<4, 3>(Imm);}]> { 20*700637cbSDimitry Andric let ParserMatchClass = UImmAsmOperand<7, "Lsb000">; 21*700637cbSDimitry Andric let EncoderMethod = "getImmOpValue"; 22*700637cbSDimitry Andric let DecoderMethod = "decodeUImmOperand<7>"; 23*700637cbSDimitry Andric let OperandType = "OPERAND_UIMM7_LSB000"; 24*700637cbSDimitry Andric let MCOperandPredicate = [{ 25*700637cbSDimitry Andric int64_t Imm; 26*700637cbSDimitry Andric if (!MCOp.evaluateAsConstantImm(Imm)) 27*700637cbSDimitry Andric return false; 28*700637cbSDimitry Andric return isShiftedUInt<4, 3>(Imm); 29*700637cbSDimitry Andric }]; 30*700637cbSDimitry Andric} 31*700637cbSDimitry Andric 32*700637cbSDimitry Andric// A 9-bit unsigned offset 33*700637cbSDimitry Andricdef uimm9 : RISCVUImmOp<9>; 34*700637cbSDimitry Andric 35*700637cbSDimitry Andric// Custom prefetch ADDR selector 36*700637cbSDimitry Andricdef AddrRegImm9 : ComplexPattern<iPTR, 2, "SelectAddrRegImm9">; 37*700637cbSDimitry Andric 38*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 39*700637cbSDimitry Andric// MIPS custom instruction formats 40*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 41*700637cbSDimitry Andric 42*700637cbSDimitry Andric// Load double pair format. 43*700637cbSDimitry Andricclass LDPFormat<dag outs, dag ins, string opcodestr, string argstr> 44*700637cbSDimitry Andric : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> { 45*700637cbSDimitry Andric bits<7> imm7; 46*700637cbSDimitry Andric bits<5> rs1; 47*700637cbSDimitry Andric bits<5> rd1; 48*700637cbSDimitry Andric bits<5> rd2; 49*700637cbSDimitry Andric 50*700637cbSDimitry Andric let Inst{31-27} = rd2; 51*700637cbSDimitry Andric let Inst{26-23} = imm7{6-3}; 52*700637cbSDimitry Andric let Inst{22-20} = 0b000; 53*700637cbSDimitry Andric let Inst{19-15} = rs1; 54*700637cbSDimitry Andric let Inst{14-12} = 0b100; 55*700637cbSDimitry Andric let Inst{11-7} = rd1; 56*700637cbSDimitry Andric let Inst{6-0} = OPC_CUSTOM_0.Value; 57*700637cbSDimitry Andric} 58*700637cbSDimitry Andric 59*700637cbSDimitry Andric// Load word pair format. 60*700637cbSDimitry Andricclass LWPFormat<dag outs, dag ins, string opcodestr, string argstr> 61*700637cbSDimitry Andric : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> { 62*700637cbSDimitry Andric bits<7> imm7; 63*700637cbSDimitry Andric bits<5> rs1; 64*700637cbSDimitry Andric bits<5> rd1; 65*700637cbSDimitry Andric bits<5> rd2; 66*700637cbSDimitry Andric 67*700637cbSDimitry Andric let Inst{31-27} = rd2; 68*700637cbSDimitry Andric let Inst{26-22} = imm7{6-2}; 69*700637cbSDimitry Andric let Inst{21-20} = 0b01; 70*700637cbSDimitry Andric let Inst{19-15} = rs1; 71*700637cbSDimitry Andric let Inst{14-12} = 0b100; 72*700637cbSDimitry Andric let Inst{11-7} = rd1; 73*700637cbSDimitry Andric let Inst{6-0} = OPC_CUSTOM_0.Value; 74*700637cbSDimitry Andric} 75*700637cbSDimitry Andric 76*700637cbSDimitry Andric// Store double pair format. 77*700637cbSDimitry Andricclass SDPFormat<dag outs, dag ins, string opcodestr, string argstr> 78*700637cbSDimitry Andric : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> { 79*700637cbSDimitry Andric bits<7> imm7; 80*700637cbSDimitry Andric bits<5> rs3; 81*700637cbSDimitry Andric bits<5> rs2; 82*700637cbSDimitry Andric bits<5> rs1; 83*700637cbSDimitry Andric 84*700637cbSDimitry Andric let Inst{31-27} = rs3; 85*700637cbSDimitry Andric let Inst{26-25} = imm7{6-5}; 86*700637cbSDimitry Andric let Inst{24-20} = rs2; 87*700637cbSDimitry Andric let Inst{19-15} = rs1; 88*700637cbSDimitry Andric let Inst{14-12} = 0b101; 89*700637cbSDimitry Andric let Inst{11-10} = imm7{4-3}; 90*700637cbSDimitry Andric let Inst{9-7} = 0b000; 91*700637cbSDimitry Andric let Inst{6-0} = OPC_CUSTOM_0.Value; 92*700637cbSDimitry Andric} 93*700637cbSDimitry Andric 94*700637cbSDimitry Andric// Store word pair format. 95*700637cbSDimitry Andricclass SWPFormat<dag outs, dag ins, string opcodestr, string argstr> 96*700637cbSDimitry Andric : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> { 97*700637cbSDimitry Andric bits<7> imm7; 98*700637cbSDimitry Andric bits<5> rs3; 99*700637cbSDimitry Andric bits<5> rs2; 100*700637cbSDimitry Andric bits<5> rs1; 101*700637cbSDimitry Andric 102*700637cbSDimitry Andric let Inst{31-27} = rs3; 103*700637cbSDimitry Andric let Inst{26-25} = imm7{6-5}; 104*700637cbSDimitry Andric let Inst{24-20} = rs2; 105*700637cbSDimitry Andric let Inst{19-15} = rs1; 106*700637cbSDimitry Andric let Inst{14-12} = 0b101; 107*700637cbSDimitry Andric let Inst{11-9} = imm7{4-2}; 108*700637cbSDimitry Andric let Inst{8-7} = 0b01; 109*700637cbSDimitry Andric let Inst{6-0} = OPC_CUSTOM_0.Value; 110*700637cbSDimitry Andric} 111*700637cbSDimitry Andric 112*700637cbSDimitry Andric// Prefetch format. 113*700637cbSDimitry Andriclet hasSideEffects = 0, mayLoad = 1, mayStore = 1 in 114*700637cbSDimitry Andricclass Mips_prefetch_ri<dag outs, dag ins, string opcodestr, string argstr> 115*700637cbSDimitry Andric : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> { 116*700637cbSDimitry Andric bits<9> imm9; 117*700637cbSDimitry Andric bits<5> rs1; 118*700637cbSDimitry Andric bits<5> hint; 119*700637cbSDimitry Andric 120*700637cbSDimitry Andric let Inst{31-29} = 0b000; 121*700637cbSDimitry Andric let Inst{28-20} = imm9; 122*700637cbSDimitry Andric let Inst{19-15} = rs1; 123*700637cbSDimitry Andric let Inst{14-12} = 0b000; 124*700637cbSDimitry Andric let Inst{11-7} = hint; 125*700637cbSDimitry Andric let Inst{6-0} = OPC_CUSTOM_0.Value; 126*700637cbSDimitry Andric} 127*700637cbSDimitry Andric 128*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 129*700637cbSDimitry Andric// MIPS extensions 130*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 131*700637cbSDimitry Andriclet Predicates = [HasVendorXMIPSCBOP] ,DecoderNamespace = "Xmipscbop" in { 132*700637cbSDimitry Andric def MIPS_PREFETCH : Mips_prefetch_ri<(outs), (ins GPR:$rs1, uimm9:$imm9, uimm5:$hint), 133*700637cbSDimitry Andric "mips.pref", "$hint, ${imm9}(${rs1})">, 134*700637cbSDimitry Andric Sched<[]>; 135*700637cbSDimitry Andric} 136*700637cbSDimitry Andric 137*700637cbSDimitry Andriclet Predicates = [HasVendorXMIPSCBOP] in { 138*700637cbSDimitry Andric // Prefetch Data Write. 139*700637cbSDimitry Andric def : Pat<(prefetch (AddrRegImm9 (XLenVT GPR:$rs1), uimm9:$imm9), 140*700637cbSDimitry Andric (i32 1), timm, (i32 1)), 141*700637cbSDimitry Andric (MIPS_PREFETCH GPR:$rs1, uimm9:$imm9, 9)>; 142*700637cbSDimitry Andric // Prefetch Data Read. 143*700637cbSDimitry Andric def : Pat<(prefetch (AddrRegImm9 (XLenVT GPR:$rs1), uimm9:$imm9), 144*700637cbSDimitry Andric (i32 0), timm, (i32 1)), 145*700637cbSDimitry Andric (MIPS_PREFETCH GPR:$rs1, uimm9:$imm9, 8)>; 146*700637cbSDimitry Andric} 147*700637cbSDimitry Andric 148*700637cbSDimitry Andriclet Predicates = [HasVendorXMIPSCMov], hasSideEffects = 0, mayLoad = 0, mayStore = 0, 149*700637cbSDimitry Andric DecoderNamespace = "Xmipscmov" in { 150*700637cbSDimitry Andricdef MIPS_CCMOV : RVInstR4<0b11, 0b011, OPC_CUSTOM_0, (outs GPR:$rd), 151*700637cbSDimitry Andric (ins GPR:$rs1, GPR:$rs2, GPR:$rs3), 152*700637cbSDimitry Andric "mips.ccmov", "$rd, $rs2, $rs1, $rs3">, 153*700637cbSDimitry Andric Sched<[]>; 154*700637cbSDimitry Andric} 155*700637cbSDimitry Andric 156*700637cbSDimitry Andriclet Predicates = [UseCCMovInsn] in { 157*700637cbSDimitry Andricdef : Pat<(select (riscv_setne (XLenVT GPR:$rs2)), 158*700637cbSDimitry Andric (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)), 159*700637cbSDimitry Andric (MIPS_CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>; 160*700637cbSDimitry Andricdef : Pat<(select (riscv_seteq (XLenVT GPR:$rs2)), 161*700637cbSDimitry Andric (XLenVT GPR:$rs3), (XLenVT GPR:$rs1)), 162*700637cbSDimitry Andric (MIPS_CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>; 163*700637cbSDimitry Andric 164*700637cbSDimitry Andricdef : Pat<(select (XLenVT GPR:$rs2), (XLenVT GPR:$rs1), (XLenVT GPR:$rs3)), 165*700637cbSDimitry Andric (MIPS_CCMOV GPR:$rs1, GPR:$rs2, GPR:$rs3)>; 166*700637cbSDimitry Andric} 167*700637cbSDimitry Andric 168*700637cbSDimitry Andriclet Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0, 169*700637cbSDimitry Andric DecoderNamespace = "Xmipslsp" in { 170*700637cbSDimitry Andriclet mayLoad = 1, mayStore = 0 in { 171*700637cbSDimitry Andricdef MIPS_LWP : LWPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, uimm7_lsb00:$imm7), 172*700637cbSDimitry Andric "mips.lwp", "$rd1, $rd2, ${imm7}(${rs1})">, 173*700637cbSDimitry Andric Sched<[WriteLDW, WriteLDW, ReadMemBase]>; 174*700637cbSDimitry Andricdef MIPS_LDP : LDPFormat<(outs GPR:$rd1, GPR:$rd2), (ins GPR:$rs1, uimm7_lsb000:$imm7), 175*700637cbSDimitry Andric "mips.ldp", "$rd1, $rd2, ${imm7}(${rs1})">, 176*700637cbSDimitry Andric Sched<[WriteLDD, WriteLDD, ReadMemBase]>; 177*700637cbSDimitry Andric} // mayLoad = 1, mayStore = 0 178*700637cbSDimitry Andric 179*700637cbSDimitry Andriclet mayLoad = 0, mayStore = 1 in { 180*700637cbSDimitry Andricdef MIPS_SWP : SWPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, uimm7_lsb00:$imm7), 181*700637cbSDimitry Andric "mips.swp", "$rs2, $rs3, ${imm7}(${rs1})">, 182*700637cbSDimitry Andric Sched<[WriteSTW, ReadStoreData, ReadStoreData, ReadMemBase]>; 183*700637cbSDimitry Andricdef MIPS_SDP : SDPFormat<(outs), (ins GPR:$rs2, GPR:$rs3, GPR:$rs1, uimm7_lsb000:$imm7), 184*700637cbSDimitry Andric "mips.sdp", "$rs2, $rs3, ${imm7}(${rs1})">, 185*700637cbSDimitry Andric Sched<[WriteSTD, ReadStoreData, ReadStoreData, ReadMemBase]>; 186*700637cbSDimitry Andric} // mayLoad = 0, mayStore = 1 187*700637cbSDimitry Andric} // Predicates = [HasVendorXMIPSLSP], hasSideEffects = 0, DecoderNamespace = "Xmipslsp" 188