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) {
109 if (way->tag == tag && way->target) {
110 DPRINTF(Indirect,
"Hit %x (target:%s)\n", br_addr, *way->target);
111 set(target, *way->target);
115 DPRINTF(Indirect,
"Miss %x\n", br_addr);
123 DPRINTF(Indirect,
"Recording %x seq:%d\n", br_addr, seq_num);
130 void * indirect_history)
132 DPRINTF(Indirect,
"Committing seq:%d\n", seq_num);
136 unsigned * previousGhr =
static_cast<unsigned *
>(indirect_history);
139 if (t_info.
pathHist.empty())
return;
154 DPRINTF(Indirect,
"Squashing seq:%d\n", seq_num);
156 auto squash_itr = t_info.
pathHist.begin();
157 while (squash_itr != t_info.
pathHist.end()) {
158 if (squash_itr->seqNum > seq_num) {
163 if (squash_itr != t_info.
pathHist.end()) {
164 DPRINTF(Indirect,
"Squashing series starting with sn:%d\n",
172 void * indirect_history)
174 unsigned * previousGhr =
static_cast<unsigned *
>(indirect_history);
187 unsigned * ghr =
static_cast<unsigned *
>(indirect_history);
190 auto hist_entry = *(t_info.
pathHist.rbegin());
195 hist_entry.targetAddr = target.
instAddr();
196 t_info.
pathHist.push_back(hist_entry);
201 for (
auto way = iset.begin(); way != iset.end(); ++way) {
202 if (way->tag == tag) {
203 DPRINTF(Indirect,
"Updating Target (seq: %d br:%x set:%d target:"
204 "%s)\n", seq_num, hist_entry.pcAddr, set_index, target);
205 set(way->target, target);
210 DPRINTF(Indirect,
"Allocating Target (seq: %d br:%x set:%d target:%s)\n",
211 seq_num, hist_entry.pcAddr, set_index, target);
213 auto &way = iset[rand() %
numWays];
215 set(way.target, target);
232 hash ^= (t_info.
pathHist[
i].targetAddr >>