44 #include "params/StatisticalCorrector.hh" 47 const StatisticalCorrectorParams *
p)
50 logSizeUp(p->logSizeUp),
51 logSizeUps(logSizeUp / 2),
52 numEntriesFirstLocalHistories(p->numEntriesFirstLocalHistories),
62 chooserConfWidth(p->chooserConfWidth),
63 updateThresholdWidth(p->updateThresholdWidth),
64 pUpdateThresholdWidth(p->pUpdateThresholdWidth),
65 extraWeightsWidth(p->extraWeightsWidth),
66 scCountersWidth(p->scCountersWidth),
131 assert(lengths.size() == numLenghts);
132 if (numLenghts == 0) {
136 for (
int i = 0;
i < numLenghts; ++
i) {
137 table[
i].resize(1 << logNumEntries, 0);
138 for (
int j = 0;
j < ((1 << logNumEntries) - 1); ++
j) {
152 return (((((branch_pc ^(branch_pc >>2))<<1) ^ (bi->
lowConf & bias)) <<1)
159 return (((((branch_pc ^ (branch_pc >> (
logBias-2)))<<1) ^
166 return ((branch_pc ^ (branch_pc >>2)) & ((1 << (
logSizeUp)) - 1));
172 return ((branch_pc ^ (branch_pc >>2)) & ((1 << (
logSizeUps)) - 1));
179 return (((int64_t) branch_pc) ^ bhist ^ (bhist >> (8 - i)) ^
180 (bhist >> (16 - 2 * i)) ^ (bhist >> (24 - 3 * i)) ^
181 (bhist >> (32 - 3 * i)) ^ (bhist >> (40 - 4 * i))) &
191 for (
int i = 0;
i < nbr;
i++) {
192 int64_t bhist = hist & ((int64_t) ((1 << length[
i]) - 1));
193 int64_t
index =
gIndex(branch_pc, bhist, logs, nbr, i);
194 int8_t ctr = tab[
i][
index];
195 percsum += (2 * ctr + 1);
197 percsum = (1 + (w[
getIndUpds(branch_pc)] >= 0)) * percsum;
208 for (
int i = 0;
i < nbr;
i++) {
209 int64_t bhist = hist & ((int64_t) ((1 << length[
i]) - 1));
210 int64_t
index =
gIndex(branch_pc, bhist, logs, nbr, i);
211 percsum += (2 * tab[
i][
index] + 1);
215 int xsum = bi->
lsum - ((w[
getIndUpds(branch_pc)] >= 0)) * percsum;
216 if ((xsum + percsum >= 0) != (xsum >= 0)) {
225 bool use_conf_ctr, int8_t conf_ctr,
unsigned conf_bits,
226 int hitBank,
int altBank, int64_t phist,
int init_lsum)
228 bool pred_taken = prev_pred_taken;
235 bi->
lowConf = (abs(2 * conf_ctr + 1) == 1);
236 bi->
medConf = (abs(2 * conf_ctr + 1) == 5);
237 bi->
highConf = (abs(2 * conf_ctr + 1) >= (1<<conf_bits) - 1);
240 int lsum = init_lsum;
243 lsum += (2 * ctr + 1);
245 lsum += (2 * ctr + 1);
247 lsum += (2 * ctr + 1);
251 int thres =
gPredictions(tid, branch_pc, bi, lsum, phist);
257 bool scPred = (lsum >= 0);
259 if (pred_taken != scPred) {
260 bool useScPred =
true;
263 if (abs (lsum) < (thres / 4)) {
265 }
else if (abs (lsum) < (thres / 2)) {
271 if (abs (lsum) < (thres / 4)) {
298 if (corrTarget < branch_pc) {
311 (taken & (corrTarget < branch_pc));
319 int altBank, int64_t phist)
321 bool scPred = (bi->
lsum >= 0);
342 if ((scPred != taken) || ((abs(bi->
lsum) < bi->
thres))) {
348 unsigned indBias =
getIndBias(branch_pc, bi, b);
350 unsigned indBiasBank =
getIndBiasBank(branch_pc, bi, hitBank, altBank);
352 int xsum = bi->
lsum -
353 ((
wb[indUpds] >= 0) * ((2 *
bias[indBias] + 1) +
354 (2 *
biasSK[indBiasSK] + 1) +
357 if ((xsum + ((2 *
bias[indBias] + 1) + (2 *
biasSK[indBiasSK] + 1) +
358 (2 *
biasBank[indBiasBank] + 1)) >= 0) != (xsum >= 0))
361 (((2 *
bias[indBias] + 1) +
362 (2 *
biasSK[indBiasSK] + 1) +
363 (2 *
biasBank[indBiasBank] + 1) >= 0) == taken),
371 gUpdates(tid, branch_pc, taken, bi, phist);
378 if (taken == bi->
scPred) {
403 .
name(
name() +
".scPredictorCorrect")
404 .
desc(
"Number of time the SC predictor is the provider and " 405 "the prediction is correct");
409 .
desc(
"Number of time the SC predictor is the provider and " 410 "the prediction is wrong");
std::vector< int8_t > biasBank
unsigned getIndUpds(Addr branch_pc) const
Stats::Scalar scPredictorWrong
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
void ctrUpdate(T &ctr, bool taken, int nbits)
const unsigned logSizeUps
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, Addr corrTarget, bool bias_bit, int hitBank, int altBank, int64_t phist)
void initGEHLTable(unsigned numLenghts, std::vector< int > lengths, std::vector< int8_t > *&table, unsigned logNumEntries, std::vector< int8_t > &w, int8_t wInitValue)
const unsigned pUpdateThresholdWidth
virtual void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi, int64_t phist)=0
virtual int gIndexLogsSubstr(int nbr, int i)=0
std::vector< int8_t > * igehl
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)
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
bool isDirectCtrl() const
bool isUncondCtrl() const
void updateLocalHistory(int ordinal, Addr branch_pc, bool taken, Addr extraXor=0)
virtual unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const =0
virtual unsigned getIndUpd(Addr branch_pc) const
int64_t gIndex(Addr branch_pc, int64_t bhist, int logs, int nbr, int i)
std::vector< int8_t > bias
const unsigned scCountersWidth
Stats::Scalar scPredictorCorrect
std::vector< int > pUpdateThreshold
SCThreadHistory * scHistory
const unsigned updateThresholdWidth
virtual SCThreadHistory * makeThreadHistory()
virtual unsigned getIndBiasSK(Addr branch_pc, BranchInfo *bi) const
const unsigned chooserConfWidth
const unsigned extraWeightsWidth
std::vector< int8_t > * bwgehl
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
virtual int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum, int64_t phist)=0
virtual const std::string name() const
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget)
virtual size_t getSizeInBits() const
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
int16_t ThreadID
Thread index/ID type.
void regStats() override
Callback to set stat parameters.
virtual unsigned getIndBias(Addr branch_pc, BranchInfo *bi, bool b) const
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)
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
std::vector< int8_t > * lgehl
virtual BranchInfo * makeBranchInfo()
StatisticalCorrector(const StatisticalCorrectorParams *p)
Abstract superclass for simulation objects.
std::vector< int8_t > wbw