50#include "debug/LTage.hh"
51#include "params/LoopPredictor.hh"
56namespace branch_prediction
61 loopTableAgeBits(
p.loopTableAgeBits),
62 loopTableConfidenceBits(
p.loopTableConfidenceBits),
63 loopTableTagBits(
p.loopTableTagBits),
64 loopTableIterBits(
p.loopTableIterBits),
65 logLoopTableAssoc(
p.logLoopTableAssoc),
66 confidenceThreshold((1 << loopTableConfidenceBits) - 1),
67 loopTagMask((1 << loopTableTagBits) - 1),
68 loopNumIterMask((1 << loopTableIterBits) - 1),
69 loopSetMask((1 << (logSizeLoopPred - logLoopTableAssoc)) - 1),
71 withLoopBits(
p.withLoopBits),
72 useDirectionBit(
p.useDirectionBit),
73 useSpeculation(
p.useSpeculation),
74 useHashing(
p.useHashing),
75 restrictAllocation(
p.restrictAllocation),
76 initialLoopIter(
p.initialLoopIter),
77 initialLoopAge(
p.initialLoopAge),
78 optionalAgeReset(
p.optionalAgeReset),
113 Addr pc = pc_in >> instShiftAmt;
131 unsigned instShiftAmt)
const
134 bi->loopPredValid =
false;
150 if (
ltable[idx].tag ==
bi->loopTag) {
157 if ((iter + 1) ==
ltable[idx].numIter) {
176 if (
bi->loopHit>=0) {
197 if (
bi->loopHit >= 0) {
199 if (
bi->loopPredValid) {
200 if (taken !=
bi->loopPred) {
208 DPRINTF(LTage,
"Loop Prediction success:%lx\n",
pc);
217 if (
ltable[idx].numIter != 0) {
228 DPRINTF(LTage,
"Loop End predicted successfully:%lx\n",
pc);
232 if (
ltable[idx].numIter < 3) {
240 DPRINTF(LTage,
"Loop End predicted incorrectly:%lx\n",
pc);
241 if (
ltable[idx].numIter == 0) {
265 if (
ltable[idx].age == 0) {
267 "Allocating loop pred entry for branch %lx\n",
290 BranchInfo*
bi,
bool prev_pred_taken,
unsigned instShiftAmt)
292 bool pred_taken = prev_pred_taken;
298 pred_taken =
bi->loopPred;
299 bi->loopPredUsed =
true;
313 if (
bi->loopHit >= 0) {
324 if (
bi->loopHit >= 0) {
335 if (
bi->loopPredUsed) {
337 if (taken ==
bi->loopPred) {
348 unsigned instShiftAmt)
355 bi->loopPred =
getLoop(branch_pc,
bi,
false, instShiftAmt);
358 if (
bi->loopPredValid) {
359 if (
bi->predTaken !=
bi->loopPred) {
361 (
bi->loopPred == taken),
371 : statistics::
Group(parent),
372 ADD_STAT(used, statistics::units::Count::get(),
373 "Number of times the loop predictor is the provider."),
374 ADD_STAT(correct, statistics::units::Count::get(),
375 "Number of times the loop predictor is the provider and the "
376 "prediction is correct"),
377 ADD_STAT(wrong, statistics::units::Count::get(),
378 "Number of times the loop predictor is the provider and the "
379 "prediction is wrong")
Abstract superclass for simulation objects.
virtual bool optionalAgeInc() const
size_t getSizeInBits() const
const unsigned loopTableAgeBits
virtual BranchInfo * makeBranchInfo()
LoopPredictor(const LoopPredictorParams &p)
void updateStats(bool taken, BranchInfo *bi)
Update the stats.
int finallindex(int lindex, int lowPcBits, int way) const
Computes the index used to access the ltable structures.
const unsigned initialLoopIter
static void unsignedCtrUpdate(uint8_t &ctr, bool up, unsigned nbits)
Updates an unsigned counter based on up/down parameter.
const uint16_t loopNumIterMask
static void signedCtrUpdate(int8_t &ctr, bool up, unsigned nbits)
const unsigned loopTableIterBits
const unsigned loopTableConfidenceBits
void specLoopUpdate(bool taken, BranchInfo *bi)
Speculatively updates the loop predictor iteration count (only for useSpeculation).
gem5::branch_prediction::LoopPredictor::LoopPredictorStats stats
const bool useDirectionBit
int lindex(Addr pc_in, unsigned instShiftAmt) const
Computes the index used to access the loop predictor.
const unsigned logLoopTableAssoc
void init() override
Initialize the loop predictor.
void condBranchUpdate(ThreadID tid, Addr branch_pc, bool taken, bool tage_pred, BranchInfo *bi, unsigned instShiftAmt)
Update LTAGE for conditional branches.
const bool optionalAgeReset
const uint8_t confidenceThreshold
void squashLoop(BranchInfo *bi)
const bool restrictAllocation
virtual bool calcConf(int index) const
const unsigned logSizeLoopPred
bool getLoop(Addr pc, BranchInfo *bi, bool speculative, unsigned instShiftAmt) const
Get a branch prediction from the loop predictor.
bool loopPredict(ThreadID tid, Addr branch_pc, bool cond_branch, BranchInfo *bi, bool prev_pred_taken, unsigned instShiftAmt)
Get the loop prediction.
void loopUpdate(Addr pc, bool Taken, BranchInfo *bi, bool tage_pred)
Updates the loop predictor.
const unsigned loopTableTagBits
void squash(ThreadID tid, BranchInfo *bi)
const unsigned initialLoopAge
const bool useSpeculation
const uint16_t loopTagMask
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
std::enable_if_t< std::is_integral_v< T >, T > random()
Use the SFINAE idiom to choose an implementation based on whether the type is integral or floating po...
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.
LoopPredictorStats(statistics::Group *parent)
statistics::Scalar correct