From 6f73f4e16c56d05e13847ae36b66c5c61f7e1b87 Mon Sep 17 00:00:00 2001 From: Alex Cockrean <84676155+ABenC377@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:23:07 +0000 Subject: [PATCH] Specifying size of constant 1 throughout --- src/lib/branchpredictors/TagePredictor.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/branchpredictors/TagePredictor.cc b/src/lib/branchpredictors/TagePredictor.cc index 9d54cb63d..dcbae3df3 100644 --- a/src/lib/branchpredictors/TagePredictor.cc +++ b/src/lib/branchpredictors/TagePredictor.cc @@ -19,19 +19,20 @@ TagePredictor::TagePredictor(ryml::ConstNodeRef config) // Calculate the saturation counter boundary between weakly taken and // not-taken. `(2 ^ num_sat_cnt_bits) / 2` gives the weakly taken state // value - uint8_t weaklyTaken = 1 << (satCntBits_ - 1); + uint8_t weaklyTaken = (uint8_t)1 << (satCntBits_ - 1); uint8_t satCntVal = (config["Branch-Predictor"]["Fallback-Static-Predictor"] .as() == "Always-Taken") ? weaklyTaken : (weaklyTaken - 1); // Create branch prediction structures btb_ = - std::vector>(1 << btbBits_, {satCntVal, 0}); + std::vector>( + (uint8_t)1 << btbBits_, {satCntVal, 0}); // Set up Tagged tables for (uint32_t i = 0; i < numTageTables_; i++) { std::vector newTable; - for (uint32_t j = 0; j < (1 << tageTableBits_); j++) { + for (uint32_t j = 0; j < (1ul << tageTableBits_); j++) { TageEntry newEntry = {2, 0, 1, 0}; newTable.push_back(newEntry); } @@ -203,26 +204,26 @@ uint64_t TagePredictor::getTaggedIndex(uint64_t address, uint8_t table) { uint64_t TagePredictor::getTag(uint64_t address, uint8_t table) { // Hash function here is pretty arbitrary. uint64_t h1 = address; - uint64_t h2 = globalHistory_.getFolded((1 << table), - ((1 << tagLength_) - 1)); - return (h1 ^ h2) & ((1 << tagLength_) - 1); + uint64_t h2 = globalHistory_.getFolded((1ull << table), + ((1ull << tagLength_) - 1)); + return (h1 ^ h2) & ((1ull << tagLength_) - 1); } void TagePredictor::updateBtb(uint64_t address, bool isTaken, uint64_t targetAddress) { // Calculate 2-bit saturating counter value - uint8_t satCntVal = btb_[((address >> 2) & ((1 << btbBits_) - 1))].first; + uint8_t satCntVal = btb_[((address >> 2) & ((1ull << btbBits_) - 1))].first; // Only alter value if it would transition to a valid state - if (!((satCntVal == (1 << satCntBits_) - 1) && isTaken) && + if (!((satCntVal == (1ull << satCntBits_) - 1) && isTaken) && !(satCntVal == 0 && !isTaken)) { satCntVal += isTaken ? 1 : -1; } // Update BTB entry - btb_[((address >> 2) & ((1 << btbBits_) - 1))].first = satCntVal; + btb_[((address >> 2) & ((1ull << btbBits_) - 1))].first = satCntVal; if (isTaken) { - btb_[((address >> 2) & ((1 << btbBits_) - 1))].second = targetAddress; + btb_[((address >> 2) & ((1ull << btbBits_) - 1))].second = targetAddress; } }