Skip to content

Commit 0743b89

Browse files
David Schalldhschall
authored andcommitted
Small fixes to align with the original TAGE
- Fix to improve usefulness update function in LLBP - Fixes to align the TAGE model with the original TAGE-SC-L.
1 parent ae03471 commit 0743b89

4 files changed

Lines changed: 39 additions & 37 deletions

File tree

analysis/mpki.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
"ax.set_xticklabels(_bms, rotation=10, horizontalalignment=\"center\", fontsize=fs-1)\n",
336336
"ax.tick_params(axis='x', which='major', pad=0)\n",
337337
"\n",
338-
"ax.set_ylim(bottom=-0.0, top=0.48)\n",
338+
"ax.set_ylim(bottom=-0.0, top=0.52)\n",
339339
"\n",
340340
"\n",
341341
"\n",

bpmodels/llbp/llbp.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ bool LLBP::isUseful(bool taken) {
278278
}
279279

280280
bool LLBP::llbpCorrect(bool taken) {
281-
return llbp.isProvider && (taken == llbp.pred);
281+
return llbp.hit && (taken == llbp.pred);
282282
}
283283

284284
bool LLBP::primCorrect(bool taken) {
285285
return (scl_provider == STC) ? (sc_pred == taken) :
286-
HitBank ? (LongestMatchPred == taken) :
287-
AltBank ? (alttaken == taken) : (bim_pred == taken);
286+
HitBank ? (LongestMatchPred == taken) :
287+
AltBank ? (alttaken == taken) : (bim_pred == taken);
288288
}
289289

290290
bool LLBP::tageCorrect(bool taken) {
@@ -293,7 +293,7 @@ bool LLBP::tageCorrect(bool taken) {
293293
}
294294

295295
bool LLBP::llbpUseful(bool taken) {
296-
return llbpCorrect(taken) && !primCorrect(taken);
296+
return llbp.isProvider && (taken == llbp.pred) && !primCorrect(taken);
297297
}
298298

299299
void LLBP::updateL2Usefulness(bool taken) {
@@ -311,13 +311,6 @@ void LLBP::updateL2Usefulness(bool taken) {
311311
HitEntry->u++;
312312
}
313313
}
314-
315-
316-
// Same for level 2. If it was the provider and was correct
317-
// but level 1 not, it was useful.
318-
if (llbp.hit && !llbp.shorter && llbp_correct && !prim_correct) {
319-
ctrupdate(llbpEntry->replace, true, ReplCtrWidth);
320-
}
321314
}
322315

323316

