Skip to content

Commit 304ae3c

Browse files
committed
Added skeleton body of TAGE
1 parent 68e0381 commit 304ae3c

File tree

6 files changed

+235
-35
lines changed

6 files changed

+235
-35
lines changed

core/fetch/BPU.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "BranchPredIF.hpp"
1111
#include "BasePredictor.hpp"
12+
#include "TAGE_SC_L.hpp"
1213

1314
#include <list>
1415

@@ -83,7 +84,7 @@ namespace olympia
8384
"Number of bits used by TAGE bimodal table to make prediction")
8485
PARAMETER(uint32_t, tage_tagged_table_num, 6,
8586
"Number of tagged components in TAGE predictor")
86-
PARAMETER(uint32_t, logical_table_num, 8, "Number of logical table in SC");
87+
PARAMETER(uint32_t, logical_table_num, 8, "Number of logical table in SC")
8788
PARAMETER(uint32_t, loop_pred_table_size, 64,
8889
"Maximum possible entries in loop predictor table")
8990
PARAMETER(uint32_t, loop_pred_table_way, 4, "Way size of loop predictor table")

core/fetch/BasePredictor.cpp

+45-29
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ namespace olympia
66
{
77
BasePredictor::BasePredictor(uint32_t pht_size, uint8_t ctr_bits, uint32_t btb_size,
88
uint32_t ras_size) :
9-
pattern_history_table(pht_size, ctr_bits),
10-
branch_target_buffer(btb_size),
11-
return_address_stack(ras_size)
9+
pattern_history_table_(pht_size, ctr_bits),
10+
branch_target_buffer_(btb_size),
11+
return_address_stack_(ras_size)
1212
{
1313
}
1414

@@ -21,78 +21,94 @@ namespace olympia
2121

2222
void PatternHistoryTable::incrementCounter(uint32_t idx)
2323
{
24-
if(pht_.find(idx) != pht_.end()) {
25-
if(pht_[idx] < ctr_bits_val_) {
24+
if (pht_.find(idx) != pht_.end())
25+
{
26+
if (pht_[idx] < ctr_bits_val_)
27+
{
2628
pht_[idx]++;
2729
}
2830
}
2931
}
3032

3133
void PatternHistoryTable::decrementCounter(uint32_t idx)
3234
{
33-
if(pht_.find(idx) != pht_.end()) {
34-
if(pht_[idx] > 0) {
35+
if (pht_.find(idx) != pht_.end())
36+
{
37+
if (pht_[idx] > 0)
38+
{
3539
pht_[idx]--;
3640
}
3741
}
3842
}
3943

4044
uint8_t PatternHistoryTable::getPrediction(uint32_t idx)
4145
{
42-
if(pht_.find(idx) != pht_.end()) {
46+
if (pht_.find(idx) != pht_.end())
47+
{
4348
return pht_[idx];
4449
}
45-
else {
50+
else
51+
{
4652
return 0;
4753
}
4854
}
4955

56+
// Branch Target Buffer
5057
BranchTargetBuffer::BranchTargetBuffer(uint32_t btb_size) : btb_size_(btb_size) {}
5158

5259
bool BranchTargetBuffer::addEntry(uint64_t PC, uint64_t targetPC)
5360
{
54-
if(btb_.size() < btb_size_) {
61+
if (btb_.size() < btb_size_)
62+
{
5563
btb_[PC] = targetPC;
5664
return true;
5765
}
5866
return false;
5967
}
6068

61-
bool BranchTargetBuffer::removeEntry(uint64_t PC)
69+
bool BranchTargetBuffer::removeEntry(uint64_t PC) { return btb_.erase(PC); }
70+
71+
bool BranchTargetBuffer::isHit(uint64_t PC)
6272
{
63-
return btb_.erase(PC);
73+
if (btb_.find(PC) != btb_.end())
74+
{
75+
return true;
76+
}
77+
else
78+
{
79+
return false;
80+
}
6481
}
6582

6683
uint64_t BranchTargetBuffer::getPredictedPC(uint64_t PC)
6784
{
68-
if(isHit(PC)) {
85+
if (isHit(PC))
86+
{
6987
return btb_[PC];
7088
}
71-
else {
89+
else
90+
{
7291
return 0; // change it later
7392
}
7493
}
7594

76-
bool BranchTargetBuffer::isHit(uint64_t PC)
95+
// Return Address Stack
96+
ReturnAddressStack::ReturnAddressStack(uint32_t ras_size) : ras_size_(ras_size) {}
97+
98+
void ReturnAddressStack::pushAddress(uint64_t PC)
7799
{
78-
if(btb_.find(PC) != btb_.end()) {
79-
return true;
100+
if (ras_.size() < ras_size_)
101+
{
102+
ras_.push(PC);
80103
}
81-
else {
82-
return false;
104+
else
105+
{
106+
return;
83107
}
84108
}
85109

86-
ReturnAddressStack::ReturnAddressStack(uint32_t ras_size) : ras_size_(ras_size) {}
87-
88-
void ReturnAddressStack::pushAddress()
89-
{
110+
uint64_t ReturnAddressStack::popAddress() { return 0; }
90111

91-
}
92-
93-
uint64_t ReturnAddressStack::popAddress()
94-
{
95-
return 0;
96-
}
112+
uint32_t ReturnAddressStack::getSize() { return ras_.size(); }
97113
} // namespace BranchPredictor
98114
} // namespace olympia

core/fetch/BasePredictor.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace olympia
3232

3333
bool addEntry(uint64_t PC, uint64_t targetPC);
3434
bool removeEntry(uint64_t PC);
35-
uint64_t getPredictedPC(uint64_t PC);
3635
bool isHit(uint64_t PC);
36+
uint64_t getPredictedPC(uint64_t PC);
3737

3838
private:
3939
const uint32_t btb_size_;
@@ -45,8 +45,9 @@ namespace olympia
4545
public:
4646
ReturnAddressStack(uint32_t ras_size);
4747

48-
void pushAddress();
48+
void pushAddress(uint64_t PC);
4949
uint64_t popAddress();
50+
uint32_t getSize();
5051

5152
private:
5253
const uint32_t ras_size_;
@@ -60,9 +61,9 @@ namespace olympia
6061
uint32_t ras_size);
6162

6263
private:
63-
PatternHistoryTable pattern_history_table;
64-
BranchTargetBuffer branch_target_buffer;
65-
ReturnAddressStack return_address_stack;
64+
PatternHistoryTable pattern_history_table_;
65+
BranchTargetBuffer branch_target_buffer_;
66+
ReturnAddressStack return_address_stack_;
6667
};
6768
} // namespace BranchPredictor
6869
} // namespace olympia

core/fetch/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@ add_library(fetch
22
Fetch.cpp
33
ICache.cpp
44
SimpleBranchPred.cpp
5+
BasePredictor.cpp
6+
TAGE_SC_L.cpp
7+
BPU.cpp
58
)
69
target_link_libraries(fetch instgen)

core/fetch/TAGE_SC_L.cpp

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "TAGE_SC_L.hpp"
2+
3+
namespace olympia
4+
{
5+
namespace BranchPredictor
6+
{
7+
8+
// Tage Tagged Component Entry
9+
TageTaggedComponentEntry::TageTaggedComponentEntry(uint8_t tage_ctr_bits,
10+
uint8_t tage_useful_bits) :
11+
tage_ctr_bits_(tage_ctr_bits),
12+
tage_useful_bits_(tage_useful_bits)
13+
{
14+
}
15+
16+
void TageTaggedComponentEntry::incrementCtr() {}
17+
18+
void TageTaggedComponentEntry::decrementCtr() {}
19+
20+
void TageTaggedComponentEntry::incrementUseful() {}
21+
22+
void TageTaggedComponentEntry::decrementUseful() {}
23+
24+
// Tagged component
25+
TageTaggedComponent::TageTaggedComponent(uint8_t tage_ctr_bits, uint8_t tage_useful_bits,
26+
uint16_t num_tagged_entry) :
27+
tage_ctr_bits_(tage_ctr_bits),
28+
tage_useful_bits_(tage_useful_bits),
29+
num_tagged_entry_(num_tagged_entry),
30+
tage_tagged_component_(num_tagged_entry_, {tage_ctr_bits_, tage_useful_bits_})
31+
{
32+
}
33+
34+
// Tage Bimodal
35+
TageBIM::TageBIM(uint32_t tage_bim_table_size, uint8_t tage_base_ctr_bits) :
36+
tage_bim_table_size_(tage_bim_table_size),
37+
tage_base_ctr_bits_(tage_base_ctr_bits)
38+
{
39+
// recheck value
40+
tage_base_max_ctr_ = 2 << tage_base_ctr_bits_;
41+
42+
// initialize counter at all index to be 0
43+
for (auto & val : Tage_Bimodal_)
44+
{
45+
val = 0;
46+
}
47+
}
48+
49+
void TageBIM::incrementCtr(uint32_t ip)
50+
{
51+
if (Tage_Bimodal_[ip] < tage_base_max_ctr_)
52+
{
53+
Tage_Bimodal_[ip]++;
54+
}
55+
}
56+
57+
void TageBIM::decrementCtr(uint32_t ip)
58+
{
59+
if (Tage_Bimodal_[ip] > 0)
60+
{
61+
Tage_Bimodal_[ip]--;
62+
}
63+
}
64+
65+
uint8_t TageBIM::getPrediction(uint32_t ip) { return Tage_Bimodal_[ip]; }
66+
67+
// TAGE
68+
Tage::Tage(uint32_t tage_bim_table_size, uint8_t tage_bim_ctr_bits,
69+
uint8_t tage_tagged_ctr_bits, uint8_t tage_tagged_useful_bits,
70+
uint8_t num_tage_component) :
71+
tage_bim_table_size_(tage_bim_table_size),
72+
tage_bim_ctr_bits_(tage_bim_ctr_bits),
73+
tage_tagged_ctr_bits_(tage_tagged_ctr_bits),
74+
tage_tagged_useful_bits_(tage_tagged_useful_bits),
75+
num_tage_component_(num_tage_component),
76+
tage_bim_(tage_bim_table_size_, tage_bim_table_size_),
77+
// for now number of tagged component entry in each component is set as 10
78+
tage_tagged_components_(num_tage_component_,
79+
{tage_tagged_ctr_bits_, tage_tagged_useful_bits_, 10})
80+
{
81+
}
82+
} // namespace BranchPredictor
83+
} // namespace olympia

core/fetch/TAGE_SC_L.hpp

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <cstdint>
5+
6+
namespace olympia
7+
{
8+
namespace BranchPredictor
9+
{
10+
class TageTaggedComponentEntry
11+
{
12+
public:
13+
TageTaggedComponentEntry(uint8_t tage_ctr_bits, uint8_t tage_useful_bits);
14+
15+
void incrementCtr();
16+
void decrementCtr();
17+
void incrementUseful();
18+
void decrementUseful();
19+
20+
private:
21+
uint16_t tag_;
22+
uint8_t tage_ctr_bits_;
23+
uint8_t tage_useful_bits_;
24+
uint8_t ctr_;
25+
uint8_t useful_;
26+
};
27+
28+
class TageTaggedComponent
29+
{
30+
public:
31+
TageTaggedComponent(uint8_t tage_ctr_bits, uint8_t tage_useful_bits,
32+
uint16_t num_tagged_entry);
33+
34+
private:
35+
uint8_t tage_ctr_bits_;
36+
uint8_t tage_useful_bits_;
37+
uint16_t num_tagged_entry_;
38+
std::vector<TageTaggedComponentEntry> tage_tagged_component_;
39+
};
40+
41+
class TageBIM
42+
{
43+
public:
44+
TageBIM(uint32_t tage_bim_table_size, uint8_t tage_base_ctr_bits);
45+
46+
void incrementCtr(uint32_t ip);
47+
void decrementCtr(uint32_t ip);
48+
uint8_t getPrediction(uint32_t ip);
49+
50+
private:
51+
uint32_t tage_bim_table_size_;
52+
uint8_t tage_base_ctr_bits_;
53+
uint8_t tage_base_max_ctr_;
54+
std::vector<uint8_t> Tage_Bimodal_;
55+
};
56+
57+
class Tage
58+
{
59+
public:
60+
Tage(uint32_t tage_bim_table_size, uint8_t tage_bim_ctr_bits,
61+
uint8_t tage_tagged_ctr_bits, uint8_t tage_tagged_useful_bits,
62+
uint8_t num_tage_component);
63+
64+
private:
65+
uint32_t tage_bim_table_size_;
66+
uint8_t tage_bim_ctr_bits_;
67+
uint8_t tage_tagged_ctr_bits_;
68+
uint8_t tage_tagged_useful_bits_;
69+
uint8_t num_tage_component_;
70+
71+
TageBIM tage_bim_;
72+
std::vector<TageTaggedComponent> tage_tagged_components_;
73+
};
74+
75+
class StatisticalCorrector
76+
{
77+
public:
78+
private:
79+
};
80+
81+
class LoopPredictor
82+
{
83+
public:
84+
private:
85+
};
86+
87+
class TAGE_SC_L
88+
{
89+
public:
90+
private:
91+
Tage tage;
92+
StatisticalCorrector sc;
93+
LoopPredictor l;
94+
};
95+
} // namespace BranchPredictor
96+
} // namespace olympia

0 commit comments

Comments
 (0)