forked from zhangxz18/TAGE-Predictor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGSharePredictor.cc
92 lines (61 loc) · 2.24 KB
/
GSharePredictor.cc
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "predictor.h"
#define PHT_CTR_MAX 3
#define PHT_CTR_INIT 2
#define HIST_LEN 17
/////////////// STORAGE BUDGET JUSTIFICATION ////////////////
// Total storage budget: 32KB + 17 bits
// Total PHT counters: 2^17
// Total PHT size = 2^17 * 2 bits/counter = 2^18 bits = 32KB
// GHR size: 17 bits
// Total Size = PHT size + GHR size
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
PREDICTOR::PREDICTOR(void){
historyLength = HIST_LEN;
ghr = 0;
numPhtEntries = (1<< HIST_LEN);
pht = new UINT32[numPhtEntries];
for(UINT32 ii=0; ii< numPhtEntries; ii++){
pht[ii]=PHT_CTR_INIT;
}
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
bool PREDICTOR::GetPrediction(UINT32 PC){
UINT32 phtIndex = (PC^ghr) % (numPhtEntries);
UINT32 phtCounter = pht[phtIndex];
if(phtCounter > PHT_CTR_MAX/2){
return TAKEN;
}else{
return NOT_TAKEN;
}
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
void PREDICTOR::UpdatePredictor(UINT32 PC, bool resolveDir, bool predDir, UINT32 branchTarget){
UINT32 phtIndex = (PC^ghr) % (numPhtEntries);
UINT32 phtCounter = pht[phtIndex];
// update the PHT
if(resolveDir == TAKEN){
pht[phtIndex] = SatIncrement(phtCounter, PHT_CTR_MAX);
}else{
pht[phtIndex] = SatDecrement(phtCounter);
}
// update the GHR
ghr = (ghr << 1);
if(resolveDir == TAKEN){
ghr++;
}
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
void PREDICTOR::TrackOtherInst(UINT32 PC, OpType opType, UINT32 branchTarget){
// This function is called for instructions which are not
// conditional branches, just in case someone decides to design
// a predictor that uses information from such instructions.
// We expect most contestants to leave this function untouched.
return;
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////