Skip to content

Commit b053601

Browse files
committed
feat: modify bpu connect
1 parent 20bc1f6 commit b053601

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

rtl/tc_l2/src/main/scala/core/if/BPU.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BPU extends Module {
2525
ghr.io.taken := io.branchInfo.taken
2626

2727
// G-share
28-
protected val idx = io.lookupPc(ConstVal.GHRLen + ConstVal.AddrAlignLen - 1, ConstVal.AddrAlignLen) ^ ghr.io.idx
28+
protected val idx = io.lookupPc(ConstVal.GHRLen - 1, 0) ^ ghr.io.idx
2929
pht.io.prevBranch := io.branchInfo.branch
3030
pht.io.prevTaken := io.branchInfo.taken
3131
pht.io.prevIdx := io.branchInfo.idx
@@ -39,7 +39,14 @@ class BPU extends Module {
3939
btb.io.lookupPc := io.lookupPc
4040

4141
// wire output signals
42-
io.predTaken := btb.io.lookupBranch && (pht.io.taken || btb.io.lookupJump)
43-
io.predTgt := btb.io.lookupTgt
44-
io.predIdx := idx
42+
// now uncond jump is always no-taken to solve 'ret' inst return 'taken'
43+
// when multiple sections call same function
44+
when(btb.io.lookupJump) {
45+
io.predTaken := false.B
46+
}.otherwise {
47+
io.predTaken := btb.io.lookupBranch && pht.io.taken
48+
}
49+
// io.predTaken := btb.io.lookupBranch && (pht.io.taken || btb.io.lookupJump)
50+
io.predTgt := btb.io.lookupTgt
51+
io.predIdx := idx
4552
}

rtl/tc_l2/src/main/scala/core/if/IFU.scala

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ package treecorel2
33
import chisel3._
44
import chisel3.util._
55

6+
import treecorel2.common.ConstVal
7+
68
class IFU extends Module {
79
val io = IO(new Bundle {
8-
val globalEn = Input(Bool())
9-
val stall = Input(Bool())
10-
val socEn = Input(Bool())
11-
val fetch = new IFIO
12-
val if2id = new IF2IDIO
13-
val nxtPC = Flipped(new NXTPCIO)
10+
val globalEn = Input(Bool())
11+
val stall = Input(Bool())
12+
val socEn = Input(Bool())
13+
val branchInfo = Flipped(new BRANCHIO)
14+
val fetch = new IFIO
15+
val if2id = new IF2IDIO
16+
val nxtPC = Flipped(new NXTPCIO)
1417
})
1518

1619
protected val startAddr = Mux(io.socEn, "h0000000030000000".U(64.W), "h0000000080000000".U(64.W))
1720
protected val valid = Mux(reset.asBool(), false.B, true.B)
1821
protected val inst = io.fetch.data
1922
protected val pc = RegInit(startAddr)
2023

21-
// protected val bpu = Module(new BPU)
22-
// bpu.io.in := 0.U
24+
protected val bpu = Module(new BPU)
25+
bpu.io.branchInfo <> io.branchInfo
26+
bpu.io.lookupPc := pc
2327

2428
when(io.globalEn) {
2529
when(io.nxtPC.trap) {
@@ -28,15 +32,18 @@ class IFU extends Module {
2832
pc := io.nxtPC.mepc
2933
}.elsewhen(io.nxtPC.branch) {
3034
pc := io.nxtPC.tgt
35+
}.elsewhen(bpu.io.predTaken) {
36+
pc := bpu.io.predTgt
3137
}.otherwise {
3238
pc := pc + 4.U
3339
}
3440
}
3541

36-
io.if2id.valid := Mux(io.stall, false.B, valid)
37-
io.if2id.inst := inst
38-
io.if2id.pc := pc
39-
42+
io.if2id.valid := Mux(io.stall, false.B, valid)
43+
io.if2id.inst := inst
44+
io.if2id.pc := pc
45+
io.if2id.branIdx := bpu.io.predIdx
46+
io.if2id.predTaken := bpu.io.predTaken
4047
// comm with crossbar to get inst back
4148
io.fetch.en := valid
4249
io.fetch.addr := pc

0 commit comments

Comments
 (0)