gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Vignyan Reddy, Dibakar Gope and Arthur Perais,
34  * from André Seznec's code.
35  */
36 
37 #ifndef __CPU_PRED_LOOP_PREDICTOR_HH__
38 #define __CPU_PRED_LOOP_PREDICTOR_HH__
39 
40 #include "base/statistics.hh"
41 #include "base/types.hh"
42 #include "sim/sim_object.hh"
43 
44 struct LoopPredictorParams;
45 
46 class LoopPredictor : public SimObject
47 {
48  protected:
49  const unsigned logSizeLoopPred;
50  const unsigned loopTableAgeBits;
51  const unsigned loopTableConfidenceBits;
52  const unsigned loopTableTagBits;
53  const unsigned loopTableIterBits;
54  const unsigned logLoopTableAssoc;
55  const uint8_t confidenceThreshold;
56  const uint16_t loopTagMask;
57  const uint16_t loopNumIterMask;
58  const int loopSetMask;
59 
60  // Prediction Structures
61  // Loop Predictor Entry
62  struct LoopEntry
63  {
64  uint16_t numIter;
65  uint16_t currentIter;
66  uint16_t currentIterSpec; // only for useSpeculation
67  uint8_t confidence;
68  uint16_t tag;
69  uint8_t age;
70  bool dir; // only for useDirectionBit
71 
72  LoopEntry() : numIter(0), currentIter(0), currentIterSpec(0),
73  confidence(0), tag(0), age(0), dir(0) { }
74  };
75 
77 
79  unsigned withLoopBits;
80 
81  const bool useDirectionBit;
82  const bool useSpeculation;
83  const bool useHashing;
84  const bool restrictAllocation;
85  const unsigned initialLoopIter;
86  const unsigned initialLoopAge;
87  const bool optionalAgeReset;
88 
89  // stats
92 
100  static inline void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
101  {
102  assert(nbits <= sizeof(uint8_t) << 3);
103  if (up) {
104  if (ctr < ((1 << nbits) - 1))
105  ctr++;
106  } else {
107  if (ctr)
108  ctr--;
109  }
110  }
111  static inline void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
112  {
113  if (up) {
114  if (ctr < ((1 << (nbits - 1)) - 1))
115  ctr++;
116  } else {
117  if (ctr > -(1 << (nbits - 1)))
118  ctr--;
119  }
120  }
121  public:
122  // Primary branch history entry
123  struct BranchInfo
124  {
125  uint16_t loopTag;
126  uint16_t currentIter;
127 
128  bool loopPred;
132  int loopIndexB; // only for useHashing
133  int loopHit;
134  bool predTaken;
135 
137  : loopTag(0), currentIter(0),
138  loopPred(false),
139  loopPredValid(false), loopIndex(0), loopIndexB(0), loopHit(0),
140  predTaken(false)
141  {}
142  };
143 
150  int lindex(Addr pc_in, unsigned instShiftAmt) const;
151 
160  int finallindex(int lindex, int lowPcBits, int way) const;
161 
173  bool getLoop(Addr pc, BranchInfo* bi, bool speculative,
174  unsigned instShiftAmt) const;
175 
184  void loopUpdate(Addr pc, bool Taken, BranchInfo* bi, bool tage_pred);
185 
193  void specLoopUpdate(bool taken, BranchInfo* bi);
194 
204  void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken,
205  bool tage_pred, BranchInfo* bi, unsigned instShiftAmt);
206 
220  bool loopPredict(
221  ThreadID tid, Addr branch_pc, bool cond_branch,
222  BranchInfo* bi, bool prev_pred_taken, unsigned instShiftAmt);
223 
230  void updateStats(bool taken, BranchInfo* bi);
231 
232  void squashLoop(BranchInfo * bi);
233 
234  void squash(ThreadID tid, BranchInfo *bi);
235 
236  virtual bool calcConf(int index) const;
237 
238  virtual bool optionalAgeInc() const;
239 
240  virtual BranchInfo *makeBranchInfo();
241 
246  int8_t getLoopUseCounter() const
247  {
248  return loopUseCounter;
249  }
250 
254  void init() override;
255 
259  void regStats() override;
260 
261  LoopPredictor(LoopPredictorParams *p);
262 
263  size_t getSizeInBits() const;
264 };
265 #endif//__CPU_PRED_LOOP_PREDICTOR_HH__
bool getLoop(Addr pc, BranchInfo *bi, bool speculative, unsigned instShiftAmt) const
Get a branch prediction from the loop predictor.
LoopEntry * ltable
void squashLoop(BranchInfo *bi)
const bool optionalAgeReset
Bitfield< 30, 0 > index
void squash(ThreadID tid, BranchInfo *bi)
Stats::Scalar loopPredictorCorrect
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, bool tage_pred, BranchInfo *bi, unsigned instShiftAmt)
Update LTAGE for conditional branches.
virtual BranchInfo * makeBranchInfo()
const unsigned loopTableAgeBits
const int loopSetMask
const bool useDirectionBit
Bitfield< 20, 16 > bi
Definition: types.hh:65
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
void init() override
Initialize the loop predictor.
Stats::Scalar loopPredictorWrong
const uint16_t loopNumIterMask
const unsigned loopTableConfidenceBits
const unsigned logLoopTableAssoc
Bitfield< 4 > pc
static void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
Updates an unsigned counter based on up/down parameter.
virtual bool calcConf(int index) const
int lindex(Addr pc_in, unsigned instShiftAmt) const
Computes the index used to access the loop predictor.
int finallindex(int lindex, int lowPcBits, int way) const
Computes the index used to access the ltable structures.
size_t getSizeInBits() const
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
static void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
const unsigned loopTableIterBits
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
Bitfield< 23 > up
Definition: types.hh:134
const uint8_t confidenceThreshold
const bool useHashing
void specLoopUpdate(bool taken, BranchInfo *bi)
Speculatively updates the loop predictor iteration count (only for useSpeculation).
void regStats() override
Register stats for this object.
LoopPredictor(LoopPredictorParams *p)
const unsigned loopTableTagBits
const unsigned initialLoopAge
const uint16_t loopTagMask
const unsigned logSizeLoopPred
const unsigned initialLoopIter
const bool useSpeculation
unsigned withLoopBits
int8_t getLoopUseCounter() const
Gets the value of the loop use counter.
Bitfield< 0 > p
bool loopPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, unsigned instShiftAmt)
Get the loop prediction.
int8_t loopUseCounter
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
void loopUpdate(Addr pc, bool Taken, BranchInfo *bi, bool tage_pred)
Updates the loop predictor.
const bool restrictAllocation
void updateStats(bool taken, BranchInfo *bi)
Update the stats.
virtual bool optionalAgeInc() const

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13