gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
tage.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022-2023 The University of Edinburgh
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2014 The University of Wisconsin
15 *
16 * Copyright (c) 2006 INRIA (Institut National de Recherche en
17 * Informatique et en Automatique / French National Research Institute
18 * for Computer Science and Applied Mathematics)
19 *
20 * All rights reserved.
21 *
22 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions are
24 * met: redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer;
26 * redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in the
28 * documentation and/or other materials provided with the distribution;
29 * neither the name of the copyright holders nor the names of its
30 * contributors may be used to endorse or promote products derived from
31 * this software without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
37 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
41 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45
46/* @file
47 * Implementation of a TAGE branch predictor
48 */
49
50#include "cpu/pred/tage.hh"
51
52#include "base/intmath.hh"
53#include "base/logging.hh"
54#include "base/random.hh"
55#include "base/trace.hh"
56#include "debug/Fetch.hh"
57#include "debug/Tage.hh"
58
59namespace gem5
60{
61
62namespace branch_prediction
63{
64
65TAGE::TAGE(const TAGEParams &params)
68{
69}
70
71// PREDICTOR UPDATE
72void
73TAGE::update(ThreadID tid, Addr pc, bool taken, void * &bp_history,
74 bool squashed, const StaticInstPtr & inst, Addr target)
75{
76 assert(bp_history);
77
78 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
79 TAGEBase::BranchInfo *tage_bi = bi->tageBranchInfo;
80
81 if (squashed) {
82 // This restores the global history, then update it
83 // and recomputes the folded histories.
84 tage->squash(tid, taken, target, inst, tage_bi);
85 return;
86 }
87
88 int nrand = rng->random<int>() & 3;
89 if (bi->tageBranchInfo->condBranch) {
90 DPRINTF(Tage, "Updating tables for branch:%lx; taken?:%d\n",
91 pc, taken);
92 tage->updateStats(taken, bi->tageBranchInfo);
93 tage->condBranchUpdate(tid, pc, taken, tage_bi, nrand,
94 target, bi->tageBranchInfo->tagePred);
95 }
96
97 // optional non speculative update of the histories
98 tage->updateHistories(tid, pc, false, taken, target, inst, tage_bi);
99 delete bi;
100 bp_history = nullptr;
101}
102
103void
104TAGE::squash(ThreadID tid, void * &bp_history)
105{
106 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
107 tage->restoreHistState(tid, bi->tageBranchInfo);
108 DPRINTF(Tage, "Deleting branch info: %lx\n", bi->tageBranchInfo->branchPC);
109 delete bi;
110 bp_history = nullptr;
111}
112
113bool
114TAGE::predict(ThreadID tid, Addr pc, bool cond_branch, void* &b)
115{
116 TageBranchInfo *bi = new TageBranchInfo(*tage, pc, cond_branch);
117 b = (void*)(bi);
118 return tage->tagePredict(tid, pc, cond_branch, bi->tageBranchInfo);
119}
120
121bool
122TAGE::lookup(ThreadID tid, Addr pc, void* &bp_history)
123{
124 bool retval = predict(tid, pc, true, bp_history);
125
126 DPRINTF(Tage, "Lookup branch: %lx; predict:%d\n", pc, retval);
127
128 return retval;
129}
130
131void
132TAGE::updateHistories(ThreadID tid, Addr pc, bool uncond, bool taken,
133 Addr target, const StaticInstPtr &inst,
134 void * &bp_history)
135{
136 if (bp_history == nullptr) {
137
138 // We should only see unconditional branches
139 assert(uncond);
140
141 predict(tid, pc, false, bp_history);
142 }
143
144 // Update the global history for all branches
145 TageBranchInfo *bi = static_cast<TageBranchInfo*>(bp_history);
146 tage->updateHistories(tid, pc, true, taken, target, inst,
147 bi->tageBranchInfo);
148}
149
150void
151TAGE::branchPlaceholder(ThreadID tid, Addr pc, bool uncond, void * &bpHistory)
152{
153 TageBranchInfo *bi = new TageBranchInfo(*tage, pc, !uncond);
154 bpHistory = (void*)(bi);
155}
156
157} // namespace branch_prediction
158} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
Random::RandomPtr rng
Definition tage.hh:82
TAGE(const TAGEParams &params)
Definition tage.cc:65
void updateHistories(ThreadID tid, Addr pc, bool uncond, bool taken, Addr target, const StaticInstPtr &inst, void *&bp_history) override
Ones done with the prediction this function updates the path and global history.
Definition tage.cc:132
bool lookup(ThreadID tid, Addr pc, void *&bp_history) override
Looks up a given conditional branch PC of in the BP to see if it is taken or not taken.
Definition tage.cc:122
virtual bool predict(ThreadID tid, Addr branch_pc, bool cond_branch, void *&b)
Definition tage.cc:114
void squash(ThreadID tid, void *&bp_history) override
Definition tage.cc:104
void branchPlaceholder(ThreadID tid, Addr pc, bool uncond, void *&bp_history) override
Special function for the decoupled front-end.
Definition tage.cc:151
void update(ThreadID tid, Addr pc, bool taken, void *&bp_history, bool squashed, const StaticInstPtr &inst, Addr target) override
Updates the BP with taken/not taken information.
Definition tage.cc:73
const Params & params() const
Bitfield< 7 > b
Bitfield< 4 > pc
Bitfield< 20, 16 > bi
Definition types.hh:80
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
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
RefCountingPtr< StaticInst > StaticInstPtr

Generated on Mon Oct 27 2025 04:13:01 for gem5 by doxygen 1.14.0