32 #include "debug/Indirect.hh"
37 namespace branch_prediction
41 const SimpleIndirectPredictorParams ¶ms)
43 hashGHR(params.indirectHashGHR),
44 hashTargets(params.indirectHashTargets),
45 numSets(params.indirectSets),
46 numWays(params.indirectWays),
47 tagBits(params.indirectTagSize),
48 pathLength(params.indirectPathLength),
49 instShift(params.instShiftAmt),
50 ghrNumBits(params.indirectGHRBits),
51 ghrMask((1 << params.indirectGHRBits)-1)
54 panic(
"Indirect predictor requires power of 2 number of sets");
69 void* & indirect_history)
74 indirect_history =
new unsigned(
threadInfo[tid].ghr);
88 void * indirect_history,
bool actually_taken)
90 unsigned * previousGhr =
static_cast<unsigned *
>(indirect_history);
91 threadInfo[tid].ghr = ((*previousGhr) << 1) + actually_taken;
104 DPRINTF(Indirect,
"Looking up %x (set:%d)\n", br_addr, set_index);
106 for (
auto way = iset.begin(); way != iset.end(); ++way) {
107 if (way->tag == tag) {
108 DPRINTF(Indirect,
"Hit %x (target:%s)\n", br_addr, way->target);
109 target = way->target;
113 DPRINTF(Indirect,
"Miss %x\n", br_addr);
121 DPRINTF(Indirect,
"Recording %x seq:%d\n", br_addr, seq_num);
128 void * indirect_history)
130 DPRINTF(Indirect,
"Committing seq:%d\n", seq_num);
134 unsigned * previousGhr =
static_cast<unsigned *
>(indirect_history);
137 if (t_info.
pathHist.empty())
return;
152 DPRINTF(Indirect,
"Squashing seq:%d\n", seq_num);
154 auto squash_itr = t_info.
pathHist.begin();
155 while (squash_itr != t_info.
pathHist.end()) {
156 if (squash_itr->seqNum > seq_num) {
161 if (squash_itr != t_info.
pathHist.end()) {
162 DPRINTF(Indirect,
"Squashing series starting with sn:%d\n",
170 void * indirect_history)
172 unsigned * previousGhr =
static_cast<unsigned *
>(indirect_history);
185 unsigned * ghr =
static_cast<unsigned *
>(indirect_history);
188 auto hist_entry = *(t_info.
pathHist.rbegin());
193 hist_entry.targetAddr = target.instAddr();
194 t_info.
pathHist.push_back(hist_entry);
199 for (
auto way = iset.begin(); way != iset.end(); ++way) {
200 if (way->tag == tag) {
201 DPRINTF(Indirect,
"Updating Target (seq: %d br:%x set:%d target:"
202 "%s)\n", seq_num, hist_entry.pcAddr, set_index, target);
203 way->target = target;
208 DPRINTF(Indirect,
"Allocating Target (seq: %d br:%x set:%d target:%s)\n",
209 seq_num, hist_entry.pcAddr, set_index, target);
211 auto &way = iset[rand() %
numWays];
230 hash ^= (t_info.
pathHist[
i].targetAddr >>