gem5 [DEVELOP-FOR-25.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
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
92 int hitBank,
93 int altBank) const
94{
95 Addr shifted_pc = branch_pc >> instShiftAmt;
96 return (bi->predBeforeSC
97 + (((hitBank + 1) / 4) << 4)
98 + (bi->highConf << 1)
99 + (bi->lowConf << 2)
100 + ((altBank != 0) << 3)
101 + ((shifted_pc ^ (shifted_pc >> 2)) << 7))
102 & ((1 << logBias) -1);
103}
104
105int
107 BranchInfo *bi, int &lsum)
108{
109 lsum += gPredict(
110 ((branch_pc >> instShiftAmt) << 1) + bi->predBeforeSC, bi->bwHist, bwm,
112
113 lsum += gPredict(
114 branch_pc, bi->pHist, pm, pgehl, pnb, logPnb, wp);
115
116 lsum += gPredict(
117 branch_pc, bi->localHistories[1], lm,
118 lgehl, lnb, logLnb, wl);
119
120 lsum += gPredict(
121 branch_pc, bi->localHistories[2], sm,
122 sgehl, snb, logSnb, ws);
123
124 lsum += gPredict(
125 branch_pc, bi->localHistories[3], tm,
126 tgehl, tnb, logTnb, wt);
127
128 lsum += gPredict(
129 branch_pc, bi->imHist, imm,
131
132 lsum += gPredict(
133 branch_pc, bi->imliCount, im, igehl, inb, logInb, wi);
134
135 int thres = (updateThreshold>>3) + pUpdateThreshold[getIndUpd(branch_pc)]
136 + 12*((wb[getIndUpds(branch_pc)] >= 0) + (wp[getIndUpds(branch_pc)] >= 0)
137 + (ws[getIndUpds(branch_pc)] >= 0) + (wt[getIndUpds(branch_pc)] >= 0)
138 + (wl[getIndUpds(branch_pc)] >= 0) + (wbw[getIndUpds(branch_pc)] >= 0)
139 + (wi[getIndUpds(branch_pc)] >= 0));
140
141 return thres;
142}
143
144int
146{
147 return (i >= (nbr - 2)) ? 1 : 0;
148}
149
150void
152 const StaticInstPtr &inst,
153 bool taken, Addr target,
154 int64_t phist)
155{
156 int brtype = inst->isDirectCtrl() ? 0 : 2;
157 if (! inst->isUncondCtrl()) {
158 ++brtype;
159 }
160 // Non speculative SC histories update
161 if (brtype & 1) {
163 static_cast<SC_64KB_ThreadHistory *>(scHistory);
164 int64_t imliCount = sh->imliCount;
165 sh->imHist[imliCount] = (sh->imHist[imliCount] << 1)
166 + taken;
167 sh->updateLocalHistory(2, branch_pc, taken, branch_pc & 15);
168 sh->updateLocalHistory(3, branch_pc, taken);
169 }
170
171 StatisticalCorrector::scHistoryUpdate(branch_pc, inst, taken,
172 target, phist);
173}
174
175void
177 BranchInfo *bi)
178{
180 auto sh = static_cast<SC_64KB_ThreadHistory *>(scHistory);
181 bi->imHist = sh->imHist[sh->imliCount];
182 bi->localHistories[2] = sh->getLocalHistory(2, branch_pc);
183 bi->localHistories[3] = sh->getLocalHistory(3, branch_pc);
184}
185
186bool
188{
190 return false;
191 }
192 auto sh = static_cast<SC_64KB_ThreadHistory *>(scHistory);
193 sh->imHist[sh->imliCount] = bi->imHist;
194 sh->setLocalHistory(2, bi->pc, bi->localHistories[2]);
195 sh->setLocalHistory(3, bi->pc, bi->localHistories[3]);
196 return true;
197}
198
199void
201 bool taken, BranchInfo *bi)
202{
203 gUpdate((pc << 1) + bi->predBeforeSC, taken, bi->bwHist, bwm,
204 bwgehl, bwnb, logBwnb, wbw, bi);
205
206 gUpdate(pc, taken, bi->pHist, pm,
207 pgehl, pnb, logPnb, wp, bi);
208
209 gUpdate(pc, taken, bi->localHistories[1], lm,
210 lgehl, lnb, logLnb, wl, bi);
211
212 gUpdate(pc, taken, bi->localHistories[2], sm,
213 sgehl, snb, logSnb, ws, bi);
214
215 gUpdate(pc, taken, bi->localHistories[3], tm,
216 tgehl, tnb, logTnb, wt, bi);
217
218 gUpdate(pc, taken, bi->imHist, imm,
219 imgehl, imnb, logImnb, wim, bi);
220
221 gUpdate(pc, taken, bi->imliCount, im,
222 igehl, inb, logInb, wi, bi);
223}
224
225int
227{
228 return index;
229}
230
231uint16_t
233{
234 // very similar to the TAGE implementation, but w/o shifting the pc
235 Addr shifted_pc = pc >> instShiftAmt;
236 int tag = shifted_pc ^ threadHistory[tid].computeTags[0][bank].comp ^
237 (threadHistory[tid].computeTags[1][bank].comp << 1);
238
239 return (tag & ((1ULL << tagTableTagWidths[bank]) - 1));
240}
241
242void
244 TAGEBase::BranchInfo *bi, int nrand)
245{
246 if (! alloc) {
247 return;
248 }
249
250 int penalty = 0;
251 int numAllocated = 0;
252 bool maxAllocReached = false;
253
254 for (int I = calcDep(bi); I < nHistoryTables; I += 2) {
255 // Handle the 2-way associativity for allocation
256 for (int j = 0; j < 2; ++j) {
257 int i = ((j == 0) ? I : (I ^ 1)) + 1;
258 if (noSkip[i]) {
259 if (gtable[i][bi->tableIndices[i]].u == 0) {
260 int8_t ctr = gtable[i][bi->tableIndices[i]].ctr;
261 if (abs (2 * ctr + 1) <= 3) {
262 gtable[i][bi->tableIndices[i]].tag = bi->tableTags[i];
263 gtable[i][bi->tableIndices[i]].ctr = taken ? 0 : -1;
264 numAllocated++;
265 maxAllocReached = (numAllocated == maxNumAlloc);
266 I += 2;
267 break;
268 } else {
269 if (gtable[i][bi->tableIndices[i]].ctr > 0) {
270 gtable[i][bi->tableIndices[i]].ctr--;
271 } else {
272 gtable[i][bi->tableIndices[i]].ctr++;
273 }
274 }
275 } else {
276 penalty++;
277 }
278 }
279 }
280 if (maxAllocReached) {
281 break;
282 }
283 }
284
285 tCounter += (penalty - 2 * numAllocated);
286
287 handleUReset();
288}
289
290void
293{
294 if (bi->hitBank > 0) {
295 if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
296 if (bi->longestMatchPred != taken) {
297 // acts as a protection
298 if (bi->altBank > 0) {
299 ctrUpdate(gtable[bi->altBank][bi->altBankIndex].ctr, taken,
301 }
302 if (bi->altBank == 0){
303 baseUpdate(branch_pc, taken, bi);
304 }
305 }
306 }
307
308 ctrUpdate(gtable[bi->hitBank][bi->hitBankIndex].ctr, taken,
310
311 //sign changes: no way it can have been useful
312 if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
313 gtable[bi->hitBank][bi->hitBankIndex].u = 0;
314 }
315
316 if (bi->altTaken == taken) {
317 if (bi->altBank > 0) {
318 int8_t ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
319 if (abs (2 * ctr + 1) == 7) {
320 if (gtable[bi->hitBank][bi->hitBankIndex].u == 1) {
321 if (bi->longestMatchPred == taken) {
322 gtable[bi->hitBank][bi->hitBankIndex].u = 0;
323 }
324 }
325 }
326 }
327 }
328 } else {
329 baseUpdate(branch_pc, taken, bi);
330 }
331
332 if ((bi->longestMatchPred != bi->altTaken) &&
333 (bi->longestMatchPred == taken) &&
334 (gtable[bi->hitBank][bi->hitBankIndex].u < (1 << tagTableUBits) -1)) {
335 gtable[bi->hitBank][bi->hitBankIndex].u++;
336 }
337}
338
339TAGE_SC_L_64KB::TAGE_SC_L_64KB(const TAGE_SC_L_64KBParams &params)
341{
342}
343
344} // namespace branch_prediction
345} // 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)
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 void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, Addr target, int64_t phist)
virtual void scRecordHistState(Addr branch_pc, BranchInfo *bi)
StatisticalCorrector(const StatisticalCorrectorParams &p)
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:244
std::vector< ThreadHistory > threadHistory
Definition tage_base.hh:526
void baseUpdate(Addr pc, bool taken, BranchInfo *bi)
Updates the bimodal predictor.
Definition tage_base.cc:285
std::vector< unsigned > tagTableTagWidths
Definition tage_base.hh:493
void scRecordHistState(Addr branch_pc, BranchInfo *bi) override
void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi) override
void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, Addr target, int64_t phist) override
int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum) 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:298
void handleUReset() override
Handles the U bits reset.
Definition tage_sc_l.cc:309
TAGE_SC_L(const TAGE_SC_LParams &params)
Definition tage_sc_l.cc:79
const Params & params() const
Bitfield< 8, 7 > sh
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 4 > pc
Bitfield< 30, 0 > index
Bitfield< 0 > p
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 May 26 2025 09:19:08 for gem5 by doxygen 1.13.2