gem5  v21.1.0.2
loop_predictor.hh
Go to the documentation of this file.
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.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are
12  * met: redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer;
14  * redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution;
17  * neither the name of the copyright holders nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef __CPU_PRED_LOOP_PREDICTOR_HH__
35 #define __CPU_PRED_LOOP_PREDICTOR_HH__
36 
37 #include "base/statistics.hh"
38 #include "base/types.hh"
39 #include "sim/sim_object.hh"
40 
41 namespace gem5
42 {
43 
44 struct LoopPredictorParams;
45 
46 namespace branch_prediction
47 {
48 
49 class LoopPredictor : public SimObject
50 {
51  protected:
52  const unsigned logSizeLoopPred;
53  const unsigned loopTableAgeBits;
54  const unsigned loopTableConfidenceBits;
55  const unsigned loopTableTagBits;
56  const unsigned loopTableIterBits;
57  const unsigned logLoopTableAssoc;
58  const uint8_t confidenceThreshold;
59  const uint16_t loopTagMask;
60  const uint16_t loopNumIterMask;
61  const int loopSetMask;
62 
63  // Prediction Structures
64  // Loop Predictor Entry
65  struct LoopEntry
66  {
67  uint16_t numIter;
68  uint16_t currentIter;
69  uint16_t currentIterSpec; // only for useSpeculation
70  uint8_t confidence;
71  uint16_t tag;
72  uint8_t age;
73  bool dir; // only for useDirectionBit
74 
76  confidence(0), tag(0), age(0), dir(0) { }
77  };
78 
80 
82  unsigned withLoopBits;
83 
84  const bool useDirectionBit;
85  const bool useSpeculation;
86  const bool useHashing;
87  const bool restrictAllocation;
88  const unsigned initialLoopIter;
89  const unsigned initialLoopAge;
90  const bool optionalAgeReset;
91 
93  {
97  } stats;
98 
106  static inline void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
107  {
108  assert(nbits <= sizeof(uint8_t) << 3);
109  if (up) {
110  if (ctr < ((1 << nbits) - 1))
111  ctr++;
112  } else {
113  if (ctr)
114  ctr--;
115  }
116  }
117  static inline void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
118  {
119  if (up) {
120  if (ctr < ((1 << (nbits - 1)) - 1))
121  ctr++;
122  } else {
123  if (ctr > -(1 << (nbits - 1)))
124  ctr--;
125  }
126  }
127  public:
128  // Primary branch history entry
129  struct BranchInfo
130  {
131  uint16_t loopTag;
132  uint16_t currentIter;
133 
134  bool loopPred;
138  int loopIndexB; // only for useHashing
139  int loopHit;
140  bool predTaken;
141 
143  : loopTag(0), currentIter(0),
144  loopPred(false),
145  loopPredValid(false), loopIndex(0), loopIndexB(0), loopHit(0),
146  predTaken(false)
147  {}
148  };
149 
156  int lindex(Addr pc_in, unsigned instShiftAmt) const;
157 
166  int finallindex(int lindex, int lowPcBits, int way) const;
167 
179  bool getLoop(Addr pc, BranchInfo* bi, bool speculative,
180  unsigned instShiftAmt) const;
181 
190  void loopUpdate(Addr pc, bool Taken, BranchInfo* bi, bool tage_pred);
191 
199  void specLoopUpdate(bool taken, BranchInfo* bi);
200 
210  void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken,
211  bool tage_pred, BranchInfo* bi, unsigned instShiftAmt);
212 
226  bool loopPredict(
227  ThreadID tid, Addr branch_pc, bool cond_branch,
228  BranchInfo* bi, bool prev_pred_taken, unsigned instShiftAmt);
229 
236  void updateStats(bool taken, BranchInfo* bi);
237 
238  void squashLoop(BranchInfo * bi);
239 
240  void squash(ThreadID tid, BranchInfo *bi);
241 
242  virtual bool calcConf(int index) const;
243 
244  virtual bool optionalAgeInc() const;
245 
246  virtual BranchInfo *makeBranchInfo();
247 
252  int8_t getLoopUseCounter() const
253  {
254  return loopUseCounter;
255  }
256 
260  void init() override;
261 
262  LoopPredictor(const LoopPredictorParams &p);
263 
264  size_t getSizeInBits() const;
265 };
266 
267 } // namespace branch_prediction
268 } // namespace gem5
269 
270 #endif//__CPU_PRED_LOOP_PREDICTOR_HH__
gem5::statistics::Scalar
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:1927
gem5::branch_prediction::LoopPredictor::LoopEntry::currentIterSpec
uint16_t currentIterSpec
Definition: loop_predictor.hh:69
gem5::branch_prediction::LoopPredictor::BranchInfo::loopIndexB
int loopIndexB
Definition: loop_predictor.hh:138
gem5::branch_prediction::LoopPredictor::BranchInfo::loopHit
int loopHit
Definition: loop_predictor.hh:139
gem5::MipsISA::index
Bitfield< 30, 0 > index
Definition: pra_constants.hh:47
gem5::branch_prediction::LoopPredictor::lindex
int lindex(Addr pc_in, unsigned instShiftAmt) const
Computes the index used to access the loop predictor.
Definition: loop_predictor.cc:92
gem5::ArmISA::up
Bitfield< 23 > up
Definition: types.hh:124
gem5::branch_prediction::LoopPredictor::squashLoop
void squashLoop(BranchInfo *bi)
Definition: loop_predictor.cc:310
gem5::branch_prediction::LoopPredictor::LoopEntry::tag
uint16_t tag
Definition: loop_predictor.hh:71
gem5::branch_prediction::LoopPredictor::LoopEntry::confidence
uint8_t confidence
Definition: loop_predictor.hh:70
gem5::branch_prediction::LoopPredictor::logLoopTableAssoc
const unsigned logLoopTableAssoc
Definition: loop_predictor.hh:57
gem5::branch_prediction::LoopPredictor::init
void init() override
Initialize the loop predictor.
Definition: loop_predictor.cc:73
gem5::branch_prediction::LoopPredictor::initialLoopIter
const unsigned initialLoopIter
Definition: loop_predictor.hh:88
gem5::branch_prediction::LoopPredictor::squash
void squash(ThreadID tid, BranchInfo *bi)
Definition: loop_predictor.cc:299
gem5::branch_prediction::LoopPredictor::loopPredict
bool loopPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, unsigned instShiftAmt)
Get the loop prediction.
Definition: loop_predictor.cc:277
gem5::branch_prediction::LoopPredictor::loopSetMask
const int loopSetMask
Definition: loop_predictor.hh:61
gem5::branch_prediction::LoopPredictor::getSizeInBits
size_t getSizeInBits() const
Definition: loop_predictor.cc:367
gem5::branch_prediction::LoopPredictor::BranchInfo::loopPredUsed
bool loopPredUsed
Definition: loop_predictor.hh:136
gem5::PowerISA::bi
Bitfield< 20, 16 > bi
Definition: types.hh:80
gem5::branch_prediction::LoopPredictor::withLoopBits
unsigned withLoopBits
Definition: loop_predictor.hh:82
gem5::branch_prediction::LoopPredictor::LoopEntry::age
uint8_t age
Definition: loop_predictor.hh:72
gem5::branch_prediction::LoopPredictor::specLoopUpdate
void specLoopUpdate(bool taken, BranchInfo *bi)
Speculatively updates the loop predictor iteration count (only for useSpeculation).
Definition: loop_predictor.cc:162
gem5::branch_prediction::LoopPredictor::BranchInfo::loopPred
bool loopPred
Definition: loop_predictor.hh:134
gem5::branch_prediction::LoopPredictor::BranchInfo::loopPredValid
bool loopPredValid
Definition: loop_predictor.hh:135
gem5::branch_prediction::LoopPredictor::logSizeLoopPred
const unsigned logSizeLoopPred
Definition: loop_predictor.hh:52
gem5::branch_prediction::LoopPredictor::optionalAgeReset
const bool optionalAgeReset
Definition: loop_predictor.hh:90
gem5::branch_prediction::LoopPredictor::loopNumIterMask
const uint16_t loopNumIterMask
Definition: loop_predictor.hh:60
sim_object.hh
gem5::branch_prediction::LoopPredictor::signedCtrUpdate
static void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
Definition: loop_predictor.hh:117
gem5::branch_prediction::LoopPredictor::useDirectionBit
const bool useDirectionBit
Definition: loop_predictor.hh:84
gem5::branch_prediction::LoopPredictor::ltable
LoopEntry * ltable
Definition: loop_predictor.hh:79
gem5::branch_prediction::LoopPredictor::optionalAgeInc
virtual bool optionalAgeInc() const
Definition: loop_predictor.cc:176
gem5::branch_prediction::LoopPredictor::LoopEntry::LoopEntry
LoopEntry()
Definition: loop_predictor.hh:75
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
statistics.hh
gem5::branch_prediction::LoopPredictor::loopTableTagBits
const unsigned loopTableTagBits
Definition: loop_predictor.hh:55
gem5::branch_prediction::LoopPredictor::unsignedCtrUpdate
static void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
Updates an unsigned counter based on up/down parameter.
Definition: loop_predictor.hh:106
gem5::branch_prediction::LoopPredictor::loopTableConfidenceBits
const unsigned loopTableConfidenceBits
Definition: loop_predictor.hh:54
gem5::branch_prediction::LoopPredictor::loopTagMask
const uint16_t loopTagMask
Definition: loop_predictor.hh:59
gem5::branch_prediction::LoopPredictor::LoopEntry::currentIter
uint16_t currentIter
Definition: loop_predictor.hh:68
gem5::branch_prediction::LoopPredictor::condBranchUpdate
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, bool tage_pred, BranchInfo *bi, unsigned instShiftAmt)
Update LTAGE for conditional branches.
Definition: loop_predictor.cc:331
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::branch_prediction::LoopPredictor::LoopPredictorStats::LoopPredictorStats
LoopPredictorStats(statistics::Group *parent)
Definition: loop_predictor.cc:354
gem5::branch_prediction::LoopPredictor::loopUpdate
void loopUpdate(Addr pc, bool Taken, BranchInfo *bi, bool tage_pred)
Updates the loop predictor.
Definition: loop_predictor.cc:182
gem5::branch_prediction::LoopPredictor::BranchInfo::BranchInfo
BranchInfo()
Definition: loop_predictor.hh:142
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::LoopPredictor::useHashing
const bool useHashing
Definition: loop_predictor.hh:86
gem5::branch_prediction::LoopPredictor::initialLoopAge
const unsigned initialLoopAge
Definition: loop_predictor.hh:89
gem5::branch_prediction::LoopPredictor::finallindex
int finallindex(int lindex, int lowPcBits, int way) const
Computes the index used to access the ltable structures.
Definition: loop_predictor.cc:109
gem5::branch_prediction::LoopPredictor::getLoopUseCounter
int8_t getLoopUseCounter() const
Gets the value of the loop use counter.
Definition: loop_predictor.hh:252
gem5::branch_prediction::LoopPredictor::updateStats
void updateStats(bool taken, BranchInfo *bi)
Update the stats.
Definition: loop_predictor.cc:321
gem5::branch_prediction::LoopPredictor::LoopPredictorStats
Definition: loop_predictor.hh:92
types.hh
gem5::branch_prediction::LoopPredictor::getLoop
bool getLoop(Addr pc, BranchInfo *bi, bool speculative, unsigned instShiftAmt) const
Get a branch prediction from the loop predictor.
Definition: loop_predictor.cc:118
gem5::branch_prediction::LoopPredictor::loopUseCounter
int8_t loopUseCounter
Definition: loop_predictor.hh:81
gem5::branch_prediction::LoopPredictor::useSpeculation
const bool useSpeculation
Definition: loop_predictor.hh:85
gem5::branch_prediction::LoopPredictor::LoopEntry::numIter
uint16_t numIter
Definition: loop_predictor.hh:67
gem5::branch_prediction::LoopPredictor::LoopEntry::dir
bool dir
Definition: loop_predictor.hh:73
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::branch_prediction::LoopPredictor
Definition: loop_predictor.hh:49
gem5::branch_prediction::LoopPredictor::BranchInfo::currentIter
uint16_t currentIter
Definition: loop_predictor.hh:132
gem5::branch_prediction::LoopPredictor::confidenceThreshold
const uint8_t confidenceThreshold
Definition: loop_predictor.hh:58
gem5::branch_prediction::LoopPredictor::calcConf
virtual bool calcConf(int index) const
Definition: loop_predictor.cc:156
gem5::branch_prediction::LoopPredictor::loopTableAgeBits
const unsigned loopTableAgeBits
Definition: loop_predictor.hh:53
gem5::branch_prediction::LoopPredictor::loopTableIterBits
const unsigned loopTableIterBits
Definition: loop_predictor.hh:56
gem5::branch_prediction::LoopPredictor::LoopEntry
Definition: loop_predictor.hh:65
gem5::branch_prediction::LoopPredictor::BranchInfo::loopIndex
int loopIndex
Definition: loop_predictor.hh:137
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::branch_prediction::LoopPredictor::LoopPredictorStats::correct
statistics::Scalar correct
Definition: loop_predictor.hh:95
gem5::branch_prediction::LoopPredictor::BranchInfo
Definition: loop_predictor.hh:129
gem5::branch_prediction::LoopPredictor::LoopPredictor
LoopPredictor(const LoopPredictorParams &p)
Definition: loop_predictor.cc:47
gem5::branch_prediction::LoopPredictor::restrictAllocation
const bool restrictAllocation
Definition: loop_predictor.hh:87
gem5::branch_prediction::LoopPredictor::makeBranchInfo
virtual BranchInfo * makeBranchInfo()
Definition: loop_predictor.cc:86
gem5::branch_prediction::LoopPredictor::BranchInfo::predTaken
bool predTaken
Definition: loop_predictor.hh:140
gem5::branch_prediction::LoopPredictor::LoopPredictorStats::wrong
statistics::Scalar wrong
Definition: loop_predictor.hh:96
gem5::branch_prediction::LoopPredictor::BranchInfo::loopTag
uint16_t loopTag
Definition: loop_predictor.hh:131
gem5::ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:242
gem5::branch_prediction::LoopPredictor::stats
gem5::branch_prediction::LoopPredictor::LoopPredictorStats stats

Generated on Tue Sep 21 2021 12:25:05 for gem5 by doxygen 1.8.17