@@ -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,22 +115,41 @@ 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 )
116118 val opc = Mux (x(12 ), Mux (x(6 ), 0x33 .U (7 .W ), 0x3B .U (7 .W )), 0x33 .U (7 .W ))
119+ def mul = {
120+ if (usingMulDiv && usingCompressedSuiteB) Mux (Cat (x(12 ), x(6 ,5 )) === 6 .U , (1 << 25 ).U , 0 .U )
121+ else 0 .U
122+ }
123+ def zca = inst(Cat (rs2p, rs1p, funct, rs1p, opc) | sub | mul, rs1p, rs1p, rs2p)
117124 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
125+ def unimp = inst(Cat (lwImm >> 5 , rs2p, rs1p, 2 .U (3 .W ), lwImm(4 ,0 ), 0x3F .U (7 .W )), rs2p, rs1p, rs2p)
126+ if (usingCompressedSuiteB){
127+ def zextb = inst(Cat (0xff .U , rs1p, 7 .U (3 .W ), rs1p, 0x13 .U (7 .W )), rs1p, rs1p, rs2p)
128+ def not = inst(Cat (0xFFF .U , rs1p, 4 .U (3 .W ), rs1p, 0x13 .U (7 .W )), rs1p, rs1p, rs2p)
129+ def zexth64 = inst(Cat (0x80 .U , rs1p, 4 .U (3 .W ), rs1p, 0x3B .U (7 .W )), rs1p, rs1p, rs2p)
130+ def sextb = {
131+ if (usingBitManip) inst(Cat (0x604 .U , rs1p, 1 .U (3 .W ), rs1p, 0x13 .U (7 .W )), rs1p, rs1p, rs2p)
132+ else unimp
133+ }
134+ def sexth = {
135+ if (usingBitManip) inst(Cat (0x605 .U , rs1p, 1 .U (3 .W ), rs1p, 0x13 .U (7 .W )), rs1p, rs1p, rs2p)
136+ else unimp
137+ }
138+ def zextw = {
139+ if (usingBitManip) inst(Cat (4 .U , x0, rs1p, 0 .U (3 .W ), rs1p, 0x3B .U (7 .W )), rs1p, rs1p, x0)
140+ else unimp
141+ }
142+ def zexth = {
143+ if (usingBitManip) {
144+ if (xLen == 32 ) inst(Cat (0x80 .U , rs1p, 4 .U (3 .W ), rs1p, 0x33 .U (7 .W )), rs1p, rs1p, rs2p)
145+ else zexth64
146+ }
147+ else unimp
148+ }
149+ Seq (zextb, sextb, zexth, sexth, zextw, not)(x(4 ,2 ))
127150 }
128- Seq (zextb, sextb, zexth, sexth, zextw, not)(x( 4 , 2 ))
151+ else unimp
129152 }
130- def zca = inst(Cat (rs2p, rs1p, funct, rs1p, opc) | sub | mul, rs1p, rs1p, rs2p)
131153 Mux (Cat (x(12 ), x(6 ,5 )) === 7 .U , zcb_q1, zca)
132154 }
133155 Seq (srli, srai, andi, rtype)(x(11 ,10 ))
@@ -190,9 +212,9 @@ class RVCExpander(useAddiForMv: Boolean = false)(implicit val p: Parameters) ext
190212
191213 if (usingCompressed) {
192214 io.rvc := io.in(1 ,0 ) =/= 3 .U
193- io.out := new RVCDecoder (io.in, p(XLen ), useAddiForMv).decode
215+ io.out := new RVCDecoder (io.in, p(XLen ), useAddiForMv, usingBitManip, usingMulDiv, usingCompressedSuiteB ).decode
194216 } else {
195217 io.rvc := false .B
196- io.out := new RVCDecoder (io.in, p(XLen ), useAddiForMv).passthrough
218+ io.out := new RVCDecoder (io.in, p(XLen ), useAddiForMv, usingBitManip, usingMulDiv, usingCompressedSuiteB ).passthrough
197219 }
198220}
0 commit comments