Skip to content

Bigger tage align#770

Open
jensen-yan wants to merge 6 commits intoxs-devfrom
bigger-tage-align
Open

Bigger tage align#770
jensen-yan wants to merge 6 commits intoxs-devfrom
bigger-tage-align

Conversation

@jensen-yan
Copy link
Collaborator

@jensen-yan jensen-yan commented Mar 5, 2026

Summary by CodeRabbit

  • New Features

    • Added configurable TAGE indexing: option to use branch PC for table index computation.
    • Added position-mix indexing for low tables (mixing branch position into index) with configurable number of mixed tables.
    • Exposed TAGE configuration defaults (ways and table sizes) for easier tuning.
  • Bug Fixes / Defaults

    • MGSC branch predictor disabled by default.

Change-Id: I3a357ccab4ae078edb30bd4ffe5e01b5c6d9ac7f
Change-Id: I0e029d43a10487cc7090e15973db1fd84a731375
Change-Id: Ibdd30c6049dca43e022e5bd4e94a89e493397c33
Change-Id: If9f2e2a8099ac58c8f9ad5b86b00292eeebc48d4
Change-Id: I06630ca8db53f4fd944355fd03a166203c5dca11
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

Adds configurable index-selection and index-mixing options to the BTBTAGE branch predictor and updates an example config and documentation. New flags control using branch PC vs stream start PC and mixing branch position into low-table indices; MGSC predictor disabled in the kmhv3 example.

Changes

Cohort / File(s) Summary
Configuration
configs/example/kmhv3.py
New TAGE fields added (useBranchPcForIndex=False, usePositionForIndexMix=True, indexMixTables=4, numWays=2, tableSizes=[2048,...]) and cpu.branchPred.mgsc.enabled set to False.
Predictor parameter registration
src/cpu/pred/BranchPredictor.py
Added new BTBTAGE parameters: useBranchPcForIndex, usePositionForIndexMix, indexMixTables.
BTBTAGE header
src/cpu/pred/btb/btb_tage.hh
Added private members useBranchPcForIndex, usePositionForIndexMix, indexMixTables and new helper buildIndexPC(...) declaration.
BTBTAGE implementation
src/cpu/pred/btb/btb_tage.cc
Initialized new members in constructors; added buildIndexPC implementation; switched index/tag computations, allocation, and update flows to use per-table indexPc (branch/start PC selection and optional position-mix for low tables). Reviewers should focus on constructor propagation, index computation changes, and update/allocation paths.
Documentation / Experiments
docs/Gem5_Docs/frontend/tage_index_capacity_exploration_20260305.md
New analysis doc describing branchPC-index experiments, position-mix proposal, parameter choices, and empirical findings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

perf, align-kmhv3

Suggested reviewers

  • CJ362ff
  • Yakkhini

Poem

🐇 I nibble bits and mix their song,
Branch PC here, positions belong.
Tables reshuffled, indices play,
A little hop toward fewer fray. ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Bigger tage align' is vague and does not clearly convey what the changes accomplish; it uses cryptic terminology without explaining the actual modification. Revise the title to be more descriptive, such as 'Add branch prediction index configuration parameters to TAGE' or 'Introduce position-mixing and branch PC indexing for TAGE predictor.'
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bigger-tage-align

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b44d5b169b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

cpu.branchPred.tage.tableSizes = [8192] * 8
cpu.branchPred.ittage.enabled = True
cpu.branchPred.mgsc.enabled = True
cpu.branchPred.mgsc.enabled = False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep MGSC enabled for RTL-aligned table settings

Setting cpu.branchPred.mgsc.enabled = False disables MGSC entirely for this kmhv3 configuration, so the following per-table enable*Table settings are dead and MGSC is not inserted into the active predictor components (DecoupledBPUWithBTB only adds it when mgsc->isEnabled(), in src/cpu/pred/btb/decoupled_bpred.cc). This is a functional behavior change (not just tuning) that can materially alter branch prediction results compared with the stated “only enable bias + path + IMLI tables” alignment goal.

Useful? React with 👍 / 👎.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
configs/example/kmhv3.py (1)

