gem5  v22.1.0.0
ltage.cc
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 /* @file
35  * Implementation of a L-TAGE branch predictor
36  */
37 
38 #include "cpu/pred/ltage.hh"
39 
40 #include "base/intmath.hh"
41 #include "base/logging.hh"
42 #include "base/random.hh"
43 #include "base/trace.hh"
44 #include "debug/Fetch.hh"
45 #include "debug/LTage.hh"
46 
47 namespace gem5
48 {
49 
50 namespace branch_prediction
51 {
52 
53 LTAGE::LTAGE(const LTAGEParams &params)
54  : TAGE(params), loopPredictor(params.loop_predictor)
55 {
56 }
57 
58 void
60 {
61  TAGE::init();
62 }
63 
64 //prediction
65 bool
66 LTAGE::predict(ThreadID tid, Addr branch_pc, bool cond_branch, void* &b)
67 {
69  b = (void*)(bi);
70 
71  bool pred_taken = tage->tagePredict(tid, branch_pc, cond_branch,
72  bi->tageBranchInfo);
73 
74  pred_taken = loopPredictor->loopPredict(tid, branch_pc, cond_branch,
75  bi->lpBranchInfo, pred_taken,
76  instShiftAmt);
77  if (cond_branch) {
78  if (bi->lpBranchInfo->loopPredUsed) {
79  bi->tageBranchInfo->provider = LOOP;
80  }
81  DPRINTF(LTage, "Predict for %lx: taken?:%d, loopTaken?:%d, "
82  "loopValid?:%d, loopUseCounter:%d, tagePred:%d, altPred:%d\n",
83  branch_pc, pred_taken, bi->lpBranchInfo->loopPred,
84  bi->lpBranchInfo->loopPredValid,
86  bi->tageBranchInfo->tagePred, bi->tageBranchInfo->altTaken);
87  }
88 
89  // record final prediction
90  bi->lpBranchInfo->predTaken = pred_taken;
91 
92  return pred_taken;
93 }
94 
95 // PREDICTOR UPDATE
96 void
97 LTAGE::update(ThreadID tid, Addr branch_pc, bool taken, void* bp_history,
98  bool squashed, const StaticInstPtr & inst, Addr corrTarget)
99 {
100  assert(bp_history);
101 
102  LTageBranchInfo* bi = static_cast<LTageBranchInfo*>(bp_history);
103 
104  if (squashed) {
106  // This restores the global history, then update it
107  // and recomputes the folded histories.
108  tage->squash(tid, taken, bi->tageBranchInfo, corrTarget);
109 
110  if (bi->tageBranchInfo->condBranch) {
111  loopPredictor->squashLoop(bi->lpBranchInfo);
112  }
113  }
114  return;
115  }
116 
117  int nrand = random_mt.random<int>() & 3;
118  if (bi->tageBranchInfo->condBranch) {
119  DPRINTF(LTage, "Updating tables for branch:%lx; taken?:%d\n",
120  branch_pc, taken);
121  tage->updateStats(taken, bi->tageBranchInfo);
122 
123  loopPredictor->updateStats(taken, bi->lpBranchInfo);
124 
125  loopPredictor->condBranchUpdate(tid, branch_pc, taken,
126  bi->tageBranchInfo->tagePred, bi->lpBranchInfo, instShiftAmt);
127 
128  tage->condBranchUpdate(tid, branch_pc, taken, bi->tageBranchInfo,
129  nrand, corrTarget, bi->lpBranchInfo->predTaken);
130  }
131 
132  tage->updateHistories(tid, branch_pc, taken, bi->tageBranchInfo, false,
133  inst, corrTarget);
134 
135  delete bi;
136 }
137 
138 void
139 LTAGE::squash(ThreadID tid, void *bp_history)
140 {
141  LTageBranchInfo* bi = (LTageBranchInfo*)(bp_history);
142 
143  if (bi->tageBranchInfo->condBranch) {
144  loopPredictor->squash(tid, bi->lpBranchInfo);
145  }
146 
147  TAGE::squash(tid, bp_history);
148 }
149 
150 } // namespace branch_prediction
151 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
Definition: bpred_unit.hh:341
void squash(ThreadID tid, void *bp_history) override
Definition: ltage.cc:139
void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, bool squashed, const StaticInstPtr &inst, Addr corrTarget) override
Updates the BP with taken/not taken information.
Definition: ltage.cc:97
LTAGE(const LTAGEParams &params)
Definition: ltage.cc:53
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: ltage.cc:59
bool predict(ThreadID tid, Addr branch_pc, bool cond_branch, void *&b) override
Get a branch prediction from LTAGE.
Definition: ltage.cc:66
LoopPredictor * loopPredictor
The loop predictor object.
Definition: ltage.hh:81
void updateStats(bool taken, BranchInfo *bi)
Update the stats.
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, bool tage_pred, BranchInfo *bi, unsigned instShiftAmt)
Update LTAGE for conditional branches.
int8_t getLoopUseCounter() const
Gets the value of the loop use counter.
bool loopPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, unsigned instShiftAmt)
Get the loop prediction.
void squash(ThreadID tid, BranchInfo *bi)
virtual void updateHistories(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *b, bool speculative, const StaticInstPtr &inst=nullStaticInstPtr, Addr target=MaxAddr)
(Speculatively) updates global histories (path and direction).
Definition: tage_base.cc:588
virtual void updateStats(bool taken, BranchInfo *bi)
Update the stats.
Definition: tage_base.cc:662
virtual void squash(ThreadID tid, bool taken, BranchInfo *bi, Addr target)
Restores speculatively updated path and direction histories.
Definition: tage_base.cc:629
bool tagePredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi)
TAGE prediction called from TAGE::predict.
Definition: tage_base.cc:360
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, int nrand, Addr corrTarget, bool pred, bool preAdjustAlloc=false)
Update TAGE for conditional branches.
Definition: tage_base.cc:514
virtual void squash(ThreadID tid, void *bp_history) override
Definition: tage.cc:90
Random random_mt
Definition: random.cc:99
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
Definition: random.hh:90
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: sim_object.cc:76
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 20, 16 > bi
Definition: types.hh:80
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

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