Skip to content

Commit bd09848

Browse files
committed
Parameterized the Zcb extension
- Added `usingCompressedSuiteB` to enable/disable `Zcb` extension. - This parameter depends upon existing `usingCompressed` parameter. - By default `Zcb` is disable in RocketCore. - Passed this parameter along with `usingBitManip` and `usingMulDiv` to RVCDecoder enable/disable the decoding of corresponding `Zcb` instructions. Signed-off-by: Abdul Wadood <[email protected]>
1 parent 0c00a2f commit bd09848

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

src/main/scala/rocket/RVC.scala

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ExpandedInstruction extends Bundle {
1616
val rs3 = UInt(5.W)
1717
}
1818

19-
class RVCDecoder(x: UInt, xLen: Int, useAddiForMv: Boolean = false) {
19+
class RVCDecoder(x: UInt, xLen: Int, useAddiForMv: Boolean = false, usingBitManip: Boolean = false, usingMulDiv: Boolean = false, usingCompressedSuiteB: Boolean = false) {
2020
def inst(bits: UInt, rd: UInt = x(11,7), rs1: UInt = x(19,15), rs2: UInt = x(24,20), rs3: UInt = x(31,27)) = {
2121
val res = Wire(new ExpandedInstruction)
2222
res.bits := bits
@@ -63,14 +63,17 @@ class RVCDecoder(x: UInt, xLen: Int, useAddiForMv: Boolean = false) {
6363
else ld
6464
}
6565
def zcb_q0 = {
66-
def lbu = Cat(lbImm, rs1p, 4.U(3.W), rs2p, 0x03.U(7.W))
67-
def lh = {
68-
val func3 = Mux(x(6), 1.U(3.W), 5.U(3.W))
69-
Cat(lhImm, rs1p, func3, rs2p, 0x03.U(7.W))
66+
if (usingCompressedSuiteB){
67+
def lbu = Cat(lbImm, rs1p, 4.U(3.W), rs2p, 0x03.U(7.W))
68+
def lh = {
69+
val func3 = Mux(x(6), 1.U(3.W), 5.U(3.W))
70+
Cat(lhImm, rs1p, func3, rs2p, 0x03.U(7.W))
71+
}
72+
def sb = Cat(rs2p, rs1p, 0.U(3.W), 0.U(3.W), lbImm(1,0), 0x23.U(7.W))
73+
def sh = Cat(rs2p, rs1p, 1.U(3.W), 0.U(3.W), lhImm(1,0), 0x23.U(7.W))
74+
inst(Seq(lbu, lh, sb, sh)(x(11,10)), rs2p, rs1p, rs2p)
7075
}
71-
def sb = Cat(rs2p, rs1p, 0.U(3.W), 0.U(3.W), lbImm(1,0), 0x23.U(7.W))
72-
def sh = Cat(rs2p, rs1p, 1.U(3.W), 0.U(3.W), lhImm(1,0), 0x23.U(7.W))
73-
inst(Seq(lbu, lh, sb, sh)(x(11,10)), rs2p, rs1p, rs2p)
76+
else inst(Cat(lwImm >> 5, rs2p, rs1p, 2.U(3.W), lwImm(4,0), 0x3F.U(7.W)), rs2p, rs1p, rs2p) // unimp
7477
}
7578
def sd = inst(Cat(ldImm >> 5, rs2p, rs1p, 3.U(3.W), ldImm(4,0), 0x23.U(7.W)), rs2p, rs1p, rs2p)
7679
def sw = inst(Cat(lwImm >> 5, rs2p, rs1p, 2.U(3.W), lwImm(4,0), 0x23.U(7.W)), rs2p, rs1p, rs2p)
@@ -112,20 +115,37 @@ class RVCDecoder(x: UInt, xLen: Int, useAddiForMv: Boolean = false) {
112115
def rtype = {
113116
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)))
114117
val sub = Mux(x(6,5) === 0.U, (1 << 30).U, 0.U)
115-
val mul = Mux(Cat(x(12), x(6,5)) === 6.U, (1 << 25).U, 0.U)
118+
val mul = if(usingMulDiv && usingCompressedSuiteB) Mux(Cat(x(12), x(6,5)) === 6.U, (1 << 25).U, 0.U)
119+
else Cat(0xFFF.U, rs1p, 4.U(3.W), rs1p, 0x13.U(7.W)) // unimp
116120
val opc = Mux(x(12), Mux(x(6), 0x33.U(7.W), 0x3B.U(7.W)), 0x33.U(7.W))
117121
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
122+
def unimp = inst(Cat(lwImm >> 5, rs2p, rs1p, 2.U(3.W), lwImm(4,0), 0x3F.U(7.W)), rs2p, rs1p, rs2p)
123+
if(usingCompressedSuiteB){
124+
def zextb = inst(Cat(0xff.U, rs1p, 7.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
125+
def not = inst(Cat(0xFFF.U, rs1p, 4.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
126+
def zexth64 = inst(Cat(0x80.U, rs1p, 4.U(3.W), rs1p, 0x3B.U(7.W)), rs1p, rs1p, rs2p)
127+
def sextb = {
128+
if(usingBitManip) inst(Cat(0x604.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
129+
else unimp
130+
}
131+
def sexth = {
132+
if(usingBitManip) inst(Cat(0x605.U, rs1p, 1.U(3.W), rs1p, 0x13.U(7.W)), rs1p, rs1p, rs2p)
133+
else unimp
134+
}
135+
def zextw = {
136+
if(usingBitManip) inst(Cat(4.U, x0, rs1p, 0.U(3.W), rs1p, 0x3B.U(7.W)), rs1p, rs1p, x0)
137+
else unimp
138+
}
139+
def zexth = {
140+
if(usingBitManip) {
141+
if (xLen == 32) inst(Cat(0x80.U, rs1p, 4.U(3.W), rs1p, 0x33.U(7.W)), rs1p, rs1p, rs2p)
142+
else zexth64
143+
}
144+
else unimp
145+
}
146+
Seq(zextb, sextb, zexth, sexth, zextw, not)(x(4,2))
127147
}
128-
Seq(zextb, sextb, zexth, sexth, zextw, not)(x(4,2))
148+
else unimp
129149
}
130150
def zca = inst(Cat(rs2p, rs1p, funct, rs1p, opc) | sub | mul, rs1p, rs1p, rs2p)
131151
Mux(Cat(x(12), x(6,5)) === 7.U, zcb_q1, zca)
@@ -190,9 +210,9 @@ class RVCExpander(useAddiForMv: Boolean = false)(implicit val p: Parameters) ext
190210

191211
if (usingCompressed) {
192212
io.rvc := io.in(1,0) =/= 3.U
193-
io.out := new RVCDecoder(io.in, p(XLen), useAddiForMv).decode
213+
io.out := new RVCDecoder(io.in, p(XLen), useAddiForMv, usingBitManip, usingMulDiv, usingCompressedSuiteB).decode
194214
} else {
195215
io.rvc := false.B
196-
io.out := new RVCDecoder(io.in, p(XLen), useAddiForMv).passthrough
216+
io.out := new RVCDecoder(io.in, p(XLen), useAddiForMv, usingBitManip, usingMulDiv, usingCompressedSuiteB).passthrough
197217
}
198218
}

src/main/scala/rocket/RocketCore.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ case class RocketCoreParams(
2323
useAtomics: Boolean = true,
2424
useAtomicsOnlyForIO: Boolean = false,
2525
useCompressed: Boolean = true,
26+
useCompressedSuiteB: Boolean = false,
2627
useRVE: Boolean = false,
2728
useSCIE: Boolean = false,
2829
useBitManip: Boolean = false,

src/main/scala/tile/Core.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ trait CoreParams {
2222
val useAtomics: Boolean
2323
val useAtomicsOnlyForIO: Boolean
2424
val useCompressed: Boolean
25+
val useCompressedSuiteB: Boolean
2526
val useBitManip: Boolean
2627
val useBitManipCrypto: Boolean
2728
val useVector: Boolean = false
@@ -86,6 +87,7 @@ trait HasCoreParameters extends HasTileParameters {
8687
val usingAtomicsOnlyForIO = coreParams.useAtomicsOnlyForIO
8788
val usingAtomicsInCache = usingAtomics && !usingAtomicsOnlyForIO
8889
val usingCompressed = coreParams.useCompressed
90+
val usingCompressedSuiteB = coreParams.useCompressedSuiteB && usingCompressed
8991
val usingBitManip = coreParams.useBitManip
9092
val usingBitManipCrypto = coreParams.hasBitManipCrypto
9193
val usingVector = coreParams.useVector

0 commit comments

Comments
 (0)