74 if (
bi->hitBank > 0) {
75 if (abs (2 *
gtable[
bi->hitBank][
bi->hitBankIndex].ctr + 1) == 1) {
76 if (
bi->longestMatchPred != taken) {
78 if (
bi->altBank > 0) {
82 if (
bi->altBank == 0){
92 if (abs (2 *
gtable[
bi->hitBank][
bi->hitBankIndex].ctr + 1) == 1) {
99 if ((
bi->longestMatchPred !=
bi->altTaken) &&
100 (
bi->longestMatchPred == taken) &&
116 if ((
rng->random<
int>() & 127) < 32) {
119 int dep =
bi->hitBank +
a;
122 int numAllocated = 0;
129 gtable[
i][
bi->tableIndices[
i]].ctr = taken ? 0 : -1;
139 }
else { assert(
false); }
142 tCounter += (penalty - numAllocated);
181 uint32_t
pc = (uint32_t) pc_in;
188 uint32_t hpc = ((uint32_t) branch_pc);
189 hpc = (hpc ^(hpc >> 4));
198 if ((taken == pred_taken) && ((
rng->random<
int>() & 31) != 0)) {
212 assert(! speculative);
220 int tmp = (branch_pc << 1) + taken;
221 int path = branch_pc;
223 int maxt = (brtype & 1) ? 1 : 4;
226 for (
int t = 0;
t < maxt;
t++) {
227 int pathbit = (
path & 127);
240 if (
bi->hitBank > 0) {
241 return (abs(2 *
gtable[
bi->hitBank][
bi->hitBankIndex].ctr + 1)) >=
246 return (bim == 0) || (bim == 3);
261 return ((
rng->random<
int>() & 7) == 0);
272 for (int8_t &pos :
wl) {
280 for (
int j = 0; j < (1 <<
logBias); j++) {
295 unsigned int truncated_pc = branch_pc;
296 return ((truncated_pc << 1) +
bi->predBeforeSC) & ((1 <<
logBias) - 1);
303 return (((branch_pc ^ (branch_pc >> (
logBias - 1))) << 1)
304 +
bi->predBeforeSC) & ((1 <<
logBias) - 1);
317 return (
i >= (nbr - 2)) ? 1 : 0;
323 return ((branch_pc ^ (branch_pc >> 4)) & ((1 << (
logSizeUp)) - 1));
332 for (
int i = 0;
i < nbr;
i++) {
333 int64_t bhist = hist & ((int64_t) ((1 << length[
i]) - 1));
342 bool prev_pred_taken,
bool bias_bit,
bool use_conf_ctr,
343 int8_t conf_ctr,
unsigned conf_bits,
int hitBank,
int altBank,
346 bool pred_taken = prev_pred_taken;
349 bi->predBeforeSC = prev_pred_taken;
351 int lsum = init_lsum;
360 bi->scPred = (lsum >= 0);
362 if (pred_taken !=
bi->scPred) {
363 pred_taken =
bi->scPred;
366 if ((abs(lsum) < thres / 3))
367 pred_taken = (
firstH < 0) ?
bi->scPred : prev_pred_taken;
368 else if ((abs(lsum) < 2 * thres / 3))
369 pred_taken = (
secondH < 0) ?
bi->scPred : prev_pred_taken;
370 else if ((abs(lsum) < thres))
371 pred_taken = (
thirdH < 0) ?
bi->scPred : prev_pred_taken;
380 const MultiperspectivePerceptronTAGEParams &
p)
386 "Speculative updates support is not implemented");
393 int numBitsTage =
tage->getSizeInBits();
397 setExtraBits(numBitsTage + numBitsLoopPred + numBitsStatisticalCorrector);
409 unsigned long long int h =
g;
411 h ^= (
bi.getPC() ^ (
bi.getPC() >> 2));
431 for (
int i = 0;
i <
specs.size();
i += 1) {
444 for (
int i = 0;
i <
specs.size();
i += 1) {
448 short int max_weight = (1 << (
specs[
i]->width - 1)) - 1;
449 short int min_weight = -(1 << (
specs[
i]->width - 1));
451 if (*
c < max_weight) {
455 if (*
c > min_weight) {
467 unsigned int hpc = (
bi.getPC() ^ (
bi.getPC() >> 2));
468 unsigned int pc =
bi.getPC();
471 unsigned short recency_pc =
pc >> 2;
480 if (hpc % (
i + 2) == 0) {
491 if (hpc % (
i + 2) == 0) {
503 for (
int i = 0;
i < blurrypath_histories.size();
i += 1)
505 if (blurrypath_histories[
i].size() > 0) {
506 unsigned int z =
pc >>
i;
507 if (blurrypath_histories[
i][0] !=
z) {
508 memmove(&blurrypath_histories[
i][1],
509 &blurrypath_histories[
i][0],
510 sizeof(
unsigned int) *
511 (blurrypath_histories[
i].size() - 1));
512 blurrypath_histories[
i][0] =
z;
525 bp_history = (
void *)
bi;
526 bool pred_taken =
tage->tagePredict(tid, instPC,
true,
bi->tageBranchInfo);
531 bi->scBranchInfo->highConf =
tage->isHighConfidence(
bi->tageBranchInfo);
535 init_lsum = -init_lsum;
540 bi->scBranchInfo, pred_taken,
false ,
544 bi->predictedTaken = pred_taken;
545 bi->lpBranchInfo->predTaken = pred_taken;
553 bool bias_bit,
int hitBank,
int altBank)
555 bool scPred = (
bi->lsum >= 0);
557 if (
bi->predBeforeSC != scPred) {
558 if (abs(
bi->lsum) <
bi->thres) {
560 if (abs(
bi->lsum) <
bi->thres / 3) {
563 }
else if (abs(
bi->lsum) < 2 *
bi->thres / 3) {
566 }
else if (abs(
bi->lsum) <
bi->thres) {
574 if ((scPred != taken) || ((abs(
bi->lsum) <
bi->thres))) {
593 void * &bp_history,
bool squashed,
601 if (
tage->isSpeculativeUpdateEnabled()) {
604 tage->squash(tid, taken, target, inst,
bi->tageBranchInfo);
605 if (
bi->tageBranchInfo->condBranch) {
612 if (
bi->isUnconditional()) {
613 tage->updateHistories(tid,
pc,
false, taken, target,
614 inst,
bi->tageBranchInfo);
616 bi->scBranchInfo, target,
617 tage->getPathHist(tid,
false));
619 tage->updateStats(taken,
bi->tageBranchInfo);
626 bool scPred = (
bi->scBranchInfo->lsum >= 0);
627 if ((scPred != taken) ||
628 ((abs(
bi->scBranchInfo->lsum) <
bi->scBranchInfo->thres))) {
632 bi->scBranchInfo, target,
637 tage->condBranchUpdate(tid,
pc, taken,
bi->tageBranchInfo,
638 rng->random<
int>(), target,
639 bi->predictedTaken,
true);
643 if (!
tage->isSpeculativeUpdateEnabled()) {
646 uint32_t truncated_target = target;
647 uint32_t truncated_pc =
pc;
648 if (truncated_target < truncated_pc) {
663 tage->updateHistories(tid,
pc,
false, taken, target,
664 inst,
bi->tageBranchInfo);
666 bi->scBranchInfo, target,
667 tage->getPathHist(tid,
672 bp_history =
nullptr;
677 bool uncond,
bool taken,
Addr target,
681 assert(uncond || bp_history);
690 bp_history = (
void *)
bi;
699 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.
virtual bool calcConf(int index) const
bool optionalAgeInc() const override
bool calcConf(int index) const override
unsigned getIndUpd(Addr branch_pc) const override
void gUpdate(Addr branch_pc, bool taken, int64_t hist, std::vector< int > &length, std::vector< int8_t > *tab, int nbr, int logs, std::vector< int8_t > &w, StatisticalCorrector::BranchInfo *bi) override
unsigned getIndBiasSK(Addr branch_pc, StatisticalCorrector::BranchInfo *bi) const override
unsigned getIndBias(Addr branch_pc, StatisticalCorrector::BranchInfo *bi, bool bias) const override
bool scPredict(ThreadID tid, Addr branch_pc, bool cond_branch, StatisticalCorrector::BranchInfo *bi, bool prev_pred_taken, bool bias_bit, bool use_conf_ctr, int8_t conf_ctr, unsigned conf_bits, int hitBank, int altBank, int init_lsum) override
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, StatisticalCorrector::BranchInfo *bi, Addr target, bool b, int hitBank, int altBank) override
std::vector< int8_t > * pgehl
unsigned getIndBiasBank(Addr branch_pc, StatisticalCorrector::BranchInfo *bi, int hitBank, int altBank) const override
int gIndexLogsSubstr(int nbr, int i) override
virtual void getBiasLSUM(Addr branch_pc, StatisticalCorrector::BranchInfo *bi, int &lsum) const =0
MPP_StatisticalCorrector(const MPP_StatisticalCorrectorParams &p)
std::vector< int8_t > * ggehl
void handleAllocAndUReset(bool alloc, bool taken, TAGEBase::BranchInfo *bi, int nrand) override
Handles Allocation and U bits reset on an update.
void resetUctr(uint8_t &u) override
Algorithm for resetting a single U counter.
int bindex(Addr pc_in) const override
Computes the index used to access the bimodal table.
std::vector< unsigned int > tunedHistoryLengths
void calculateParameters() override
Calculates the history lengths and some other paramters in derived classes.
void updateHistories(ThreadID tid, Addr branch_pc, bool speculative, bool taken, Addr target, const StaticInstPtr &inst, TAGEBase::BranchInfo *bi) override
(Speculatively) updates global histories (path and direction).
void handleTAGEUpdate(Addr branch_pc, bool taken, TAGEBase::BranchInfo *bi) override
Handles the update of the TAGE entries.
bool isHighConfidence(TAGEBase::BranchInfo *bi) const override
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 ...
unsigned getUseAltIdx(TAGEBase::BranchInfo *bi, Addr branch_pc) override
Calculation of the index for useAltPredForNewlyAllocated On this base TAGE implementation it is alway...
void handleUReset() override
Handles the U bits reset.
bool lookup(ThreadID tid, Addr instPC, void *&bp_history) override
Looks up a given conditional branch PC of in the BP to see if it is taken or not taken.
void squash(ThreadID tid, void *&bp_history) override
int computePartialSum(ThreadID tid, MPPTAGEBranchInfo &bi) const
LoopPredictor * loopPredictor
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.
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
MultiperspectivePerceptronTAGE(const MultiperspectivePerceptronTAGEParams &p)
StatisticalCorrector * statisticalCorrector
unsigned int getIndex(ThreadID tid, MPPTAGEBranchInfo &bi, const HistorySpec &spec, int index) const
void updatePartial(ThreadID tid, MPPTAGEBranchInfo &bi, bool taken)
void updateHistories(ThreadID tid, MPPTAGEBranchInfo &bi, bool taken)
std::vector< ThreadData * > threadData
const unsigned long long int imli_mask4
std::vector< int > modpath_lengths
MultiperspectivePerceptron(const MultiperspectivePerceptronParams ¶ms)
std::vector< int > modhist_indices
std::vector< int > modhist_lengths
std::vector< int > table_sizes
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
void setExtraBits(int bits)
Sets the starting number of storage bits to compute the number of table entries.
std::vector< HistorySpec * > specs
Predictor tables.
std::vector< int > modpath_indices
const unsigned long long int imli_mask1
void initGEHLTable(unsigned numLenghts, std::vector< int > lengths, std::vector< int8_t > *&table, unsigned logNumEntries, std::vector< int8_t > &w, int8_t wInitValue)
virtual int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum)=0
const unsigned scCountersWidth
StatisticalCorrector(const StatisticalCorrectorParams &p)
void ctrUpdate(T &ctr, bool taken, int nbits)
const unsigned chooserConfWidth
std::vector< int8_t > biasSK
std::vector< int > pUpdateThreshold
int64_t gIndex(Addr branch_pc, int64_t bhist, int logs, int nbr, int i)
std::vector< int8_t > bias
const unsigned pUpdateThresholdWidth
virtual void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi)=0
const unsigned tagTableUBits
static void ctrUpdate(T &ctr, bool taken, int nbits)
Updates a direction counter based on the actual branch outcome.
const unsigned logRatioBiModalHystEntries
std::vector< bool > btableHysteresis
std::vector< bool > btablePrediction
const unsigned nHistoryTables
std::vector< ThreadHistory > threadHistory
std::vector< int > logTagTableSizes
void baseUpdate(Addr pc, bool taken, BranchInfo *bi)
Updates the bimodal predictor.
std::vector< bool > noSkip
const bool speculativeHistUpdate
const unsigned tagTableCounterBits
void updateGHist(ThreadID tid, uint64_t bv, uint8_t n)
Internal history update function.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
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.
RefCountingPtr< StaticInst > StaticInstPtr
Branch information data type.
Base class to implement the predictor tables.
virtual unsigned int getHash(ThreadID tid, Addr pc, Addr pc2, int t) const =0
Gets the hash to index the table, using the pc of the branch, and the index of the table.