115-120: Consider removing redundant MGSC table configuration.

These MGSC table enable/disable settings have no effect since mgsc.enabled = False on line 111. You may want to remove them to reduce configuration clutter, or keep them if they serve as documentation for future reference.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@configs/example/kmhv3.py` around lines 115 - 120, The MGSC table
enable/disable lines (cpu.branchPred.mgsc.enableBwTable, enableLTable,
enableITable, enableGTable, enablePTable, enableBiasTable) are redundant because
cpu.branchPred.mgsc.enabled is set to False; remove these per-table settings to
reduce clutter, or alternatively leave a single commented note documenting the
intended defaults if you want them for future reference—either delete the six
cpu.branchPred.mgsc.enable* lines or replace them with a one-line comment
referencing mgsc.enabled and the intended table defaults.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@configs/example/kmhv3.py`:
- Around line 115-120: The MGSC table enable/disable lines
(cpu.branchPred.mgsc.enableBwTable, enableLTable, enableITable, enableGTable,
enablePTable, enableBiasTable) are redundant because cpu.branchPred.mgsc.enabled
is set to False; remove these per-table settings to reduce clutter, or
alternatively leave a single commented note documenting the intended defaults if
you want them for future reference—either delete the six
cpu.branchPred.mgsc.enable* lines or replace them with a one-line comment
referencing mgsc.enabled and the intended table defaults.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e4592414-45b1-43ab-88f9-7e915039121a

📥 Commits

Reviewing files that changed from the base of the PR and between 318c57c and b44d5b1.

📒 Files selected for processing (4)
  • configs/example/kmhv3.py
  • src/cpu/pred/BranchPredictor.py
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_tage.hh

Change-Id: Ib8b67365d8196e4b2ec0044a8883e6983b88b2f6
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.2203 -
This PR 2.2679 📈 +0.0476 (+2.14%)

✅ Difftest smoke test passed!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
docs/Gem5_Docs/frontend/tage_index_capacity_exploration_20260305.md (3)

107-117: Commit-chain section may go stale; link to immutable PR artifacts.

The hardcoded short-hash list is useful now but brittle over time. Consider adding direct links to the PR commits (or a permalinked range) so readers can always resolve the exact history.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/Gem5_Docs/frontend/tage_index_capacity_exploration_20260305.md` around
lines 107 - 117, The commit list under the section "7. 当前分支提交链(CI触发)" is
brittle; replace the hardcoded short-hash entries for branch `bigger-tage-align`
with immutable links (full commit SHAs or permalink URLs) pointing to each
commit or a single permalinked range/PR so readers can always resolve history;
update the five listed items (including the one mentioning `tableSizes`) to use
their respective commit URLs or the PR permalink and leave the descriptive text
unchanged.

85-94: Prefer a compact table with relative deltas.

For quick comparison, present off/mix2/mix4/mix8 as a table and include % deltas vs off for both IPC and mispred. This will make trend strength and tradeoffs much clearer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/Gem5_Docs/frontend/tage_index_capacity_exploration_20260305.md` around
lines 85 - 94, Replace the current bullet lists for gobmk and sjeng with a
compact table for each benchmark (or a single combined table) that lists the
metrics IPC and mispred as rows and columns for off, mix2, mix4, mix8, plus
additional columns showing the percent delta vs off for each mix (e.g., "mix2
Δ%" = (mix2 - off)/off * 100). Keep the original numeric values (IPC: 2.544804,
2.580220, 2.583373, 2.580409; mispred: 44249, 42602, 42686, 42887 for gobmk; and
IPC: 2.116851, 2.120000, 2.129908, 2.124130; mispred: 47856, 47515, 47429, 47691
for sjeng), format them into columns Off / Mix2 / Mix4 / Mix8 and append
percent-change columns for each mix relative to Off so readers can quickly see
trend strength and tradeoffs.

22-30: Add full reproducibility metadata for the reported numbers.

The setup/results sections still miss key replay inputs (exact command line, checkpoint ID/path, random seed policy, binary/input identifiers). Please add them so others can reproduce the 5M-window IPC/mispred numbers exactly.

