@@ -38,7 +38,7 @@ using namespace std;
3838
3939#define COND (stats.total >= 00000 )
4040
41- #define USEPATH 1
41+ #define USEPATH
4242
4343namespace 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
436437void 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
471482int 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 ;
0 commit comments