50namespace branch_prediction
55 localPredictorSize(params.localPredictorSize),
56 localCtrBits(params.localCtrBits),
57 localCtrs(localPredictorSize,
SatCounter8(localCtrBits)),
58 localHistoryTableSize(params.localHistoryTableSize),
59 localHistoryBits(
ceilLog2(params.localPredictorSize)),
60 globalPredictorSize(params.globalPredictorSize),
61 globalCtrBits(params.globalCtrBits),
62 globalCtrs(globalPredictorSize,
SatCounter8(globalCtrBits)),
63 globalHistory(params.numThreads, 0),
65 ceilLog2(params.globalPredictorSize) >
66 ceilLog2(params.choicePredictorSize) ?
67 ceilLog2(params.globalPredictorSize) :
68 ceilLog2(params.choicePredictorSize)),
69 choicePredictorSize(params.choicePredictorSize),
70 choiceCtrBits(params.choiceCtrBits),
71 choiceCtrs(choicePredictorSize,
SatCounter8(choiceCtrBits))
74 fatal(
"Invalid local predictor size!\n");
78 fatal(
"Invalid global predictor size!\n");
84 fatal(
"Invalid local history table size!\n");
98 fatal(
"Invalid choice predictor size!\n");
110 fatal(
"Global predictor too large for global history bits!\n");
113 fatal(
"Choice predictor too large for global history bits!\n");
118 inform(
"More global history bits than required by predictors\n");
155 bool local_prediction;
156 unsigned local_history_idx;
157 unsigned local_predictor_idx;
159 bool global_prediction;
160 bool choice_prediction;
184 bp_history = (
void *)history;
190 if (choice_prediction) {
191 return global_prediction;
193 return local_prediction;
199 bool taken,
Addr target,
void * &bp_history)
201 assert(uncond || bp_history);
211 bp_history =
static_cast<void *
>(history);
219 auto history =
static_cast<BPHistory *
>(bp_history);
227 void * &bp_history,
bool squashed,
251 if (old_local_pred_valid) {
267 old_local_pred_valid)
272 unsigned choice_predictor_idx =
286 unsigned global_predictor_idx =
290 if (old_local_pred_valid) {
295 if (old_local_pred_valid) {
302 bp_history =
nullptr;
320 bp_history =
nullptr;
325TournamentBP::BPHistory::newCount = 0;
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.
unsigned globalHistoryMask
Mask to apply to globalHistory to access global history table.
std::vector< SatCounter8 > choiceCtrs
Array of counters that make up the choice predictor.
unsigned globalHistoryBits
Number of bits for the global history.
void updateGlobalHist(ThreadID tid, bool taken)
Updates global history with the given direction.
TournamentBP(const TournamentBPParams ¶ms)
Default branch predictor constructor.
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.
unsigned globalPredictorSize
Number of entries in the global predictor.
std::vector< SatCounter8 > localCtrs
Local counters.
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.
unsigned localPredictorMask
Mask to truncate values stored in the local history table.
void squash(ThreadID tid, void *&bp_history) override
unsigned historyRegisterMask
Mask to control how much history is stored.
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.
static const int invalidPredictorIndex
Flag for invalid predictor index.
unsigned localHistoryBits
Number of bits for each entry of the local history table.
std::vector< unsigned > localHistoryTable
Array of local history table entries.
unsigned localCtrBits
Number of bits of the local predictor's counters.
unsigned localThreshold
Thresholds for the counter value; above the threshold is taken, equal to or below the threshold is no...
unsigned choiceHistoryMask
Mask to apply to globalHistory to access choice history table.
void updateLocalHist(unsigned local_history_idx, bool taken)
Updates local histories.
std::vector< SatCounter8 > globalCtrs
Array of counters that make up the global predictor.
unsigned localPredictorSize
Number of counters in the local predictor.
unsigned calcLocHistIdx(Addr &branch_addr)
Returns the local history index, given a branch address.
std::vector< unsigned > globalHistory
Global history register.
unsigned globalCtrBits
Number of bits of the global predictor's counters.
unsigned choiceCtrBits
Number of bits in the choice predictor's counters.
unsigned localHistoryTableSize
Number of entries in the local history table.
unsigned choicePredictorSize
Number of entries in the choice predictor.
static constexpr int ceilLog2(const T &n)
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.
The branch history information that is created upon predicting a branch.