gem5  v22.1.0.0
multiperspective_perceptron_tage.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Texas A&M University
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Author: Daniel A. Jiménez
31  * Adapted to gem5 by: Javier Bueno Hedo
32  *
33  */
34 
35 /*
36  * Multiperspective Perceptron Predictor with TAGE (by Daniel A. Jiménez)
37  */
38 
39 #ifndef __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_TAGE_HH__
40 #define __CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_TAGE_HH__
41 
45 #include "cpu/pred/tage_base.hh"
46 #include "params/MPP_LoopPredictor.hh"
47 #include "params/MPP_StatisticalCorrector.hh"
48 #include "params/MPP_TAGE.hh"
49 #include "params/MultiperspectivePerceptronTAGE.hh"
50 
51 namespace gem5
52 {
53 
54 namespace branch_prediction
55 {
56 
57 class MPP_TAGE : public TAGEBase
58 {
60  public:
62  {
64  {}
65  virtual ~BranchInfo()
66  {}
67  };
68 
69  MPP_TAGE(const MPP_TAGEParams &p) : TAGEBase(p),
71  {}
72 
73  void calculateParameters() override;
74  void handleTAGEUpdate(Addr branch_pc, bool taken, TAGEBase::BranchInfo* bi)
75  override;
76  void handleAllocAndUReset(bool alloc, bool taken, TAGEBase::BranchInfo* bi,
77  int nrand) override;
78  void handleUReset() override;
79  void resetUctr(uint8_t &u) override;
80  int bindex(Addr pc_in) const override;
81  bool isHighConfidence(TAGEBase::BranchInfo *bi) const override;
82 
83  unsigned getUseAltIdx(TAGEBase::BranchInfo* bi, Addr branch_pc) override;
84  void adjustAlloc(bool & alloc, bool taken, bool pred_taken) override;
85  void updateHistories(ThreadID tid, Addr branch_pc, bool taken,
86  TAGEBase::BranchInfo* b, bool speculative,
87  const StaticInstPtr &inst, Addr target) override;
88 
89  void updatePathAndGlobalHistory(ThreadHistory& tHist, int brtype,
90  bool taken, Addr branch_pc, Addr target);
91 };
92 
94 {
95  public:
96  MPP_LoopPredictor(const MPP_LoopPredictorParams &p) : LoopPredictor(p)
97  {}
98 
99  bool calcConf(int index) const override;
100  bool optionalAgeInc() const override;
101 };
102 
104 {
105  protected:
106  int8_t thirdH;
107  // global branch history variation GEHL
108  const unsigned pnb;
109  const unsigned logPnb;
113 
114  // global branch history GEHL
115  const unsigned gnb;
116  const unsigned logGnb;
120 
122  {
124  historyStackPointer(0) {}
125  int64_t globalHist; // global history
127  unsigned int historyStackPointer;
128 
129  int64_t getHistoryStackEntry() const
130  {
132  }
133 
134  void updateHistoryStack(Addr target, bool taken, bool is_call,
135  bool is_return)
136  {
137  unsigned int truncated_target = target;
139  (historyStack[historyStackPointer] << 1) ^ (truncated_target ^
140  (truncated_target >> 5) ^ taken);
141  if (is_return) {
143  historyStack.size();
144  }
145  if (is_call) {
146  int index = (historyStackPointer + 1) % historyStack.size();
149  }
150  }
151  unsigned int getPointer() const { return historyStackPointer; }
152  };
153 
154  public:
156  {
157  virtual ~BranchInfo()
158  {}
159  };
160  MPP_StatisticalCorrector(const MPP_StatisticalCorrectorParams &p);
161 
162  void initBias() override;
163  unsigned getIndBias(Addr branch_pc, StatisticalCorrector::BranchInfo* bi,
164  bool bias) const override;
166  const override;
167  unsigned getIndBiasBank(Addr branch_pc,
168  StatisticalCorrector::BranchInfo* bi, int hitBank,
169  int altBank) const override;
170  unsigned getIndUpd(Addr branch_pc) const override;
171  int gIndexLogsSubstr(int nbr, int i) override;
172 
173  bool scPredict(ThreadID tid, Addr branch_pc, bool cond_branch,
174  StatisticalCorrector::BranchInfo* bi, bool prev_pred_taken,
175  bool bias_bit, bool use_conf_ctr, int8_t conf_ctr,
176  unsigned conf_bits, int hitBank, int altBank, int64_t phist,
177  int init_lsum) override;
178 
179  void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken,
181  Addr corrTarget, bool b, int hitBank, int altBank,
182  int64_t phist) override;
183 
184  virtual void getBiasLSUM(Addr branch_pc,
185  StatisticalCorrector::BranchInfo *bi, int &lsum) const = 0;
186 
187  void gUpdate(
188  Addr branch_pc, bool taken, int64_t hist, std::vector<int> & length,
189  std::vector<int8_t> * tab, int nbr, int logs,
191 };
192 
194 {
198 
203  {
212  tageBranchInfo(tage.makeBranchInfo()),
213  lpBranchInfo(loopPredictor.makeBranchInfo()),
214  scBranchInfo(statisticalCorrector.makeBranchInfo()),
215  predictedTaken(false)
216  {}
218  {
219  delete tageBranchInfo;
220  delete lpBranchInfo;
221  delete scBranchInfo;
222  }
223  };
224 
225  unsigned int getIndex(ThreadID tid, MPPTAGEBranchInfo &bi,
226  const HistorySpec &spec, int index) const;
227  int computePartialSum(ThreadID tid, MPPTAGEBranchInfo &bi) const;
228  void updatePartial(ThreadID tid, MPPTAGEBranchInfo &bi, bool taken);
229  void updateHistories(ThreadID tid, MPPTAGEBranchInfo &bi, bool taken);
230 
231  public:
233  const MultiperspectivePerceptronTAGEParams &p);
234 
235  void init() override;
236 
237  bool lookup(ThreadID tid, Addr instPC, void * &bp_history) override;
238 
239  void update(ThreadID tid, Addr instPC, bool taken,
240  void *bp_history, bool squashed,
241  const StaticInstPtr & inst,
242  Addr corrTarget) override;
243  void uncondBranch(ThreadID tid, Addr pc, void * &bp_history) override;
244  void squash(ThreadID tid, void *bp_history) override;
245 
246 };
247 
248 } // namespace branch_prediction
249 } // namespace gem5
250 
251 #endif//__CPU_PRED_MULTIPERSPECTIVE_PERCEPTRON_TAGE_HH__
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, StatisticalCorrector::BranchInfo *bi) override
unsigned getIndBiasSK(Addr branch_pc, StatisticalCorrector::BranchInfo *bi) const override
unsigned getIndBias(Addr branch_pc, StatisticalCorrector::BranchInfo *bi, bool bias) const override
bool scPredict(ThreadID tid, Addr branch_pc, bool cond_branch, StatisticalCorrector::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) override
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, StatisticalCorrector::BranchInfo *bi, Addr corrTarget, bool b, int hitBank, int altBank, int64_t phist) override
unsigned getIndBiasBank(Addr branch_pc, StatisticalCorrector::BranchInfo *bi, int hitBank, int altBank) const override
virtual void getBiasLSUM(Addr branch_pc, StatisticalCorrector::BranchInfo *bi, int &lsum) const =0
MPP_StatisticalCorrector(const MPP_StatisticalCorrectorParams &p)
void handleAllocAndUReset(bool alloc, bool taken, TAGEBase::BranchInfo *bi, int nrand) override
Handles Allocation and U bits reset on an update.
void resetUctr(uint8_t &u) override
Algorithm for resetting a single U counter.
int bindex(Addr pc_in) const override
Computes the index used to access the bimodal table.
void calculateParameters() override
Calculates the history lengths and some other paramters in derived classes.
void updatePathAndGlobalHistory(ThreadHistory &tHist, int brtype, bool taken, Addr branch_pc, Addr target)
void updateHistories(ThreadID tid, Addr branch_pc, bool taken, TAGEBase::BranchInfo *b, bool speculative, const StaticInstPtr &inst, Addr target) override
(Speculatively) updates global histories (path and direction).
void handleTAGEUpdate(Addr branch_pc, bool taken, TAGEBase::BranchInfo *bi) override
Handles the update of the TAGE entries.
bool isHighConfidence(TAGEBase::BranchInfo *bi) const override
void adjustAlloc(bool &alloc, bool taken, bool pred_taken) override
Extra calculation to tell whether TAGE allocaitons may happen or not on an update For this base TAGE ...
unsigned getUseAltIdx(TAGEBase::BranchInfo *bi, Addr branch_pc) override
Calculation of the index for useAltPredForNewlyAllocated On this base TAGE implementation it is alway...
void handleUReset() override
Handles the U bits reset.
bool lookup(ThreadID tid, Addr instPC, void *&bp_history) override
Looks up a given PC in the BP to see if it is taken or not taken.
void update(ThreadID tid, Addr instPC, bool taken, void *bp_history, bool squashed, const StaticInstPtr &inst, Addr corrTarget) override
Updates the BP with taken/not taken information.
int computePartialSum(ThreadID tid, MPPTAGEBranchInfo &bi) const
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
MultiperspectivePerceptronTAGE(const MultiperspectivePerceptronTAGEParams &p)
void uncondBranch(ThreadID tid, Addr pc, void *&bp_history) override
unsigned int getIndex(ThreadID tid, MPPTAGEBranchInfo &bi, const HistorySpec &spec, int index) const
void updatePartial(ThreadID tid, MPPTAGEBranchInfo &bi, bool taken)
void updateHistories(ThreadID tid, MPPTAGEBranchInfo &bi, bool taken)
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 22 > u
Definition: misc_types.hh:359
Bitfield< 4 > pc
Bitfield< 30, 0 > index
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
void updateHistoryStack(Addr target, bool taken, bool is_call, bool is_return)
MPPTAGEBranchInfo(Addr pc, int pcshift, bool cond, TAGEBase &tage, LoopPredictor &loopPredictor, StatisticalCorrector &statisticalCorrector)

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