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

Generated on Thu Jul 28 2022 13:32:29 for gem5 by doxygen 1.8.17