Skip to content

Commit 8835e00

Browse files
committed
refactor: use muxlookup to simplify code
1 parent 6fe2b62 commit 8835e00

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

rtl/tc_l2/src/main/scala/core/exec/BEU.scala

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,44 @@ class BEU extends Module with InstConfig {
1818
val tgt = Output(UInt(XLen.W))
1919
})
2020

21-
protected val beq = (io.isa === instBEQ) && (io.src1 === io.src2)
22-
protected val bne = (io.isa === instBNE) && (io.src1 =/= io.src2)
23-
protected val bgeu = (io.isa === instBGEU) && (io.src1 >= io.src2)
24-
protected val bltu = (io.isa === instBLTU) && (io.src1 < io.src2)
25-
protected val bge = (io.isa === instBGE) && (io.src1.asSInt >= io.src2.asSInt)
26-
protected val blt = (io.isa === instBLT) && (io.src1.asSInt < io.src2.asSInt)
27-
protected val b = beq | bne | bgeu | bltu | bge | blt
28-
protected val bInst = (io.isa === instBEQ) || (io.isa === instBNE) || (io.isa === instBGEU) || (io.isa === instBLTU) ||
29-
(io.isa === instBGE) || (io.isa === instBLT) || (io.isa === instJAL) || (io.isa === instJALR)
21+
protected val b = MuxLookup(
22+
io.isa,
23+
false.B,
24+
Seq(
25+
instBEQ -> (io.src1 === io.src2),
26+
instBNE -> (io.src1 =/= io.src2),
27+
instBGEU -> (io.src1 >= io.src2),
28+
instBLTU -> (io.src1 < io.src2),
29+
instBGE -> (io.src1.asSInt >= io.src2.asSInt),
30+
instBLT -> (io.src1.asSInt < io.src2.asSInt)
31+
)
32+
)
33+
34+
protected val bInst = MuxLookup(
35+
io.isa,
36+
false.B,
37+
Seq(
38+
instBEQ -> true.B,
39+
instBNE -> true.B,
40+
instBGEU -> true.B,
41+
instBLTU -> true.B,
42+
instBGE -> true.B,
43+
instBLT -> true.B
44+
)
45+
)
3046

3147
protected val jal = io.isa === instJAL
3248
protected val jalr = io.isa === instJALR
33-
34-
protected val b_tgt = io.pc + io.imm
35-
protected val jal_tgt = io.pc + io.imm
36-
protected val jalr_tgt = io.src1 + io.imm
37-
3849
io.branch := b | jal | jalr
3950

40-
when(jal) {
41-
io.tgt := jal_tgt
42-
}.elsewhen(jalr) {
43-
io.tgt := jalr_tgt
44-
}.otherwise {
45-
io.tgt := b_tgt
46-
}
51+
io.tgt := MuxLookup(
52+
io.isa,
53+
(io.pc + io.imm), // NOTE: branch target
54+
Seq(
55+
instJAL -> (io.pc + io.imm),
56+
instJALR -> (io.src1 + io.imm),
57+
)
58+
)
4759

4860
io.branchInfo.branch := bInst
4961
io.branchInfo.jump := jal || jalr

rtl/tc_l2/src/main/scala/core/exec/CSRReg.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import chisel3._
44
import chisel3.util._
55
import difftest._
66

7-
import treecorel2.common.{ConstVal, InstConfig}
7+
import treecorel2.common.InstConfig
88

99
object CSRReg {
1010
val timeCause = "h8000_0000_0000_0007".U(64.W)

0 commit comments

Comments
 (0)