Skip to content

Commit 57c99c0

Browse files
committed
refactor: move bpu const var to instconfig
1 parent a944822 commit 57c99c0

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

rtl/tc_l2/src/main/scala/common/ConstVal.scala

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,4 @@ object ConstVal {
2727
val MSipOffset = 0x0.U(CLINTAddrLen.W)
2828
val MTimeOffset = 0xbff8.U(CLINTAddrLen.W)
2929
val MTimeCmpOffset = 0x4000.U(CLINTAddrLen.W)
30-
31-
// branch prediction
32-
val GHRLen = 5
33-
val PHTSize = 1 << GHRLen
34-
val BTBIdxLen = 5
35-
val BTBPcLen = AddrLen - BTBIdxLen
36-
val BTBTgtLen = AddrLen
37-
val BTBSize = 1 << BTBIdxLen
3830
}

rtl/tc_l2/src/main/scala/common/InstConfig.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ trait InstConfig {
9595
val instFENCE_I = 59.U(InstValLen.W)
9696
val instCUST = 60.U(InstValLen.W)
9797

98+
// branch prediction
99+
val GHRLen = 5
100+
val PHTSize = 1 << GHRLen
101+
val BTBIdxLen = 5
102+
val BTBPcLen = XLen - BTBIdxLen
103+
val BTBTgtLen = XLen
104+
val BTBSize = 1 << BTBIdxLen
105+
98106
// cache
99107
val NWay = 4
100108
val NBank = 4

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

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

6-
import treecorel2.common.{ConstVal, InstConfig}
6+
import treecorel2.common.InstConfig
77

88
class BEU extends Module with InstConfig {
99
val io = IO(new Bundle {
@@ -12,7 +12,7 @@ class BEU extends Module with InstConfig {
1212
val src1 = Input(UInt(XLen.W))
1313
val src2 = Input(UInt(XLen.W))
1414
val pc = Input(UInt(XLen.W))
15-
val branIdx = Input(UInt(ConstVal.GHRLen.W))
15+
val branIdx = Input(UInt(GHRLen.W))
1616
val branchInfo = new BRANCHIO
1717
val branch = Output(Bool())
1818
val tgt = Output(UInt(XLen.W))

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

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

6-
import treecorel2.common.ConstVal
6+
import treecorel2.common.{ConstVal, InstConfig}
77

8-
class BPU extends Module {
8+
class BPU extends Module with InstConfig {
99
// 2BP 2BC
1010
// Two-level adaptive predictor
1111
val io = IO(new Bundle {
@@ -14,7 +14,7 @@ class BPU extends Module {
1414
val lookupPc = Input(UInt(ConstVal.AddrLen.W))
1515
val predTaken = Output(Bool())
1616
val predTgt = Output(UInt(ConstVal.AddrLen.W))
17-
val predIdx = Output(UInt(ConstVal.GHRLen.W))
17+
val predIdx = Output(UInt(GHRLen.W))
1818
})
1919

2020
protected val ghr = Module(new GHR)
@@ -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 - 1, 0) ^ ghr.io.idx
28+
protected val idx = io.lookupPc(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

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

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

6-
import treecorel2.common.ConstVal
6+
import treecorel2.common.{ConstVal, InstConfig}
77

88
class BTBLine extends Bundle {
99
val pc = UInt(ConstVal.AddrLen.W)
1010
val tgt = UInt(ConstVal.AddrLen.W)
1111
val jump = Bool()
1212
}
1313

14-
class BTB extends Module {
14+
class BTB extends Module with InstConfig {
1515
val io = IO(new Bundle {
1616
// branch info (from idu)
1717
val branch = Input(Bool())
@@ -26,11 +26,11 @@ class BTB extends Module {
2626
})
2727

2828
// definitions of BTB lines and valid bits
29-
protected val valids = RegInit(VecInit(Seq.fill(ConstVal.BTBSize) { false.B }))
30-
protected val lines = Mem(ConstVal.BTBSize, new BTBLine)
29+
protected val valids = RegInit(VecInit(Seq.fill(BTBSize) { false.B }))
30+
protected val lines = Mem(BTBSize, new BTBLine)
3131

3232
// branch info for BTB lines
33-
protected val idx = io.pc(ConstVal.BTBIdxLen - 1, 0)
33+
protected val idx = io.pc(BTBIdxLen - 1, 0)
3434
// write to BTB lines
3535
when(io.branch) {
3636
valids(idx) := true.B
@@ -40,7 +40,7 @@ class BTB extends Module {
4040
}
4141

4242
// signals about BTB lookup
43-
protected val lookupIdx = io.lookupPc(ConstVal.BTBIdxLen - 1, 0)
43+
protected val lookupIdx = io.lookupPc(BTBIdxLen - 1, 0)
4444
protected val lookupPcSel = io.lookupPc
4545
protected val btbHit = valids(lookupIdx) && lines(lookupIdx).pc === lookupPcSel
4646

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

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

6-
import treecorel2.common.ConstVal
6+
import treecorel2.common.{ConstVal, InstConfig}
77

8-
class GHR extends Module {
8+
class GHR extends Module with InstConfig {
99
val io = IO(new Bundle {
1010
val branch = Input(Bool())
1111
val taken = Input(Bool())
12-
val idx = Output(UInt(ConstVal.GHRLen.W))
12+
val idx = Output(UInt(GHRLen.W))
1313
})
1414

15-
protected val shiftReg = Reg(UInt(ConstVal.GHRLen.W))
15+
protected val shiftReg = Reg(UInt(GHRLen.W))
1616

1717
when(io.branch) {
18-
shiftReg := Cat(shiftReg(ConstVal.GHRLen - 2, 0), io.taken)
18+
shiftReg := Cat(shiftReg(GHRLen - 2, 0), io.taken)
1919
}
2020

2121
io.idx := shiftReg

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

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

6-
import treecorel2.common.ConstVal
6+
import treecorel2.common.InstConfig
77

8-
class PHT extends Module {
8+
class PHT extends Module with InstConfig {
99
val io = IO(new Bundle {
1010
// branch info (from idu)
1111
val prevBranch = Input(Bool())
1212
val prevTaken = Input(Bool())
13-
val prevIdx = Input(UInt(ConstVal.GHRLen.W))
13+
val prevIdx = Input(UInt(GHRLen.W))
1414
// index for looking up counter table
15-
val idx = Input(UInt(ConstVal.GHRLen.W))
15+
val idx = Input(UInt(GHRLen.W))
1616
// prediction result
1717
val taken = Output(Bool())
1818
})
1919

20-
protected val init = Seq.fill(ConstVal.PHTSize) { "b10".U(2.W) }
20+
protected val init = Seq.fill(PHTSize) { "b10".U(2.W) }
2121
protected val counters = RegInit(VecInit(init))
2222

2323
// update counter

rtl/tc_l2/src/main/scala/port/BRANCH.scala

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

6-
import treecorel2.common.ConstVal
6+
import treecorel2.common.{ConstVal, InstConfig}
77

88
class BRANCHIO extends Bundle {
99
val branch = Output(Bool()) // prev inst is a b/j
1010
val jump = Output(Bool()) // is 'jal' or 'jalr'
1111
val taken = Output(Bool()) // is prev branch taken
12-
val idx = Output(UInt(ConstVal.GHRLen.W)) // prev idx of PHT
12+
val idx = Output(UInt(5.W)) // prev idx of PHT(GHRLen)
1313
val pc = Output(UInt(ConstVal.AddrLen.W)) // prev instruction PC
1414
val tgt = Output(UInt(ConstVal.AddrLen.W)) // prev branch tgt
1515
}

rtl/tc_l2/src/main/scala/port/IF2IDIO.scala

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

6-
import treecorel2.common.ConstVal
6+
import treecorel2.common.InstConfig
77

88
class IF2IDIO extends Bundle {
99
val valid = Output(Bool())
1010
val inst = Output(UInt(32.W))
1111
val pc = Output(UInt(64.W))
12-
val branIdx = Output(UInt(ConstVal.GHRLen.W))
12+
val branIdx = Output(UInt(5.W)) // (GHRLen)
1313
val predTaken = Output(Bool())
1414
}

0 commit comments

Comments
 (0)