gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tage_sc_l_8KB.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Metempsy Technology Consulting
3  * All rights reserved.
4  *
5  * Copyright (c) 2006 INRIA (Institut National de Recherche en
6  * Informatique et en Automatique / French National Research Institute
7  * for Computer Science and Applied Mathematics)
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met: redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer;
15  * redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution;
18  * neither the name of the copyright holders nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Author: André Seznec, Pau Cabre, Javier Bueno
35  *
36  */
37 
38 /*
39  * 8KB TAGE-SC-L branch predictor (devised by Andre Seznec)
40  */
41 
43 
44 #include "base/random.hh"
45 #include "debug/TageSCL.hh"
46 
48  const TAGE_SC_L_8KB_StatisticalCorrectorParams &p)
50  gnb(p.gnb),
51  logGnb(p.logGnb),
52  gm(p.gm)
53 {
55 }
56 
59 {
61  sh->setNumOrdinalHistories(1);
62  sh->initLocalHistory(1, numEntriesFirstLocalHistories, 2);
63  return sh;
64 }
65 
66 unsigned
68  BranchInfo* bi, int hitBank, int altBank) const
69 {
70  return (bi->predBeforeSC + (((hitBank+1)/4)<<4) + (bi->highConf<<1) +
71  (bi->lowConf <<2) +((altBank!=0)<<3)) & ((1<<logBias) -1);
72 }
73 
74 int
76  ThreadID tid, Addr branch_pc, BranchInfo* bi, int & lsum, int64_t phist)
77 {
79  lsum += gPredict(
80  branch_pc, sh->globalHist, gm, ggehl, gnb, logGnb, wg);
81 
82  lsum += gPredict(
83  branch_pc, sh->bwHist, bwm, bwgehl, bwnb, logBwnb, wbw);
84 
85  // only 1 local history here
86  lsum += gPredict(
87  branch_pc, sh->getLocalHistory(1, branch_pc), lm,
88  lgehl, lnb, logLnb, wl);
89 
90  lsum += gPredict(
91  branch_pc, sh->imliCount, im, igehl, inb, logInb, wi);
92 
93  int thres = (updateThreshold>>3)+pUpdateThreshold[getIndUpd(branch_pc)];
94 
95  return thres;
96 }
97 
99 {
100  return 0;
101 }
102 
103 void
105  const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi,
106  Addr corrTarget)
107 {
108  int brtype = inst->isDirectCtrl() ? 0 : 2;
109  if (! inst->isUncondCtrl()) {
110  ++brtype;
111  }
112  // Non speculative SC histories update
113  if (brtype & 1) {
115  static_cast<SC_8KB_ThreadHistory *>(scHistory);
116  sh->globalHist = (sh->globalHist << 1) + taken;
117  }
118 
119  StatisticalCorrector::scHistoryUpdate(branch_pc, inst, taken, tage_bi,
120  corrTarget);
121 }
122 
123 void
125  BranchInfo* bi, int64_t phist)
126 {
128  gUpdate(pc, taken, sh->globalHist, gm, ggehl, gnb, logGnb, wg, bi);
129  gUpdate(pc, taken, sh->bwHist, bwm, bwgehl, bwnb, logBwnb, wbw, bi);
130  gUpdate(pc, taken, sh->getLocalHistory(1, pc), lm, lgehl, lnb, logLnb, wl,
131  bi);
132  gUpdate(pc, taken, sh->imliCount, im, igehl, inb, logInb, wi, bi);
133 }
134 
135 TAGE_SC_L_8KB::TAGE_SC_L_8KB(const TAGE_SC_L_8KBParams &params)
136  : TAGE_SC_L(params)
137 {
138 }
139 
140 void
142 {
143  // Some hardcoded values are used here
144  // (they do not seem to depend on any parameter)
145  for (int i = 1; i <= nHistoryTables; i++) {
146  history.computeIndices[i].init(
147  histLengths[i], 17 + (2 * ((i - 1) / 2) % 4));
148  history.computeTags[0][i].init(
149  history.computeIndices[i].origLength, 13);
150  history.computeTags[1][i].init(
151  history.computeIndices[i].origLength, 11);
152  DPRINTF(TageSCL, "HistLength:%d, TTSize:%d, TTTWidth:%d\n",
154  }
155 }
156 
157 int
159 {
160  return (index ^ (index >> logTagTableSizes[bank])
161  ^ (index >> 2 * logTagTableSizes[bank]));
162 }
163 
164 uint16_t
166 {
167  int tag = (threadHistory[tid].computeIndices[bank - 1].comp << 2) ^ pc ^
168  (pc >> instShiftAmt) ^
169  threadHistory[tid].computeIndices[bank].comp;
170  int hlen = (histLengths[bank] > pathHistBits) ? pathHistBits :
171  histLengths[bank];
172 
173  tag = (tag >> 1) ^ ((tag & 1) << 10) ^
174  F(threadHistory[tid].pathHist, hlen, bank);
175  tag ^= threadHistory[tid].computeTags[0][bank].comp ^
176  (threadHistory[tid].computeTags[1][bank].comp << 1);
177 
178  return ((tag ^ (tag >> tagTableTagWidths[bank]))
179  & ((ULL(1) << tagTableTagWidths[bank]) - 1));
180 }
181 
182 void
184  bool alloc, bool taken, TAGEBase::BranchInfo* bi, int nrand)
185 {
186  if (!alloc) {
187  return;
188  }
189 
190  int penalty = 0;
191  int truePen = 0;
192  int numAllocated = 0;
193  bool maxAllocReached = false;
194 
195  for (int I = calcDep(bi); I < nHistoryTables; I += 2) {
196  // Handle the 2-way associativity for allocation
197  for (int j = 0; j < 2; ++j) {
198  int i = ((j == 0) ? I : (I ^ 1)) + 1;
199  if (i > nHistoryTables) {
200  break;
201  }
202  if (noSkip[i]) {
203  if (gtable[i][bi->tableIndices[i]].u == 0) {
204  gtable[i][bi->tableIndices[i]].u =
205  ((random_mt.random<int>() & 31) == 0);
206  // protect randomly from fast replacement
207  gtable[i][bi->tableIndices[i]].tag = bi->tableTags[i];
208  gtable[i][bi->tableIndices[i]].ctr = taken ? 0 : -1;
209  numAllocated++;
210 
211  if (numAllocated == maxNumAlloc) {
212  maxAllocReached = true;
213  break;
214  }
215  I += 2;
216  } else {
217  int8_t ctr = gtable[i][bi->tableIndices[i]].ctr;
218  if ((gtable[i][bi->tableIndices[i]].u == 1) &
219  (abs (2 * ctr + 1) == 1)) {
220  if ((random_mt.random<int>() & 7) == 0) {
221  gtable[i][bi->tableIndices[i]].u = 0;
222  }
223  } else {
224  truePen++;
225  }
226  penalty++;
227  }
228  } else {
229  break;
230  }
231  }
232  if (maxAllocReached) {
233  break;
234  }
235  }
236 
237  tCounter += (truePen + penalty - 5 * numAllocated);
238 
239  handleUReset();
240 }
241 
242 void
244 {
245  // On real HW it should be u >>= 1 instead of if > 0 then u--
246  if (u > 0) {
247  u--;
248  }
249 }
250 
251 void
254 {
255  if (bi->hitBank > 0) {
256  if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
257  if (bi->longestMatchPred != taken) { // acts as a protection
258  if (bi->altBank > 0) {
259  int8_t ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
260  if (abs (2 * ctr + 1) == 1) {
261  gtable[bi->altBank][bi->altBankIndex].u = 0;
262  }
263 
264  //just mute from protected to unprotected
265  ctrUpdate(gtable[bi->altBank][bi->altBankIndex].ctr, taken,
267  ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
268  if (abs (2 * ctr + 1) == 1) {
269  gtable[bi->altBank][bi->altBankIndex].u = 0;
270  }
271  }
272  if (bi->altBank == 0) {
273  baseUpdate(branch_pc, taken, bi);
274  }
275  }
276  }
277 
278  //just mute from protected to unprotected
279  if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
280  gtable[bi->hitBank][bi->hitBankIndex].u = 0;
281  }
282 
283  ctrUpdate(gtable[bi->hitBank][bi->hitBankIndex].ctr, taken,
285 
286  //sign changes: no way it can have been useful
287  if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
288  gtable[bi->hitBank][bi->hitBankIndex].u = 0;
289  }
290 
291  if (bi->altTaken == taken) {
292  if (bi->altBank > 0) {
293  int8_t ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
294  if (abs (2*ctr + 1) == 7) {
295  if (gtable[bi->hitBank][bi->hitBankIndex].u == 1) {
296  if (bi->longestMatchPred == taken) {
297  gtable[bi->hitBank][bi->hitBankIndex].u = 0;
298  }
299  }
300  }
301  }
302  }
303  } else {
304  baseUpdate(branch_pc, taken, bi);
305  }
306 
307  if ((bi->longestMatchPred != bi->altTaken) &&
308  (bi->longestMatchPred == taken) &&
309  (gtable[bi->hitBank][bi->hitBankIndex].u < (1 << tagTableUBits) -1)) {
310  gtable[bi->hitBank][bi->hitBankIndex].u++;
311  }
312 }
TAGEBase::tagTableTagWidths
std::vector< unsigned > tagTableTagWidths
Definition: tage_base.hh:425
StaticInst::isDirectCtrl
bool isDirectCtrl() const
Definition: static_inst.hh:182
TAGE_SC_L_8KB_StatisticalCorrector::SC_8KB_ThreadHistory
Definition: tage_sc_l_8KB.hh:79
ArmISA::sh
Bitfield< 8, 7 > sh
Definition: miscregs_types.hh:654
TAGEBase::TageEntry::u
uint8_t u
Definition: tage_base.hh:72
TAGEBase::nHistoryTables
const unsigned nHistoryTables
Definition: tage_base.hh:417
MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:44
TAGE_SC_L_TAGE_8KB::gindex_ext
int gindex_ext(int index, int bank) const override
Definition: tage_sc_l_8KB.cc:158
TAGEBase::histLengths
int * histLengths
Definition: tage_base.hh:462
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:233
TAGE_SC_L_8KB_StatisticalCorrector::logGnb
const unsigned logGnb
Definition: tage_sc_l_8KB.hh:74
TAGE_SC_L_8KB::TAGE_SC_L_8KB
TAGE_SC_L_8KB(const TAGE_SC_L_8KBParams &params)
Definition: tage_sc_l_8KB.cc:135
TAGE_SC_L_TAGE::calcDep
int calcDep(TAGEBase::BranchInfo *bi)
Definition: tage_sc_l.cc:299
random.hh
TAGEBase::ThreadHistory::computeTags
FoldedHistory * computeTags[2]
Definition: tage_base.hh:452
TAGEBase::BranchInfo
Definition: tage_base.hh:120
StatisticalCorrector::logInb
const unsigned logInb
Definition: statistical_corrector.hh:157
TAGEBase::maxNumAlloc
unsigned maxNumAlloc
Definition: tage_base.hh:472
TAGE_SC_L_8KB_StatisticalCorrector::scHistoryUpdate
void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget) override
Definition: tage_sc_l_8KB.cc:104
StatisticalCorrector::lgehl
std::vector< int8_t > * lgehl
Definition: statistical_corrector.hh:152
TAGE_SC_L_8KB_StatisticalCorrector::wg
std::vector< int8_t > wg
Definition: tage_sc_l_8KB.hh:77
StatisticalCorrector::pUpdateThreshold
std::vector< int > pUpdateThreshold
Definition: statistical_corrector.hh:169
TAGEBase::ThreadHistory
Definition: tage_base.hh:434
TAGE_SC_L_8KB_StatisticalCorrector::TAGE_SC_L_8KB_StatisticalCorrector
TAGE_SC_L_8KB_StatisticalCorrector(const TAGE_SC_L_8KB_StatisticalCorrectorParams &p)
Definition: tage_sc_l_8KB.cc:47
TAGEBase::noSkip
std::vector< bool > noSkip
Definition: tage_base.hh:477
StatisticalCorrector::numEntriesFirstLocalHistories
const unsigned numEntriesFirstLocalHistories
Definition: statistical_corrector.hh:139
TAGE_SC_L_8KB_StatisticalCorrector::ggehl
std::vector< int8_t > * ggehl
Definition: tage_sc_l_8KB.hh:76
StatisticalCorrector::getIndUpd
virtual unsigned getIndUpd(Addr branch_pc) const
Definition: statistical_corrector.cc:165
StatisticalCorrector::wi
std::vector< int8_t > wi
Definition: statistical_corrector.hh:160
Random::random
std::enable_if_t< std::is_integral< T >::value, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:86
StatisticalCorrector::SCThreadHistory
Definition: statistical_corrector.hh:69
StatisticalCorrector::logLnb
const unsigned logLnb
Definition: statistical_corrector.hh:150
random_mt
Random random_mt
Definition: random.cc:96
TAGE_SC_L_8KB_StatisticalCorrector::gPredictions
int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum, int64_t phist) override
Definition: tage_sc_l_8KB.cc:75
StatisticalCorrector::bwgehl
std::vector< int8_t > * bwgehl
Definition: statistical_corrector.hh:145
TAGEBase::threadHistory
std::vector< ThreadHistory > threadHistory
Definition: tage_base.hh:455
PowerISA::bi
Bitfield< 20, 16 > bi
Definition: types.hh:63
TAGE_SC_L_8KB_StatisticalCorrector::gUpdates
void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi, int64_t phist) override
Definition: tage_sc_l_8KB.cc:124
ArmISA::j
Bitfield< 24 > j
Definition: miscregs_types.hh:54
TAGE_SC_L_TAGE_8KB::initFoldedHistories
void initFoldedHistories(ThreadHistory &history) override
Initialization of the folded histories.
Definition: tage_sc_l_8KB.cc:141
TAGEBase::tCounter
int64_t tCounter
Definition: tage_base.hh:467
TAGEBase::pathHistBits
const unsigned pathHistBits
Definition: tage_base.hh:423
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
TAGE_SC_L_TAGE_8KB::gtag
uint16_t gtag(ThreadID tid, Addr pc, int bank) const override
Computes the partial tag of a tagged table.
Definition: tage_sc_l_8KB.cc:165
StatisticalCorrector::gUpdate
virtual void gUpdate(Addr branch_pc, bool taken, int64_t hist, std::vector< int > &length, std::vector< int8_t > *tab, int nbr, int logs, std::vector< int8_t > &w, BranchInfo *bi)
Definition: statistical_corrector.cc:203
TAGE_SC_L_TAGE_8KB::handleAllocAndUReset
void handleAllocAndUReset(bool alloc, bool taken, TAGEBase::BranchInfo *bi, int nrand) override
Handles Allocation and U bits reset on an update.
Definition: tage_sc_l_8KB.cc:183
StatisticalCorrector::wbw
std::vector< int8_t > wbw
Definition: statistical_corrector.hh:146
TAGE_SC_L_TAGE::F
int F(int phist, int size, int bank) const override
Utility function to shuffle the path history depending on which tagged table we are accessing.
Definition: tage_sc_l.cc:193
StatisticalCorrector::lm
std::vector< int > lm
Definition: statistical_corrector.hh:151
TAGE_SC_L
Definition: tage_sc_l.hh:148
TAGE_SC_L_TAGE::handleUReset
void handleUReset() override
Handles the U bits reset.
Definition: tage_sc_l.cc:310
TAGEBase::baseUpdate
void baseUpdate(Addr pc, bool taken, BranchInfo *bi)
Updates the bimodal predictor.
Definition: tage_base.cc:296
TAGEBase::TageEntry::ctr
int8_t ctr
Definition: tage_base.hh:70
StatisticalCorrector::im
std::vector< int > im
Definition: statistical_corrector.hh:158
TAGEBase::logTagTableSizes
std::vector< int > logTagTableSizes
Definition: tage_base.hh:426
TAGE_SC_L_8KB_StatisticalCorrector::makeThreadHistory
SCThreadHistory * makeThreadHistory() override
Definition: tage_sc_l_8KB.cc:58
TAGE_SC_L_TAGE_8KB::handleTAGEUpdate
void handleTAGEUpdate(Addr branch_pc, bool taken, TAGEBase::BranchInfo *bi) override
Handles the update of the TAGE entries.
Definition: tage_sc_l_8KB.cc:252
TAGEBase::tagTableCounterBits
const unsigned tagTableCounterBits
Definition: tage_base.hh:418
StatisticalCorrector::scHistory
SCThreadHistory * scHistory
Definition: statistical_corrector.hh:132
StatisticalCorrector::updateThreshold
int updateThreshold
Definition: statistical_corrector.hh:168
TAGEBase::TageEntry::tag
uint16_t tag
Definition: tage_base.hh:71
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
TAGE_SC_L_8KB_StatisticalCorrector::gnb
const unsigned gnb
Definition: tage_sc_l_8KB.hh:73
StatisticalCorrector::scHistoryUpdate
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget)
Definition: statistical_corrector.cc:289
StatisticalCorrector::initGEHLTable
void initGEHLTable(unsigned numLenghts, std::vector< int > lengths, std::vector< int8_t > *&table, unsigned logNumEntries, std::vector< int8_t > &w, int8_t wInitValue)
Definition: statistical_corrector.cc:128
TAGEBase::ctrUpdate
static void ctrUpdate(T &ctr, bool taken, int nbits)
Updates a direction counter based on the actual branch outcome.
Definition: tage_base.cc:255
StatisticalCorrector::inb
const unsigned inb
Definition: statistical_corrector.hh:156
StatisticalCorrector::wl
std::vector< int8_t > wl
Definition: statistical_corrector.hh:153
TAGEBase::gtable
TageEntry ** gtable
Definition: tage_base.hh:430
ArmISA::u
Bitfield< 22 > u
Definition: miscregs_types.hh:348
tage_sc_l_8KB.hh
StatisticalCorrector::logBwnb
const unsigned logBwnb
Definition: statistical_corrector.hh:143
TAGEBase::FoldedHistory::init
void init(int original_length, int compressed_length)
Definition: tage_base.hh:92
TAGEBase::instShiftAmt
const unsigned instShiftAmt
Definition: tage_base.hh:481
StatisticalCorrector::BranchInfo
Definition: statistical_corrector.hh:192
StatisticalCorrector::igehl
std::vector< int8_t > * igehl
Definition: statistical_corrector.hh:159
StatisticalCorrector
Definition: statistical_corrector.hh:52
StatisticalCorrector::gPredict
int gPredict(Addr branch_pc, int64_t hist, std::vector< int > &length, std::vector< int8_t > *tab, int nbr, int logs, std::vector< int8_t > &w)
Definition: statistical_corrector.cc:187
StatisticalCorrector::logBias
const unsigned logBias
Definition: statistical_corrector.hh:134
TAGEBase::FoldedHistory::origLength
int origLength
Definition: tage_base.hh:83
TAGE_SC_L_8KB_StatisticalCorrector::gIndexLogsSubstr
int gIndexLogsSubstr(int nbr, int i) override
Definition: tage_sc_l_8KB.cc:98
TAGEBase::tagTableUBits
const unsigned tagTableUBits
Definition: tage_base.hh:419
StatisticalCorrector::lnb
const unsigned lnb
Definition: statistical_corrector.hh:149
RefCountingPtr< StaticInst >
StatisticalCorrector::bwnb
const unsigned bwnb
Definition: statistical_corrector.hh:142
TAGE_SC_L_8KB_StatisticalCorrector::gm
std::vector< int > gm
Definition: tage_sc_l_8KB.hh:75
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
TAGEBase::ThreadHistory::computeIndices
FoldedHistory * computeIndices
Definition: tage_base.hh:451
TAGE_SC_L_TAGE_8KB::resetUctr
void resetUctr(uint8_t &u) override
Algorithm for resetting a single U counter.
Definition: tage_sc_l_8KB.cc:243
ULL
#define ULL(N)
uint64_t constant
Definition: types.hh:46
TAGE_SC_L_8KB_StatisticalCorrector::getIndBiasBank
unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const override
Definition: tage_sc_l_8KB.cc:67
StaticInst::isUncondCtrl
bool isUncondCtrl() const
Definition: static_inst.hh:185
StatisticalCorrector::bwm
std::vector< int > bwm
Definition: statistical_corrector.hh:144

Generated on Tue Mar 23 2021 19:41:25 for gem5 by doxygen 1.8.17