1*700637cbSDimitry Andric//===-- RISCVInstrInfoP.td - RISC-V 'P' instructions -------*- 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 RISC-V instructions from the standard 'Base P' 10*700637cbSDimitry Andric// Packed SIMD instruction set extension. 11*700637cbSDimitry Andric// 12*700637cbSDimitry Andric// This version is still experimental as the 'P' extension hasn't been 13*700637cbSDimitry Andric// ratified yet. 14*700637cbSDimitry Andric// 15*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 16*700637cbSDimitry Andric 17*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 18*700637cbSDimitry Andric// Operand and SDNode transformation definitions. 19*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 20*700637cbSDimitry Andric 21*700637cbSDimitry Andricdef simm10 : RISCVSImmLeafOp<10>; 22*700637cbSDimitry Andric 23*700637cbSDimitry Andricdef SImm10UnsignedAsmOperand : SImmAsmOperand<10, "Unsigned"> { 24*700637cbSDimitry Andric let RenderMethod = "addSImm10UnsignedOperands"; 25*700637cbSDimitry Andric} 26*700637cbSDimitry Andric 27*700637cbSDimitry Andric// A 10-bit signed immediate allowing range [-512, 1023] 28*700637cbSDimitry Andric// but represented as [-512, 511]. 29*700637cbSDimitry Andricdef simm10_unsigned : RISCVOp { 30*700637cbSDimitry Andric let ParserMatchClass = SImm10UnsignedAsmOperand; 31*700637cbSDimitry Andric let EncoderMethod = "getImmOpValue"; 32*700637cbSDimitry Andric let DecoderMethod = "decodeSImmOperand<10>"; 33*700637cbSDimitry Andric let OperandType = "OPERAND_SIMM10"; 34*700637cbSDimitry Andric let MCOperandPredicate = [{ 35*700637cbSDimitry Andric int64_t Imm; 36*700637cbSDimitry Andric if (!MCOp.evaluateAsConstantImm(Imm)) 37*700637cbSDimitry Andric return false; 38*700637cbSDimitry Andric return isInt<10>(Imm); 39*700637cbSDimitry Andric }]; 40*700637cbSDimitry Andric} 41*700637cbSDimitry Andric 42*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 43*700637cbSDimitry Andric// Instruction class templates 44*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 45*700637cbSDimitry Andric 46*700637cbSDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in 47*700637cbSDimitry Andricclass RVPUnaryImm10<bits<7> funct7, string opcodestr, 48*700637cbSDimitry Andric DAGOperand TyImm10 = simm10> 49*700637cbSDimitry Andric : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins TyImm10:$imm10), 50*700637cbSDimitry Andric opcodestr, "$rd, $imm10"> { 51*700637cbSDimitry Andric bits<10> imm10; 52*700637cbSDimitry Andric 53*700637cbSDimitry Andric let Inst{31-25} = funct7; 54*700637cbSDimitry Andric let Inst{24-16} = imm10{8-0}; 55*700637cbSDimitry Andric let Inst{15} = imm10{9}; 56*700637cbSDimitry Andric} 57*700637cbSDimitry Andric 58*700637cbSDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in 59*700637cbSDimitry Andricclass RVPUnaryImm8<bits<8> funct8, string opcodestr> 60*700637cbSDimitry Andric : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins uimm8:$uimm8), 61*700637cbSDimitry Andric opcodestr, "$rd, $uimm8"> { 62*700637cbSDimitry Andric bits<8> uimm8; 63*700637cbSDimitry Andric 64*700637cbSDimitry Andric let Inst{31-24} = funct8; 65*700637cbSDimitry Andric let Inst{23-16} = uimm8; 66*700637cbSDimitry Andric let Inst{15} = 0b0; 67*700637cbSDimitry Andric} 68*700637cbSDimitry Andric 69*700637cbSDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in 70*700637cbSDimitry Andricclass RVPUnary<bits<3> f, string opcodestr, dag operands, string argstr> 71*700637cbSDimitry Andric : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), operands, opcodestr, argstr> { 72*700637cbSDimitry Andric bits<5> imm; 73*700637cbSDimitry Andric bits<5> rs1; 74*700637cbSDimitry Andric 75*700637cbSDimitry Andric let Inst{31} = 0b1; 76*700637cbSDimitry Andric let Inst{30-28} = f; 77*700637cbSDimitry Andric let Inst{27} = 0b0; 78*700637cbSDimitry Andric let Inst{19-15} = rs1; 79*700637cbSDimitry Andric} 80*700637cbSDimitry Andric 81*700637cbSDimitry Andricclass RVPUnaryImm5<bits<3> f, string opcodestr> 82*700637cbSDimitry Andric : RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm5:$uimm5), "$rd, $rs1, $uimm5"> { 83*700637cbSDimitry Andric bits<5> uimm5; 84*700637cbSDimitry Andric 85*700637cbSDimitry Andric let imm = uimm5; 86*700637cbSDimitry Andric let Inst{26-25} = 0b01; 87*700637cbSDimitry Andric let Inst{24-20} = uimm5; 88*700637cbSDimitry Andric} 89*700637cbSDimitry Andric 90*700637cbSDimitry Andricclass RVPUnaryImm4<bits<3> f, string opcodestr> 91*700637cbSDimitry Andric : RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm4:$uimm4), "$rd, $rs1, $uimm4"> { 92*700637cbSDimitry Andric bits<4> uimm4; 93*700637cbSDimitry Andric 94*700637cbSDimitry Andric let Inst{26-24} = 0b001; 95*700637cbSDimitry Andric let Inst{23-20} = uimm4; 96*700637cbSDimitry Andric} 97*700637cbSDimitry Andric 98*700637cbSDimitry Andricclass RVPUnaryImm3<bits<3> f, string opcodestr> 99*700637cbSDimitry Andric : RVPUnary<f, opcodestr, (ins GPR:$rs1, uimm3:$uimm3), "$rd, $rs1, $uimm3"> { 100*700637cbSDimitry Andric bits<3> uimm3; 101*700637cbSDimitry Andric 102*700637cbSDimitry Andric let Inst{26-23} = 0b0001; 103*700637cbSDimitry Andric let Inst{22-20} = uimm3; 104*700637cbSDimitry Andric} 105*700637cbSDimitry Andric 106*700637cbSDimitry Andriclet hasSideEffects = 0, mayLoad = 0, mayStore = 0 in 107*700637cbSDimitry Andricclass RVPUnaryWUF<bits<2> w, bits<5> uf, string opcodestr> 108*700637cbSDimitry Andric : RVInstIBase<0b010, OPC_OP_IMM_32, (outs GPR:$rd), (ins GPR:$rs1), 109*700637cbSDimitry Andric opcodestr, "$rd, $rs1"> { 110*700637cbSDimitry Andric let Inst{31-27} = 0b11100; 111*700637cbSDimitry Andric let Inst{26-25} = w; 112*700637cbSDimitry Andric let Inst{24-20} = uf; 113*700637cbSDimitry Andric} 114*700637cbSDimitry Andric 115*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 116*700637cbSDimitry Andric// Instructions 117*700637cbSDimitry Andric//===----------------------------------------------------------------------===// 118*700637cbSDimitry Andric 119*700637cbSDimitry Andriclet Predicates = [HasStdExtP] in { 120*700637cbSDimitry Andricdef CLS : Unary_r<0b011000000011, 0b001, "cls">; 121*700637cbSDimitry Andricdef ABS : Unary_r<0b011000000111, 0b001, "abs">; 122*700637cbSDimitry Andric} // Predicates = [HasStdExtP] 123*700637cbSDimitry Andriclet Predicates = [HasStdExtP, IsRV32] in 124*700637cbSDimitry Andricdef REV_RV32 : Unary_r<0b011010011111, 0b101, "rev">; 125*700637cbSDimitry Andric 126*700637cbSDimitry Andriclet Predicates = [HasStdExtP, IsRV64] in { 127*700637cbSDimitry Andricdef REV16 : Unary_r<0b011010110000, 0b101, "rev16">; 128*700637cbSDimitry Andricdef REV_RV64 : Unary_r<0b011010111111, 0b101, "rev">; 129*700637cbSDimitry Andric 130*700637cbSDimitry Andricdef CLSW : UnaryW_r<0b011000000011, 0b001, "clsw">; 131*700637cbSDimitry Andricdef ABSW : UnaryW_r<0b011000000111, 0b001, "absw">; 132*700637cbSDimitry Andric} // Predicates = [HasStdExtP, IsRV64] 133*700637cbSDimitry Andric 134*700637cbSDimitry Andriclet Predicates = [HasStdExtP] in { 135*700637cbSDimitry Andricdef PSLLI_B : RVPUnaryImm3<0b000, "pslli.b">; 136*700637cbSDimitry Andricdef PSLLI_H : RVPUnaryImm4<0b000, "pslli.h">; 137*700637cbSDimitry Andricdef PSSLAI_H : RVPUnaryImm4<0b101, "psslai.h">; 138*700637cbSDimitry Andric} // Predicates = [HasStdExtP] 139*700637cbSDimitry Andriclet DecoderNamespace = "RV32Only", 140*700637cbSDimitry Andric Predicates = [HasStdExtP, IsRV32] in 141*700637cbSDimitry Andricdef SSLAI : RVPUnaryImm5<0b101, "sslai">; 142*700637cbSDimitry Andriclet Predicates = [HasStdExtP, IsRV64] in { 143*700637cbSDimitry Andricdef PSLLI_W : RVPUnaryImm5<0b000, "pslli.w">; 144*700637cbSDimitry Andricdef PSSLAI_W : RVPUnaryImm5<0b101, "psslai.w">; 145*700637cbSDimitry Andric} // Predicates = [HasStdExtP, IsRV64] 146*700637cbSDimitry Andric 147*700637cbSDimitry Andriclet Predicates = [HasStdExtP] in 148*700637cbSDimitry Andricdef PLI_H : RVPUnaryImm10<0b1011000, "pli.h">; 149*700637cbSDimitry Andriclet Predicates = [HasStdExtP, IsRV64] in 150*700637cbSDimitry Andricdef PLI_W : RVPUnaryImm10<0b1011001, "pli.w">; 151*700637cbSDimitry Andriclet Predicates = [HasStdExtP] in 152*700637cbSDimitry Andricdef PLI_B : RVPUnaryImm8<0b10110100, "pli.b">; 153*700637cbSDimitry Andric 154*700637cbSDimitry Andriclet Predicates = [HasStdExtP] in { 155*700637cbSDimitry Andricdef PSEXT_H_B : RVPUnaryWUF<0b00, 0b00100, "psext.h.b">; 156*700637cbSDimitry Andricdef PSABS_H : RVPUnaryWUF<0b00, 0b00111, "psabs.h">; 157*700637cbSDimitry Andricdef PSABS_B : RVPUnaryWUF<0b10, 0b00111, "psabs.b">; 158*700637cbSDimitry Andric} // Predicates = [HasStdExtP] 159*700637cbSDimitry Andriclet Predicates = [HasStdExtP, IsRV64] in { 160*700637cbSDimitry Andricdef PSEXT_W_B : RVPUnaryWUF<0b01, 0b00100, "psext.w.b">; 161*700637cbSDimitry Andricdef PSEXT_W_H : RVPUnaryWUF<0b01, 0b00101, "psext.w.h">; 162*700637cbSDimitry Andric} // Predicates = [HasStdExtP, IsRV64] 163*700637cbSDimitry Andric 164*700637cbSDimitry Andriclet Predicates = [HasStdExtP] in 165*700637cbSDimitry Andricdef PLUI_H : RVPUnaryImm10<0b1111000, "plui.h", simm10_unsigned>; 166*700637cbSDimitry Andriclet Predicates = [HasStdExtP, IsRV64] in 167*700637cbSDimitry Andricdef PLUI_W : RVPUnaryImm10<0b1111001, "plui.w", simm10_unsigned>; 168