Gem5 version: v25.1.0.0

Gem5 仅实现了最普通的 SimpleBTB , 为 O3CPU 默认使用

Gem5 BTB 协议

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
virtual void memInvalidate() override = 0;

/** Checks if a branch address is in the BTB. Intended as a quick check
* before calling lookup. Does not update statistics.
* @param inst_PC The address of the branch to look up.
* @return Whether or not the branch exists in the BTB.
*/
virtual bool valid(ThreadID tid, Addr instPC) = 0;

/** Looks up an address in the BTB to get the target of the branch.
* @param inst_PC The address of the branch to look up.
* @param type Optional type of the branch to look up.
* @return The target of the branch or nullptr if the branch is not
* in the BTB.
*/
virtual const PCStateBase *lookup(ThreadID tid, Addr instPC,
BranchType type = BranchType::NoBranch) = 0;

/** Looks up an address in the BTB and return the instruction
* information if existant. Does not update statistics.
* @param inst_PC The address of the branch to look up.
* @return Returns the target of the branch.
*/
virtual const StaticInstPtr getInst(ThreadID tid, Addr instPC) = 0;


/** Updates the BTB with the target of a branch.
* @param inst_pc The address of the branch being updated.
* @param target_pc The target address of the branch.
*/
virtual void update(ThreadID tid, Addr inst_pc,
const PCStateBase &target_pc,
BranchType type = BranchType::NoBranch,
StaticInstPtr inst = nullptr) = 0;

/** Update BTB statistics
*/
virtual void incorrectTarget(Addr inst_pc,
BranchType type = BranchType::NoBranch)
{
stats.mispredict[type]++;
}

BPU 对 BTB 的调用

in src/cpu/pred/bpred_unit.cc

  1. update
    • decode 阶段发现分支为 unconditional PC-relative,则预测错误