46#include "debug/Fetch.hh"
51namespace branch_prediction
56 localPredictorSize(params.localPredictorSize),
57 localCtrBits(params.localCtrBits),
58 localPredictorSets(localPredictorSize / localCtrBits),
59 localCtrs(localPredictorSets,
SatCounter8(localCtrBits)),
60 indexMask(localPredictorSets - 1)
63 fatal(
"Invalid local predictor size!\n");
67 fatal(
"Invalid number of local predictor sets! Check localCtrBits.\n");
72 DPRINTF(Fetch,
"local predictor size: %i\n",
77 DPRINTF(Fetch,
"instruction shift amount: %i\n",
83 bool taken,
Addr target,
void * &bp_history)
95 DPRINTF(Fetch,
"Looking up index %#x\n",
98 uint8_t counter_val =
localCtrs[local_predictor_idx];
100 DPRINTF(Fetch,
"prediction is %i.\n",
112 assert(bp_history == NULL);
113 unsigned local_predictor_idx;
124 DPRINTF(Fetch,
"Looking up index %#x\n", local_predictor_idx);
127 DPRINTF(Fetch,
"Branch updated as taken.\n");
130 DPRINTF(Fetch,
"Branch updated as not taken.\n");
Basically a wrapper class to hold both the branch predictor and the BTB.
const unsigned instShiftAmt
Number of bits to shift instructions by for predictor addresses.
const unsigned localPredictorSize
Size of the local predictor.
bool getPrediction(uint8_t &count)
Returns the taken/not taken prediction given the value of the counter.
const unsigned localCtrBits
Number of bits of the local predictor's counters.
const unsigned localPredictorSets
Number of sets.
void update(ThreadID tid, Addr pc, bool taken, void *&bp_history, bool squashed, const StaticInstPtr &inst, Addr target) override
Updates the BP with taken/not taken information.
LocalBP(const LocalBPParams ¶ms)
Default branch predictor constructor.
void updateHistories(ThreadID tid, Addr pc, bool uncond, bool taken, Addr target, void *&bp_history) override
Ones done with the prediction this function updates the path and global history.
bool lookup(ThreadID tid, Addr pc, void *&bp_history) override
Looks up a given conditional branch PC of in the BP to see if it is taken or not taken.
const unsigned indexMask
Mask to get index bits.
std::vector< SatCounter8 > localCtrs
Array of counters that make up the local predictor.
unsigned getLocalIndex(Addr &PC)
Calculates the local index based on the PC.
static constexpr bool isPowerOf2(const T &n)
#define fatal(...)
This implements a cprintf based fatal() function.
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.