gem5 v24.0.0.0
Loading...
Searching...
No Matches
tage_sc_l_64KB.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Metempsy Technology Consulting
3 * All rights reserved.
4 *
5 * Copyright (c) 2006 INRIA (Institut National de Recherche en
6 * Informatique et en Automatique / French National Research Institute
7 * for Computer Science and Applied Mathematics)
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are
13 * met: redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer;
15 * redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution;
18 * neither the name of the copyright holders nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 * Author: André Seznec, Pau Cabre, Javier Bueno
35 *
36 */
37
38/*
39 * 64KB TAGE-SC-L branch predictor (devised by Andre Seznec)
40 */
41
43
44namespace gem5
45{
46
47namespace branch_prediction
48{
49
51 const TAGE_SC_L_64KB_StatisticalCorrectorParams &p)
53 numEntriesSecondLocalHistories(p.numEntriesSecondLocalHistories),
54 numEntriesThirdLocalHistories(p.numEntriesThirdLocalHistories),
55 pnb(p.pnb),
56 logPnb(p.logPnb),
57 pm(p.pm),
58 snb(p.snb),
59 logSnb(p.logSnb),
60 sm(p.sm),
61 tnb(p.tnb),
62 logTnb(p.logTnb),
63 tm(p.tm),
64 imnb(p.imnb),
65 logImnb(p.logImnb),
66 imm(p.imm)
67{
72
73}
74
77{
79
80 sh->setNumOrdinalHistories(3);
81 sh->initLocalHistory(1, numEntriesFirstLocalHistories, 2);
82 sh->initLocalHistory(2, numEntriesSecondLocalHistories, 5);
83 sh->initLocalHistory(3, numEntriesThirdLocalHistories, logTnb);
84
85 sh->imHist.resize(1 << im[0]);
86 return sh;
87}
88
89unsigned
91 BranchInfo* bi, int hitBank, int altBank) const
92{
93 return (bi->predBeforeSC + (((hitBank+1)/4)<<4) + (bi->highConf<<1) +
94 (bi->lowConf <<2) + ((altBank!=0)<<3) +
95 ((branch_pc^(branch_pc>>2))<<7)) & ((1<<logBias) -1);
96}
97
98int
100 BranchInfo* bi, int & lsum, int64_t pathHist)
101{
103 static_cast<SC_64KB_ThreadHistory *>(scHistory);
104
105 lsum += gPredict(
106 (branch_pc << 1) + bi->predBeforeSC, sh->bwHist, bwm,
108
109 lsum += gPredict(
110 branch_pc, pathHist, pm, pgehl, pnb, logPnb, wp);
111
112 lsum += gPredict(
113 branch_pc, sh->getLocalHistory(1, branch_pc), lm,
114 lgehl, lnb, logLnb, wl);
115
116 lsum += gPredict(
117 branch_pc, sh->getLocalHistory(2, branch_pc), sm,
118 sgehl, snb, logSnb, ws);
119
120 lsum += gPredict(
121 branch_pc, sh->getLocalHistory(3, branch_pc), tm,
122 tgehl, tnb, logTnb, wt);
123
124 lsum += gPredict(
125 branch_pc, sh->imHist[scHistory->imliCount], imm,
127
128 lsum += gPredict(
129 branch_pc, sh->imliCount, im, igehl, inb, logInb, wi);
130
131 int thres = (updateThreshold>>3) + pUpdateThreshold[getIndUpd(branch_pc)]
132 + 12*((wb[getIndUpds(branch_pc)] >= 0) + (wp[getIndUpds(branch_pc)] >= 0)
133 + (ws[getIndUpds(branch_pc)] >= 0) + (wt[getIndUpds(branch_pc)] >= 0)
134 + (wl[getIndUpds(branch_pc)] >= 0) + (wbw[getIndUpds(branch_pc)] >= 0)
135 + (wi[getIndUpds(branch_pc)] >= 0));
136
137 return thres;
138}
139
140int
142{
143 return (i >= (nbr - 2)) ? 1 : 0;
144}
145
146void
148 const StaticInstPtr &inst, bool taken, BranchInfo* tage_bi,
149 Addr corrTarget)
150{
151 int brtype = inst->isDirectCtrl() ? 0 : 2;
152 if (! inst->isUncondCtrl()) {
153 ++brtype;
154 }
155 // Non speculative SC histories update
156 if (brtype & 1) {
158 static_cast<SC_64KB_ThreadHistory *>(scHistory);
159 int64_t imliCount = sh->imliCount;
160 sh->imHist[imliCount] = (sh->imHist[imliCount] << 1)
161 + taken;
162 sh->updateLocalHistory(2, branch_pc, taken, branch_pc & 15);
163 sh->updateLocalHistory(3, branch_pc, taken);
164 }
165
166 StatisticalCorrector::scHistoryUpdate(branch_pc, inst, taken, tage_bi,
167 corrTarget);
168}
169
170void
172 bool taken, BranchInfo* bi, int64_t phist)
173{
175 static_cast<SC_64KB_ThreadHistory *>(scHistory);
176
177 gUpdate((pc << 1) + bi->predBeforeSC, taken, sh->bwHist, bwm,
178 bwgehl, bwnb, logBwnb, wbw, bi);
179
180 gUpdate(pc, taken, phist, pm,
181 pgehl, pnb, logPnb, wp, bi);
182
183 gUpdate(pc, taken, sh->getLocalHistory(1, pc), lm,
184 lgehl, lnb, logLnb, wl, bi);
185
186 gUpdate(pc, taken, sh->getLocalHistory(2, pc), sm,
187 sgehl, snb, logSnb, ws, bi);
188
189 gUpdate(pc, taken, sh->getLocalHistory(3, pc), tm,
190 tgehl, tnb, logTnb, wt, bi);
191
192 gUpdate(pc, taken, sh->imHist[scHistory->imliCount], imm,
193 imgehl, imnb, logImnb, wim, bi);
194
195 gUpdate(pc, taken, sh->imliCount, im,
196 igehl, inb, logInb, wi, bi);
197}
198
199int
201{
202 return index;
203}
204
205uint16_t
207{
208 // very similar to the TAGE implementation, but w/o shifting the pc
209 int tag = pc ^ threadHistory[tid].computeTags[0][bank].comp ^
210 (threadHistory[tid].computeTags[1][bank].comp << 1);
211
212 return (tag & ((1ULL << tagTableTagWidths[bank]) - 1));
213}
214
215void
217 bool alloc, bool taken, TAGEBase::BranchInfo* bi, int nrand)
218{
219 if (! alloc) {
220 return;
221 }
222
223 int penalty = 0;
224 int numAllocated = 0;
225 bool maxAllocReached = false;
226
227 for (int I = calcDep(bi); I < nHistoryTables; I += 2) {
228 // Handle the 2-way associativity for allocation
229 for (int j = 0; j < 2; ++j) {
230 int i = ((j == 0) ? I : (I ^ 1)) + 1;
231 if (noSkip[i]) {
232 if (gtable[i][bi->tableIndices[i]].u == 0) {
233 int8_t ctr = gtable[i][bi->tableIndices[i]].ctr;
234 if (abs (2 * ctr + 1) <= 3) {
235 gtable[i][bi->tableIndices[i]].tag = bi->tableTags[i];
236 gtable[i][bi->tableIndices[i]].ctr = taken ? 0 : -1;
237 numAllocated++;
238 maxAllocReached = (numAllocated == maxNumAlloc);
239 I += 2;
240 break;
241 } else {
242 if (gtable[i][bi->tableIndices[i]].ctr > 0) {
243 gtable[i][bi->tableIndices[i]].ctr--;
244 } else {
245 gtable[i][bi->tableIndices[i]].ctr++;
246 }
247 }
248 } else {
249 penalty++;
250 }
251 }
252 }
253 if (maxAllocReached) {
254 break;
255 }
256 }
257
258 tCounter += (penalty - 2 * numAllocated);
259
260 handleUReset();
261}
262
263void
266{
267 if (bi->hitBank > 0) {
268 if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
269 if (bi->longestMatchPred != taken) {
270 // acts as a protection
271 if (bi->altBank > 0) {
272 ctrUpdate(gtable[bi->altBank][bi->altBankIndex].ctr, taken,
274 }
275 if (bi->altBank == 0){
276 baseUpdate(branch_pc, taken, bi);
277 }
278 }
279 }
280
281 ctrUpdate(gtable[bi->hitBank][bi->hitBankIndex].ctr, taken,
283
284 //sign changes: no way it can have been useful
285 if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
286 gtable[bi->hitBank][bi->hitBankIndex].u = 0;
287 }
288
289 if (bi->altTaken == taken) {
290 if (bi->altBank > 0) {
291 int8_t ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
292 if (abs (2 * ctr + 1) == 7) {
293 if (gtable[bi->hitBank][bi->hitBankIndex].u == 1) {
294 if (bi->longestMatchPred == taken) {
295 gtable[bi->hitBank][bi->hitBankIndex].u = 0;
296 }
297 }
298 }
299 }
300 }
301 } else {
302 baseUpdate(branch_pc, taken, bi);
303 }
304
305 if ((bi->longestMatchPred != bi->altTaken) &&
306 (bi->longestMatchPred == taken) &&
307 (gtable[bi->hitBank][bi->hitBankIndex].u < (1 << tagTableUBits) -1)) {
308 gtable[bi->hitBank][bi->hitBankIndex].u++;
309 }
310}
311
312TAGE_SC_L_64KB::TAGE_SC_L_64KB(const TAGE_SC_L_64KBParams &params)
313 : TAGE_SC_L(params)
314{
315}
316
317} // namespace branch_prediction
318} // namespace gem5
bool isDirectCtrl() const
bool isUncondCtrl() const
void initGEHLTable(unsigned numLenghts, std::vector< int > lengths, std::vector< int8_t > *&table, unsigned logNumEntries, std::vector< int8_t > &w, int8_t wInitValue)
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget)
int gPredict(Addr branch_pc, int64_t hist, std::vector< int > &length, std::vector< int8_t > *tab, int nbr, int logs, std::vector< int8_t > &w)
virtual unsigned getIndUpd(Addr branch_pc) const
virtual 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, BranchInfo *bi)
static void ctrUpdate(T &ctr, bool taken, int nbits)
Updates a direction counter based on the actual branch outcome.
Definition tage_base.cc:261
std::vector< ThreadHistory > threadHistory
Definition tage_base.hh:464
void baseUpdate(Addr pc, bool taken, BranchInfo *bi)
Updates the bimodal predictor.
Definition tage_base.cc:302
std::vector< unsigned > tagTableTagWidths
Definition tage_base.hh:433
void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget) override
void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi, int64_t phist) override
int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum, int64_t phist) override
unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const override
TAGE_SC_L_64KB_StatisticalCorrector(const TAGE_SC_L_64KB_StatisticalCorrectorParams &p)
TAGE_SC_L_64KB(const TAGE_SC_L_64KBParams &params)
void handleTAGEUpdate(Addr branch_pc, bool taken, TAGEBase::BranchInfo *bi) override
Handles the update of the TAGE entries.
uint16_t gtag(ThreadID tid, Addr pc, int bank) const override
Computes the partial tag of a tagged table.
int gindex_ext(int index, int bank) const override
void handleAllocAndUReset(bool alloc, bool taken, TAGEBase::BranchInfo *bi, int nrand) override
Handles Allocation and U bits reset on an update.
int calcDep(TAGEBase::BranchInfo *bi)
Definition tage_sc_l.cc:317
void handleUReset() override
Handles the U bits reset.
Definition tage_sc_l.cc:328
Bitfield< 7, 0 > imm
Definition types.hh:132
Bitfield< 8, 7 > sh
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0, 0 > sm
Bitfield< 4 > pc
Bitfield< 30, 0 > index
Bitfield< 0 > p
Bitfield< 20, 16 > bi
Definition types.hh:80
Bitfield< 32 > tm
Definition misc.hh:112
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0