Skip to content

Commit 0c00a2f

Browse files
committed
Added support of Q1 Zcb Instructions.
- Implement the 16 to 32 bit Decoder for `Zcb` Instructions having OP[1:0] = 2'b01 - The 16 bit -> 32 bit instruction mapping is given as follows: c.zext.b -> andi c.sext.b -> sext.b (require Zbb) c.zext.h -> zext.h (require Zbb) c.sext.h -> sext.h (require Zbb) c.zext.w -> add.uw (require Zba, only for RV64) c.not -> xori c.mul -> mul (Require M standard extension) Signed-off-by: Abdul Wadood <[email protected]>
1 parent cf10d81 commit 0c00a2f

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/main/scala/rocket/RVC.scala

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,31 @@ class RVCDecoder(x: UInt, xLen: Int, useAddiForMv: Boolean = false) {
106106
def beqz = inst(Cat(bImm(12), bImm(10,5), x0, rs1p, 0.U(3.W), bImm(4,1), bImm(11), 0x63.U(7.W)), rs1p, rs1p, x0)
107107
def bnez = inst(Cat(bImm(12), bImm(10,5), x0, rs1p, 1.U(3.W), bImm(4,1), bImm(11), 0x63.U(7.W)), x0, rs1p, x0)
108108
def arith = {
109-
def srli = Cat(shamt, rs1p, 5.U(3.W), rs1p, 0x13.U(7.W))
110-
def srai = srli | (1 << 30).U
111-
def andi = Cat(addiImm, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W))
109+
def srli = inst(Cat(shamt, rs1p, 5.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
110+
def srai = inst(Cat(0x10.U, shamt, rs1p, 5.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
111+
def andi = inst(Cat(addiImm, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
112112
def rtype = {
113-
val funct = Seq(0.U, 4.U, 6.U, 7.U, 0.U, 0.U, 2.U, 3.U)(Cat(x(12), x(6,5)))
113+
val funct = Seq(0.U, 4.U, 6.U, 7.U, 0.U, 0.U, 0.U, 3.U)(Cat(x(12), x(6,5)))
114114
val sub = Mux(x(6,5) === 0.U, (1 << 30).U, 0.U)
115-
val opc = Mux(x(12), 0x3B.U(7.W), 0x33.U(7.W))
116-
Cat(rs2p, rs1p, funct, rs1p, opc) | sub
115+
val mul = Mux(Cat(x(12), x(6,5)) === 6.U, (1 << 25).U, 0.U)
116+
val opc = Mux(x(12), Mux(x(6), 0x33.U(7.W), 0x3B.U(7.W)), 0x33.U(7.W))
117+
def zcb_q1 = {
118+
def zextb = inst(Cat(0xff.U, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
119+
def sextb = inst(Cat(0x604.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
120+
def sexth = inst(Cat(0x605.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
121+
def not = inst(Cat(0xFFF.U, rs1p, 4.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
122+
def zextw = inst(Cat(4.U, x0, rs1p, 0.U(3.W), rs1p, 0x3B.U(7.W)), rs1p, rs1p, x0)
123+
def zexth64 = inst(Cat(0x80.U, rs1p, 4.U(3.W), rs1p, 0x3B.U(7.W)), rs1p, rs1p, rs2p)
124+
def zexth = {
125+
if (xLen == 32) inst(Cat(0x80.U, rs1p, 4.U(3.W), rs1p, 0x33.U(7.W)), rs1p, rs1p, rs2p)
126+
else zexth64
127+
}
128+
Seq(zextb, sextb, zexth, sexth, zextw, not)(x(4,2))
129+
}
130+
def zca = inst(Cat(rs2p, rs1p, funct, rs1p, opc) | sub | mul, rs1p, rs1p, rs2p)
131+
Mux(Cat(x(12), x(6,5)) === 7.U, zcb_q1, zca)
117132
}
118-
inst(Seq(srli, srai, andi, rtype)(x(11,10)), rs1p, rs1p, rs2p)
133+
Seq(srli, srai, andi, rtype)(x(11,10))
119134
}
120135
Seq(addi, jal, li, lui, arith, j, beqz, bnez)
121136
}

0 commit comments

Comments
 (0)