gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
tage_sc_l_8KB.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 * 8KB TAGE-SC-L branch predictor (devised by Andre Seznec)
40 */
41
43
44#include "base/random.hh"
45#include "debug/TageSCL.hh"
46
47namespace gem5
48{
49
50namespace branch_prediction
51{
52
54 const TAGE_SC_L_8KB_StatisticalCorrectorParams &p)
56 gnb(p.gnb),
58 gm(p.gm)
59{
61}
62
65{
67 sh->setNumOrdinalHistories(1);
68 sh->initLocalHistory(1, numEntriesFirstLocalHistories, 2);
69 return sh;
70}
71
72unsigned
75 int hitBank,
76 int altBank) const
77{
78 return (bi->predBeforeSC
79 + (((hitBank + 1) / 4) << 4)
80 + (bi->highConf << 1)
81 + (bi->lowConf << 2)
82 + ((altBank != 0) << 3))
83 & ((1 << logBias) -1);
84}
85
86int
88 ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum)
89{
90 lsum += gPredict(
91 branch_pc, bi->globalHist, gm, ggehl, gnb, logGnb, wg);
92
93 lsum += gPredict(
94 branch_pc, bi->bwHist, bwm, bwgehl, bwnb, logBwnb, wbw);
95
96 // only 1 local history here
97 lsum += gPredict(
98 branch_pc, bi->localHistories[1], lm,
99 lgehl, lnb, logLnb, wl);
100
101 lsum += gPredict(
102 branch_pc, bi->imliCount, im, igehl, inb, logInb, wi);
103
104 int thres = (updateThreshold>>3)+pUpdateThreshold[getIndUpd(branch_pc)];
105
106 return thres;
107}
108
110{
111 return 0;
112}
113
114void
116 const StaticInstPtr &inst,
117 bool taken, Addr target,
118 int64_t phist)
119{
120 int brtype = inst->isDirectCtrl() ? 0 : 2;
121 if (! inst->isUncondCtrl()) {
122 ++brtype;
123 }
124 // Non speculative SC histories update
125 if (brtype & 1) {
127 static_cast<SC_8KB_ThreadHistory *>(scHistory);
128 sh->globalHist = (sh->globalHist << 1) + taken;
129 }
130
131 StatisticalCorrector::scHistoryUpdate(branch_pc, inst, taken,
132 target, phist);
133}
134
135void
137 BranchInfo *bi)
138{
140 auto sh = static_cast<SC_8KB_ThreadHistory *>(scHistory);
141 bi->globalHist = sh->globalHist;
142}
143
144bool
146{
148 return false;
149 }
150 auto sh = static_cast<SC_8KB_ThreadHistory *>(scHistory);
151 sh->globalHist = bi->globalHist;
152 return true;
153}
154
155void
157 BranchInfo *bi)
158{
159 gUpdate(pc, taken, bi->globalHist, gm, ggehl, gnb, logGnb, wg, bi);
160 gUpdate(pc, taken, bi->bwHist, bwm, bwgehl, bwnb, logBwnb, wbw, bi);
161 gUpdate(pc, taken, bi->localHistories[1], lm, lgehl, lnb, logLnb, wl,
162 bi);
163 gUpdate(pc, taken, bi->imliCount, im, igehl, inb, logInb, wi, bi);
164}
165
166TAGE_SC_L_8KB::TAGE_SC_L_8KB(const TAGE_SC_L_8KBParams &params)
168{
169}
170
171void
173{
174 // Some hardcoded values are used here
175 // (they do not seem to depend on any parameter)
176 for (int i = 1; i <= nHistoryTables; i++) {
177 history.computeIndices[i].init(
178 histLengths[i], 17 + (2 * ((i - 1) / 2) % 4));
179 history.computeTags[0][i].init(
180 history.computeIndices[i].origLength, 13);
181 history.computeTags[1][i].init(
182 history.computeIndices[i].origLength, 11);
183 DPRINTF(TageSCL, "HistLength:%d, TTSize:%d, TTTWidth:%d\n",
185 }
186}
187
188int
190{
191 return (index ^ (index >> logTagTableSizes[bank])
192 ^ (index >> 2 * logTagTableSizes[bank]));
193}
194
195uint16_t
197{
198 Addr shifted_pc = pc >> instShiftAmt;
199 int tag = (threadHistory[tid].computeIndices[bank - 1].comp << 2)
200 ^ shifted_pc ^ (shifted_pc >> 2) ^
201 threadHistory[tid].computeIndices[bank].comp;
202 int hlen = (histLengths[bank] > pathHistBits) ? pathHistBits :
203 histLengths[bank];
204
205 tag = (tag >> 1) ^ ((tag & 1) << 10) ^
206 F(threadHistory[tid].pathHist, hlen, bank);
207 tag ^= threadHistory[tid].computeTags[0][bank].comp ^
208 (threadHistory[tid].computeTags[1][bank].comp << 1);
209
210 return ((tag ^ (tag >> tagTableTagWidths[bank]))
211 & ((1ULL << tagTableTagWidths[bank]) - 1));
212}
213
214void
216 TAGEBase::BranchInfo *bi, int nrand)
217{
218 if (!alloc) {
219 return;
220 }
221
222 int penalty = 0;
223 int truePen = 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 (i > nHistoryTables) {
232 break;
233 }
234 if (noSkip[i]) {
235 if (gtable[i][bi->tableIndices[i]].u == 0) {
236 gtable[i][bi->tableIndices[i]].u =
237 ((rng->random<int>() & 31) == 0);
238 // protect randomly from fast replacement
239 gtable[i][bi->tableIndices[i]].tag = bi->tableTags[i];
240 gtable[i][bi->tableIndices[i]].ctr = taken ? 0 : -1;
241 numAllocated++;
242
243 if (numAllocated == maxNumAlloc) {
244 maxAllocReached = true;
245 break;
246 }
247 I += 2;
248 } else {
249 int8_t ctr = gtable[i][bi->tableIndices[i]].ctr;
250 if ((gtable[i][bi->tableIndices[i]].u == 1) &
251 (abs (2 * ctr + 1) == 1)) {
252 if ((rng->random<int>() & 7) == 0) {
253 gtable[i][bi->tableIndices[i]].u = 0;
254 }
255 } else {
256 truePen++;
257 }
258 penalty++;
259 }
260 } else {
261 break;
262 }
263 }
264 if (maxAllocReached) {
265 break;
266 }
267 }
268
269 tCounter += (truePen + penalty - 5 * numAllocated);
270
271 handleUReset();
272}
273
274void
276{
277 // On real HW it should be u >>= 1 instead of if > 0 then u--
278 if (u > 0) {
279 u--;
280 }
281}
282
283void
286{
287 if (bi->hitBank > 0) {
288 if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
289 if (bi->longestMatchPred != taken) { // acts as a protection
290 if (bi->altBank > 0) {
291 int8_t ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
292 if (abs (2 * ctr + 1) == 1) {
293 gtable[bi->altBank][bi->altBankIndex].u = 0;
294 }
295
296 //just mute from protected to unprotected
297 ctrUpdate(gtable[bi->altBank][bi->altBankIndex].ctr, taken,
299 ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
300 if (abs (2 * ctr + 1) == 1) {
301 gtable[bi->altBank][bi->altBankIndex].u = 0;
302 }
303 }
304 if (bi->altBank == 0) {
305 baseUpdate(branch_pc, taken, bi);
306 }
307 }
308 }
309
310 //just mute from protected to unprotected
311 if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
312 gtable[bi->hitBank][bi->hitBankIndex].u = 0;
313 }
314
315 ctrUpdate(gtable[bi->hitBank][bi->hitBankIndex].ctr, taken,
317
318 //sign changes: no way it can have been useful
319 if (abs (2 * gtable[bi->hitBank][bi->hitBankIndex].ctr + 1) == 1) {
320 gtable[bi->hitBank][bi->hitBankIndex].u = 0;
321 }
322
323 if (bi->altTaken == taken) {
324 if (bi->altBank > 0) {
325 int8_t ctr = gtable[bi->altBank][bi->altBankIndex].ctr;
326 if (abs (2*ctr + 1) == 7) {
327 if (gtable[bi->hitBank][bi->hitBankIndex].u == 1) {
328 if (bi->longestMatchPred == taken) {
329 gtable[bi->hitBank][bi->hitBankIndex].u = 0;
330 }
331 }
332 }
333 }
334 }
335 } else {
336 baseUpdate(branch_pc, taken, bi);
337 }
338
339 if ((bi->longestMatchPred != bi->altTaken) &&
340 (bi->longestMatchPred == taken) &&
341 (gtable[bi->hitBank][bi->hitBankIndex].u < (1 << tagTableUBits) -1)) {
342 gtable[bi->hitBank][bi->hitBankIndex].u++;
343 }
344}
345
346} // namespace branch_prediction
347} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
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
std::vector< int > logTagTableSizes
Definition tage_base.hh:494
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
TAGE_SC_L_8KB_StatisticalCorrector(const TAGE_SC_L_8KB_StatisticalCorrectorParams &p)
unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const override
int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum) override
void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, Addr target, int64_t phist) override
void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi) override
TAGE_SC_L_8KB(const TAGE_SC_L_8KBParams &params)
void handleAllocAndUReset(bool alloc, bool taken, TAGEBase::BranchInfo *bi, int nrand) override
Handles Allocation and U bits reset on an update.
uint16_t gtag(ThreadID tid, Addr pc, int bank) const override
Computes the partial tag of a tagged table.
void initFoldedHistories(ThreadHistory &history) override
Initialization of the folded histories.
int gindex_ext(int index, int bank) const override
void resetUctr(uint8_t &u) override
Algorithm for resetting a single U counter.
void handleTAGEUpdate(Addr branch_pc, bool taken, TAGEBase::BranchInfo *bi) override
Handles the update of the TAGE entries.
int calcDep(TAGEBase::BranchInfo *bi)
Definition tage_sc_l.cc:298
int F(int phist, int size, int bank) const override
Utility function to shuffle the path history depending on which tagged table we are accessing.
Definition tage_sc_l.cc:212
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< 22 > u
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
void init(int original_length, int compressed_length)
Definition tage_base.hh:100

Generated on Mon May 26 2025 09:19:08 for gem5 by doxygen 1.13.2