gem5  v22.1.0.0
tage.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 TAGE branch predictor
36  */
37 
38 #include "cpu/pred/tage.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/Tage.hh"
46 
47 namespace gem5
48 {
49 
50 namespace branch_prediction
51 {
52 
53 TAGE::TAGE(const TAGEParams &params) : BPredUnit(params), tage(params.tage)
54 {
55 }
56 
57 // PREDICTOR UPDATE
58 void
59 TAGE::update(ThreadID tid, Addr branch_pc, bool taken, void* bp_history,
60  bool squashed, const StaticInstPtr & inst, Addr corrTarget)
61 {
62  assert(bp_history);
63 
64  TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
65  TAGEBase::BranchInfo *tage_bi = bi->tageBranchInfo;
66 
67  if (squashed) {
68  // This restores the global history, then update it
69  // and recomputes the folded histories.
70  tage->squash(tid, taken, tage_bi, corrTarget);
71  return;
72  }
73 
74  int nrand = random_mt.random<int>() & 3;
75  if (bi->tageBranchInfo->condBranch) {
76  DPRINTF(Tage, "Updating tables for branch:%lx; taken?:%d\n",
77  branch_pc, taken);
78  tage->updateStats(taken, bi->tageBranchInfo);
79  tage->condBranchUpdate(tid, branch_pc, taken, tage_bi, nrand,
80  corrTarget, bi->tageBranchInfo->tagePred);
81  }
82 
83  // optional non speculative update of the histories
84  tage->updateHistories(tid, branch_pc, taken, tage_bi, false, inst,
85  corrTarget);
86  delete bi;
87 }
88 
89 void
90 TAGE::squash(ThreadID tid, void *bp_history)
91 {
92  TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
93  DPRINTF(Tage, "Deleting branch info: %lx\n", bi->tageBranchInfo->branchPC);
94  delete bi;
95 }
96 
97 bool
98 TAGE::predict(ThreadID tid, Addr branch_pc, bool cond_branch, void* &b)
99 {
100  TageBranchInfo *bi = new TageBranchInfo(*tage);//nHistoryTables+1);
101  b = (void*)(bi);
102  return tage->tagePredict(tid, branch_pc, cond_branch, bi->tageBranchInfo);
103 }
104 
105 bool
106 TAGE::lookup(ThreadID tid, Addr branch_pc, void* &bp_history)
107 {
108  bool retval = predict(tid, branch_pc, true, bp_history);
109 
110  TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
111 
112  DPRINTF(Tage, "Lookup branch: %lx; predict:%d\n", branch_pc, retval);
113 
114  tage->updateHistories(tid, branch_pc, retval, bi->tageBranchInfo, true);
115 
116  return retval;
117 }
118 
119 void
120 TAGE::btbUpdate(ThreadID tid, Addr branch_pc, void* &bp_history)
121 {
122  TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
123  tage->btbUpdate(tid, branch_pc, bi->tageBranchInfo);
124 }
125 
126 void
127 TAGE::uncondBranch(ThreadID tid, Addr br_pc, void* &bp_history)
128 {
129  DPRINTF(Tage, "UnConditionalBranch: %lx\n", br_pc);
130  predict(tid, br_pc, false, bp_history);
131  TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
132  tage->updateHistories(tid, br_pc, true, bi->tageBranchInfo, true);
133 }
134 
135 } // namespace branch_prediction
136 } // namespace gem5
#define DPRINTF(x,...)
Definition: trace.hh:186
Basically a wrapper class to hold both the branch predictor and the BTB.
Definition: bpred_unit.hh:69
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
void btbUpdate(ThreadID tid, Addr branch_addr, BranchInfo *&bi)
Definition: tage_base.cc:188
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
void btbUpdate(ThreadID tid, Addr branch_addr, void *&bp_history) override
If a branch is not taken, because the BTB address is invalid or missing, this function sets the appro...
Definition: tage.cc:120
TAGE(const TAGEParams &params)
Definition: tage.cc:53
bool lookup(ThreadID tid, Addr branch_addr, void *&bp_history) override
Looks up a given PC in the BP to see if it is taken or not taken.
Definition: tage.cc:106
virtual void squash(ThreadID tid, void *bp_history) override
Definition: tage.cc:90
void uncondBranch(ThreadID tid, Addr br_pc, void *&bp_history) override
Definition: tage.cc:127
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: tage.cc:59
virtual bool predict(ThreadID tid, Addr branch_pc, bool cond_branch, void *&b)
Definition: tage.cc:98
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
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