45#include "params/StatisticalCorrector.hh"
54 const StatisticalCorrectorParams &
p)
110 for (
int j = 0; j < (1 <<
logBias); j++) {
140 unsigned logNumEntries,
143 assert(lengths.size() == numLenghts);
144 if (numLenghts == 0) {
148 for (
int i = 0;
i < numLenghts; ++
i) {
149 table[
i].resize(1 << logNumEntries, 0);
150 for (
int j = 0; j < ((1 << logNumEntries) - 1); ++j) {
165 return (((((shifted_pc ^ (shifted_pc >> 2)) << 1)
166 ^ (
bi->lowConf &
bias)) << 1) +
bi->predBeforeSC)
174 return (((((shifted_pc ^ (shifted_pc >> (
logBias - 2))) << 1)
175 ^
bi->highConf) << 1) +
bi->predBeforeSC)
183 return ((shifted_pc ^ (shifted_pc >> 2)) & ((1 <<
logSizeUp) - 1));
190 return ((shifted_pc ^ (shifted_pc >> 2)) & ((1 <<
logSizeUps) - 1));
198 bhist ^ (bhist >> (8 -
i)) ^
199 (bhist >> (16 - 2 *
i)) ^ (bhist >> (24 - 3 *
i)) ^
200 (bhist >> (32 - 3 *
i)) ^ (bhist >> (40 - 4 *
i))) &
211 for (
int i = 0;
i < nbr;
i++) {
212 int64_t bhist = hist & ((int64_t) ((1 << length[
i]) - 1));
214 int8_t ctr = tab[
i][
index];
215 percsum += (2 * ctr + 1);
217 percsum = (1 + (
w[
getIndUpds(branch_pc)] >= 0)) * percsum;
228 for (
int i = 0;
i < nbr;
i++) {
229 int64_t bhist = hist & ((int64_t) ((1 << length[
i]) - 1));
231 percsum += (2 * tab[
i][
index] + 1);
235 int xsum =
bi->lsum - ((
w[
getIndUpds(branch_pc)] >= 0)) * percsum;
236 if ((xsum + percsum >= 0) != (xsum >= 0)) {
245 bool bias_bit,
bool use_conf_ctr,
246 int8_t conf_ctr,
unsigned conf_bits,
247 int hitBank,
int altBank,
int init_lsum)
249 bool pred_taken = prev_pred_taken;
252 bi->predBeforeSC = prev_pred_taken;
253 int lsum = init_lsum;
256 use_conf_ctr, conf_ctr, conf_bits, hitBank, altBank);
269 bool scPred = (lsum >= 0);
271 if (pred_taken != scPred) {
272 bool useScPred =
true;
275 if (abs (lsum) < (thres / 4)) {
277 }
else if (abs (lsum) < (thres / 2)) {
283 if (abs (lsum) < (thres / 4)) {
288 bi->usedScPred = useScPred;
301 bool use_conf_ctr, int8_t conf_ctr,
302 unsigned conf_bits,
int hitBank,
int altBank)
306 bi->lowConf = (abs(2 * conf_ctr + 1) == 1);
307 bi->medConf = (abs(2 * conf_ctr + 1) == 5);
308 bi->highConf = (abs(2 * conf_ctr + 1) >= (1<<conf_bits) - 1);
314 lsum += (2 * ctr + 1);
316 lsum += (2 * ctr + 1);
318 lsum += (2 * ctr + 1);
355 Addr target, int64_t phist)
365 if (target < branch_pc) {
378 (taken & (target < branch_pc));
379 scHistory->updateLocalHistory(1, branch_pc, taken);
390 bi->localHistories[1] =
scHistory->getLocalHistory(1, branch_pc);
401 scHistory->setLocalHistory(1,
bi->pc,
bi->localHistories[1]);
409 Addr corrTarget,
bool b,
int hitBank,
418 0, 0, hitBank, altBank);
422 bool scPred = (
bi->lsum >= 0);
424 if (
bi->predBeforeSC != scPred) {
425 if (abs(
bi->lsum) <
bi->thres) {
427 if ((abs(
bi->lsum) <
bi->thres / 2)) {
428 if ((abs(
bi->lsum) >=
bi->thres / 4)) {
436 if ((abs(
bi->lsum) <
bi->thres / 4)) {
443 if ((scPred != taken) || ((abs(
bi->lsum) <
bi->thres))) {
453 int xsum =
bi->lsum -
454 ((
wb[indUpds] >= 0) * ((2 *
bias[indBias] + 1) +
455 (2 *
biasSK[indBiasSK] + 1) +
458 if ((xsum + ((2 *
bias[indBias] + 1) + (2 *
biasSK[indBiasSK] + 1) +
459 (2 *
biasBank[indBiasBank] + 1)) >= 0) != (xsum >= 0))
462 (((2 *
bias[indBias] + 1) +
463 (2 *
biasSK[indBiasSK] + 1) +
464 (2 *
biasBank[indBiasBank] + 1) >= 0) == taken),
479 if (taken ==
bi->scPred) {
504 "Number of time the SC predictor is the provider and the "
505 "prediction is correct"),
507 "Number of time the SC predictor is the provider and the "
508 "prediction is wrong")
bool isDirectCtrl() const
bool isUncondCtrl() const
const unsigned logSizeUps
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
std::vector< int8_t > * lgehl
gem5::branch_prediction::StatisticalCorrector::StatisticalCorrectorStats stats
void updateStats(bool taken, BranchInfo *bi)
virtual bool scRestoreHistState(BranchInfo *bi)
virtual unsigned getIndBiasSK(Addr branch_pc, BranchInfo *bi) const
int gPredict(Addr branch_pc, int64_t hist, std::vector< int > &length, std::vector< int8_t > *tab, int nbr, int logs, std::vector< int8_t > &w)
const unsigned scCountersWidth
const unsigned numEntriesFirstLocalHistories
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, Addr target, int64_t phist)
virtual void scRecordHistState(Addr branch_pc, BranchInfo *bi)
StatisticalCorrector(const StatisticalCorrectorParams &p)
const unsigned instShiftAmt
virtual unsigned getIndUpd(Addr branch_pc) const
const bool speculativeHistUpdate
int calcBias(Addr branch_pc, BranchInfo *bi, bool bias_bit, bool use_conf_ctr, int8_t conf_ctr, unsigned conf_bits, int hitBank, int altBank)
virtual unsigned getIndBias(Addr branch_pc, BranchInfo *bi, bool b) const
void ctrUpdate(T &ctr, bool taken, int nbits)
void updateHistories(Addr branch_pc, bool speculative, const StaticInstPtr &inst, bool taken, BranchInfo *bi, Addr target, int64_t phist)
const unsigned extraWeightsWidth
SCThreadHistory * scHistory
const unsigned chooserConfWidth
virtual size_t getSizeInBits() const
virtual 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, BranchInfo *bi)
std::vector< int8_t > biasSK
std::vector< int8_t > * bwgehl
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
std::vector< int8_t > biasBank
std::vector< int > pUpdateThreshold
virtual unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const =0
virtual SCThreadHistory * makeThreadHistory()
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, Addr corrTarget, bool bias_bit, int hitBank, int altBank)
unsigned getIndUpds(Addr branch_pc) const
std::vector< int8_t > wbw
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, int init_lsum=0)
const unsigned updateThresholdWidth
virtual int gIndexLogsSubstr(int nbr, int i)=0
int64_t gIndex(Addr branch_pc, int64_t bhist, int logs, int nbr, int i)
std::vector< int8_t > * igehl
virtual BranchInfo * makeBranchInfo()
std::vector< int8_t > bias
const unsigned pUpdateThresholdWidth
virtual void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi)=0
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
SimObject(const Params &p)
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
statistics::Scalar correct
StatisticalCorrectorStats(statistics::Group *parent)