Skip to content

Commit

Permalink
Turning vectors for indices and tags in the ftq into shared_ptrs of a…
Browse files Browse the repository at this point in the history
… fixed but dynamically chosen size
  • Loading branch information
ABenC377 committed Dec 17, 2024
1 parent 768db53 commit 14789a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
9 changes: 5 additions & 4 deletions src/include/simeng/branchpredictors/TagePredictor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <deque>
#include <map>
#include <vector>
#include <memory>

#include "simeng/branchpredictors/BranchHistory.hh"
#include "simeng/branchpredictors/BranchPredictor.hh"
Expand All @@ -25,8 +26,8 @@ struct TageEntry {
* in the Fetch Target Queue. */
struct ftqEntry {
uint8_t predTable;
std::vector<uint64_t> indices;
std::vector<uint64_t> tags;
std::shared_ptr<uint64_t[]> indices;
std::shared_ptr<uint64_t[]> tags;
BranchPrediction prediction;
BranchPrediction altPrediction;
};
Expand Down Expand Up @@ -88,8 +89,8 @@ class TagePredictor : public BranchPredictor {
* tagged tables for a branch with the provided address. */
void getTaggedPrediction(uint64_t address, BranchPrediction* prediction,
BranchPrediction* altPrediction, uint8_t* predTable,
std::vector<uint64_t>* indices,
std::vector<uint64_t>* tags);
std::shared_ptr<uint64_t[]> indices,
std::shared_ptr<uint64_t[]> tags);

/** Returns the index of a branch in a tagged table for a given address and
* table. */
Expand Down
35 changes: 18 additions & 17 deletions src/lib/branchpredictors/TagePredictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ BranchPrediction TagePredictor::predict(uint64_t address, BranchType type,
BranchPrediction prediction;
BranchPrediction altPrediction;
uint8_t predTable;
std::vector<uint64_t> indices;
std::vector<uint64_t> tags;
std::shared_ptr<uint64_t[]> indices(new uint64_t[numTageTables_]);
std::shared_ptr<uint64_t[]> tags(new uint64_t[numTageTables_]);
getTaggedPrediction(address, &prediction, &altPrediction, &predTable,
&indices, &tags);
indices, tags);

// If known offset then overwrite predicted target with this
if (knownOffset != 0) prediction.target = address + knownOffset;
Expand Down Expand Up @@ -89,7 +89,8 @@ BranchPrediction TagePredictor::predict(uint64_t address, BranchType type,
}

// Store prediction data so that update() has the info it needs
ftqEntry newEntry = {predTable, indices, tags, prediction, altPrediction};
ftqEntry newEntry = {predTable, indices, tags,
prediction, altPrediction};
ftq_.push_back(newEntry);

// Speculatively update the global history
Expand Down Expand Up @@ -155,8 +156,8 @@ void TagePredictor::getTaggedPrediction(uint64_t address,
BranchPrediction* prediction,
BranchPrediction* altPrediction,
uint8_t* predTable,
std::vector<uint64_t>* indices,
std::vector<uint64_t>* tags) {
std::shared_ptr<uint64_t[]> indices,
std::shared_ptr<uint64_t[]> tags) {
// Get a basic prediction from the btb
BranchPrediction basePrediction = getBtbPrediction(address);
prediction->isTaken = basePrediction.isTaken;
Expand All @@ -171,9 +172,9 @@ void TagePredictor::getTaggedPrediction(uint64_t address,
// Determine the index and tag for this table, as they vary depending on
// the length of global history
uint64_t index = getTaggedIndex(address, table);
indices->push_back(index);
indices.get()[table] = index;
uint64_t tag = getTag(address, table);
tags->push_back(tag);
tags.get()[table] = tag;

// If tag matches, then use this prediction
if (tageTables_[table][index].tag == tag) {
Expand Down Expand Up @@ -233,13 +234,13 @@ void TagePredictor::updateBtb(uint64_t address, bool isTaken,
void TagePredictor::updateTaggedTables(bool isTaken, uint64_t target) {
// Get stored information from the FTQ
uint8_t predTable = ftq_.front().predTable;
std::vector<uint64_t> indices = ftq_.front().indices;
std::vector<uint64_t> tags = ftq_.front().tags;
std::shared_ptr<uint64_t[]> indices = ftq_.front().indices;
std::shared_ptr<uint64_t[]> tags = ftq_.front().tags;
BranchPrediction pred = ftq_.front().prediction;
BranchPrediction altPred = ftq_.front().altPrediction;

// Update the prediction counter
uint64_t predIndex = indices[predTable];
uint64_t predIndex = indices.get()[predTable];
if (isTaken && (tageTables_[predTable][predIndex].satCnt < 3)) {
(tageTables_[predTable][predIndex].satCnt)++;
} else if (!isTaken && (tageTables_[predTable][predIndex].satCnt > 0)) {
Expand All @@ -252,9 +253,9 @@ void TagePredictor::updateTaggedTables(bool isTaken, uint64_t target) {
// non-useful entry that can be replaced
if (isTaken != pred.isTaken || (isTaken && (target != pred.target))) {
for (uint8_t table = predTable + 1; table < numTageTables_; table++) {
if (tageTables_[table][indices[table]].u <= 1) {
tageTables_[table][indices[table]] = {
(isTaken ? (uint8_t)2 : (uint8_t)1), tags[table], (uint8_t)2,
if (tageTables_[table][indices.get()[table]].u <= 1) {
tageTables_[table][indices.get()[table]] = {
(isTaken ? (uint8_t)2 : (uint8_t)1), tags.get()[table], (uint8_t)2,
target};
break;
}
Expand All @@ -265,13 +266,13 @@ void TagePredictor::updateTaggedTables(bool isTaken, uint64_t target) {
if (pred.isTaken != altPred.isTaken ||
(pred.isTaken && (pred.target != altPred.target))) {
bool wasUseful = (pred.isTaken == isTaken);
uint8_t currentU = tageTables_[predTable][indices[predTable]].u;
uint8_t currentU = tageTables_[predTable][indices.get()[predTable]].u;
// Make sure that update is possible
if (wasUseful && currentU < 3) {
(tageTables_[predTable][indices[predTable]].u)++;
(tageTables_[predTable][indices.get()[predTable]].u)++;
}
if (!wasUseful && currentU > 0) {
(tageTables_[predTable][indices[predTable]].u)--;
(tageTables_[predTable][indices.get()[predTable]].u)--;
}
}
}
Expand Down

0 comments on commit 14789a6

Please sign in to comment.