58#include "debug/TageSCL.hh"
63namespace branch_prediction
80 :
LTAGE(
p), statisticalCorrector(
p.statistical_corrector)
99 for (
int i = 2;
i <= numHistLengths;
i++) {
102 (
double) (
i - 1) / (
double) ((numHistLengths - 1))))
197 unsigned int shortPc =
pc;
215 a =
a & ((1ULL << size) - 1);
246 int tmp = ((branch_pc ^ (branch_pc >>
instShiftAmt))) ^ taken;
249 if ((brtype == 3) & taken) {
255 int maxt = (brtype == 2) ? 3 : 2;
257 for (
int t = 0;
t < maxt;
t++) {
258 bool dir = (tmp & 1);
260 int pathbit = (
path & 127);
285 assert(! speculative);
295 DPRINTF(TageSCL,
"Updating global histories with branch:%lx; taken?:%d, "
296 "path Hist: %x; pointer:%d\n", branch_pc, taken, tHist.
pathHist,
304 fatal(
"Speculation is not implemented");
323 return ((((
bi->hitBank - 1 + 2 *
a) & 0xffe)) ^
360 bi->highConf = (bim == 0) || (bim == 3);
361 bi->lowConf = !
bi->highConf;
362 bi->altConf =
bi->highConf;
373 tage_scl_bi->
altConf = (abs(2*ctr + 1) > 1);
387 bi->lpBranchInfo, pred_taken,
390 if (
bi->lpBranchInfo->loopPredUsed) {
391 bi->tageBranchInfo->provider =
LOOP;
399 bi->scBranchInfo->highConf = tage_scl_bi->
highConf;
400 bi->scBranchInfo->altConf = tage_scl_bi->
altConf;
401 bi->scBranchInfo->medConf = tage_scl_bi->
medConf;
403 bool use_tage_ctr =
bi->tageBranchInfo->hitBank > 0;
404 int8_t tage_ctr = use_tage_ctr ?
406 bool bias = (
bi->tageBranchInfo->longestMatchPred !=
407 bi->tageBranchInfo->altTaken);
410 bi->scBranchInfo, pred_taken, bias, use_tage_ctr, tage_ctr,
414 if (
bi->scBranchInfo->usedScPred) {
415 bi->tageBranchInfo->provider =
SC;
419 bi->lpBranchInfo->predTaken = pred_taken;
439 if (
bi->tageBranchInfo->condBranch) {
448 DPRINTF(TageSCL,
"Updating tables for branch:%lx; taken?:%d\n",
456 bool bias = (
bi->tageBranchInfo->longestMatchPred !=
457 bi->tageBranchInfo->altTaken);
459 bi->scBranchInfo, target, bias,
bi->tageBranchInfo->hitBank,
466 nrand, target,
bi->lpBranchInfo->predTaken);
471 bi->scBranchInfo, target);
478 bp_history =
nullptr;
static std::stack< std::string > path
bool isDirectCtrl() const
bool isUncondCtrl() const
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
LoopPredictor * loopPredictor
The loop predictor object.
void updateStats(bool taken, BranchInfo *bi)
Update the stats.
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, bool tage_pred, BranchInfo *bi, unsigned instShiftAmt)
Update LTAGE for conditional branches.
void squashLoop(BranchInfo *bi)
virtual bool calcConf(int index) const
bool loopPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, unsigned instShiftAmt)
Get the loop prediction.
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget)
void updateStats(bool taken, BranchInfo *bi)
virtual bool scPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, bool bias_bit, bool use_conf_ctr, int8_t conf_ctr, unsigned conf_bits, int hitBank, int altBank, int64_t phist, int init_lsum=0)
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, Addr corrTarget, bool bias_bit, int hitBank, int altBank, int64_t phist)
virtual void updateHistories(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *b, bool speculative, const StaticInstPtr &inst=nullStaticInstPtr, Addr target=MaxAddr)
(Speculatively) updates global histories (path and direction).
bool isSpeculativeUpdateEnabled() const
virtual void resetUctr(uint8_t &u)
Algorithm for resetting a single U counter.
unsigned getTageCtrBits() const
virtual void updateStats(bool taken, BranchInfo *bi)
Update the stats.
const unsigned logRatioBiModalHystEntries
std::vector< bool > btableHysteresis
void updateGHist(uint8_t *&h, bool dir, uint8_t *tab, int &PT)
(Speculatively) updates the global branch history.
std::vector< bool > btablePrediction
const unsigned nHistoryTables
std::vector< ThreadHistory > threadHistory
virtual bool getBimodePred(Addr pc, BranchInfo *bi) const
Get a branch prediction from the bimodal predictor.
const unsigned pathHistBits
int8_t getCtr(int hitBank, int hitBankIndex) const
std::vector< int > logTagTableSizes
const unsigned instShiftAmt
virtual void squash(ThreadID tid, bool taken, BranchInfo *bi, Addr target)
Restores speculatively updated path and direction histories.
bool tagePredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi)
TAGE prediction called from TAGE::predict.
std::vector< bool > noSkip
const bool speculativeHistUpdate
int getPathHist(ThreadID tid) const
std::vector< unsigned > tagTableTagWidths
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.
virtual bool optionalAgeInc() const override
virtual bool calcConf(int index) const override
const unsigned shortTagsTageFactor
void updatePathAndGlobalHistory(ThreadHistory &tHist, int brtype, bool taken, Addr branch_pc, Addr target)
void extraAltCalc(TAGEBase::BranchInfo *bi) override
Extra steps for calculating altTaken For this base TAGE class it does nothing.
void calculateIndicesAndTags(ThreadID tid, Addr branch_pc, TAGEBase::BranchInfo *bi) override
On a prediction, calculates the TAGE indices and tags for all the different history lengths.
int bindex(Addr pc_in) const override
Computes the index used to access the bimodal table.
int calcDep(TAGEBase::BranchInfo *bi)
bool getBimodePred(Addr branch_pc, TAGEBase::BranchInfo *tage_bi) const override
Get a branch prediction from the bimodal predictor.
const unsigned longTagsTageFactor
const bool truncatePathHist
const unsigned longTagsSize
virtual TAGEBase::BranchInfo * makeBranchInfo() override
int gindex(ThreadID tid, Addr pc, int bank) const override
Computes the index used to access a partially tagged table.
virtual int gindex_ext(int index, int bank) const =0
const unsigned shortTagsSize
const unsigned firstLongTagTable
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.
void calculateParameters() override
Calculates the history lengths and some other paramters in derived classes.
void squash(ThreadID tid, bool taken, TAGEBase::BranchInfo *bi, Addr target) override
Restores speculatively updated path and direction histories.
void adjustAlloc(bool &alloc, bool taken, bool pred_taken) override
Extra calculation to tell whether TAGE allocaitons may happen or not on an update For this base TAGE ...
void buildTageTables() override
Instantiates the TAGE table entries.
unsigned getUseAltIdx(TAGEBase::BranchInfo *bi, Addr branch_pc) override
Calculation of the index for useAltPredForNewlyAllocated On this base TAGE implementation it is alway...
virtual uint16_t gtag(ThreadID tid, Addr pc, int bank) const override=0
Computes the partial tag of a tagged table.
const unsigned logTagTableSize
void updateHistories(ThreadID tid, Addr branch_pc, bool taken, TAGEBase::BranchInfo *b, bool speculative, const StaticInstPtr &inst, Addr target) override
(Speculatively) updates global histories (path and direction).
void handleUReset() override
Handles the U bits reset.
bool predict(ThreadID tid, Addr pc, bool cond_branch, void *&b) override
Get a branch prediction from LTAGE.
void update(ThreadID tid, Addr pc, bool taken, void *&bp_history, bool squashed, const StaticInstPtr &inst, Addr target) override
Updates the BP with taken/not taken information.
TAGE_SC_L(const TAGE_SC_LParams ¶ms)
StatisticalCorrector * statisticalCorrector
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
#define fatal(...)
This implements a cprintf based fatal() function.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
int16_t ThreadID
Thread index/ID type.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
FoldedHistory * computeIndices
FoldedHistory * computeTags[2]