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
0 commit comments