Go to the documentation of this file.
42 #include "debug/Fetch.hh"
43 #include "debug/Tage.hh"
47 logRatioBiModalHystEntries(
p->logRatioBiModalHystEntries),
48 nHistoryTables(
p->nHistoryTables),
49 tagTableCounterBits(
p->tagTableCounterBits),
50 tagTableUBits(
p->tagTableUBits),
51 histBufferSize(
p->histBufferSize),
54 pathHistBits(
p->pathHistBits),
55 tagTableTagWidths(
p->tagTableTagWidths),
56 logTagTableSizes(
p->logTagTableSizes),
57 threadHistory(
p->numThreads),
58 logUResetPeriod(
p->logUResetPeriod),
59 initialTCounterValue(
p->initialTCounterValue),
60 numUseAltOnNa(
p->numUseAltOnNa),
61 useAltOnNaBits(
p->useAltOnNaBits),
62 maxNumAlloc(
p->maxNumAlloc),
64 speculativeHistUpdate(
p->speculativeHistUpdate),
65 instShiftAmt(
p->instShiftAmt),
67 stats(this, nHistoryTables)
105 history.pathHist = 0;
107 history.gHist = history.globalHistory;
154 DPRINTF(Tage,
"HistLength:%d, TTSize:%d, TTTWidth:%d\n",
186 DPRINTF(Tage,
"BTB miss resets prediction: %lx\n", branch_pc);
211 A = A & ((
ULL(1) << size) - 1);
257 assert(nbits <=
sizeof(T) << 3);
259 if (ctr < ((1 << (nbits - 1)) - 1))
262 if (ctr > -(1 << (nbits - 1)))
275 assert(nbits <=
sizeof(uint8_t) << 3);
277 if (ctr < ((1 << nbits) - 1))
303 }
else if (inter > 0) {
306 const bool pred = inter >> 1;
307 const bool hyst = inter & 1;
310 DPRINTF(Tage,
"Updating branch %lx, pred:%d, hyst:%d\n",
pc, pred, hyst);
319 DPRINTF(Tage,
"Rolling over the histories\n");
330 h[0] = (dir) ? 1 : 0;
358 bool pred_taken =
true;
379 for (
int i =
bi->hitBank - 1;
i > 0;
i--) {
388 if (
bi->hitBank > 0) {
389 if (
bi->altBank > 0) {
397 bi->longestMatchPred =
406 || !
bi->pseudoNewAlloc) {
407 bi->tagePred =
bi->longestMatchPred;
410 bi->tagePred =
bi->altTaken;
416 bi->tagePred =
bi->altTaken;
417 bi->longestMatchPred =
bi->altTaken;
422 pred_taken = (
bi->tagePred);
423 DPRINTF(Tage,
"Predict for %lx: taken?:%d, tagePred:%d, altPred:%d\n",
424 branch_pc, pred_taken,
bi->tagePred,
bi->altTaken);
426 bi->branchPC = branch_pc;
427 bi->condBranch = cond_branch;
455 int X =
bi->hitBank + 1;
468 unsigned numAllocated = 0;
515 if (preAdjustAlloc) {
519 if (
bi->hitBank > 0) {
522 bool PseudoNewAlloc =
bi->pseudoNewAlloc;
525 if (PseudoNewAlloc) {
526 if (
bi->longestMatchPred == taken) {
531 if (
bi->longestMatchPred !=
bi->altTaken) {
539 if (!preAdjustAlloc) {
551 if (
bi->hitBank > 0) {
552 DPRINTF(Tage,
"Updating tag table entry (%d,%d) for branch %lx\n",
553 bi->hitBank,
bi->hitBankIndex, branch_pc);
558 if (
gtable[
bi->hitBank][
bi->hitBankIndex].
u == 0) {
559 if (
bi->altBank > 0) {
562 DPRINTF(Tage,
"Updating tag table entry (%d,%d) for"
563 " branch %lx\n",
bi->hitBank,
bi->hitBankIndex,
566 if (
bi->altBank == 0) {
572 if (
bi->tagePred !=
bi->altTaken) {
615 DPRINTF(Tage,
"Updating global histories with branch:%lx; taken?:%d, "
616 "path Hist: %x; pointer:%d\n", branch_pc, taken, tHist.
pathHist,
632 DPRINTF(Tage,
"Restoring branch info: %lx; taken? %d; PathHistory:%x, "
633 "pointer:%d\n",
bi->branchPC,taken,
bi->pathHist,
bi->ptGhist);
637 tHist.
gHist[0] = (taken ? 1 : 0);
658 if (taken ==
bi->tagePred) {
660 switch (
bi->provider) {
670 switch (
bi->provider) {
674 if (
bi->altTaken == taken) {
686 switch (
bi->provider) {
689 if (
bi->longestMatchPred == taken) {
695 switch (
bi->provider) {
708 for (
unsigned i = 0;
i < 32;
i++) {
710 int gh_offset =
bi->ptGhist +
i;
721 :
Stats::Group(parent),
722 ADD_STAT(longestMatchProviderCorrect,
"Number of times TAGE Longest"
723 " Match is the provider and the prediction is correct"),
724 ADD_STAT(altMatchProviderCorrect,
"Number of times TAGE Alt Match"
725 " is the provider and the prediction is correct"),
726 ADD_STAT(bimodalAltMatchProviderCorrect,
"Number of times TAGE Alt"
727 " Match is the bimodal and it is the provider and the prediction"
729 ADD_STAT(bimodalProviderCorrect,
"Number of times there are no"
730 " hits on the TAGE tables and the bimodal prediction is correct"),
731 ADD_STAT(longestMatchProviderWrong,
"Number of times TAGE Longest"
732 " Match is the provider and the prediction is wrong"),
733 ADD_STAT(altMatchProviderWrong,
"Number of times TAGE Alt Match is"
734 " the provider and the prediction is wrong"),
735 ADD_STAT(bimodalAltMatchProviderWrong,
"Number of times TAGE Alt Match"
736 " is the bimodal and it is the provider and the prediction is"
738 ADD_STAT(bimodalProviderWrong,
"Number of times there are no hits"
739 " on the TAGE tables and the bimodal prediction is wrong"),
740 ADD_STAT(altMatchProviderWouldHaveHit,
"Number of times TAGE"
741 " Longest Match is the provider, the prediction is wrong and"
742 " Alt Match prediction was correct"),
743 ADD_STAT(longestMatchProviderWouldHaveHit,
"Number of times"
744 " TAGE Alt Match is the provider, the prediction is wrong and"
745 " Longest Match prediction was correct"),
746 ADD_STAT(longestMatchProvider,
"TAGE provider for longest match"),
747 ADD_STAT(altMatchProvider,
"TAGE provider for alt match")
756 return gtable[hitBank][hitBankIndex].
ctr;
786 bits += bimodalTableSize;
795 TAGEBaseParams::create()
std::vector< unsigned > tagTableTagWidths
unsigned getGHR(ThreadID tid, BranchInfo *bi) const
Stats::Vector longestMatchProvider
virtual BranchInfo * makeBranchInfo()
virtual void initFoldedHistories(ThreadHistory &history)
Initialization of the folded histories.
Stats::Scalar bimodalProviderCorrect
const unsigned nHistoryTables
unsigned getTageCtrBits() const
int16_t ThreadID
Thread index/ID type.
FoldedHistory * computeTags[2]
virtual void handleTAGEUpdate(Addr branch_pc, bool taken, BranchInfo *bi)
Handles the update of the TAGE entries.
std::vector< bool > noSkip
virtual bool getBimodePred(Addr pc, BranchInfo *bi) const
Get a branch prediction from the bimodal predictor.
int8_t getCtr(int hitBank, int hitBankIndex) const
virtual int gindex(ThreadID tid, Addr pc, int bank) const
Computes the index used to access a partially tagged table.
std::vector< ThreadHistory > threadHistory
std::vector< bool > btableHysteresis
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, int nrand, Addr corrTarget, bool pred, bool preAdjustAlloc=false)
Update TAGE for conditional branches.
static void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
Updates an unsigned counter based on up/down parameter.
virtual uint16_t gtag(ThreadID tid, Addr pc, int bank) const
Computes the partial tag of a tagged table.
std::vector< bool > btablePrediction
virtual void handleAllocAndUReset(bool alloc, bool taken, BranchInfo *bi, int nrand)
Handles Allocation and U bits reset on an update.
const unsigned pathHistBits
virtual void calculateIndicesAndTags(ThreadID tid, Addr branch_pc, BranchInfo *bi)
On a prediction, calculates the TAGE indices and tags for all the different history lengths.
Stats::Scalar bimodalAltMatchProviderWrong
virtual int F(int phist, int size, int bank) const
Utility function to shuffle the path history depending on which tagged table we are accessing.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
virtual void extraAltCalc(BranchInfo *bi)
Extra steps for calculating altTaken For this base TAGE class it does nothing.
void baseUpdate(Addr pc, bool taken, BranchInfo *bi)
Updates the bimodal predictor.
virtual void resetUctr(uint8_t &u)
Algorithm for resetting a single U counter.
virtual void updateHistories(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *b, bool speculative, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr, Addr target=MaxAddr)
(Speculatively) updates global histories (path and direction).
Stats::Scalar bimodalAltMatchProviderCorrect
TAGEBase(const TAGEBaseParams *p)
virtual void handleUReset()
Handles the U bits reset.
std::vector< int > logTagTableSizes
const unsigned tagTableCounterBits
std::vector< int8_t > useAltPredForNewlyAllocated
virtual void updateStats(bool taken, BranchInfo *bi)
Update the stats.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
virtual void squash(ThreadID tid, bool taken, BranchInfo *bi, Addr target)
Restores speculatively updated path and direction histories.
Derived & init(size_type size)
Set this vector to have the given size.
size_t getSizeInBits() const
const unsigned logRatioBiModalHystEntries
static void ctrUpdate(T &ctr, bool taken, int nbits)
Updates a direction counter based on the actual branch outcome.
Stats::Scalar longestMatchProviderWrong
const int64_t initialTCounterValue
bool isSpeculativeUpdateEnabled() const
const unsigned histBufferSize
TAGEBaseStats(Stats::Group *parent, unsigned nHistoryTables)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Stats::Scalar longestMatchProviderCorrect
Stats::Scalar longestMatchProviderWouldHaveHit
void init(int original_length, int compressed_length)
const unsigned instShiftAmt
void btbUpdate(ThreadID tid, Addr branch_addr, BranchInfo *&bi)
virtual unsigned getUseAltIdx(BranchInfo *bi, Addr branch_pc)
Calculation of the index for useAltPredForNewlyAllocated On this base TAGE implementation it is alway...
Stats::Scalar bimodalProviderWrong
TAGEBase::TAGEBaseStats stats
bool tagePredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi)
TAGE prediction called from TAGE::predict.
Stats::Scalar altMatchProviderWrong
const unsigned tagTableUBits
virtual void adjustAlloc(bool &alloc, bool taken, bool pred_taken)
Extra calculation to tell whether TAGE allocaitons may happen or not on an update For this base TAGE ...
virtual void calculateParameters()
Calculates the history lengths and some other paramters in derived classes.
Stats::Vector altMatchProvider
Stats::Scalar altMatchProviderCorrect
FoldedHistory * computeIndices
#define ULL(N)
uint64_t constant
Stats::Scalar altMatchProviderWouldHaveHit
virtual void buildTageTables()
Instantiates the TAGE table entries.
void updateGHist(uint8_t *&h, bool dir, uint8_t *tab, int &PT)
(Speculatively) updates the global branch history.
int getPathHist(ThreadID tid) const
const bool speculativeHistUpdate
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Abstract superclass for simulation objects.
virtual int bindex(Addr pc_in) const
Computes the index used to access the bimodal table.
Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17