44#include "params/StatisticalCorrector.hh"
49namespace branch_prediction
53 const StatisticalCorrectorParams &
p)
56 logSizeUp(
p.logSizeUp),
57 logSizeUps(logSizeUp / 2),
58 numEntriesFirstLocalHistories(
p.numEntriesFirstLocalHistories),
68 chooserConfWidth(
p.chooserConfWidth),
69 updateThresholdWidth(
p.updateThresholdWidth),
70 pUpdateThresholdWidth(
p.pUpdateThresholdWidth),
71 extraWeightsWidth(
p.extraWeightsWidth),
72 scCountersWidth(
p.scCountersWidth),
107 for (
int j = 0; j < (1 <<
logBias); j++) {
138 assert(lengths.size() == numLenghts);
139 if (numLenghts == 0) {
143 for (
int i = 0;
i < numLenghts; ++
i) {
144 table[
i].resize(1 << logNumEntries, 0);
145 for (
int j = 0; j < ((1 << logNumEntries) - 1); ++j) {
159 return (((((branch_pc ^(branch_pc >>2))<<1) ^ (
bi->lowConf &
bias)) <<1)
166 return (((((branch_pc ^ (branch_pc >> (
logBias-2)))<<1) ^
167 (
bi->highConf))<<1) +
bi->predBeforeSC) & ((1<<
logBias) -1);
173 return ((branch_pc ^ (branch_pc >>2)) & ((1 << (
logSizeUp)) - 1));
179 return ((branch_pc ^ (branch_pc >>2)) & ((1 << (
logSizeUps)) - 1));
186 return (((int64_t) branch_pc) ^ bhist ^ (bhist >> (8 -
i)) ^
187 (bhist >> (16 - 2 *
i)) ^ (bhist >> (24 - 3 *
i)) ^
188 (bhist >> (32 - 3 *
i)) ^ (bhist >> (40 - 4 *
i))) &
198 for (
int i = 0;
i < nbr;
i++) {
199 int64_t bhist = hist & ((int64_t) ((1 << length[
i]) - 1));
201 int8_t ctr = tab[
i][
index];
202 percsum += (2 * ctr + 1);
204 percsum = (1 + (
w[
getIndUpds(branch_pc)] >= 0)) * percsum;
215 for (
int i = 0;
i < nbr;
i++) {
216 int64_t bhist = hist & ((int64_t) ((1 << length[
i]) - 1));
218 percsum += (2 * tab[
i][
index] + 1);
222 int xsum =
bi->lsum - ((
w[
getIndUpds(branch_pc)] >= 0)) * percsum;
223 if ((xsum + percsum >= 0) != (xsum >= 0)) {
232 bool use_conf_ctr, int8_t conf_ctr,
unsigned conf_bits,
233 int hitBank,
int altBank, int64_t phist,
int init_lsum)
235 bool pred_taken = prev_pred_taken;
238 bi->predBeforeSC = prev_pred_taken;
242 bi->lowConf = (abs(2 * conf_ctr + 1) == 1);
243 bi->medConf = (abs(2 * conf_ctr + 1) == 5);
244 bi->highConf = (abs(2 * conf_ctr + 1) >= (1<<conf_bits) - 1);
247 int lsum = init_lsum;
250 lsum += (2 * ctr + 1);
252 lsum += (2 * ctr + 1);
254 lsum += (2 * ctr + 1);
264 bool scPred = (lsum >= 0);
266 if (pred_taken != scPred) {
267 bool useScPred =
true;
270 if (abs (lsum) < (thres / 4)) {
272 }
else if (abs (lsum) < (thres / 2)) {
278 if (abs (lsum) < (thres / 4)) {
283 bi->usedScPred = useScPred;
305 if (corrTarget < branch_pc) {
318 (taken & (corrTarget < branch_pc));
326 int altBank, int64_t phist)
328 bool scPred = (
bi->lsum >= 0);
330 if (
bi->predBeforeSC != scPred) {
331 if (abs(
bi->lsum) <
bi->thres) {
333 if ((abs(
bi->lsum) <
bi->thres / 2)) {
334 if ((abs(
bi->lsum) >=
bi->thres / 4)) {
342 if ((abs(
bi->lsum) <
bi->thres / 4)) {
349 if ((scPred != taken) || ((abs(
bi->lsum) <
bi->thres))) {
359 int xsum =
bi->lsum -
360 ((
wb[indUpds] >= 0) * ((2 *
bias[indBias] + 1) +
361 (2 *
biasSK[indBiasSK] + 1) +
364 if ((xsum + ((2 *
bias[indBias] + 1) + (2 *
biasSK[indBiasSK] + 1) +
365 (2 *
biasBank[indBiasBank] + 1)) >= 0) != (xsum >= 0))
368 (((2 *
bias[indBias] + 1) +
369 (2 *
biasSK[indBiasSK] + 1) +
370 (2 *
biasBank[indBiasBank] + 1) >= 0) == taken),
385 if (taken ==
bi->scPred) {
408 : statistics::
Group(parent),
409 ADD_STAT(correct, statistics::units::Count::get(),
410 "Number of time the SC predictor is the provider and the "
411 "prediction is correct"),
412 ADD_STAT(wrong, statistics::units::Count::get(),
413 "Number of time the SC predictor is the provider and the "
414 "prediction is wrong")
Abstract superclass for simulation objects.
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)
std::vector< int8_t > * lgehl
gem5::branch_prediction::StatisticalCorrector::StatisticalCorrectorStats stats
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget)
virtual void gUpdates(ThreadID tid, Addr pc, bool taken, BranchInfo *bi, int64_t phist)=0
void updateStats(bool taken, 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
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)
StatisticalCorrector(const StatisticalCorrectorParams &p)
virtual unsigned getIndUpd(Addr branch_pc) const
virtual unsigned getIndBias(Addr branch_pc, BranchInfo *bi, bool b) const
void ctrUpdate(T &ctr, bool taken, int nbits)
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
virtual int gPredictions(ThreadID tid, Addr branch_pc, BranchInfo *bi, int &lsum, int64_t phist)=0
std::vector< int > pUpdateThreshold
virtual unsigned getIndBiasBank(Addr branch_pc, BranchInfo *bi, int hitBank, int altBank) const =0
virtual SCThreadHistory * makeThreadHistory()
unsigned getIndUpds(Addr branch_pc) const
virtual void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *bi, Addr corrTarget, bool bias_bit, int hitBank, int altBank, int64_t phist)
std::vector< int8_t > wbw
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
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
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.
void updateLocalHistory(int ordinal, Addr branch_pc, bool taken, Addr extraXor=0)
statistics::Scalar correct
StatisticalCorrectorStats(statistics::Group *parent)