49#include "debug/LTage.hh"
50#include "params/LoopPredictor.hh"
55namespace branch_prediction
60 loopTableAgeBits(
p.loopTableAgeBits),
61 loopTableConfidenceBits(
p.loopTableConfidenceBits),
62 loopTableTagBits(
p.loopTableTagBits),
63 loopTableIterBits(
p.loopTableIterBits),
64 logLoopTableAssoc(
p.logLoopTableAssoc),
65 confidenceThreshold((1 << loopTableConfidenceBits) - 1),
66 loopTagMask((1 << loopTableTagBits) - 1),
67 loopNumIterMask((1 << loopTableIterBits) - 1),
68 loopSetMask((1 << (logSizeLoopPred - logLoopTableAssoc)) - 1),
70 withLoopBits(
p.withLoopBits),
71 useDirectionBit(
p.useDirectionBit),
72 useSpeculation(
p.useSpeculation),
73 useHashing(
p.useHashing),
74 restrictAllocation(
p.restrictAllocation),
75 initialLoopIter(
p.initialLoopIter),
76 initialLoopAge(
p.initialLoopAge),
77 optionalAgeReset(
p.optionalAgeReset),
112 Addr pc = pc_in >> instShiftAmt;
130 unsigned instShiftAmt)
const
133 bi->loopPredValid =
false;
149 if (
ltable[idx].tag ==
bi->loopTag) {
156 if ((iter + 1) ==
ltable[idx].numIter) {
175 if (
bi->loopHit>=0) {
196 if (
bi->loopHit >= 0) {
198 if (
bi->loopPredValid) {
199 if (taken !=
bi->loopPred) {
207 DPRINTF(LTage,
"Loop Prediction success:%lx\n",
pc);
216 if (
ltable[idx].numIter != 0) {
227 DPRINTF(LTage,
"Loop End predicted successfully:%lx\n",
pc);
231 if (
ltable[idx].numIter < 3) {
239 DPRINTF(LTage,
"Loop End predicted incorrectly:%lx\n",
pc);
240 if (
ltable[idx].numIter == 0) {
260 int nrand =
rng->random<
int>();
264 if (
ltable[idx].age == 0) {
266 "Allocating loop pred entry for branch %lx\n",
289 BranchInfo*
bi,
bool prev_pred_taken,
unsigned instShiftAmt)
291 bool pred_taken = prev_pred_taken;
297 pred_taken =
bi->loopPred;
298 bi->loopPredUsed =
true;
312 if (
bi->loopHit >= 0) {
323 if (
bi->loopHit >= 0) {
334 if (
bi->loopPredUsed) {
336 if (taken ==
bi->loopPred) {
347 unsigned instShiftAmt)
354 bi->loopPred =
getLoop(branch_pc,
bi,
false, instShiftAmt);
357 if (
bi->loopPredValid) {
358 if (
bi->predTaken !=
bi->loopPred) {
360 (
bi->loopPred == taken),
370 : statistics::
Group(parent),
371 ADD_STAT(used, statistics::units::Count::get(),
372 "Number of times the loop predictor is the provider."),
373 ADD_STAT(correct, statistics::units::Count::get(),
374 "Number of times the loop predictor is the provider and the "
375 "prediction is correct"),
376 ADD_STAT(wrong, statistics::units::Count::get(),
377 "Number of times the loop predictor is the provider and the "
378 "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.
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.
LoopPredictorStats(statistics::Group *parent)
statistics::Scalar correct