Also applies to: 83-94

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/Gem5_Docs/frontend/tage_index_capacity_exploration_20260305.md` around
lines 22 - 30, The docs are missing full reproducibility metadata for the
reported 5M-window IPC/mispred numbers; update the setup/results sections to
include the exact gem5 command line used (including --maxinsts=5000000
--warmup-insts-no-switch=0 and any other flags), the exact checkpoint identifier
or path and how it was created, the random seed policy (seed value or how seeds
were chosen), and precise binary/input identifiers for each reported slice
(e.g., gobmk_nngs_18098, sjeng_84999) plus any config toggles used
(system.cpu[0].branchPred.mgsc.enabled and
system.cpu[0].branchPred.tage.enableBankConflict); apply the same additions to
the other occurrence mentioned (lines 83-94) so anyone can reproduce the
IPC/mispred values exactly.
src/cpu/pred/btb/btb_tage.cc (1)

87-90: Consider normalizing indexMixTables against numPredictors.

If configured larger than numPredictors, behavior silently becomes “mix all tables”. Clamping (or warning) would make config intent clearer.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cpu/pred/btb/btb_tage.cc` around lines 87 - 90, Clamp or validate the
indexMixTables value against numPredictors to prevent silent “mix all tables”
behavior: in the constructor (where indexMixTables is initialized) or
immediately after configuration, check if indexMixTables > numPredictors and
either set indexMixTables = numPredictors (clamp) or log a warning and adjust
accordingly; reference the members indexMixTables and numPredictors and update
any code that reads indexMixTables so it uses the validated/clamped value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/cpu/pred/btb/btb_tage.cc`:
- Around line 217-224: The bank-conflict bookkeeping must use the same PC used
for index calculation (the derived indexPc/baseIndexPc) instead of always using
startPC; update the bank-tracking logic that runs alongside the predictor loop
(when enableBankConflict is true) to compute bank/index IDs from indexPc (or
baseIndexPc) the same way getTageIndex uses it so conflict/defer decisions match
the selected indexed PC; locate where bank bookkeeping references startPC and
replace it to derive bank indices from indexPc (or reuse baseIndexPc) consistent
with buildIndexPC/useBranchPcForIndex and the loop over i, and ensure predMeta
paths (indexFoldedHist) are still honored.

---

Nitpick comments:
In `@docs/Gem5_Docs/frontend/tage_index_capacity_exploration_20260305.md`:
- Around line 107-117: The commit list under the section "7. 当前分支提交链(CI触发)" is
brittle; replace the hardcoded short-hash entries for branch `bigger-tage-align`
with immutable links (full commit SHAs or permalink URLs) pointing to each
commit or a single permalinked range/PR so readers can always resolve history;
update the five listed items (including the one mentioning `tableSizes`) to use
their respective commit URLs or the PR permalink and leave the descriptive text
unchanged.
- Around line 85-94: Replace the current bullet lists for gobmk and sjeng with a
compact table for each benchmark (or a single combined table) that lists the
metrics IPC and mispred as rows and columns for off, mix2, mix4, mix8, plus
additional columns showing the percent delta vs off for each mix (e.g., "mix2
Δ%" = (mix2 - off)/off * 100). Keep the original numeric values (IPC: 2.544804,
2.580220, 2.583373, 2.580409; mispred: 44249, 42602, 42686, 42887 for gobmk; and
IPC: 2.116851, 2.120000, 2.129908, 2.124130; mispred: 47856, 47515, 47429, 47691
for sjeng), format them into columns Off / Mix2 / Mix4 / Mix8 and append
percent-change columns for each mix relative to Off so readers can quickly see
trend strength and tradeoffs.
- Around line 22-30: The docs are missing full reproducibility metadata for the
reported 5M-window IPC/mispred numbers; update the setup/results sections to
include the exact gem5 command line used (including --maxinsts=5000000
--warmup-insts-no-switch=0 and any other flags), the exact checkpoint identifier
or path and how it was created, the random seed policy (seed value or how seeds
were chosen), and precise binary/input identifiers for each reported slice
(e.g., gobmk_nngs_18098, sjeng_84999) plus any config toggles used
(system.cpu[0].branchPred.mgsc.enabled and
system.cpu[0].branchPred.tage.enableBankConflict); apply the same additions to
the other occurrence mentioned (lines 83-94) so anyone can reproduce the
IPC/mispred values exactly.

In `@src/cpu/pred/btb/btb_tage.cc`:
- Around line 87-90: Clamp or validate the indexMixTables value against
numPredictors to prevent silent “mix all tables” behavior: in the constructor
(where indexMixTables is initialized) or immediately after configuration, check
if indexMixTables > numPredictors and either set indexMixTables = numPredictors
(clamp) or log a warning and adjust accordingly; reference the members
indexMixTables and numPredictors and update any code that reads indexMixTables
so it uses the validated/clamped value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2636f8a7-bf63-429d-946f-21ef7bd864f3

📥 Commits

Reviewing files that changed from the base of the PR and between b44d5b1 and 9774e83.

📒 Files selected for processing (5)
  • configs/example/kmhv3.py
  • docs/Gem5_Docs/frontend/tage_index_capacity_exploration_20260305.md
  • src/cpu/pred/BranchPredictor.py
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_tage.hh
🚧 Files skipped from review as they are similar to previous changes (1)
  • configs/example/kmhv3.py

Comment on lines +217 to +224
Addr baseIndexPc = useBranchPcForIndex ? btb_entry.pc : startPC;

for (int i = numPredictors - 1; i >= 0; --i) {
Addr indexPc = buildIndexPC(baseIndexPc, position, i);
// Calculate index and tag: use snapshot if provided, otherwise use current folded history
// Tag includes position XOR (like RTL: tag = tempTag ^ cfiPosition)
Addr index = predMeta ? getTageIndex(startPC, i, predMeta->indexFoldedHist[i].get())
: getTageIndex(startPC, i);
Addr index = predMeta ? getTageIndex(indexPc, i, predMeta->indexFoldedHist[i].get())
: getTageIndex(indexPc, i);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Bank-conflict model is now inconsistent with indexed PC selection.

When Line 217 and Line 220 switch index derivation to btb_entry.pc/mixed indexPc, bank-conflict bookkeeping still tracks startPC banks, so conflict/defer behavior can be wrong when enableBankConflict is enabled.

Suggested safeguard (short-term)
@@ BTBTAGE::BTBTAGE(const Params& p):
     if (!p.updateOnRead) {
         warn("BTBTAGE: Bank simulation works better with updateOnRead=true");
     }
+    if (enableBankConflict && (useBranchPcForIndex || usePositionForIndexMix)) {
+        warn("BTBTAGE: disabling bank conflict simulation because bank tracking is startPC-based while index PC is remapped");
+        enableBankConflict = false;
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cpu/pred/btb/btb_tage.cc` around lines 217 - 224, The bank-conflict
bookkeeping must use the same PC used for index calculation (the derived
indexPc/baseIndexPc) instead of always using startPC; update the bank-tracking
logic that runs alongside the predictor loop (when enableBankConflict is true)
to compute bank/index IDs from indexPc (or baseIndexPc) the same way
getTageIndex uses it so conflict/defer decisions match the selected indexed PC;
locate where bank bookkeeping references startPC and replace it to derive bank
indices from indexPc (or reuse baseIndexPc) consistent with
buildIndexPC/useBranchPcForIndex and the loop over i, and ensure predMeta paths
(indexFoldedHist) are still honored.

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.2203 -
This PR 2.2328 📈 +0.0125 (+0.56%)

✅ Difftest smoke test passed!

@XiangShanRobot
Copy link

[Generated by GEM5 Performance Robot]
commit: 9774e83
workflow: gem5 Align BTB Performance Test(0.3c)

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.72 17.84 -0.70 🔴

[Generated by GEM5 Performance Robot]
commit: 9774e83
workflow: gem5 Align BTB Performance Test(0.3c)

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.72 17.92 -1.14 🔴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants