Deleted Added
sdiff udiff text old ( 13455:56e25a5f9603 ) new ( 13626:d6a6358aa6db )
full compact
1/*
2 * Copyright (c) 2014 The University of Wisconsin
3 *
4 * Copyright (c) 2006 INRIA (Institut National de Recherche en
5 * Informatique et en Automatique / French National Research Institute
6 * for Computer Science and Applied Mathematics)
7 *
8 * All rights reserved.

--- 33 unchanged lines hidden (view full) ---

42
43#include "base/intmath.hh"
44#include "base/logging.hh"
45#include "base/random.hh"
46#include "base/trace.hh"
47#include "debug/Fetch.hh"
48#include "debug/Tage.hh"
49
50TAGE::TAGE(const TAGEParams *params) : BPredUnit(params), tage(params->tage)
51{
52}
53
54// Get GHR for hashing indirect predictor
55// Build history backwards from pointer in
56// bp_history.
57unsigned
58TAGE::getGHR(ThreadID tid, void *bp_history) const
59{
60 TageBranchInfo* bi = static_cast<TageBranchInfo*>(bp_history);
61 return tage->getGHR(tid, bi->tageBranchInfo);
62}
63
64// PREDICTOR UPDATE
65void
66TAGE::update(ThreadID tid, Addr branch_pc, bool taken, void* bp_history,
67 bool squashed, const StaticInstPtr & inst, Addr corrTarget)
68{
69 assert(bp_history);
70
71 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
72
73 assert(corrTarget != MaxAddr);
74
75 if (squashed) {
76 // This restores the global history, then update it
77 // and recomputes the folded histories.
78 tage->squash(tid, taken, bi->tageBranchInfo, corrTarget);
79 return;
80 }
81
82 int nrand = TAGEBase::getRandom() & 3;
83 if (bi->tageBranchInfo->condBranch) {
84 DPRINTF(Tage, "Updating tables for branch:%lx; taken?:%d\n",
85 branch_pc, taken);
86 tage->updateStats(taken, bi->tageBranchInfo);
87 tage->condBranchUpdate(tid, branch_pc, taken, bi->tageBranchInfo,
88 nrand, corrTarget);
89 }
90
91 tage->updateHistories(tid, branch_pc, taken, bi->tageBranchInfo, false,
92 inst, corrTarget);
93
94 delete bi;
95}
96
97void
98TAGE::squash(ThreadID tid, void *bp_history)
99{
100 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
101 DPRINTF(Tage, "Deleting branch info: %lx\n", bi->tageBranchInfo->branchPC);
102 delete bi;
103}
104
105bool
106TAGE::predict(ThreadID tid, Addr branch_pc, bool cond_branch, void* &b)
107{
108 TageBranchInfo *bi = new TageBranchInfo(*tage);
109 b = (void*)(bi);
110 return tage->tagePredict(tid, branch_pc, cond_branch, bi->tageBranchInfo);
111}
112
113bool
114TAGE::lookup(ThreadID tid, Addr branch_pc, void* &bp_history)
115{
116 bool retval = predict(tid, branch_pc, true, bp_history);
117
118 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
119
120 DPRINTF(Tage, "Lookup branch: %lx; predict:%d\n", branch_pc, retval);
121
122 tage->updateHistories(tid, branch_pc, retval, bi->tageBranchInfo, true);
123
124 return retval;
125}
126
127void
128TAGE::btbUpdate(ThreadID tid, Addr branch_pc, void* &bp_history)
129{
130 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
131 tage->btbUpdate(tid, branch_pc, bi->tageBranchInfo);
132}
133
134void
135TAGE::uncondBranch(ThreadID tid, Addr br_pc, void* &bp_history)
136{
137 DPRINTF(Tage, "UnConditionalBranch: %lx\n", br_pc);
138 predict(tid, br_pc, false, bp_history);
139 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
140 tage->updateHistories(tid, br_pc, true, bi->tageBranchInfo, true);
141}
142
143TAGE*
144TAGEParams::create()
145{
146 return new TAGE(this);
147}