gem5  v20.1.0.0
statistical_corrector.hh
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  * Statistical corrector base class
40  */
41 
42 #ifndef __CPU_PRED_STATISTICAL_CORRECTOR_HH
43 #define __CPU_PRED_STATISTICAL_CORRECTOR_HH
44 
45 #include "base/statistics.hh"
46 #include "base/types.hh"
47 #include "cpu/static_inst.hh"
48 #include "sim/sim_object.hh"
49 
50 struct StatisticalCorrectorParams;
51 
53 {
54  protected:
55  template<typename T>
56  inline void ctrUpdate(T & ctr, bool taken, int nbits) {
57  assert(nbits <= sizeof(T) << 3);
58  if (nbits > 0) {
59  if (taken) {
60  if (ctr < ((1 << (nbits - 1)) - 1))
61  ctr++;
62  } else {
63  if (ctr > -(1 << (nbits - 1)))
64  ctr--;
65  }
66  }
67  }
68  // histories used for the statistical corrector
69  struct SCThreadHistory {
71  bwHist = 0;
73  imliCount = 0;
74  }
75  int64_t bwHist; // backward global history
76  int64_t imliCount;
77 
78  void setNumOrdinalHistories(unsigned num)
79  {
80  numOrdinalHistories = num;
81  assert(num > 0);
82  shifts.resize(num);
84  }
85 
86  void initLocalHistory(int ordinal, int numHistories, int shift)
87  {
88  assert((ordinal >= 1) && (ordinal <= numOrdinalHistories));
89  shifts[ordinal - 1] = shift;
90  assert(isPowerOf2(numHistories));
91  localHistories[ordinal - 1].resize(numHistories, 0);
92  }
93 
94  int64_t getLocalHistory(int ordinal, Addr pc)
95  {
96  assert((ordinal >= 1) && (ordinal <= numOrdinalHistories));
97  unsigned idx = ordinal - 1;
98  return localHistories[idx][getEntry(pc, idx)];
99  }
100 
102  int ordinal, Addr branch_pc, bool taken, Addr extraXor = 0)
103  {
104  assert((ordinal >= 1) && (ordinal <= numOrdinalHistories));
105  unsigned idx = ordinal - 1;
106 
107  unsigned entry = getEntry(branch_pc, idx);
108  int64_t hist = (localHistories[idx][entry] << 1) + taken;
109 
110  if (extraXor) {
111  hist = hist ^ extraXor;
112  }
113 
114  localHistories[idx][entry] = hist;
115  }
116 
117  private:
121 
122  unsigned getEntry(Addr pc, unsigned idx)
123  {
124  return (pc ^ (pc >> shifts[idx])) & (localHistories[idx].size()-1);
125  }
126  };
127 
128  // For SC history we use global (i.e. not per thread) non speculative
129  // histories, as some of the strucures needed are quite big and it is not
130  // reasonable to make them per thread and it would be difficult to
131  // rollback on miss-predictions
133 
134  const unsigned logBias;
135 
136  const unsigned logSizeUp;
137  const unsigned logSizeUps;
138 
140 
141  // global backward branch history GEHL
142  const unsigned bwnb;
143  const unsigned logBwnb;
147 
148  // First local history GEHL
149  const unsigned lnb;
150  const unsigned logLnb;
154 
155  // IMLI GEHL
156  const unsigned inb;
157  const unsigned logInb;
161 
165 
167 
170 
171  // The two counters used to choose between TAGE ang SC on High Conf
172  // TAGE/Low Conf SC
173  const unsigned chooserConfWidth;
174 
175  const unsigned updateThresholdWidth;
176  const unsigned pUpdateThresholdWidth;
177 
178  const unsigned extraWeightsWidth;
179 
180  const unsigned scCountersWidth;
181 
182  int8_t firstH;
183  int8_t secondH;
184 
189  } stats;
190 
191  public:
192  struct BranchInfo
193  {
194  BranchInfo() : lowConf(false), highConf(false), altConf(false),
195  medConf(false), scPred(false), lsum(0), thres(0),
196  predBeforeSC(false), usedScPred(false)
197  {}
198 
199  // confidences calculated on tage and used on the statistical
200  // correction
201  bool lowConf;
202  bool highConf;
203  bool altConf;
204  bool medConf;
205 
206  bool scPred;
207  int lsum;
208  int thres;
211  };
212 
213  StatisticalCorrector(const StatisticalCorrectorParams *p);
214 
215  virtual BranchInfo *makeBranchInfo();
217 
218  virtual void initBias();
219 
220  virtual bool scPredict(
221  ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo* bi,
222  bool prev_pred_taken, bool bias_bit, bool use_conf_ctr,
223  int8_t conf_ctr, unsigned conf_bits, int hitBank, int altBank,
224  int64_t phist, int init_lsum = 0);
225 
226  virtual unsigned getIndBias(Addr branch_pc, BranchInfo* bi, bool b) const;
227 
228  virtual unsigned getIndBiasSK(Addr branch_pc, BranchInfo* bi) const;
229 
230  virtual unsigned getIndBiasBank( Addr branch_pc, BranchInfo* bi,
231  int hitBank, int altBank) const = 0;
232 
233  virtual unsigned getIndUpd(Addr branch_pc) const;
234  unsigned getIndUpds(Addr branch_pc) const;
235 
236  virtual int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo* bi,
237  int & lsum, int64_t phist) = 0;
238 
239  int64_t gIndex(Addr branch_pc, int64_t bhist, int logs, int nbr, int i);
240 
241  virtual int gIndexLogsSubstr(int nbr, int i) = 0;
242 
243  int gPredict(
244  Addr branch_pc, int64_t hist, std::vector<int> & length,
245  std::vector<int8_t> * tab, int nbr, int logs,
247 
248  virtual void gUpdate(
249  Addr branch_pc, bool taken, int64_t hist, std::vector<int> & length,
250  std::vector<int8_t> * tab, int nbr, int logs,
252 
253  void initGEHLTable(
254  unsigned numLenghts, std::vector<int> lengths,
255  std::vector<int8_t> * & table, unsigned logNumEntries,
256  std::vector<int8_t> & w, int8_t wInitValue);
257 
258  virtual void scHistoryUpdate(
259  Addr branch_pc, const StaticInstPtr &inst , bool taken,
260  BranchInfo * tage_bi, Addr corrTarget);
261 
262  virtual void gUpdates( ThreadID tid, Addr pc, bool taken, BranchInfo* bi,
263  int64_t phist) = 0;
264 
265  void init() override;
266  void updateStats(bool taken, BranchInfo *bi);
267 
268  virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken,
269  BranchInfo *bi, Addr corrTarget, bool bias_bit,
270  int hitBank, int altBank, int64_t phist);
271 
272  virtual size_t getSizeInBits() const;
273 };
274 #endif//__CPU_PRED_STATISTICAL_CORRECTOR_HH
StatisticalCorrector::updateThresholdWidth
const unsigned updateThresholdWidth
Definition: statistical_corrector.hh:175
StatisticalCorrector::gUpdates
virtual void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi, int64_t phist)=0
StatisticalCorrector::SCThreadHistory::setNumOrdinalHistories
void setNumOrdinalHistories(unsigned num)
Definition: statistical_corrector.hh:78
StatisticalCorrector::logSizeUps
const unsigned logSizeUps
Definition: statistical_corrector.hh:137
StatisticalCorrector::secondH
int8_t secondH
Definition: statistical_corrector.hh:183
length
uint8_t length
Definition: inet.hh:422
StatisticalCorrector::getIndBiasBank
virtual unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const =0
StatisticalCorrector::gIndex
int64_t gIndex(Addr branch_pc, int64_t bhist, int logs, int nbr, int i)
Definition: statistical_corrector.cc:177
StatisticalCorrector::getSizeInBits
virtual size_t getSizeInBits() const
Definition: statistical_corrector.cc:394
StatisticalCorrector::BranchInfo::highConf
bool highConf
Definition: statistical_corrector.hh:202
StatisticalCorrector::makeThreadHistory
virtual SCThreadHistory * makeThreadHistory()
Definition: statistical_corrector.cc:93
StatisticalCorrector::gPredictions
virtual int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum, int64_t phist)=0
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
StatisticalCorrector::getIndUpds
unsigned getIndUpds(Addr branch_pc) const
Definition: statistical_corrector.cc:171
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
StatisticalCorrector::chooserConfWidth
const unsigned chooserConfWidth
Definition: statistical_corrector.hh:173
StatisticalCorrector::bias
std::vector< int8_t > bias
Definition: statistical_corrector.hh:162
StatisticalCorrector::BranchInfo::altConf
bool altConf
Definition: statistical_corrector.hh:203
StatisticalCorrector::StatisticalCorrector
StatisticalCorrector(const StatisticalCorrectorParams *p)
Definition: statistical_corrector.cc:46
StatisticalCorrector::logInb
const unsigned logInb
Definition: statistical_corrector.hh:157
StatisticalCorrector::lgehl
std::vector< int8_t > * lgehl
Definition: statistical_corrector.hh:152
std::vector< int64_t >
StatisticalCorrector::SCThreadHistory::localHistories
std::vector< int64_t > * localHistories
Definition: statistical_corrector.hh:118
StatisticalCorrector::scCountersWidth
const unsigned scCountersWidth
Definition: statistical_corrector.hh:180
StatisticalCorrector::getIndBias
virtual unsigned getIndBias(Addr branch_pc, BranchInfo *bi, bool b) const
Definition: statistical_corrector.cc:150
StatisticalCorrector::pUpdateThreshold
std::vector< int > pUpdateThreshold
Definition: statistical_corrector.hh:169
StatisticalCorrector::SCThreadHistory::initLocalHistory
void initLocalHistory(int ordinal, int numHistories, int shift)
Definition: statistical_corrector.hh:86
StatisticalCorrector::numEntriesFirstLocalHistories
const unsigned numEntriesFirstLocalHistories
Definition: statistical_corrector.hh:139
StatisticalCorrector::SCThreadHistory::numOrdinalHistories
unsigned numOrdinalHistories
Definition: statistical_corrector.hh:120
StatisticalCorrector::BranchInfo::lowConf
bool lowConf
Definition: statistical_corrector.hh:201
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
StatisticalCorrector::SCThreadHistory::shifts
std::vector< int > shifts
Definition: statistical_corrector.hh:119
StatisticalCorrector::StatisticalCorrectorStats::wrong
Stats::Scalar wrong
Definition: statistical_corrector.hh:188
StatisticalCorrector::SCThreadHistory
Definition: statistical_corrector.hh:69
StatisticalCorrector::logLnb
const unsigned logLnb
Definition: statistical_corrector.hh:150
StatisticalCorrector::SCThreadHistory::getEntry
unsigned getEntry(Addr pc, unsigned idx)
Definition: statistical_corrector.hh:122
Stats::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2533
StatisticalCorrector::bwgehl
std::vector< int8_t > * bwgehl
Definition: statistical_corrector.hh:145
PowerISA::bi
Bitfield< 20, 16 > bi
Definition: types.hh:63
StatisticalCorrector::makeBranchInfo
virtual BranchInfo * makeBranchInfo()
Definition: statistical_corrector.cc:87
StatisticalCorrector::SCThreadHistory::updateLocalHistory
void updateLocalHistory(int ordinal, Addr branch_pc, bool taken, Addr extraXor=0)
Definition: statistical_corrector.hh:101
StatisticalCorrector::biasBank
std::vector< int8_t > biasBank
Definition: statistical_corrector.hh:164
StatisticalCorrector::StatisticalCorrectorStats::correct
Stats::Scalar correct
Definition: statistical_corrector.hh:187
MipsISA::w
Bitfield< 0 > w
Definition: pra_constants.hh:278
sim_object.hh
ArmISA::shift
Bitfield< 6, 5 > shift
Definition: types.hh:126
StatisticalCorrector::BranchInfo::scPred
bool scPred
Definition: statistical_corrector.hh:206
StatisticalCorrector::StatisticalCorrectorStats::StatisticalCorrectorStats
StatisticalCorrectorStats(Stats::Group *parent)
Definition: statistical_corrector.cc:400
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
statistics.hh
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
StatisticalCorrector::wbw
std::vector< int8_t > wbw
Definition: statistical_corrector.hh:146
StatisticalCorrector::updateStats
void updateStats(bool taken, BranchInfo *bi)
Definition: statistical_corrector.cc:377
StatisticalCorrector::lm
std::vector< int > lm
Definition: statistical_corrector.hh:151
StatisticalCorrector::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: statistical_corrector.cc:387
StatisticalCorrector::im
std::vector< int > im
Definition: statistical_corrector.hh:158
StatisticalCorrector::stats
StatisticalCorrector::StatisticalCorrectorStats stats
StatisticalCorrector::logSizeUp
const unsigned logSizeUp
Definition: statistical_corrector.hh:136
StatisticalCorrector::gIndexLogsSubstr
virtual int gIndexLogsSubstr(int nbr, int i)=0
static_inst.hh
StatisticalCorrector::scHistory
SCThreadHistory * scHistory
Definition: statistical_corrector.hh:132
StatisticalCorrector::BranchInfo::predBeforeSC
bool predBeforeSC
Definition: statistical_corrector.hh:209
StatisticalCorrector::updateThreshold
int updateThreshold
Definition: statistical_corrector.hh:168
StatisticalCorrector::StatisticalCorrectorStats
Definition: statistical_corrector.hh:185
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
StatisticalCorrector::SCThreadHistory::bwHist
int64_t bwHist
Definition: statistical_corrector.hh:75
StatisticalCorrector::scPredict
virtual bool scPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, bool bias_bit, bool use_conf_ctr, int8_t conf_ctr, unsigned conf_bits, int hitBank, int altBank, int64_t phist, int init_lsum=0)
Definition: statistical_corrector.cc:224
StatisticalCorrector::BranchInfo::thres
int thres
Definition: statistical_corrector.hh:208
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
StatisticalCorrector::inb
const unsigned inb
Definition: statistical_corrector.hh:156
StatisticalCorrector::wl
std::vector< int8_t > wl
Definition: statistical_corrector.hh:153
StatisticalCorrector::biasSK
std::vector< int8_t > biasSK
Definition: statistical_corrector.hh:163
StatisticalCorrector::BranchInfo::lsum
int lsum
Definition: statistical_corrector.hh:207
StatisticalCorrector::getIndBiasSK
virtual unsigned getIndBiasSK(Addr branch_pc, BranchInfo *bi) const
Definition: statistical_corrector.cc:158
StatisticalCorrector::SCThreadHistory::imliCount
int64_t imliCount
Definition: statistical_corrector.hh:76
ArmISA::b
Bitfield< 7 > b
Definition: miscregs_types.hh:376
StatisticalCorrector::logBwnb
const unsigned logBwnb
Definition: statistical_corrector.hh:143
StatisticalCorrector::ctrUpdate
void ctrUpdate(T &ctr, bool taken, int nbits)
Definition: statistical_corrector.hh:56
types.hh
StatisticalCorrector::BranchInfo
Definition: statistical_corrector.hh:192
StatisticalCorrector::igehl
std::vector< int8_t > * igehl
Definition: statistical_corrector.hh:159
StatisticalCorrector::condBranchUpdate
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, Addr corrTarget, bool bias_bit, int hitBank, int altBank, int64_t phist)
Definition: statistical_corrector.cc:318
Stats::Group
Statistics container.
Definition: group.hh:83
StatisticalCorrector::firstH
int8_t firstH
Definition: statistical_corrector.hh:182
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
StatisticalCorrector::SCThreadHistory::getLocalHistory
int64_t getLocalHistory(int ordinal, Addr pc)
Definition: statistical_corrector.hh:94
StatisticalCorrector::pUpdateThresholdWidth
const unsigned pUpdateThresholdWidth
Definition: statistical_corrector.hh:176
StatisticalCorrector::BranchInfo::BranchInfo
BranchInfo()
Definition: statistical_corrector.hh:194
StatisticalCorrector::lnb
const unsigned lnb
Definition: statistical_corrector.hh:149
RefCountingPtr< StaticInst >
StatisticalCorrector::bwnb
const unsigned bwnb
Definition: statistical_corrector.hh:142
StatisticalCorrector::extraWeightsWidth
const unsigned extraWeightsWidth
Definition: statistical_corrector.hh:178
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
StatisticalCorrector::initBias
virtual void initBias()
Definition: statistical_corrector.cc:99
isPowerOf2
bool isPowerOf2(const T &n)
Definition: intmath.hh:102
StatisticalCorrector::BranchInfo::usedScPred
bool usedScPred
Definition: statistical_corrector.hh:210
StatisticalCorrector::SCThreadHistory::SCThreadHistory
SCThreadHistory()
Definition: statistical_corrector.hh:70
StatisticalCorrector::wb
std::vector< int8_t > wb
Definition: statistical_corrector.hh:166
StatisticalCorrector::BranchInfo::medConf
bool medConf
Definition: statistical_corrector.hh:204
StatisticalCorrector::bwm
std::vector< int > bwm
Definition: statistical_corrector.hh:144
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17