Skip to content

Commit 05ee78a

Browse files
committed
Optimization: Update RVC.scala for zcb instructions
Signed-off-by: Abdul Wadood <[email protected]>
1 parent 0ebed64 commit 05ee78a

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

src/main/scala/rocket/RVC.scala

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,9 @@ class RVCDecoder(x: UInt, xLen: Int, useAddiForMv: Boolean = false, usingBitMani
119119
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)
120120
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)
121121
def arith = {
122-
val srai_srli_common = Cat(shamt, rs1p, 5.U(3.W), rs1p, 0x13.U(7.W))
123-
def srli = inst(srai_srli_common, rs1p, rs1p, rs2p)
124-
def srai = inst(Cat(0x10.U, srai_srli_common), rs1p, rs1p, rs2p)
125-
def andi = inst(Cat(addiImm, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
122+
def srli = Cat(shamt, rs1p, 5.U(3.W), rs1p, 0x13.U(7.W))
123+
def srai = Cat(0x10.U, srli)
124+
def andi = Cat(addiImm, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W))
126125
def rtype = {
127126
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)))
128127
val sub = Mux(x(6,5) === 0.U, (1 << 30).U, 0.U)
@@ -131,39 +130,35 @@ class RVCDecoder(x: UInt, xLen: Int, useAddiForMv: Boolean = false, usingBitMani
131130
if(usingMulDiv && usingCompressedSuiteB) Mux(Cat(x(12), x(6,5)) === 6.U, (1 << 25).U, 0.U)
132131
else 0.U
133132
}
134-
def zca = inst(Cat(rs2p, rs1p, funct, rs1p, opc) | sub | mul, rs1p, rs1p, rs2p)
133+
def zca = Cat(rs2p, rs1p, funct, rs1p, opc) | sub | mul
135134
def zcb_q1 = {
136-
def unimp = inst(Cat(lwImm >> 5, rs2p, rs1p, 2.U(3.W), lwImm(4,0), 0x3F.U(7.W)), rs2p, rs1p, rs2p)
135+
def unimp = Cat(lwImm >> 5, rs2p, rs1p, 2.U(3.W), lwImm(4,0), 0x3F.U(7.W))
137136
if(usingCompressedSuiteB){
138-
def zextb = inst(Cat(0xFF.U, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
139-
def not = inst(Cat(0xFFF.U, rs1p, 4.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
140-
def sextb = {
141-
if(usingBitManip) inst(Cat(0x604.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
142-
else unimp
143-
}
144-
def sexth = {
145-
if(usingBitManip) inst(Cat(0x605.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
146-
else unimp
147-
}
148-
def zextw = {
149-
if(usingBitManip) inst(Cat(4.U, x0, rs1p, 0.U(3.W), rs1p, 0x3B.U(7.W)), rs1p, rs1p, x0)
150-
else unimp
151-
}
137+
def zextb = Cat(0xFF.U, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W))
138+
def not = Cat(0xFFF.U, rs1p, 4.U(3.W), rs1p, 0x13.U(7.W))
139+
def sextb = Cat(0x604.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W))
140+
def sexth = Cat(0x605.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W))
141+
def zextw = Cat(4.U, x0, rs1p, 0.U(3.W), rs1p, 0x3B.U(7.W))
152142
def zexth = {
153-
if(usingBitManip) {
154-
val zexth_common = Cat(0x80.U, rs1p, 4.U(3.W), rs1p)
155-
if (xLen == 32) inst(Cat(zexth_common, 0x33.U(7.W)), rs1p, rs1p, rs2p)
156-
else inst(Cat(zexth_common, 0x3B.U(7.W)), rs1p, rs1p, rs2p)
157-
}
158-
else unimp
143+
val zexth_common = Cat(0x80.U, rs1p, 4.U(3.W), rs1p)
144+
if (xLen == 32) Cat(zexth_common, 0x33.U(7.W))
145+
else Cat(zexth_common, 0x3B.U(7.W))
146+
}
147+
if(usingBitManip){
148+
Seq(zextb, sextb, zexth, sexth, zextw, not, unimp, unimp)(x(4,2))
149+
} else {
150+
Mux (x(4,2)=== 5.U, not, Mux (x(4,2) === 0.U, zextb, unimp))
159151
}
160-
Seq(zextb, sextb, zexth, sexth, zextw, not)(x(4,2))
161152
}
162153
else unimp
163154
}
164155
Mux(Cat(x(12), x(6,5)) === 7.U, zcb_q1, zca)
165156
}
166-
Seq(srli, srai, andi, rtype)(x(11,10))
157+
def op2 = {
158+
if(usingCompressedSuiteB) Mux(Cat(x(15,10), x(6,2)) === 0x4FC.U, x0, rs2p)
159+
else rs2p
160+
}
161+
inst(Seq(srli, srai, andi, rtype)(x(11,10)), rs1p, rs1p, op2)
167162
}
168163
Seq(addi, jal, li, lui, arith, j, beqz, bnez)
169164
}

0 commit comments

Comments
 (0)