gem5  v20.0.0.3
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 struct LoopPredictorParams;
42 
43 class LoopPredictor : public SimObject
44 {
45  protected:
46  const unsigned logSizeLoopPred;
47  const unsigned loopTableAgeBits;
48  const unsigned loopTableConfidenceBits;
49  const unsigned loopTableTagBits;
50  const unsigned loopTableIterBits;
51  const unsigned logLoopTableAssoc;
52  const uint8_t confidenceThreshold;
53  const uint16_t loopTagMask;
54  const uint16_t loopNumIterMask;
55  const int loopSetMask;
56 
57  // Prediction Structures
58  // Loop Predictor Entry
59  struct LoopEntry
60  {
61  uint16_t numIter;
62  uint16_t currentIter;
63  uint16_t currentIterSpec; // only for useSpeculation
64  uint8_t confidence;
65  uint16_t tag;
66  uint8_t age;
67  bool dir; // only for useDirectionBit
68 
69  LoopEntry() : numIter(0), currentIter(0), currentIterSpec(0),
70  confidence(0), tag(0), age(0), dir(0) { }
71  };
72 
74 
76  unsigned withLoopBits;
77 
78  const bool useDirectionBit;
79  const bool useSpeculation;
80  const bool useHashing;
81  const bool restrictAllocation;
82  const unsigned initialLoopIter;
83  const unsigned initialLoopAge;
84  const bool optionalAgeReset;
85 
86  // stats
89 
97  static inline void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
98  {
99  assert(nbits <= sizeof(uint8_t) << 3);
100  if (up) {
101  if (ctr < ((1 << nbits) - 1))
102  ctr++;
103  } else {
104  if (ctr)
105  ctr--;
106  }
107  }
108  static inline void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
109  {
110  if (up) {
111  if (ctr < ((1 << (nbits - 1)) - 1))
112  ctr++;
113  } else {
114  if (ctr > -(1 << (nbits - 1)))
115  ctr--;
116  }
117  }
118  public:
119  // Primary branch history entry
120  struct BranchInfo
121  {
122  uint16_t loopTag;
123  uint16_t currentIter;
124 
125  bool loopPred;
129  int loopIndexB; // only for useHashing
130  int loopHit;
131  bool predTaken;
132 
134  : loopTag(0), currentIter(0),
135  loopPred(false),
136  loopPredValid(false), loopIndex(0), loopIndexB(0), loopHit(0),
137  predTaken(false)
138  {}
139  };
140 
147  int lindex(Addr pc_in, unsigned instShiftAmt) const;
148 
157  int finallindex(int lindex, int lowPcBits, int way) const;
158 
170  bool getLoop(Addr pc, BranchInfo* bi, bool speculative,
171  unsigned instShiftAmt) const;
172 
181  void loopUpdate(Addr pc, bool Taken, BranchInfo* bi, bool tage_pred);
182 
190  void specLoopUpdate(bool taken, BranchInfo* bi);
191 
201  void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken,
202  bool tage_pred, BranchInfo* bi, unsigned instShiftAmt);
203 
217  bool loopPredict(
218  ThreadID tid, Addr branch_pc, bool cond_branch,
219  BranchInfo* bi, bool prev_pred_taken, unsigned instShiftAmt);
220 
227  void updateStats(bool taken, BranchInfo* bi);
228 
229  void squashLoop(BranchInfo * bi);
230 
231  void squash(ThreadID tid, BranchInfo *bi);
232 
233  virtual bool calcConf(int index) const;
234 
235  virtual bool optionalAgeInc() const;
236 
237  virtual BranchInfo *makeBranchInfo();
238 
243  int8_t getLoopUseCounter() const
244  {
245  return loopUseCounter;
246  }
247 
251  void init() override;
252 
256  void regStats() override;
257 
258  LoopPredictor(LoopPredictorParams *p);
259 
260  size_t getSizeInBits() const;
261 };
262 #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:63
Declaration of Statistics objects.
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2505
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:140
static void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
const unsigned loopTableIterBits
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:225
Bitfield< 23 > up
Definition: types.hh:132
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:93
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 Jul 3 2020 15:53:00 for gem5 by doxygen 1.8.13