46 #include "debug/TageSCL.hh" 62 TAGE_SC_L_LoopPredictorParams::create()
68 :
LTAGE(p), statisticalCorrector(p->statistical_corrector)
80 unsigned numHistLengths = nHistoryTables/2;
81 histLengths[1] = minHist;
82 histLengths[numHistLengths] = maxHist;
87 for (
int i = 2;
i <= numHistLengths;
i++) {
88 histLengths[
i] = (int) (((
double) minHist *
89 pow ((
double) (maxHist) / (
double) minHist,
90 (
double) (
i - 1) / (
double) ((numHistLengths - 1))))
96 for (
int i = nHistoryTables;
i > 1;
i--)
98 histLengths[
i] = histLengths[(
i + 1) / 2];
101 for (
int i = 1;
i <= nHistoryTables;
i++)
103 tagTableTagWidths.push_back(
104 (
i < firstLongTagTable) ? shortTagsSize : longTagsSize);
106 logTagTableSizes.push_back(logTagTableSize);
116 gtable[1] =
new TageEntry[shortTagsTageFactor * (1 << logTagTableSize)];
117 gtable[firstLongTagTable] =
118 new TageEntry[longTagsTageFactor * (1 << logTagTableSize)];
119 for (
int i = 2;
i < firstLongTagTable; ++
i) {
120 gtable[
i] = gtable[1];
122 for (
int i = firstLongTagTable + 1;
i <= nHistoryTables; ++
i) {
123 gtable[
i] = gtable[firstLongTagTable];
133 for (
int i = 1;
i <= nHistoryTables;
i += 2) {
134 tableIndices[
i] = gindex(tid, pc,
i);
135 tableTags[
i] = gtag(tid, pc,
i);
136 tableTags[
i + 1] = tableTags[
i];
137 tableIndices[
i + 1] = tableIndices[
i] ^
138 (tableTags[
i] & ((1 << logTagTableSizes[
i]) - 1));
144 Addr t = (pc ^ (threadHistory[tid].pathHist &
145 ((1 << histLengths[firstLongTagTable]) - 1)))
146 % longTagsTageFactor;
148 for (
int i = firstLongTagTable;
i <= nHistoryTables;
i++) {
150 tableIndices[
i] += (t << logTagTableSizes[
i]);
153 t = t % longTagsTageFactor;
157 t = (pc ^ (threadHistory[tid].pathHist & ((1 << histLengths[1]) - 1)))
158 % shortTagsTageFactor;
160 for (
int i = 1;
i <= firstLongTagTable - 1;
i++) {
162 tableIndices[
i] += (t << logTagTableSizes[
i]);
165 t = t % shortTagsTageFactor;
175 idx = ((((bi->
hitBank-1)/8)<<1)+tbi->
altConf) % (numUseAltOnNa-1);
183 int hlen = (histLengths[bank] > pathHistBits) ? pathHistBits :
185 unsigned int shortPc =
pc;
189 (shortPc >> ((int) abs(logTagTableSizes[bank] - bank) + 1)) ^
190 threadHistory[tid].computeIndices[bank].comp ^
191 F(threadHistory[tid].pathHist, hlen, bank);
193 index = gindex_ext(index, bank);
195 return (index & ((
ULL(1) << (logTagTableSizes[bank])) - 1));
203 a = a & ((
ULL(1) << size) - 1);
204 a1 = (a & ((
ULL(1) << logTagTableSizes[bank]) - 1));
205 a2 = (a >> logTagTableSizes[bank]);
207 if (bank < logTagTableSizes[bank]) {
208 a2 = ((a2 << bank) & ((
ULL(1) << logTagTableSizes[bank]) - 1))
209 + (a2 >> (logTagTableSizes[bank] - bank));
214 if (bank < logTagTableSizes[bank]) {
215 a = ((a << bank) & ((
ULL(1) << logTagTableSizes[bank]) - 1))
216 + (a >> (logTagTableSizes[bank] - bank));
226 ((
ULL(1) << (logTagTableSizes[0])) - 1));
234 int tmp = ((branch_pc ^ (branch_pc >>
instShiftAmt))) ^ taken;
237 if ((brtype == 3) & taken) {
243 int maxt = (brtype == 2) ? 3 : 2;
245 for (
int t = 0;
t < maxt;
t++) {
246 bool dir = (tmp & 1);
248 int pathbit = (path & 127);
252 if (truncatePathHist) {
256 for (
int i = 1;
i <= nHistoryTables;
i++) {
269 if (speculative != speculativeHistUpdate) {
273 assert(! speculative);
281 updatePathAndGlobalHistory(tHist, brtype, taken, branch_pc, target);
283 DPRINTF(TageSCL,
"Updating global histories with branch:%lx; taken?:%d, " 284 "path Hist: %x; pointer:%d\n", branch_pc, taken, tHist.
pathHist,
292 fatal(
"Speculation is not implemented");
311 return ((((bi->
hitBank - 1 + 2 * a) & 0xffe)) ^
324 if (tCounter >= ((
ULL(1) << logUResetPeriod))) {
326 for (
int j = 0;
j < (shortTagsTageFactor*(1<<logTagTableSize));
j++) {
327 resetUctr(gtable[1][
j].
u);
331 for (
int j = 0;
j < (longTagsTageFactor*(1<<logTagTableSize));
j++) {
332 resetUctr(gtable[firstLongTagTable][
j].
u);
346 + btableHysteresis[bi->
bimodalIndex >> logRatioBiModalHystEntries];
348 bi->
highConf = (bim == 0) || (bim == 3);
361 tage_scl_bi->
altConf = (abs(2*ctr + 1) > 1);
375 bi->lpBranchInfo, pred_taken,
378 if (bi->lpBranchInfo->loopPredUsed) {
379 bi->tageBranchInfo->provider =
LOOP;
391 bool use_tage_ctr = bi->tageBranchInfo->hitBank > 0;
392 int8_t tage_ctr = use_tage_ctr ?
394 bool bias = (bi->tageBranchInfo->longestMatchPred !=
395 bi->tageBranchInfo->altTaken);
398 bi->
scBranchInfo, pred_taken, bias, use_tage_ctr, tage_ctr,
403 bi->tageBranchInfo->provider =
SC;
407 bi->lpBranchInfo->predTaken = pred_taken;
426 tage->
squash(tid, taken, tage_bi, corrTarget);
427 if (bi->tageBranchInfo->condBranch) {
436 DPRINTF(TageSCL,
"Updating tables for branch:%lx; taken?:%d\n",
444 bool bias = (bi->tageBranchInfo->longestMatchPred !=
445 bi->tageBranchInfo->altTaken);
447 bi->
scBranchInfo, corrTarget, bias, bi->tageBranchInfo->hitBank,
451 bi->tageBranchInfo->tagePred, bi->lpBranchInfo,
instShiftAmt);
454 nrand, corrTarget, bi->lpBranchInfo->predTaken);
void squashLoop(BranchInfo *bi)
void updatePathAndGlobalHistory(ThreadHistory &tHist, int brtype, bool taken, Addr branch_pc, Addr target)
TAGE_SC_L_LoopPredictor(TAGE_SC_L_LoopPredictorParams *p)
void update(ThreadID tid, Addr branch_addr, bool taken, void *bp_history, bool squashed, const StaticInstPtr &inst, Addr corrTarget=MaxAddr) override
Updates the BP with taken/not taken information.
#define fatal(...)
This implements a cprintf based fatal() function.
StatisticalCorrector::BranchInfo * scBranchInfo
TAGE_SC_L(const TAGE_SC_LParams *params)
static std::stack< std::string > path
void regStats() override
Registers statistics.
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, bool tage_pred, BranchInfo *bi, unsigned instShiftAmt)
Update LTAGE for conditional branches.
void buildTageTables() override
Instantiates the TAGE table entries.
void squash(ThreadID tid, bool taken, TAGEBase::BranchInfo *bi, Addr target) override
Restores speculatively updated path and direction histories.
bool isSpeculativeUpdateEnabled() 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)
virtual void updateStats(bool taken, BranchInfo *bi)
Update the stats.
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 void regStats() override
Registers statistics.
int calcDep(TAGEBase::BranchInfo *bi)
FoldedHistory * computeTags[2]
bool isDirectCtrl() const
bool isUncondCtrl() const
std::enable_if< std::is_integral< T >::value, T >::type random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
bool predict(ThreadID tid, Addr branch_pc, bool cond_branch, void *&b) override
Get a branch prediction from LTAGE.
StatisticalCorrector * statisticalCorrector
virtual bool optionalAgeInc() const override
bool getBimodePred(Addr branch_pc, TAGEBase::BranchInfo *tage_bi) const override
Get a branch prediction from the bimodal predictor.
int bindex(Addr pc_in) const override
Computes the index used to access the bimodal table.
virtual void squash(ThreadID tid, bool taken, BranchInfo *bi, Addr target)
Restores speculatively updated path and direction histories.
void calculateParameters() override
Calculates the history lengths and some other paramters in derived classes.
int gindex(ThreadID tid, Addr pc, int bank) const override
Computes the index used to access a partially tagged table.
virtual bool calcConf(int index) const
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...
virtual bool getBimodePred(Addr pc, BranchInfo *bi) const
Get a branch prediction from the bimodal predictor.
virtual bool calcConf(int index) const override
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...
void handleUReset() override
Handles the U bits reset.
int getPathHist(ThreadID tid) const
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
#define ULL(N)
uint64_t constant
bool tagePredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi)
TAGE prediction called from TAGE::predict.
virtual void scHistoryUpdate(Addr branch_pc, const StaticInstPtr &inst, bool taken, BranchInfo *tage_bi, Addr corrTarget)
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).
int16_t ThreadID
Thread index/ID type.
unsigned getTageCtrBits() const
virtual TAGEBase::BranchInfo * makeBranchInfo() override
unsigned getUseAltIdx(TAGEBase::BranchInfo *bi, Addr branch_pc) override
Calculation of the index for useAltPredForNewlyAllocated On this base TAGE implementation it is alway...
void extraAltCalc(TAGEBase::BranchInfo *bi) override
Extra steps for calculating altTaken For this base TAGE class it does nothing.
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)
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 ...
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
LoopPredictor * loopPredictor
The loop predictor object.
FoldedHistory * computeIndices
bool loopPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, unsigned instShiftAmt)
Get the loop prediction.
virtual void updateHistories(ThreadID tid, Addr branch_pc, bool taken, BranchInfo *b, bool speculative, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr, Addr target=MaxAddr)
(Speculatively) updates global histories (path and direction).
int8_t getCtr(int hitBank, int hitBankIndex) const
void updateStats(bool taken, BranchInfo *bi)
Update the stats.