gem5  v22.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 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__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Abstract superclass for simulation objects.
Definition: sim_object.hh:148
void initGEHLTable(unsigned numLenghts, std::vector< int > lengths, std::vector< int8_t > *&table, unsigned logNumEntries, std::vector< int8_t > &w, int8_t wInitValue)
gem5::branch_prediction::StatisticalCorrector::StatisticalCorrectorStats stats
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget)
virtual void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi, int64_t phist)=0
virtual unsigned getIndBiasSK(Addr branch_pc, BranchInfo *bi) const
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)
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)
StatisticalCorrector(const StatisticalCorrectorParams &p)
virtual unsigned getIndUpd(Addr branch_pc) const
virtual unsigned getIndBias(Addr branch_pc, BranchInfo *bi, bool b) const
void ctrUpdate(T &ctr, bool taken, int nbits)
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)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
virtual int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum, int64_t phist)=0
virtual unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const =0
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, Addr corrTarget, bool bias_bit, int hitBank, int altBank, int64_t phist)
virtual int gIndexLogsSubstr(int nbr, int i)=0
int64_t gIndex(Addr branch_pc, int64_t bhist, int logs, int nbr, int i)
Statistics container.
Definition: group.hh:94
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1931
static constexpr bool isPowerOf2(const T &n)
Definition: intmath.hh:98
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 6, 5 > shift
Definition: types.hh:117
Bitfield< 4 > pc
Bitfield< 20, 16 > bi
Definition: types.hh:80
Bitfield< 6 > w
Definition: pagetable.hh:59
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:235
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
Declaration of Statistics objects.
void initLocalHistory(int ordinal, int numHistories, int shift)
void updateLocalHistory(int ordinal, Addr branch_pc, bool taken, Addr extraXor=0)

Generated on Wed Dec 21 2022 10:22:31 for gem5 by doxygen 1.9.1