diff --git a/configs/example/kmhv3.py b/configs/example/kmhv3.py index 71844d9478..c5cad62a29 100644 --- a/configs/example/kmhv3.py +++ b/configs/example/kmhv3.py @@ -105,7 +105,7 @@ def setKmhV3Params(args, system): cpu.branchPred.mbtb.enabled = True cpu.branchPred.tage.enabled = True cpu.branchPred.ittage.enabled = True - cpu.branchPred.mgsc.enabled = False + cpu.branchPred.mgsc.enabled = True cpu.branchPred.ras.enabled = True # l1 cache per core diff --git a/src/cpu/pred/BranchPredictor.py b/src/cpu/pred/BranchPredictor.py index a5132f48af..c79ffa47f5 100644 --- a/src/cpu/pred/BranchPredictor.py +++ b/src/cpu/pred/BranchPredictor.py @@ -1126,7 +1126,7 @@ class BTBMGSC(TimedBaseBTBPredictor): thresholdTablelogSize = Param.Unsigned(6, "Log size of update threshold counters tables") - updateThresholdWidth = Param.Unsigned(12, + updateThresholdWidth = Param.Unsigned(14, "Number of bits for the update threshold counter") pUpdateThresholdWidth = Param.Unsigned(8, diff --git a/src/cpu/pred/btb/btb_mgsc.cc b/src/cpu/pred/btb/btb_mgsc.cc index 694bb0b3c1..50c5ae1397 100755 --- a/src/cpu/pred/btb/btb_mgsc.cc +++ b/src/cpu/pred/btb/btb_mgsc.cc @@ -413,6 +413,9 @@ BTBMGSC::generateSinglePrediction(const BTBEntry &btb_entry, const Addr &startPC int p_update_thres = enablePCThreshold ? findThreshold(pUpdateThreshold, btb_entry.pc) : 0; int total_thres = (updateThreshold / 8) + p_update_thres; + // Threshold is used as a confidence gate; avoid negative values which + // effectively disable the gate (abs(sum) > negative is almost always true). + total_thres = std::max(total_thres, 0); bool use_sc_pred = forceUseSC; // Force use SC if configured if (!use_sc_pred) { @@ -656,6 +659,11 @@ void BTBMGSC::updateGlobalThreshold(Addr pc, bool update_direction) { updateCounter(update_direction, updateThresholdWidth, updateThreshold); + // Keep global threshold non-negative; negative thresholds make SC gating + // degenerate and can cause overuse of SC. + if (updateThreshold < 0) { + updateThreshold = 0; + } } void