Skip to content

Commit c7f74fb

Browse files
committed
Added high level structure of the BasePredictor
1 parent efa02d3 commit c7f74fb

File tree

5 files changed

+100
-2
lines changed

5 files changed

+100
-2
lines changed

core/fetch/BPU.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ namespace olympia
2121
tage_tagged_table_num_(p->tage_tagged_table_num),
2222
logical_table_num_(p->logical_table_num),
2323
loop_pred_table_size_(p->loop_pred_table_size),
24-
loop_pred_table_way_(p->loop_pred_table_way)
24+
loop_pred_table_way_(p->loop_pred_table_way),
25+
base_predictor_(pht_size_, ctr_bits_, btb_size_, ras_size_)
2526
{
2627
in_fetch_predictionRequest_.registerConsumerHandler(
2728
CREATE_SPARTA_HANDLER_WITH_DATA(BPU, recievePredictionRequest_, PredictionRequest));

core/fetch/BPU.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "sparta/utils/LogUtils.hpp"
99

1010
#include "BranchPredIF.hpp"
11+
#include "BasePredictor.hpp"
1112

1213
#include <list>
1314

@@ -126,6 +127,8 @@ namespace olympia
126127
uint32_t predictionRequestCredits_ = 0;
127128
uint32_t predictionOutputCredits_ = 0;
128129

130+
BasePredictor base_predictor_;
131+
129132
///////////////////////////////////////////////////////////////////////////////
130133
// Ports
131134
///////////////////////////////////////////////////////////////////////////////

core/fetch/BasePredictor.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "BasePredictor.hpp"
2+
3+
namespace olympia
4+
{
5+
namespace BranchPredictor
6+
{
7+
BasePredictor::BasePredictor(uint32_t pht_size, uint8_t ctr_bits, uint32_t btb_size,
8+
uint32_t ras_size) :
9+
pattern_history_table(pht_size, ctr_bits),
10+
branch_target_buffer(btb_size),
11+
return_address_stack(ras_size)
12+
{
13+
}
14+
15+
PatternHistoryTable::PatternHistoryTable(uint32_t pht_size, uint8_t ctr_bits) :
16+
pht_size_(pht_size),
17+
ctr_bits_(ctr_bits),
18+
ctr_bits_val_(pow(2, ctr_bits))
19+
{
20+
}
21+
22+
BranchTargetBuffer::BranchTargetBuffer(uint32_t btb_size) : btb_size_(btb_size) {}
23+
24+
ReturnAddressStack::ReturnAddressStack(uint32_t ras_size) : ras_size_(ras_size) {}
25+
} // namespace BranchPredictor
26+
} // namespace olympia

core/fetch/BasePredictor.hpp

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <cmath>
5+
#include <map>
6+
#include <stack>
7+
8+
namespace olympia
9+
{
10+
namespace BranchPredictor
11+
{
12+
class PatternHistoryTable
13+
{
14+
public:
15+
PatternHistoryTable(uint32_t pht_size, uint8_t ctr_bits);
16+
17+
void incrementCounter(uint32_t idx);
18+
void decrementCounter(uint32_t idx);
19+
uint8_t getPrediction(uint32_t idx);
20+
21+
private:
22+
const uint32_t pht_size_;
23+
const uint8_t ctr_bits_;
24+
const uint8_t ctr_bits_val_;
25+
std::map<uint64_t, uint8_t> pht_;
26+
};
27+
28+
class BranchTargetBuffer
29+
{
30+
public:
31+
BranchTargetBuffer(uint32_t btb_size);
32+
33+
bool addEntry(uint64_t PC, uint64_t targetPC);
34+
bool removeEntry(uint64_t PC);
35+
uint64_t getPredictedPC(uint64_t PC);
36+
bool isHit(uint64_t PC);
37+
38+
private:
39+
const uint32_t btb_size_;
40+
std::map<uint64_t, uint64_t> btb_;
41+
};
42+
43+
class ReturnAddressStack
44+
{
45+
public:
46+
ReturnAddressStack(uint32_t ras_size);
47+
48+
void pushAddress();
49+
uint64_t popAddress();
50+
51+
private:
52+
const uint32_t ras_size_;
53+
std::stack<uint64_t> ras_;
54+
};
55+
56+
class BasePredictor
57+
{
58+
public:
59+
BasePredictor(uint32_t pht_size, uint8_t ctr_bits, uint32_t btb_size,
60+
uint32_t ras_size);
61+
62+
private:
63+
PatternHistoryTable pattern_history_table;
64+
BranchTargetBuffer branch_target_buffer;
65+
ReturnAddressStack return_address_stack;
66+
};
67+
} // namespace BranchPredictor
68+
} // namespace olympia

test/core/bpu/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(BPUDir ../../../core/fetch)
1111

1212
project(${PRJ})
1313

14-
add_executable(${EXE} BPU_testbench.cpp ${BPUDir}/BPU.cpp ${BPUDir}/BPU.hpp BPUSource.hpp BPUSink.hpp)
14+
add_executable(${EXE} BPU_testbench.cpp ${BPUDir}/BPU.cpp ${BPUDir}/BPU.hpp ${BPUDir}/BasePredictor.cpp ${BPUDir}/BasePredictor.hpp BPUSource.hpp BPUSink.hpp)
1515
target_include_directories(${EXE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
1616

1717
target_link_libraries(${EXE} core common_test ${STF_LINK_LIBS} mavis SPARTA::sparta)

0 commit comments

Comments
 (0)