@@ -491,7 +484,6 @@ void LLBP::llbpUpdate(uint64_t pc, bool resolveDir, bool predDir) {
491484
// - If a pattern becomes low confident (incorrect prediction)
492485
// the replacement counter is decreased
493486
if (llbpEntry->ctr == (resolveDir ? 1 : -2)) {
494-
// else if (llbpEntry->ctr == (resolveDir ? 2 : -3)) {
495487
// entry became medium confident
496488
ctrupdate(HitContext->replace, true, CtxReplCtrWidth);
497489
}

bpmodels/tage/tage.cc

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ using namespace std;
3838

3939
#define COND (stats.total >= 00000)
4040

41-
#define USEPATH 1
41+
#define USEPATH
4242

4343
namespace LLBP {
4444

@@ -58,7 +58,7 @@ TageBase::TageBase(TageConfig cfg)
5858
Tbits(cfg.Tbits),
5959
uwidth(cfg.uwidth),
6060
cwidth(cfg.cwidth),
61-
// size_use_alt(1 << (cfg.log_size_use_alt)),
61+
size_use_alt(1 << (cfg.log_size_use_alt)),
6262
ghr(histbufferlen),
6363
disableInterleaving(cfg.disableInterleaving)
6464
{
@@ -214,7 +214,7 @@ int TageBase::predictorsize() {
214214

215215
printf("nhist= %d; MInhist= %d; MAXHIST= %d; STORAGESIZE= %d, %dKB; "
216216
"NBENTRY= %d\n",
217-
nhist, minhist, minhist, STORAGESIZE, STORAGESIZE / 1024, NBENTRY);
217+
nhist, minhist, maxhist, STORAGESIZE, STORAGESIZE / 1024, NBENTRY);
218218

219219
return (STORAGESIZE);
220220
}
@@ -271,7 +271,7 @@ int TageBase::gindex(unsigned int PC, int bank) {
271271

272272

273273
#ifdef USEPATH
274-
int M = (m[bank] > 16) ? 16 : m[bank];
274+
int M = (m[bank] > phistwidth) ? phistwidth : m[bank];
275275
index ^= F(phist, M, bank);
276276
#endif
277277

@@ -317,6 +317,7 @@ bool TageBase::predict(uint64_t PC) {
317317

318318
// 2. The TAGE prediction
319319
tagePredict(PC);
320+
provider = tage_provider;
320321
return tage_pred;
321322
}
322323

@@ -332,7 +333,7 @@ void TageBase::calcIndicesAndTags(uint64_t PC) {
332333
}
333334

334335

335-
int T = (PC) % nbankhigh;
336+
int T = (PC ^ (phist & ((1 << m[born]) - 1))) % nbankhigh;
336337
T = disableInterleaving ? 1 : T;
337338

338339
for (int i = born; i <= nhist; i++)
@@ -342,7 +343,7 @@ void TageBase::calcIndicesAndTags(uint64_t PC) {
342343
T = T % nbankhigh;
343344
}
344345

345-
T = (PC) % nbanklow;
346+
T = (PC ^ (phist & ((1 << m[1]) - 1))) % nbanklow;
346347
T = disableInterleaving ? 1 : T;
347348

348349
for (int i = 1; i <= born - 1; i++)
@@ -435,25 +436,35 @@ void TageBase::tagePredict(uint64_t PC) {
435436

436437
void TageBase::updateHistory(const uint64_t pc, const bool taken,
437438
const OpType opType, const uint64_t target) {
438-
int historyBits = taken;
439+
440+
bool indirect = (opType == OPTYPE_CALL_INDIRECT_COND) ||
441+
(opType == OPTYPE_CALL_INDIRECT_UNCOND) ||
442+
(opType == OPTYPE_JMP_INDIRECT_COND) ||
443+
(opType == OPTYPE_JMP_INDIRECT_UNCOND) ||
444+
(opType == OPTYPE_RET_COND) ||
445+
(opType == OPTYPE_RET_UNCOND);
446+
447+
int tbits = indirect ? nHistBits+1 : nHistBits;
448+
449+
int historyBits = taken ? 1 : 0;
439450
if (nHistBits > 1) {
440451
historyBits ^= pc ^ (pc >> 2);
441452
}
442-
if (takenHistory) {
443-
// don't update the history if the branch was not taken
444-
if (!taken) {
445-
return;
446-
}
447-
historyBits = (pc >> 2) ^ (target >> 3);
448-
}
449-
450453
ghr_l = (ghr_l << 1) | (taken & 1);
454+
int PATH = pc ^ (pc >> 2) ^ (pc >> 4);
451455

452-
for (int t = 0; t < nHistBits; t++) {
456+
for (int t = 0; t < tbits; t++) {
453457
// update history
458+
454459
bool brDir = (historyBits & 1);
455460
updateGHist(brDir);
456461
historyBits >>= 1;
462+
#ifdef USEPATH
463+
int PATHBIT = (PATH & 127);
464+
PATH >>= 1;
465+
phist = (phist << 1) ^ PATHBIT;
466+
phist &= (1<<phistwidth)-1;
467+
#endif
457468
}
458469
}
459470

@@ -469,7 +480,7 @@ void TageBase::updateGHist(const bool bit) {
469480

470481

471482
int TageBase::idxChooser() {
472-
bool add1 = (altConf == LowConf);
483+
bool add1 = (altConf != LowConf);
473484
return ((((HitBank - 1) / 8) << 1) + add1) % (size_use_alt - 1);
474485
}
475486

@@ -481,8 +492,9 @@ unsigned TageBase::chooseProvider() {
481492
// low) and USE_ALT_ON_NA is positive use the alternate prediction
482493

483494
// If the longest is somehow certain use its prediction.
484-
if (tageConf != LowConf)
495+
if (tageConf != LowConf) {
485496
return LONGEST;
497+
}
486498

487499
// Use on low confidence if the USE_ALT_ON_NA is negative
488500
if (use_alt_on_na[idxChooser()] < 0) {
@@ -547,7 +559,7 @@ TageBase::allocateTables(int nalloc, uint64_t PC, bool resolveDir) {
547559

548560
// T is the number of entries additionally allocated to at
549561
// least one entry per missprediction.
550-
int T = nalloc -1;
562+
int T = nalloc - 1;
551563

552564
int A = 1;
553565
if ((MYRANDOM() & 127) < 32) A = 2;

bpmodels/tage/tage.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,14 @@ class TageBase : public BasePredictor {
122122

123123
// the counter(s) to chose between longest match and alternate prediction on
124124
// TAGE when weak counters
125-
static const int log_size_use_alt = 4;
126125
unsigned tageConf; // Different confidence levels
127126
unsigned baseConf;
128127
unsigned altConf;
129128
int provVal;
130129
// For chooser between alt and longest match
131130
const int alt_width = 5;
132-
static const int size_use_alt = (1 << (log_size_use_alt));
133-
int8_t use_alt_on_na[size_use_alt];
131+
const int size_use_alt;
132+
int8_t use_alt_on_na[10]; // 10 is not the actual size, but the maximum.
134133

135134
int TICK; // for the reset of the u counter
136135

@@ -317,7 +316,7 @@ class TageBase : public BasePredictor {
317316
struct TageConfig {
318317

319318
int nhist = 36;
320-
int minhist = 4;
319+
int minhist = 6;
321320
int maxhist = 3000;
322321
int LogG = 10;
323322
int LogB = 13;
@@ -366,5 +365,4 @@ class Tage64k : public TageBase {
366365

367366

368367

369-
370368
}; // namespace LLBP

0 commit comments

Comments
 (0)