38#include "debug/LTage.hh"
39#include "params/LoopPredictor.hh"
44namespace branch_prediction
49 loopTableAgeBits(
p.loopTableAgeBits),
50 loopTableConfidenceBits(
p.loopTableConfidenceBits),
51 loopTableTagBits(
p.loopTableTagBits),
52 loopTableIterBits(
p.loopTableIterBits),
53 logLoopTableAssoc(
p.logLoopTableAssoc),
54 confidenceThreshold((1 << loopTableConfidenceBits) - 1),
55 loopTagMask((1 << loopTableTagBits) - 1),
56 loopNumIterMask((1 << loopTableIterBits) - 1),
57 loopSetMask((1 << (logSizeLoopPred - logLoopTableAssoc)) - 1),
59 withLoopBits(
p.withLoopBits),
60 useDirectionBit(
p.useDirectionBit),
61 useSpeculation(
p.useSpeculation),
62 useHashing(
p.useHashing),
63 restrictAllocation(
p.restrictAllocation),
64 initialLoopIter(
p.initialLoopIter),
65 initialLoopAge(
p.initialLoopAge),
66 optionalAgeReset(
p.optionalAgeReset),
101 Addr pc = pc_in >> instShiftAmt;
119 unsigned instShiftAmt)
const
122 bi->loopPredValid =
false;
138 if (
ltable[idx].tag ==
bi->loopTag) {
145 if ((iter + 1) ==
ltable[idx].numIter) {
164 if (
bi->loopHit>=0) {
185 if (
bi->loopHit >= 0) {
187 if (
bi->loopPredValid) {
188 if (taken !=
bi->loopPred) {
196 DPRINTF(LTage,
"Loop Prediction success:%lx\n",
pc);
205 if (
ltable[idx].numIter != 0) {
216 DPRINTF(LTage,
"Loop End predicted successfully:%lx\n",
pc);
220 if (
ltable[idx].numIter < 3) {
228 DPRINTF(LTage,
"Loop End predicted incorrectly:%lx\n",
pc);
229 if (
ltable[idx].numIter == 0) {
253 if (
ltable[idx].age == 0) {
255 "Allocating loop pred entry for branch %lx\n",
278 BranchInfo*
bi,
bool prev_pred_taken,
unsigned instShiftAmt)
280 bool pred_taken = prev_pred_taken;
286 pred_taken =
bi->loopPred;
287 bi->loopPredUsed =
true;
301 if (
bi->loopHit >= 0) {
312 if (
bi->loopHit >= 0) {
323 if (taken ==
bi->loopPred) {
333 unsigned instShiftAmt)
340 bi->loopPred =
getLoop(branch_pc,
bi,
false, instShiftAmt);
343 if (
bi->loopPredValid) {
344 if (
bi->predTaken !=
bi->loopPred) {
346 (
bi->loopPred == taken),
356 : statistics::
Group(parent),
357 ADD_STAT(correct, statistics::units::Count::get(),
358 "Number of times the loop predictor is the provider and the "
359 "prediction is correct"),
360 ADD_STAT(wrong, statistics::units::Count::get(),
361 "Number of times the loop predictor is the provider and the "
362 "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...
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
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