57#include "debug/TageSCL.hh"
62namespace branch_prediction
75 return (
rng->random<
int>() & 7) == 0;
79 :
LTAGE(
p), statisticalCorrector(
p.statistical_corrector)
98 for (
int i = 2;
i <= numHistLengths;
i++) {
101 (
double) (
i - 1) / (
double) ((numHistLengths - 1))))
196 unsigned int shortPc =
pc;
214 a =
a & ((1ULL << size) - 1);
245 int tmp = ((branch_pc ^ (branch_pc >>
instShiftAmt))) ^ taken;
248 if ((brtype == 3) & taken) {
254 int maxt = (brtype == 2) ? 3 : 2;
256 for (
int t = 0;
t < maxt;
t++) {
257 bool dir = (tmp & 1);
259 int pathbit = (
path & 127);
284 assert(! speculative);
294 DPRINTF(TageSCL,
"Updating global histories with branch:%lx; taken?:%d, "
295 "path Hist: %x; pointer:%d\n", branch_pc, taken, tHist.
pathHist,
303 fatal(
"Speculation is not implemented");
310 if ((taken == pred_taken) && ((
rng->random<
int>() & 31) != 0)) {
319 if ((
rng->random<
int>() & 127) < 32) {
322 return ((((
bi->hitBank - 1 + 2 *
a) & 0xffe)) ^
323 (
rng->random<
int>() & 1));
359 bi->highConf = (bim == 0) || (bim == 3);
360 bi->lowConf = !
bi->highConf;
361 bi->altConf =
bi->highConf;
372 tage_scl_bi->
altConf = (abs(2*ctr + 1) > 1);
386 bi->lpBranchInfo, pred_taken,
389 if (
bi->lpBranchInfo->loopPredUsed) {
390 bi->tageBranchInfo->provider =
LOOP;
398 bi->scBranchInfo->highConf = tage_scl_bi->
highConf;
399 bi->scBranchInfo->altConf = tage_scl_bi->
altConf;
400 bi->scBranchInfo->medConf = tage_scl_bi->
medConf;
402 bool use_tage_ctr =
bi->tageBranchInfo->hitBank > 0;
403 int8_t tage_ctr = use_tage_ctr ?
405 bool bias = (
bi->tageBranchInfo->longestMatchPred !=
406 bi->tageBranchInfo->altTaken);
409 bi->scBranchInfo, pred_taken, bias, use_tage_ctr, tage_ctr,
413 if (
bi->scBranchInfo->usedScPred) {
414 bi->tageBranchInfo->provider =
SC;
418 bi->lpBranchInfo->predTaken = pred_taken;
438 if (
bi->tageBranchInfo->condBranch) {
445 int nrand =
rng->random<
int>() & 3;
447 DPRINTF(TageSCL,
"Updating tables for branch:%lx; taken?:%d\n",
455 bool bias = (
bi->tageBranchInfo->longestMatchPred !=
456 bi->tageBranchInfo->altTaken);
458 bi->scBranchInfo, target, bias,
bi->tageBranchInfo->hitBank,
465 nrand, target,
bi->lpBranchInfo->predTaken);
470 bi->scBranchInfo, target);
477 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
#define fatal(...)
This implements a cprintf based fatal() function.
Copyright (c) 2024 Arm Limited 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]