Skip to content

cpu-o3:Implement predwrongSource method - #683

Merged
CaoJiaming776 merged 13 commits into
xs-devfrom
add-source-pred-align
Jan 8, 2026
Merged

cpu-o3:Implement predwrongSource method#683
CaoJiaming776 merged 13 commits into
xs-devfrom
add-source-pred-align

Conversation

@CaoJiaming776

@CaoJiaming776 CaoJiaming776 commented Dec 26, 2025

Copy link
Copy Markdown
Member

Change-Id: If763f1cc4fd54da740fde677d0ded7801ecee023

Summary by CodeRabbit

  • New Features

    • Track prediction sources (s1/s3) end-to-end and add source-specific prediction statistics.
  • Bug Fixes

    • Better deduplication to prevent duplicate predictions.
    • Improved handling to reduce stale/incorrect indirect targets.
    • Ensure prediction entries are labeled with their originating component.
  • Refactor

    • Allow in-place BTB entry updates during lookup and streamline source propagation.
  • Tests

    • Added unit-test hooks to record/commit branch outcomes.
  • Chores

    • Removed one obsolete public prediction statistic.

✏️ Tip: You can customize this high-level summary in your review settings.

Change-Id: If763f1cc4fd54da740fde677d0ded7801ecee023
@coderabbitai

coderabbitai Bot commented Dec 26, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Threads per-entry source and s1/s3 source metadata through BTB prediction and commit paths, updates several BTB components to mark entries with their producing component, adds commit-time blame attribution and new stats, and exposes small API/UNIT_TEST helpers in TAGE/ITTAGE/MBTB.

Changes

Cohort / File(s) Summary
Core stream/entry structs
src/cpu/pred/btb/stream_struct.hh
Added int source to BTBEntry with accessors and init; added s1Source/s3Source to FetchStream and FullBTBPrediction with initialization.
Decoupled BPU + stats
src/cpu/pred/btb/decoupled_bpred.hh, src/cpu/pred/btb/decoupled_bpred.cc, src/cpu/pred/btb/decoupled_bpred_stats.cc
Threaded s1Source/s3Source into finalPred and FSQ entries; added commitPredWrongSource declaration+impl; added new stats (branchClassCountsTotal, s1PredWrongFallthrough, s1PredWrongUbtb, s1PredWrongAbtb, s3PredWrongMbtb, s3PredWrongTage, s3PredWrongIttage, s3PredWrongRas); commitBranch now invokes blame attribution on mispredicts.
AheadBTB / UBTB / ABTB
src/cpu/pred/btb/abtb.cc, src/cpu/pred/btb/btb_ubtb.cc
Set entry.source = getComponentIdx() before calling update/write paths; ABTB: invalidate mixed_entries matching UBTB pc and deduplicate by sorting and dropping invalid entries.
TAGE / ITTAGE
src/cpu/pred/btb/btb_tage.hh, src/cpu/pred/btb/btb_tage.cc, src/cpu/pred/btb/btb_ittage.hh, src/cpu/pred/btb/btb_ittage.cc
lookupHelper now accepts std::vector<BTBEntry>& (non-const) for in-place edits; added tageHit() and several history helpers in ITTAGE; added UNIT_TEST commitBranch hooks and a default TagePrediction ctor; added s3PredwrongTage stat.
MBTB
src/cpu/pred/btb/mbtb.cc, src/cpu/pred/btb/mbtb.hh
Removed updating indirect target in buildUpdatedEntry for taken indirect branches; added UNIT_TEST commitBranch; removed predHitCount stat from MBTB stats.
Misc / formatting & guards
src/cpu/pred/btb/abtb.cc (additional), small edits across files
Minor formatting/UNIT_TEST guard adjustments and small structural edits (e.g., getPreviousPC) with no API surface changes.

Sequence Diagram

sequenceDiagram
    participant Fetch as Fetch stage
    participant Decoupled as DecoupledBPU
    participant S1 as Stage0 BTB (S1)
    participant S3 as Stage2 BTB (S3)
    participant FSQ as FetchStream/FSQ
    participant Commit as Commit path

    Fetch->>Decoupled: request prediction
    Decoupled->>S1: query S1 BTB
    S1-->>Decoupled: S1 entries (with entry.source)
    Decoupled->>S3: query S3 BTB
    S3-->>Decoupled: S3 taken-classification (with entry.source)
    Decoupled->>Decoupled: derive finalPred.s1Source / finalPred.s3Source
    Decoupled->>FSQ: createFetchStreamEntry (propagate s1/s3 sources)
    Note right of FSQ: instruction executes later
    FSQ->>Commit: commitBranch(entry)
    Commit->>Commit: on mispredict -> commitPredWrongSource(entry)
    alt s1 blame
        Commit->>Commit: inspect entry.s1Source -> increment s1PredWrong* or Fallthrough stat
    end
    alt s3 blame
        Commit->>Commit: inspect entry.s3Source & exeBranchInfo -> increment s3PredWrong*
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested labels

align-kmhv3

Suggested reviewers

  • jensen-yan

Poem

🐰 I hop through BTB entries, tagging each trace,
S1 and S3 carry my quiet, carrot-paced grace.
When branches swerve off path and stray,
I tally and point where errors lay.
A nibble of data, a hop, and a trace. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.96% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'cpu-o3:Implement predwrongSource method' accurately reflects the main objective of implementing the predwrongSource method across multiple BTB-related files.
✨ Finishing touches
  • 📝 Generate docstrings

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/cpu/pred/btb/btb_tage.cc (1)

1122-1125: Empty predwrongSource implementation for BTBTAGE.

This no-op implementation is consistent with the broader pattern of adding predwrongSource hooks across BTB predictors. However, BTBTAGE handles conditional branches and could benefit from wrong-source tracking similar to the s1PredwrongAbtb/s1PredwrongUbtb counters added to AheadBTB and UBTB.

If wrong-source tracking is needed for TAGE, consider adding a statistics counter similar to AheadBTB and UBTB:

🔎 Proposed enhancement

In btb_tage.hh, add to TageStats:

 struct TageStats : public statistics::Group {
+    Scalar s1PredwrongTage;
     // ... existing stats

In the stats constructor, initialize it:

+    ADD_STAT(s1PredwrongTage, statistics::units::Count::get(), "S1 wrong-source predictions from TAGE"),

Then update the implementation:

 void
 BTBTAGE::predwrongSource(){
+    tageStats.s1PredwrongTage++;
 }
src/cpu/pred/btb/btb_ittage.cc (1)

562-563: Empty predwrongSource stub for ITTAGE.

The no-op implementation establishes the interface hook for ITTAGE wrong-source tracking. Since ITTAGE predicts indirect branches (calls, jumps), consider adding a statistics counter in future work similar to s1PredwrongAbtb/s1PredwrongUbtb for complete observability.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea20857 and 1d5c770.

📒 Files selected for processing (19)
  • src/cpu/pred/btb/abtb.cc
  • src/cpu/pred/btb/abtb.hh
  • src/cpu/pred/btb/btb_ittage.cc
  • src/cpu/pred/btb/btb_ittage.hh
  • src/cpu/pred/btb/btb_mgsc.cc
  • src/cpu/pred/btb/btb_mgsc.hh
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_tage.hh
  • src/cpu/pred/btb/btb_ubtb.cc
  • src/cpu/pred/btb/btb_ubtb.hh
  • src/cpu/pred/btb/decoupled_bpred.cc
  • src/cpu/pred/btb/decoupled_bpred.hh
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
  • src/cpu/pred/btb/mbtb.cc
  • src/cpu/pred/btb/mbtb.hh
  • src/cpu/pred/btb/ras.cc
  • src/cpu/pred/btb/ras.hh
  • src/cpu/pred/btb/stream_struct.hh
  • src/cpu/pred/btb/timed_base_pred.hh
🧰 Additional context used
🧬 Code graph analysis (8)
src/cpu/pred/btb/btb_ittage.cc (6)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (710-713)
  • predwrongSource (711-711)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1122-1125)
  • predwrongSource (1123-1123)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (812-813)
  • predwrongSource (813-813)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-438)
  • predwrongSource (436-436)
src/cpu/pred/btb/btb_mgsc.cc (6)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (710-713)
  • predwrongSource (711-711)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (562-563)
  • predwrongSource (563-563)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1122-1125)
  • predwrongSource (1123-1123)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (812-813)
  • predwrongSource (813-813)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-438)
  • predwrongSource (436-436)
src/cpu/pred/btb/decoupled_bpred.cc (2)
src/cpu/pred/btb/decoupled_bpred.hh (3)
  • entry (191-191)
  • entry (193-193)
  • entry (922-927)
src/cpu/pred/btb/stream_struct.hh (1)
  • entry (514-536)
src/cpu/pred/btb/abtb.cc (6)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (562-563)
  • predwrongSource (563-563)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1122-1125)
  • predwrongSource (1123-1123)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (812-813)
  • predwrongSource (813-813)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-438)
  • predwrongSource (436-436)
src/cpu/pred/btb/btb_tage.cc (6)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (710-713)
  • predwrongSource (711-711)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (562-563)
  • predwrongSource (563-563)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (812-813)
  • predwrongSource (813-813)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-438)
  • predwrongSource (436-436)
src/cpu/pred/btb/mbtb.cc (6)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (710-713)
  • predwrongSource (711-711)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (562-563)
  • predwrongSource (563-563)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1122-1125)
  • predwrongSource (1123-1123)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-438)
  • predwrongSource (436-436)
src/cpu/pred/btb/stream_struct.hh (1)
src/cpu/pred/ftb/stream_struct.hh (3)
  • BranchInfo (66-66)
  • BranchInfo (67-77)
  • BranchInfo (140-140)
src/cpu/pred/btb/btb_ubtb.cc (6)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (710-713)
  • predwrongSource (711-711)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (562-563)
  • predwrongSource (563-563)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1122-1125)
  • predwrongSource (1123-1123)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (812-813)
  • predwrongSource (813-813)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-438)
  • predwrongSource (436-436)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)
🔇 Additional comments (23)
src/cpu/pred/btb/btb_ubtb.hh (1)

135-136: LGTM!

The predwrongSource() override declaration is correctly placed and follows the established pattern for BTB predictor interfaces.

src/cpu/pred/btb/timed_base_pred.hh (1)

85-85: LGTM!

The virtual predwrongSource() method with empty default implementation follows good design practices, allowing derived classes to optionally override this hook for source-tracking purposes.

src/cpu/pred/btb/mbtb.hh (1)

127-129: LGTM!

The predwrongSource() override declaration is correctly positioned and formatted. The empty implementation in mbtb.cc is consistent with other non-first-stage BTB predictors.

src/cpu/pred/btb/btb_ubtb.cc (2)

215-215: Source tracking implementation looks correct.

The call to takenEntry.setsource(getComponentIdx()) properly marks the prediction source when UBTB updates using S3 predictions. This enables per-component accountability for predictions.

Note: This change depends on the setsource() method being available on BTBEntry, which appears to be added in stream_struct.hh (mentioned in the AI summary but not included in this review).


322-325: Implementation correct but depends on stat initialization fix.

The predwrongSource() implementation correctly increments the s1PredwrongUbtb counter, consistent with similar implementations in abtb.cc. However, this stat must be initialized in the UBTBStats constructor (see comment on lines 332-333 in btb_ubtb.hh).

src/cpu/pred/btb/btb_tage.hh (1)

156-157: LGTM!

The predwrongSource() override declaration is properly placed. The empty implementation in btb_tage.cc is appropriate since BTBTAGE is not a first-stage predictor and doesn't need per-source tracking.

src/cpu/pred/btb/mbtb.cc (1)

812-813: LGTM!

The empty predwrongSource() implementation is appropriate for MBTB, which is not a first-stage predictor. This is consistent with the pattern where only UBTB and ABTB (first-stage predictors) have actual implementations that increment counters.

src/cpu/pred/btb/decoupled_bpred.cc (1)

1021-1022: LGTM!

The assignment of entry.s1Source = finalPred.s1Source correctly propagates the source tracking information from the final prediction to the fetch stream entry. This depends on the s1Source logic in generateFinalPredAndCreateBubbles() being correct (see comment on lines 244-254).

src/cpu/pred/btb/btb_mgsc.hh (1)

162-163: LGTM!

The predwrongSource() override declaration is correctly positioned. The empty implementation in btb_mgsc.cc is appropriate since BTBMGSC is a statistical corrector component that doesn't require per-source tracking.

src/cpu/pred/btb/abtb.hh (1)

129-129: LGTM: predwrongSource implementation for AheadBTB.

The addition of the predwrongSource() override (line 129) and corresponding statistic s1PredwrongAbtb (line 474) properly implements wrong-source prediction tracking for AheadBTB. This is consistent with the UBTB implementation pattern and enables per-component accounting of S1 mispredictions.

Also applies to: 474-474

src/cpu/pred/btb/ras.hh (1)

105-105: predwrongSource declaration added to RAS interface.

The declaration is correctly placed and consistent with the override pattern across other BTB predictors. The corresponding implementation in ras.cc is currently a no-op placeholder.

src/cpu/pred/btb/btb_ittage.hh (1)

114-114: predwrongSource declaration added to ITTAGE.

The override declaration is correctly positioned and follows the established pattern across BTB predictor interfaces.

src/cpu/pred/btb/stream_struct.hh (2)

350-351: LGTM: Per-stage source tracking infrastructure.

The addition of s1Source and s3Source fields to both FetchStream and FullBTBPrediction enables proper tracking of which predictor component provided predictions at each pipeline stage. This infrastructure supports the new predwrongSource() hooks and per-component misprediction statistics.

The fields are consistently initialized to 0 in constructors and follow a clear naming convention.

Also applies to: 376-378, 499-500, 511-512


180-192: Document the off-by-one indexing invariant in source accessors.

The getsource() and setsource() methods implement a consistent off-by-one scheme where setsource(int src) stores src + 1 and getsource() returns source - 1. This preserves the external component index while using internal storage where the initial value of 0 appears to represent an uninitialized state. Add a comment to stream_struct.hh documenting this invariant for maintainers.

src/cpu/pred/btb/decoupled_bpred.hh (1)

371-371: New statistic for S1 full-through wrong predictions properly implemented.

The addition of s1Predwrongfullthrough correctly complements the per-component wrong-source counters by tracking S1 predictions that propagate through the entire pipeline without correction. The statistic is properly initialized in the constructor and incremented when no misprediction source component intervenes.

src/cpu/pred/btb/ras.cc (1)

435-438: Empty predwrongSource() implementation is correct for RAS.

RAS already tracks mispredictions through rasStats.PredWrong++ in the commitBranch() method when the predicted target differs from the actual next PC. Unlike UBTB and AheadBTB which use predwrongSource() as their primary wrong-source notification hook, RAS validates predictions during commit and tracks mismatches directly, making the empty predwrongSource() override appropriate.

Likely an incorrect or invalid review comment.

src/cpu/pred/btb/btb_mgsc.cc (1)

1098-1099: LGTM!

The no-op implementation is consistent with other BTB components (BTBTAGE, MBTB, RAS, BTBITTAGE) and appropriate for MGSC, which serves as a statistical correction layer rather than a direct prediction source.

src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

500-501: LGTM!

The new s1Predwrongfullthrough statistic is properly initialized and follows the existing naming convention for tracking S1 prediction misses that don't originate from a specific component.

src/cpu/pred/btb/abtb.cc (5)

216-232: LGTM!

The two-step deduplication approach (invalidate duplicates, then erase invalid entries) correctly prioritizes UBTB predictions over ABTB predictions when the same PC appears in both. This is the expected behavior since UBTB (micro-BTB) is a faster, more recent predictor.


604-604: LGTM!

Correctly marks the BTB entry as originating from AheadBTB before updating. This source tracking enables the predwrongSource() mechanism to attribute mispredictions to the correct component.


680-680: LGTM!

Correctly marks the BTB entry as originating from AheadBTB in the standard update path, consistent with the S3 prediction update path (line 604).


710-713: LGTM!

The implementation correctly increments the ABTB-specific misprediction counter, consistent with the UBTB implementation pattern. This enables per-component accounting of wrong S1 predictions.


855-856: LGTM!

The new s1PredwrongAbtb statistic is properly initialized and follows the naming convention for tracking ABTB-specific wrong predictions. The comma on line 855 correctly continues the initialization list.

Comment thread src/cpu/pred/btb/btb_ubtb.hh Outdated
Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc
Comment thread src/cpu/pred/btb/decoupled_bpred.cc Outdated
@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.53 +0.19 🟢

Cao Jiaming added 2 commits December 26, 2025 15:29
Change-Id: I78091441671e564579c3e81f06daf51414a095fc
Change-Id: I787f662435b5ab49b0f7103f7d9b7fbecbcfe270
@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.53 +0.21 🟢

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

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.57 17.57 0.00

Cao Jiaming added 2 commits December 27, 2025 16:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

866-895: Add bounds checking for component array access.

This code accesses components[s1PredSource] and components[s3WrongBranchSource] with assert-based validation that only works in debug builds and doesn't check against components.size(). This could lead to undefined behavior if the source indices are out of range.

Additionally:

  • The assertions are asymmetric: s1PredSource < 2 for s1, but s3WrongBranchSource > 2 for s3 with no upper bound check.
  • If no matching entry is found in predBTBEntries, exeBranch remains default-constructed with source = -1, which is correctly handled.
🔎 Proposed fix with proper bounds checking
     //here add final counter
     if (mispred) {
         int s1PredSource = entry.s1Source;
-        if (s1PredSource >= 0) {
-            assert(s1PredSource < 2);
+        if (s1PredSource >= 0 && static_cast<size_t>(s1PredSource) < components.size()) {
             components[s1PredSource]->predwrongSource();
-
-        }else {
+        } else {
             dbpBtbStats.s1Predwrongfullthrough++;
         }

         auto exeBranchinfo = entry.exeBranchInfo;
         auto exeBranch = BTBEntry();
-        for (auto btb_entry: entry.predBTBEntries){//find the exe branch in the btb entries
-            if (btb_entry.pc == exeBranchinfo.pc){
+        for (const auto &btb_entry : entry.predBTBEntries) {
+            if (btb_entry.pc == exeBranchinfo.pc) {
                 exeBranch = btb_entry;
                 break;
             }
         }

         auto s3WrongBranchSource = exeBranch.source;
-        if (s3WrongBranchSource >= 0) {
-            assert(s3WrongBranchSource >2);
+        if (s3WrongBranchSource >= 0 && 
+            static_cast<size_t>(s3WrongBranchSource) < components.size()) {
             components[s3WrongBranchSource]->predwrongSource();
-
         } else {
             dbpBtbStats.s3Predwrongfullthrough++;
         }
-
     }
🧹 Nitpick comments (2)
src/cpu/pred/btb/ras.cc (1)

478-479: Statistic description may be misleading for RAS.

The description says "number of stage 3 conditional branch mispredictions by RAS", but RAS handles return instructions, not conditional branches. Consider updating to "number of stage 3 return mispredictions by RAS" for accuracy.

🔎 Suggested fix
-    ADD_STAT(s3PredwrongRas, statistics::units::Count::get(),"number of stage 3 conditional branch mispredictions by RAS")
+    ADD_STAT(s3PredwrongRas, statistics::units::Count::get(),"number of stage 3 return mispredictions by RAS")
src/cpu/pred/btb/btb_ittage.cc (1)

652-653: Statistic description mentions conditional branches but ITTAGE handles indirect branches.

The description says "number of stage 3 conditional branch mispredictions by ittage", but ITTAGE specifically handles indirect non-return branches. Consider updating to "number of stage 3 indirect branch mispredictions by ittage" for accuracy.

🔎 Suggested fix
-    ADD_STAT(s3PredwrongIttage, statistics::units::Count::get(), "number of stage 3 conditional branch mispredictions by ittage")
+    ADD_STAT(s3PredwrongIttage, statistics::units::Count::get(), "number of stage 3 indirect branch mispredictions by ittage")
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6fa252d and 8230a2c.

📒 Files selected for processing (13)
  • src/cpu/pred/btb/abtb.cc
  • src/cpu/pred/btb/btb_ittage.cc
  • src/cpu/pred/btb/btb_ittage.hh
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_tage.hh
  • src/cpu/pred/btb/btb_ubtb.cc
  • src/cpu/pred/btb/decoupled_bpred.cc
  • src/cpu/pred/btb/decoupled_bpred.hh
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
  • src/cpu/pred/btb/mbtb.cc
  • src/cpu/pred/btb/mbtb.hh
  • src/cpu/pred/btb/ras.cc
  • src/cpu/pred/btb/ras.hh
🧰 Additional context used
🧬 Code graph analysis (8)
src/cpu/pred/btb/btb_ubtb.cc (6)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (564-567)
  • predwrongSource (565-565)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1129-1132)
  • predwrongSource (1130-1130)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (714-717)
  • predwrongSource (715-715)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (817-820)
  • predwrongSource (818-818)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (441-445)
  • predwrongSource (442-442)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/abtb.cc (1)
src/cpu/pred/btb/abtb.hh (4)
  • TickedBTBEntry (108-109)
  • TickedBTBEntry (110-110)
  • a (339-342)
  • a (339-339)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)
src/cpu/pred/btb/stream_struct.hh (2)
  • BTBEntry (182-182)
  • BTBEntry (183-183)
src/cpu/pred/btb/btb_ittage.hh (2)
src/cpu/pred/btb/btb_mgsc.hh (1)
  • stream_start (226-227)
src/cpu/pred/ftb/ftb_tage.hh (1)
  • stream_start (116-119)
src/cpu/pred/btb/btb_tage.cc (4)
src/cpu/pred/btb/btb_tage.hh (4)
  • TagePrediction (105-105)
  • TagePrediction (107-110)
  • taken (284-284)
  • pred (387-387)
src/cpu/pred/btb/btb_ittage.cc (4)
  • lookupHelper (75-159)
  • lookupHelper (76-76)
  • predwrongSource (564-567)
  • predwrongSource (565-565)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (817-820)
  • predwrongSource (818-818)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (441-445)
  • predwrongSource (442-442)
src/cpu/pred/btb/btb_ittage.cc (4)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1129-1132)
  • predwrongSource (1130-1130)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (714-717)
  • predwrongSource (715-715)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (817-820)
  • predwrongSource (818-818)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (441-445)
  • predwrongSource (442-442)
src/cpu/pred/btb/mbtb.cc (6)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (564-567)
  • predwrongSource (565-565)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1129-1132)
  • predwrongSource (1130-1130)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (714-717)
  • predwrongSource (715-715)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (441-445)
  • predwrongSource (442-442)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/ras.cc (5)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (564-567)
  • predwrongSource (565-565)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1129-1132)
  • predwrongSource (1130-1130)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (714-717)
  • predwrongSource (715-715)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (817-820)
  • predwrongSource (818-818)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)
🔇 Additional comments (35)
src/cpu/pred/btb/btb_ubtb.cc (3)

215-215: LGTM! Source tracking correctly assigned.

Setting source = getComponentIdx() appropriately marks UBTB as the prediction source when it adopts S3 predictions into its own entries for subsequent s1 predictions.


322-325: LGTM! Implementation consistent with other BTB predictors.

The predwrongSource() method correctly follows the established pattern across BTB components (ABTB, MBTB, RAS, TAGE, ITTAGE) by incrementing the component-specific misprediction counter. Using an s1-stage statistic aligns with UBTB's role as an s1 predictor.


471-472: LGTM! Statistic properly registered.

The s1PredwrongUbtb statistic is correctly added to the UBTBStats group with an appropriate description.

src/cpu/pred/btb/mbtb.hh (2)

127-128: LGTM!

The predwrongSource() override declaration is correctly placed and follows the consistent pattern established across other BTB predictor components.


473-473: LGTM!

The s3PredwrongMbtb statistic field is appropriately added to track stage-3 mispredictions, consistent with similar counters in other predictors (e.g., s3PredwrongTage, s3PredwrongRas).

src/cpu/pred/btb/btb_ittage.hh (3)

114-115: LGTM!

The predwrongSource() override declaration is correctly added, following the established pattern across BTB predictor components.


124-124: Signature change to non-const reference is intentional.

The change from const std::vector<BTBEntry>& to std::vector<BTBEntry>& enables in-place modification of btb_entry.source within lookupHelper. This is consistent with the corresponding change in BTBTAGE::lookupHelper.


234-234: LGTM!

The s3PredwrongIttage statistic is correctly declared to track stage-3 ITTAGE mispredictions.

src/cpu/pred/btb/ras.cc (2)

104-109: LGTM!

The source assignment for return BTB entries is correctly implemented, finding the first return entry in the current delay's stage predictions and assigning the component index.


441-445: LGTM!

The predwrongSource() implementation correctly increments s3PredwrongRas, following the established pattern across other BTB predictors.

src/cpu/pred/btb/ras.hh (2)

105-106: LGTM!

The predwrongSource() override declaration is correctly placed and follows the established pattern.


238-239: LGTM!

The s3PredwrongRas statistic field is correctly declared in the RASStats structure.

src/cpu/pred/btb/mbtb.cc (3)

587-587: Unconditional source assignment in buildUpdatedEntry.

Unlike BTBTAGE and BTBITTAGE which conditionally set source based on coverage flags (e.g., tageCovered), MBTB unconditionally sets entry_to_write.source = getComponentIdx() for all updated entries. Verify this is the intended behavior for MBTB's source tracking.


816-820: LGTM!

The predwrongSource() implementation correctly increments s3PredwrongMbtb, following the established pattern.


969-969: LGTM!

The statistic initialization for s3PredwrongMbtb is correctly added with an appropriate description.

src/cpu/pred/btb/btb_tage.cc (5)

296-298: LGTM!

The tageCovered flag correctly captures when TAGE provides a meaningful prediction (not falling back to the base table). The logic !(use_alt && !alt_provided) appropriately identifies cases where either the main prediction or an alternative TAGE table prediction is used.


309-309: Signature change to non-const reference is correct.

The change from const std::vector<BTBEntry>& to std::vector<BTBEntry>& enables in-place modification of btb_entry.source within the loop, which is necessary for the new source tracking functionality.


322-324: Source assignment is stage-3 specific.

The conditional getDelay() == 3 restricts source assignment to stage-3 predictions only. This appears intentional for the s3 (stage-3) tracking mechanism. The ternary preserves the existing source if TAGE didn't cover the branch.


1047-1048: LGTM!

The statistic initialization for s3PredwrongTage is correctly added.


1128-1132: LGTM!

The predwrongSource() implementation correctly increments s3PredwrongTage, following the established pattern across other BTB predictors.

src/cpu/pred/btb/btb_ittage.cc (3)

76-76: LGTM!

The signature change to a non-const reference is consistent with the corresponding change in BTBTAGE and enables in-place modification of btb_entry.source.


152-154: Source assignment differs from BTBTAGE - missing getDelay() check.

BTBTAGE guards the source assignment with if (getDelay() == 3) (line 322-324 in btb_tage.cc), but BTBITTAGE sets source unconditionally for any delay value. This may be intentional if ITTAGE handles indirect branches differently, but verify this is the intended behavior for consistency with the stage-3 tracking mechanism.


564-567: LGTM!

The predwrongSource() implementation correctly increments s3PredwrongIttage.

src/cpu/pred/btb/btb_tage.hh (4)

103-110: LGTM!

The tageCovered field is correctly added to TagePrediction with proper initialization in both default and parameterized constructors.


158-158: LGTM!

The predwrongSource() override declaration is correctly placed and follows the established pattern.


172-173: LGTM!

The lookupHelper signature change to accept a non-const reference is consistent with the implementation and enables in-place modification of BTB entries.


378-379: LGTM!

The s3PredwrongTage statistic field is correctly declared in the TageStats structure.

src/cpu/pred/btb/decoupled_bpred.hh (1)

319-319: LGTM!

The new statistic declarations follow the existing patterns and naming conventions in the DBPBTBStats struct.

Also applies to: 372-374

src/cpu/pred/btb/decoupled_bpred.cc (1)

1033-1034: LGTM!

The propagation of s1Source from finalPred to the fetch stream entry is consistent with how other prediction metadata is handled.

src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

706-706: LGTM!

The increment of branchClassCountsTotal when a misprediction occurs correctly tracks the total number of mispredicted classified branches.

src/cpu/pred/btb/abtb.cc (5)

681-681: Consistent source tracking in standard update path.

This mirrors the source assignment in updateUsingS3Pred() (line 605), ensuring both update paths properly mark entries as owned by AheadBTB.


858-859: Statistics addition looks good.

The new s1PredwrongAbtb statistic is properly added to the BTBStats initializer list with a clear description. The comma on line 858 correctly continues the initialization sequence.


714-717: The method is invoked correctly from the DecoupledBPU misprediction handling.

The predwrongSource() implementation correctly increments the ABTB-specific wrong-prediction counter (btbStats.s1PredwrongAbtb). It is properly called from decoupled_bpred_stats.cc (lines 871, 889) when mispredictions are detected and dispatched, with the call routed to the appropriate BTB component based on the prediction source.


605-605: Source assignment correctly marks entry ownership.

entry.source = getComponentIdx() properly sets the source field to track that this entry is owned by AheadBTB (component index 0). This is consistent with the identical pattern at line 681 and aligns with the source tracking objective used across all BTB predictor components.


216-233: No issue here—lookup() filters entries by validity before returning.

The deduplication logic safely invalidates and removes the matching aBTB entry (lines 216-233). Since lookup() only returns entries where way.valid is true (checked at line 384 of lookupSingleBlock), all entries passed to fillStagePredictions() are already guaranteed valid. The remove_if operation removes only the one entry intentionally invalidated during deduplication, not pre-existing invalid entries.

Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc Outdated
Comment thread src/cpu/pred/btb/decoupled_bpred.cc
@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.53 +0.21 🟢

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

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.57 17.57 0.00

Change-Id: Ieab9cfbd9c70c0b5cc7885c39fc313eeaac9717a

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
src/cpu/pred/btb/decoupled_bpred_stats.cc (2)

502-503: Typo in statistics description.

The description for s3Predwrongfullthrough says "S2pred wrong full throughs" but should say "S3pred wrong full throughs" to match the variable name.

🔎 Proposed fix
     ADD_STAT(s1Predwrongfullthrough, statistics::units::Count::get(), "S1pred wrong full throughs"),
-    ADD_STAT(s3Predwrongfullthrough, statistics::units::Count::get(), "S2pred wrong full throughs")
+    ADD_STAT(s3Predwrongfullthrough, statistics::units::Count::get(), "S3pred wrong full throughs")

866-894: Add bounds checking for component array access.

The code accesses components[s1PredSource] at line 871 and components[s3WrongBranchSource] at line 888 without verifying that the indices are within valid bounds. If entry.s1Source or exeBranch.source are corrupted or out of range, this could lead to undefined behavior.

🔎 Proposed fix with bounds checking
     if (mispred) {
         int s1PredSource = entry.s1Source;
         if (s1PredSource >= 0) {
-            assert(s1PredSource < 2);
-            components[s1PredSource]->predwrongSource();
+            if (s1PredSource < components.size()) {
+                components[s1PredSource]->predwrongSource();
+            } else {
+                dbpBtbStats.s1Predwrongfullthrough++;
+            }
 
         }else {
             dbpBtbStats.s1Predwrongfullthrough++;
         }
 
         auto exeBranchinfo = entry.exeBranchInfo;
         auto exeBranch = BTBEntry();
         for (auto btb_entry: entry.predBTBEntries){
             if (btb_entry.pc == exeBranchinfo.pc){
                 exeBranch = btb_entry;
                 break;
             }
         }
 
         auto s3WrongBranchSource = exeBranch.source;
         if (s3WrongBranchSource >= 0) {
-            components[s3WrongBranchSource]->predwrongSource();
+            if (s3WrongBranchSource < components.size()) {
+                components[s3WrongBranchSource]->predwrongSource();
+            } else {
+                dbpBtbStats.s3Predwrongfullthrough++;
+            }
 
         } else {
             dbpBtbStats.s3Predwrongfullthrough++;
         }
 
     }
🧹 Nitpick comments (3)
src/cpu/pred/btb/decoupled_bpred_stats.cc (3)

457-457: Clarify the semantics of branchClassCountsTotal.

The statistic branchClassCountsTotal is described as "total number of classified branches", but line 706 only increments it when mispred is true. This suggests it's actually tracking total mispredictions across all classes, not total branches.

Either rename the statistic to branchClassMissesTotal or update the description to clarify it counts mispredictions, not all branches.

🔎 Proposed fix

Option 1: Rename the statistic

-    ADD_STAT(branchClassCountsTotal, statistics::units::Count::get(), "total number of classified branches"),
+    ADD_STAT(branchClassMissesTotal, statistics::units::Count::get(), "total number of classified branch mispredictions"),

Then update line 706:

-        dbpBtbStats.branchClassCountsTotal++;
+        dbpBtbStats.branchClassMissesTotal++;

Option 2: Update the description

-    ADD_STAT(branchClassCountsTotal, statistics::units::Count::get(), "total number of classified branches"),
+    ADD_STAT(branchClassCountsTotal, statistics::units::Count::get(), "total number of classified branch mispredictions"),

Also applies to: 706-706


870-870: Replace hardcoded assertion value with components.size().

The assertion checks s1PredSource < 2 with a hardcoded value. If the number of components changes, this becomes incorrect. Use components.size() instead for better maintainability.

🔎 Proposed fix
         int s1PredSource = entry.s1Source;
         if (s1PredSource >= 0) {
-            assert(s1PredSource < 2);
+            assert(s1PredSource < components.size());
             components[s1PredSource]->predwrongSource();

Note: This should be combined with the bounds checking fix from the previous comment to properly handle out-of-bounds indices.


877-877: Fix variable naming inconsistency.

The variable is named exeBranchinfo (lowercase 'i') but the struct field is entry.exeBranchInfo (capital 'I'). Use consistent naming for clarity.

🔎 Proposed fix
-        auto exeBranchinfo = entry.exeBranchInfo;
+        auto exeBranchInfo = entry.exeBranchInfo;
         auto exeBranch = BTBEntry();
         for (auto btb_entry: entry.predBTBEntries){
-            if (btb_entry.pc == exeBranchinfo.pc){
+            if (btb_entry.pc == exeBranchInfo.pc){
                 exeBranch = btb_entry;
                 break;
             }
         }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8230a2c and 7f4a375.

📒 Files selected for processing (1)
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
🧰 Additional context used
🧬 Code graph analysis (1)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)
src/cpu/pred/btb/stream_struct.hh (2)
  • BTBEntry (182-182)
  • BTBEntry (183-183)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)

@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.53 +0.21 🟢

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

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.57 17.57 0.00

Change-Id: Ied49f642bc88a6be31bdf51d3f6de608f8661910

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

867-901: Add bounds checking for component array access.

This is related to a previous review comment that wasn't fully addressed. There are two bounds-safety concerns:

  1. Line 871-872: The assertion assert(s1PredSource < 2) doesn't verify against components.size(). If components.size() < 2, accessing components[s1PredSource] with source values 0 or 1 would still cause undefined behavior in release builds (where asserts are disabled).

  2. Line 894: components[s3WrongBranchSource]->predwrongSource() is called when s3WrongBranchSource >= 2 without any upper bound check. If the source value exceeds components.size(), this will cause undefined behavior.

🔎 Proposed fix with bounds checking
     //here add final counter
     if (mispred) {
         int s1PredSource = entry.s1Source;
-        if (s1PredSource >= 0) {
-            assert(s1PredSource < 2);
-            components[s1PredSource]->predwrongSource();
-
-        }else {
+        if (s1PredSource >= 0 && s1PredSource < components.size()) {
+            components[s1PredSource]->predwrongSource();
+        } else {
             dbpBtbStats.s1Predwrongfallthrough++;
         }

         auto exeBranchinfo = entry.exeBranchInfo;
         auto exeBranch = BTBEntry();
-        for (auto btb_entry: entry.predBTBEntries){//find the exe branch in the btb entries
-            if (btb_entry.pc == exeBranchinfo.pc){
+        for (const auto& btb_entry : entry.predBTBEntries) {
+            if (btb_entry.pc == exeBranchinfo.pc) {
                 exeBranch = btb_entry;
                 break;
             }
         }

         auto s3WrongBranchSource = exeBranch.source;
         if (s3WrongBranchSource >= 0) {
-            if (s3WrongBranchSource == 0||s3WrongBranchSource ==1) {
-                //final pred from s1 stage because mbtb miss
+            if (s3WrongBranchSource == 0 || s3WrongBranchSource == 1) {
+                // Final pred from s1 stage because mbtb miss
                 dbpBtbStats.s3Predwrongfallthrough++;
                 dbpBtbStats.s3fallthroughbuts1hit++;
-            }else {
+            } else if (s3WrongBranchSource < components.size()) {
                 components[s3WrongBranchSource]->predwrongSource();
+            } else {
+                dbpBtbStats.s3Predwrongfallthrough++;
             }
-
         } else {
             dbpBtbStats.s3Predwrongfallthrough++;
         }
-
     }

Based on learnings from the past review comment on this file.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7f4a375 and 6f7f733.

📒 Files selected for processing (3)
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/decoupled_bpred.hh
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cpu/pred/btb/decoupled_bpred.hh
🧰 Additional context used
🧬 Code graph analysis (1)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)
src/cpu/pred/btb/stream_struct.hh (2)
  • BTBEntry (182-182)
  • BTBEntry (183-183)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)
🔇 Additional comments (6)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

457-457: LGTM on declaration.

The statistic is properly declared. However, see comment on line 707 regarding its usage.

src/cpu/pred/btb/btb_tage.cc (5)

296-298: LGTM: tageCovered logic correctly identifies TAGE coverage.

The computation tageCovered = !(use_alt && !alt_provided) correctly identifies when TAGE provides meaningful prediction (either main prediction or alt from TAGE tables) versus falling back to the base table. This is the right criterion for source attribution.


322-324: LGTM: Source assignment correctly implements stage-3 ownership tracking.

The condition getDelay() == 2 appropriately restricts source assignment to stage-3 predictions, and the tageCovered check ensures TAGE only claims ownership when it meaningfully contributes to the prediction rather than falling back to the base table.


1047-1048: LGTM: Statistics properly declared.

Both predMiss and s3PredwrongTage counters follow the correct declaration pattern and naming conventions.


1128-1132: No action needed—predwrongSource() is correctly called from the DecoupledBPU statistics handler.

The method is invoked in src/cpu/pred/btb/decoupled_bpred_stats.cc at lines 872 and 894 when mispredictions are detected. When a branch mispredicts and its source field matches a component's index, that component's predwrongSource() is called to update its statistics. The method is not called within btb_tage.cc because the call site is in the decoupled predictor's main statistics logic, not in individual component implementations.


309-310: All call sites are compatible with the non-const parameter.

The single call site at line 381 passes stage_pred.btbEntries as a mutable reference, which is compatible with the function signature. The non-const parameter is justified by the source assignment at line 323.

Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc Outdated
Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

Change-Id: I9d8c591468d5af33145f58ff80762ae95c69840e

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (1)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

504-504: Fix typo in statistics description.

The description contains "throug" which should be "through".

🔎 Proposed fix
-    ADD_STAT(s3fallthroughbuts1hit,statistics::units::Count::get(), "S3full throug but s1 hit" )
+    ADD_STAT(s3fallthroughbuts1hit, statistics::units::Count::get(), "S3 fallthrough but s1 hit")
🧹 Nitpick comments (2)
src/cpu/pred/btb/decoupled_bpred_stats.cc (2)

867-872: Consider improving the comment.

The comment "here add final counter" is vague. Consider a more descriptive comment explaining what commitPredWrongSource does.

🔎 Suggested improvement
-    //here add final counter
-
+    // Track which predictor component made the wrong prediction
     if (mispred) {
         commitPredWrongSource(entry);
     }
-

888-895: Use const references to avoid unnecessary copies.

The code creates copies of exeBranchInfo and each btb_entry in the loop. Use const references for better performance.

🔎 Proposed optimization
-    auto exeBranchinfo = entry.exeBranchInfo;
+    const auto& exeBranchInfo = entry.exeBranchInfo;
     auto exeBranch = BTBEntry();
-    for (auto btb_entry: entry.predBTBEntries){//find the exe branch in the btb entries
-        if (btb_entry.pc == exeBranchinfo.pc){
+    // Find the executed branch in the BTB entries
+    for (const auto& btb_entry : entry.predBTBEntries) {
+        if (btb_entry.pc == exeBranchInfo.pc) {
             exeBranch = btb_entry;
             break;
         }
     }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f7f733 and d4de496.

📒 Files selected for processing (2)
  • src/cpu/pred/btb/decoupled_bpred.hh
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cpu/pred/btb/decoupled_bpred.hh
🧰 Additional context used
🧬 Code graph analysis (1)
src/cpu/pred/btb/decoupled_bpred_stats.cc (2)
src/cpu/pred/btb/decoupled_bpred.hh (4)
  • entry (191-191)
  • entry (193-193)
  • entry (917-917)
  • entry (928-933)
src/cpu/pred/btb/stream_struct.hh (2)
  • BTBEntry (182-182)
  • BTBEntry (183-183)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)

Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc
Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc
Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc Outdated
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

Change-Id: I39d8808a2c9467f5362739623a09433e7a1559df
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.53 +0.21 🟢

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

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.57 17.57 0.00

Change-Id: I9ccb31f8e110c4ba13d53aad7dd3bbdbd6ba9358

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cpu/pred/btb/stream_struct.hh (1)

174-193: Initialize BTBEntry::tag in the BranchInfo constructor to avoid uninitialized state.

The new source field and s1/s3 tracking fields are fine, but:

  • BTBEntry(const BranchInfo &bi) currently sets valid/alwaysTaken/ctr/source but leaves tag uninitialized, unlike the default ctor which sets tag(0).
  • Several code paths construct BTBEntry from BranchInfo and only later assign tag; any intermediate use (logging, comparisons, accidental copies) would read an indeterminate value.

Recommend updating the ctor to mirror the default initialization:

-    BTBEntry(const BranchInfo &bi) : BranchInfo(bi), valid(true), alwaysTaken(true), ctr(0),source(-1){}
+    BTBEntry(const BranchInfo &bi)
+        : BranchInfo(bi),
+          valid(true),
+          alwaysTaken(true),
+          ctr(0),
+          tag(0),
+          source(-1)
+    {}

Optionally, consider renaming getsource/setsource to getSource/setSource for consistency with getBranchInfo() etc., but that’s stylistic.

Also applies to: 350-379, 481-513

♻️ Duplicate comments (3)
src/cpu/pred/btb/decoupled_bpred_stats.cc (3)

444-458: Align branchClassCountsTotal semantics with its description or rename it.

branchClassCountsTotal is described as “total number of classified branches” but it is only incremented when mispred is true (Line 707), i.e., on mispredictions.

Either:

  • Move dbpBtbStats.branchClassCountsTotal++ outside the if (mispred) block so it counts all classified branches, or
  • Rename it (and its description) to explicitly represent mispredictions only (e.g. branchClassMispredTotal).

Also applies to: 695-708


501-505: Fix typos and wording in new wrong‑source statistic descriptions.

Minor text issues:

  • "S1pred wrong full throughs" / "S3pred wrong full throughs" likely meant "fallthroughs", not "full throughs".
  • "S3full throug but s1 hit" has a typo ("throug").

Recommend updating these description strings for clarity/readability.


869-930: Add bounds checks when using entry.s1Source / s3blame to index components.

In commitPredWrongSource:

  • s1PredSource and s3PredSource come from runtime stream metadata (entry.s1Source/s3Source), not from trusted compile‑time constants.
  • You assert s1PredSource < mbtbid, but in release builds or if metadata is corrupted, components[s1PredSource] or components[s3blame] can still go out of range.

To harden this:

  • Gate both accesses with explicit bounds checks:
-    if (s1PredSource >= 0) {
-        assert(s1PredSource < mbtbid);
-        components[s1PredSource]->predwrongSource();
-    } else {
+    if (s1PredSource >= 0 &&
+        s1PredSource < static_cast<int>(components.size())) {
+        assert(s1PredSource < mbtbid);
+        components[s1PredSource]->predwrongSource();
+    } else {
         dbpBtbStats.s1Predwrongfallthrough++;
     }
@@
-    components[s3blame]->predwrongSource();
+    if (s3blame >= 0 && s3blame < static_cast<int>(components.size())) {
+        components[s3blame]->predwrongSource();
+    } else {
+        // Treat impossible/invalid blame index as a fallthrough case
+        dbpBtbStats.s3Predwrongfallthrough++;
+    }

This preserves your blame logic while preventing undefined behavior if a source index is ever out of range.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d5c5d8 and 496d40e.

📒 Files selected for processing (8)
  • src/cpu/pred/btb/btb_ittage.cc
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_tage.hh
  • src/cpu/pred/btb/decoupled_bpred.cc
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
  • src/cpu/pred/btb/mbtb.cc
  • src/cpu/pred/btb/ras.cc
  • src/cpu/pred/btb/stream_struct.hh
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cpu/pred/btb/btb_tage.hh
🧰 Additional context used
🧬 Code graph analysis (6)
src/cpu/pred/btb/mbtb.cc (6)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (561-564)
  • predwrongSource (562-562)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1125-1128)
  • predwrongSource (1126-1126)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-439)
  • predwrongSource (436-436)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (714-717)
  • predwrongSource (715-715)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/stream_struct.hh (1)
src/cpu/pred/ftb/stream_struct.hh (3)
  • BranchInfo (66-66)
  • BranchInfo (67-77)
  • BranchInfo (140-140)
src/cpu/pred/btb/ras.cc (6)
src/cpu/pred/btb/btb_ittage.cc (2)
  • predwrongSource (561-564)
  • predwrongSource (562-562)
src/cpu/pred/btb/btb_tage.cc (2)
  • predwrongSource (1125-1128)
  • predwrongSource (1126-1126)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (816-819)
  • predwrongSource (817-817)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (714-717)
  • predwrongSource (715-715)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/decoupled_bpred_stats.cc (2)
src/cpu/pred/btb/decoupled_bpred.hh (4)
  • entry (191-191)
  • entry (193-193)
  • entry (917-917)
  • entry (928-933)
src/cpu/pred/btb/stream_struct.hh (1)
  • entry (514-536)
src/cpu/pred/btb/btb_tage.cc (6)
src/cpu/pred/btb/btb_mgsc.cc (4)
  • lookupHelper (350-370)
  • lookupHelper (351-352)
  • predwrongSource (1098-1099)
  • predwrongSource (1099-1099)
src/cpu/pred/btb/btb_tage.hh (2)
  • startPC (172-173)
  • startPC (434-441)
src/cpu/pred/btb/mbtb.cc (2)
  • predwrongSource (816-819)
  • predwrongSource (817-817)
src/cpu/pred/btb/ras.cc (2)
  • predwrongSource (435-439)
  • predwrongSource (436-436)
src/cpu/pred/btb/btb_ubtb.cc (2)
  • predwrongSource (322-325)
  • predwrongSource (323-323)
src/cpu/pred/btb/abtb.cc (2)
  • predwrongSource (714-717)
  • predwrongSource (715-715)
src/cpu/pred/btb/decoupled_bpred.cc (1)
src/cpu/pred/btb/stream_struct.hh (1)
  • entry (514-536)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)
🔇 Additional comments (4)
src/cpu/pred/btb/ras.cc (1)

435-439: RAS predwrongSource wiring looks consistent with other predictors.

BTBRAS::predwrongSource() simply bumps rasStats.s3PredwrongRas, and the stat is properly registered in RASStats. This aligns with the pattern used in UBTB/MBTB/TAGE/ITTAGE and is fine as-is.

Also applies to: 471-474

src/cpu/pred/btb/mbtb.cc (1)

812-820: MBTB predwrongSource hook is correctly wired to the new statistic.

MBTB::predwrongSource() increments btbStats.s3PredwrongMbtb, and the stat is declared via ADD_STAT in BTBStats. This matches the pattern used by other predictors and looks fine.

Also applies to: 924-972

src/cpu/pred/btb/btb_ittage.cc (1)

75-156: ITTAGE predwrongSource and stats extension look correct.

  • Changing lookupHelper to take std::vector<BTBEntry>& is consistent with the header and doesn’t alter behavior (no mutation of btbEntries here).
  • BTBITTAGE::predwrongSource() correctly increments ittageStats.s3PredwrongIttage, and the stat is registered in IttageStats.

No issues from a correctness standpoint.

Also applies to: 561-564, 625-651

src/cpu/pred/btb/btb_tage.cc (1)

307-334: TAGE wrong‑source plumbing and lookupHelper signature change are consistent.

  • lookupHelper now takes std::vector<BTBEntry>& and still only reads entries; matches the updated declaration and is safe.
  • BTBTAGE::predwrongSource() increments tageStats.s3PredwrongTage, and the stat is added via ADD_STAT alongside existing prediction stats.

This integrates cleanly with the new wrong‑source accounting.

Also applies to: 1009-1045, 1125-1128

Comment thread src/cpu/pred/btb/decoupled_bpred.cc
@github-actions

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.53 +0.21 🟢

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

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.57 17.57 0.00

@XiangShanRobot

Copy link
Copy Markdown

[Generated by GEM5 Performance Robot]
commit: 496d40e
workflow: On-Demand SPEC Test (Tier 1.5)

Ideal BTB Performance

Overall Score

PR Master Diff(%)
Score 20.04 20.07 -0.11 🔴

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

711-715: Naming inconsistency: branchClassCountsTotal only increments on mispredictions.

The statistic is described as "total number of classified branches" but is only incremented when mispred is true. Either rename the statistic to reflect misprediction-only counting (e.g., branchClassMispredTotal) or move the increment outside the if (mispred) block to count all classified branches.

This issue was previously flagged in earlier review rounds but has not yet been addressed.

🧹 Nitpick comments (2)
src/cpu/pred/btb/abtb.cc (1)

216-233: Review the deduplication logic change.

The new deduplication approach invalidates matching entries before adding the UBTB entry, then removes all invalid entries after sorting. While this is more explicit than the previous approach, there's a potential issue:

If any entry in mixed_entries legitimately has valid=false before line 216, it will be incorrectly removed at lines 229-233. Please verify that all entries in mixed_entries at this point are guaranteed to have valid=true, or adjust the logic to only remove entries that were explicitly invalidated in this function.

Consider a more robust approach
 for (auto &entry : mixed_entries) {
     if (entry.pc == ubtb_pred_entry.pc) {
         entry.valid = false; // invalidate duplicated entry from aBTB
         break;
     }
 }
 mixed_entries.push_back(TickedBTBEntry(ubtb_pred_entry, curTick()));
 // Deduplicate entries by pc (order can change)
 std::sort(mixed_entries.begin(), mixed_entries.end(),
       [](const TickedBTBEntry& a, const TickedBTBEntry& b) {
           return a.pc < b.pc;
       });
-// Drop entries invalidated during deduplication above
-mixed_entries.erase(std::remove_if(mixed_entries.begin(), mixed_entries.end(),
-      [](const TickedBTBEntry& entry) {
-          return !entry.valid;
-      }),
-      mixed_entries.end());
+// Drop only the entry we explicitly invalidated above (if present)
+auto it = std::find_if(mixed_entries.begin(), mixed_entries.end(),
+      [&ubtb_pred_entry](const TickedBTBEntry& entry) {
+          return !entry.valid && entry.pc == ubtb_pred_entry.pc;
+      });
+if (it != mixed_entries.end()) {
+    mixed_entries.erase(it);
+}

Alternatively, track which entry was invalidated explicitly rather than relying on the valid flag.

src/cpu/pred/btb/btb_tage.cc (1)

308-334: Consider reverting to const reference if entries aren't modified.

The signature changed to accept a non-const reference std::vector<BTBEntry> &btbEntries, but the function body only reads from the vector—it never modifies any entries. This is inconsistent with the related BTBMGSC::lookupHelper (lines 349-369 in btb_mgsc.cc) which still uses a const reference for the same pattern.

If source-tracking fields are intended to be set in-place in the future, consider adding that logic now or documenting the intent. Otherwise, revert to const std::vector<BTBEntry> &btbEntries to accurately reflect the function's behavior and maintain consistency with similar components.

🔎 Proposed fix to restore const correctness
 void
-BTBTAGE::lookupHelper(const Addr &startPC, std::vector<BTBEntry> &btbEntries,
+BTBTAGE::lookupHelper(const Addr &startPC, const std::vector<BTBEntry> &btbEntries,
                       std::unordered_map<Addr, TageInfoForMGSC> &tageInfoForMgscs, CondTakens& results)
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 496d40e and 901bc82.

📒 Files selected for processing (10)
  • src/cpu/pred/btb/abtb.cc
  • src/cpu/pred/btb/btb_ittage.cc
  • src/cpu/pred/btb/btb_ittage.hh
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_tage.hh
  • src/cpu/pred/btb/btb_ubtb.cc
  • src/cpu/pred/btb/decoupled_bpred.hh
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
  • src/cpu/pred/btb/mbtb.cc
  • src/cpu/pred/btb/mbtb.hh
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/cpu/pred/btb/btb_ittage.hh
  • src/cpu/pred/btb/btb_ubtb.cc
🧰 Additional context used
🧬 Code graph analysis (4)
src/cpu/pred/btb/btb_ittage.cc (2)
src/cpu/pred/btb/btb_tage.cc (2)
  • lookupHelper (307-334)
  • lookupHelper (308-309)
src/cpu/pred/ftb/ftb_tage.cc (2)
  • lookupHelper (141-199)
  • lookupHelper (142-146)
src/cpu/pred/btb/decoupled_bpred_stats.cc (4)
src/cpu/pred/btb/decoupled_bpred.hh (4)
  • entry (192-192)
  • entry (194-194)
  • entry (922-922)
  • entry (933-938)
src/cpu/pred/btb/btb_tage.hh (5)
  • entry (88-90)
  • entry (153-153)
  • entry (154-154)
  • entry (155-155)
  • entry (427-430)
src/cpu/pred/btb/timed_base_pred.hh (7)
  • entry (75-75)
  • entry (75-75)
  • entry (79-79)
  • entry (79-79)
  • entry (80-80)
  • entry (80-80)
  • entry (83-83)
src/cpu/pred/btb/test/abtb.test.cc (1)
  • abtb (59-67)
src/cpu/pred/btb/btb_tage.cc (2)
src/cpu/pred/btb/btb_mgsc.cc (2)
  • lookupHelper (350-370)
  • lookupHelper (351-352)
src/cpu/pred/btb/btb_tage.hh (2)
  • startPC (171-172)
  • startPC (433-440)
src/cpu/pred/btb/abtb.cc (1)
src/cpu/pred/btb/abtb.hh (4)
  • TickedBTBEntry (108-109)
  • TickedBTBEntry (110-110)
  • a (338-341)
  • a (338-338)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)
🔇 Additional comments (16)
src/cpu/pred/btb/btb_tage.hh (3)

104-110: LGTM: Default constructor addition.

The addition of a default constructor for TagePrediction follows standard C++ practices and enables default initialization without altering existing behavior.


377-378: LGTM: New statistic for source-based misprediction tracking.

The addition of s3PredwrongTage aligns with the broader feature to track mispredictions by predictor source, enabling more granular performance analysis.


171-172: The const qualifier should remain on the btbEntries parameter.

The lookupHelper method only reads from btbEntries (accessing fields like isCond, valid, pc, and alwaysTaken) without modifying the vector itself. The removal of the const qualifier is unnecessary and creates an inconsistency with the related BTBMGSC::lookupHelper method, which correctly maintains const on its btbEntries parameter for the same read-only pattern. Restore the const qualifier to accurately reflect the method's intent.

Likely an incorrect or invalid review comment.

src/cpu/pred/btb/abtb.cc (3)

605-605: LGTM: Source tracking implementation.

Setting entry.source to mark the predictor component origin enables the new source-based misprediction attribution feature.


681-681: LGTM: Consistent source tracking.

Marking the entry source in the update path maintains consistency with the source attribution feature.


714-811: LGTM: Comprehensive commit-time statistics tracking.

The new commitBranch method implements detailed per-branch-type statistics collection at commit time, tracking hits, misses, and prediction correctness. The logic correctly handles different branch types (conditional, unconditional, indirect, calls, returns) and filters out non-speculative branches appropriately.

src/cpu/pred/btb/decoupled_bpred.hh (4)

12-12: LGTM: Explicit statistics header inclusion.

Adding the explicit include for base/statistics.hh follows best practices and makes the dependency clear, even if it was previously available transitively.


320-320: LGTM: Total counter for branch classifications.

Adding branchClassCountsTotal provides a convenient aggregate metric for the per-class branchClassCounts vector, facilitating percentage calculations and overall analysis.


373-379: LGTM: Per-source misprediction statistics.

The new statistics fields enable fine-grained tracking of which predictor components are responsible for mispredictions at different stages (s1 and s3). This supports detailed performance analysis and helps identify which components need improvement.


921-922: LGTM: New method for source-based misprediction tracking.

The declaration of commitPredWrongSource completes the public API for the source-tracking feature, enabling commit-time analysis of which predictor sources contributed to mispredictions.

src/cpu/pred/btb/btb_ittage.cc (1)

76-76: The mutable reference for btbEntries matches the btb_tage.hh pattern but the implementation only reads from the vector.

The lookupHelper implementation iterates through btbEntries and reads fields like pc, alwaysTaken, valid, and target, but does not modify the entries or vector. Modifications occur only to the output parameters (results and meta->preds). The mutable reference is consistent with btb_tage.hh but is not actually utilized for in-place modifications in the current code. Callers passing stage_pred.btbEntries can safely provide mutable vectors.

src/cpu/pred/btb/btb_tage.cc (1)

1123-1160: LGTM!

The new commitBranch implementation correctly:

  • Filters for conditional branches (TAGE's domain)
  • Retrieves prediction metadata and compares with actual outcomes
  • Updates fine-grained statistics for prediction hits/misses and correctness

The logic is clear and aligns with the component's responsibilities.

src/cpu/pred/btb/mbtb.cc (1)

816-917: LGTM!

The new commitBranch implementation provides comprehensive branch tracking:

  • Correctly identifies BTB hits/misses by PC lookup
  • Tracks fine-grained statistics for conditional, unconditional, indirect, call, and return branches
  • Properly validates indirect target predictions
  • Appropriately filters non-speculative branches (e.g., syscalls) from indirect/call/return statistics

The implementation is thorough and aligns well with MBTB's responsibilities as the main BTB component.

src/cpu/pred/btb/decoupled_bpred_stats.cc (3)

6-7: LGTM!

The added includes for base/stats/group.hh and base/stats/units.hh are appropriate for the new statistics declarations introduced in this file.


874-879: LGTM!

The integration of commitPredWrongSource into the misprediction path is clean and appropriately placed after propagating the commit to individual predictor components.


503-511: LGTM!

The new statistics declarations provide clear attribution of mispredictions to specific predictor components (S1: UBTB/ABTB/fallthrough; S3: MBTB/TAGE/ITTAGE/RAS). The naming is consistent and descriptive, enabling detailed analysis of which components contribute to misprediction blame.

Comment thread src/cpu/pred/btb/decoupled_bpred_stats.cc
@github-actions

github-actions Bot commented Jan 5, 2026

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.53 +0.21 🟢

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

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.57 17.57 0.00

jensen-yan
jensen-yan previously approved these changes Jan 5, 2026
Change-Id: Ic8a5757f4f87dbaf448df998fcd714e46f80d9a8

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Fix all issues with AI Agents 🤖
In @src/cpu/pred/btb/abtb.cc:
- Around line 216-221: The loop that checks mixed_entries against
ubtb_pred_entry.pc only invalidates the first matching entry due to the break;
update the logic in the loop that iterates over mixed_entries (the block
referencing mixed_entries, entry.pc, ubtb_pred_entry.pc and entry.valid) so that
all entries with entry.pc == ubtb_pred_entry.pc are marked invalid (remove the
break or replace it with a continue) to ensure no duplicate PCs from the aBTB
remain in the final prediction while preserving the "only use for align counter"
intent.
♻️ Duplicate comments (4)
src/cpu/pred/btb/decoupled_bpred.cc (2)

246-253: Remove redundant always-true condition and add validity check.

Line 248 contains entry.ctr >= 0 which is always true since ctr is initialized to 0 in BTBEntry and remains non-negative. Additionally, the code should verify entry.valid before using the entry's source.

🔎 Proposed fix
     if (predsOfEachStage[0].btbEntries.size() != 0) {
-        for (auto entry : predsOfEachStage[0].btbEntries){
-            if (entry.isIndirect || entry.isDirect || entry.ctr >= 0 ||entry.alwaysTaken){
+        for (const auto &entry : predsOfEachStage[0].btbEntries) {
+            if (entry.valid && (entry.isIndirect || entry.isDirect)) {
                 finalPred.s1Source = entry.source;
                 break;
             }
         }
     }

255-286: Guard hardcoded stage index and remove always-true condition.

Line 258 uses a hardcoded stage index [2] without verifying that numStages > 2. This will cause out-of-bounds access if the pipeline is configured with fewer stages. Line 259 also contains the redundant entry.ctr >= 0 condition.

🔎 Proposed fix
     bool found_s3_taken = false;
     bool na_s3_taken_but_have_cond = false;
 
-    for (BTBEntry entry : predsOfEachStage[2].btbEntries) {
-        if (entry.isDirect || entry.isIndirect || entry.ctr >= 0 || entry.alwaysTaken) {
-            found_s3_taken = true;
-        }else if (entry.isCond){
-            //only use when there's no taken prediction in s3
-            na_s3_taken_but_have_cond = true;
+    // Use the final stage for S3 source determination
+    const int s3Stage = numStages - 1;
+    if (s3Stage >= 0 && s3Stage < predsOfEachStage.size()) {
+        for (const BTBEntry &entry : predsOfEachStage[s3Stage].btbEntries) {
+            if (entry.valid && (entry.isDirect || entry.isIndirect || entry.alwaysTaken)) {
+                found_s3_taken = true;
+            } else if (entry.isCond) {
+                // Only use when there's no taken prediction in s3
+                na_s3_taken_but_have_cond = true;
+            }
         }
     }
src/cpu/pred/btb/decoupled_bpred_stats.cc (2)

711-715: Move counter increment outside misprediction check to match statistic description.

Line 714 increments branchClassCountsTotal only when mispred is true, but the statistic is described as "total number of classified branches" (line 459). This creates a discrepancy where the counter only tracks mispredicted branches, not all classified branches.

🔎 Proposed fix
     dbpBtbStats.branchClassCounts[idx]++;
+    dbpBtbStats.branchClassCountsTotal++;
     if (mispred) {
         dbpBtbStats.branchClassMisses[idx]++;
-        dbpBtbStats.branchClassCountsTotal++;
     }

899-906: Replace assertion with bounds check for component array access.

Line 899 uses assert(s1PredSource < mbtbid) which:

  1. Only validates against mbtbid, not the actual array size components.size()
  2. Is removed in release builds, leaving the code unprotected

Add a proper bounds check before accessing components[s1PredSource]:

🔎 Proposed fix
     int s1PredSource = entry.s1Source;
     int s3PredSource = entry.s3Source;
 
     auto exeBranchInfo = entry.exeBranchInfo;
 
     bool onlyDirectionWrong = entry.exeTaken != entry.predTaken;
 
-    assert(s1PredSource < mbtbid);
-    if (s1PredSource == ubtbid) {
+    if (s1PredSource >= 0 && s1PredSource < components.size()) {
+        if (s1PredSource == ubtbid) {
         dbpBtbStats.s1PredWrongUbtb++;
-    } else if (s1PredSource == abtbid) {
+        } else if (s1PredSource == abtbid) {
         dbpBtbStats.s1PredWrongAbtb++;
-    }else {
+        } else {
+            dbpBtbStats.s1PredWrongFallthrough++;
+        }
+    } else {
         dbpBtbStats.s1PredWrongFallthrough++;
     }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 901bc82 and aace287.

📒 Files selected for processing (5)
  • src/cpu/pred/btb/abtb.cc
  • src/cpu/pred/btb/btb_ittage.cc
  • src/cpu/pred/btb/btb_ittage.hh
  • src/cpu/pred/btb/decoupled_bpred.cc
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/cpu/pred/btb/btb_ittage.hh
🧰 Additional context used
🧬 Code graph analysis (4)
src/cpu/pred/btb/decoupled_bpred.cc (2)
src/cpu/pred/btb/btb_tage.hh (5)
  • entry (88-90)
  • entry (153-153)
  • entry (154-154)
  • entry (155-155)
  • entry (427-430)
src/cpu/pred/btb/stream_struct.hh (1)
  • entry (514-536)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)
src/cpu/pred/btb/decoupled_bpred.hh (4)
  • entry (192-192)
  • entry (194-194)
  • entry (922-922)
  • entry (933-938)
src/cpu/pred/btb/abtb.cc (2)
src/cpu/pred/btb/stream_struct.hh (1)
  • entry (514-536)
src/cpu/pred/btb/abtb.hh (4)
  • TickedBTBEntry (108-109)
  • TickedBTBEntry (110-110)
  • a (338-341)
  • a (338-338)
src/cpu/pred/btb/btb_ittage.cc (2)
src/cpu/pred/btb/btb_tage.cc (4)
  • lookupHelper (307-334)
  • lookupHelper (308-309)
  • getPredictionMeta (382-385)
  • getPredictionMeta (383-383)
src/cpu/pred/btb/abtb.cc (2)
  • getPredictionMeta (315-324)
  • getPredictionMeta (316-316)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)
🔇 Additional comments (5)
src/cpu/pred/btb/abtb.cc (1)

605-605: LGTM! Entry source tagging implemented correctly.

The addition of entry.source = getComponentIdx() in both updateUsingS3Pred and update properly tags entries with their originating component (AheadBTB), enabling the new source-based misprediction attribution functionality.

Also applies to: 681-681

src/cpu/pred/btb/decoupled_bpred.cc (1)

1055-1056: LGTM! Source propagation to fetch stream implemented correctly.

The s1Source and s3Source values are correctly propagated from the final prediction into the fetch stream entry, enabling downstream stages to track prediction sources.

src/cpu/pred/btb/btb_ittage.cc (2)

498-511: LGTM! tageHit() correctly reports ITTAGE hit status.

The method properly checks if any prediction has a main provider hit (mainInfo.found), which is used by decoupled_bpred.cc to determine if ITTAGE contributed to the S3 prediction. The implementation correctly iterates through all predictions in the metadata.


76-76: Revert parameter to const or correct the justification.

The parameter std::vector<BTBEntry> &btbEntries is non-const, but lookupHelper does not actually modify the vector or its elements—it only reads BTB entries to generate predictions stored in meta->preds and results. The review comment claims this enables in-place modification with "source-tagging functionality where entries are updated with their predictor source," but no such modifications exist in the code. Either the parameter should be const for correct const-correctness, or if modifications are planned, they must be implemented.

Likely an incorrect or invalid review comment.

src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

908-948: [Your rewritten review comment text here]
[Exactly ONE classification tag]

Comment thread src/cpu/pred/btb/abtb.cc
@github-actions

github-actions Bot commented Jan 5, 2026

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

Change-Id: If8e15a0d38292a384106d88d8495b06cb6ea1589

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cpu/pred/btb/mbtb.cc (1)

960-964: Add back the missing ADD_STAT for predHitCount.

The ADD_STAT registration for predHitCount was removed, but the metric is still actively being sampled at line 222 (btbStats.predHitCount.sample(hitNum)) and initialized at line 963. This breaks the statistic registration. Restore the ADD_STAT call to ensure the metric is properly registered and reported.

♻️ Duplicate comments (2)
src/cpu/pred/btb/decoupled_bpred_stats.cc (2)

709-713: Naming inconsistency: branchClassCountsTotal only counts mispredictions.

The statistic branchClassCountsTotal is described as "total number of classified branches" but is only incremented when mispred is true (line 712). This contradicts its name and description.

Recommended fix: Move the increment outside the if (mispred) block to count all classified branches, not just mispredictions.

🔎 Proposed fix
     dbpBtbStats.branchClassCounts[idx]++;
+    dbpBtbStats.branchClassCountsTotal++;
     if (mispred) {
         dbpBtbStats.branchClassMisses[idx]++;
-        dbpBtbStats.branchClassCountsTotal++;
     }

890-904: Add bounds checking for s1Source before classification.

The code checks s1PredSource < mbtbid via assertion (line 897), but assertions are disabled in release builds. The actual valid range should be checked against components.size(). While the current logic doesn't directly index components[s1PredSource], it's important to validate the source value to ensure correct statistics classification.

Recommended fix: Add explicit bounds validation.

🔎 Proposed fix
     int s1PredSource = entry.s1Source;
     int s3PredSource = entry.s3Source;
 
     auto exeBranchInfo = entry.exeBranchInfo;
 
     bool onlyDirectionWrong = entry.exeTaken != entry.predTaken;
 
-    assert(s1PredSource < mbtbid);
-    if (s1PredSource == ubtbid) {
+    // Validate S1 source is within expected range
+    if (s1PredSource < 0 || s1PredSource >= mbtbid) {
+        dbpBtbStats.s1PredWrongFallthrough++;
+    } else if (s1PredSource == ubtbid) {
         dbpBtbStats.s1PredWrongUbtb++;
     } else if (s1PredSource == abtbid) {
         dbpBtbStats.s1PredWrongAbtb++;
-    }else {
+    } else {
         dbpBtbStats.s1PredWrongFallthrough++;
     }
🧹 Nitpick comments (2)
src/cpu/pred/btb/decoupled_bpred_stats.cc (2)

872-877: Consider improving the comment clarity.

The comment //here add final counter at line 872 could be more descriptive. Consider something like:

// Track wrong-source attribution for mispredictions

This makes the purpose clearer for future maintainers.


906-947: Add bounds checking for s3Source classification.

The s3 source classification logic compares s3PredSource against various component indices (rasid, ittageid, tageid, mbtbid) but doesn't validate that these indices are within the bounds of the components array. While the current code doesn't directly index into components, future modifications or incorrect component index assignments could lead to misclassification.

Recommended enhancement: Add validation to ensure all component indices are valid before performing comparisons.

🔎 Proposed validation
+    // Validate component indices are within bounds
+    assert(ubtbid >= 0 && ubtbid < components.size());
+    assert(abtbid >= 0 && abtbid < components.size());
+    assert(mbtbid >= 0 && mbtbid < components.size());
+    assert(tageid >= 0 && tageid < components.size());
+    assert(ittageid >= 0 && ittageid < components.size());
+    assert(rasid >= 0 && rasid < components.size());
+
     if (s3PredSource == rasid) {
         if (exeBranchInfo.isCond) {
             dbpBtbStats.s3PredWrongTage++;
         } else if (exeBranchInfo.isReturn) {
             dbpBtbStats.s3PredWrongRas++;
         } else {
             dbpBtbStats.s3PredWrongMbtb++;
         }
     } // ... rest of logic
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aace287 and d8ce37b.

📒 Files selected for processing (7)
  • src/cpu/pred/btb/btb_ittage.cc
  • src/cpu/pred/btb/btb_ittage.hh
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_tage.hh
  • src/cpu/pred/btb/decoupled_bpred.hh
  • src/cpu/pred/btb/decoupled_bpred_stats.cc
  • src/cpu/pred/btb/mbtb.cc
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/cpu/pred/btb/btb_tage.cc
  • src/cpu/pred/btb/btb_ittage.cc
🧰 Additional context used
🧬 Code graph analysis (2)
src/cpu/pred/btb/decoupled_bpred_stats.cc (1)
src/cpu/pred/btb/decoupled_bpred.hh (5)
  • dbpBtbStats (906-908)
  • entry (191-191)
  • entry (193-193)
  • entry (921-921)
  • entry (932-937)
src/cpu/pred/btb/decoupled_bpred.hh (5)
src/cpu/pred/btb/btb_mgsc.hh (1)
  • entry (160-160)
src/cpu/pred/btb/mbtb.hh (1)
  • entry (284-284)
src/cpu/pred/btb/timed_base_pred.hh (8)
  • entry (75-75)
  • entry (75-75)
  • entry (79-79)
  • entry (79-79)
  • entry (80-80)
  • entry (80-80)
  • entry (83-83)
  • entry (83-83)
src/cpu/pred/btb/stream_struct.hh (1)
  • entry (514-536)
src/cpu/pred/btb/test/decoupled_bpred.hh (2)
  • entry (140-140)
  • entry (142-142)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Quick Build, Unit Tests & Smoke Test
  • GitHub Check: perf_test / XS-GEM5 - Run performance test (spec06-0.3c)
🔇 Additional comments (7)
src/cpu/pred/btb/btb_tage.hh (2)

104-111: LGTM! Constructor changes look good.

The default constructor properly initializes all member fields, and the brace formatting change on the parameterized constructor is cosmetic with no functional impact.


377-377: Appropriate addition for wrong-source tracking.

The new s3PredwrongTage statistic aligns with the PR's implementation of predwrongSource method and follows the existing naming convention.

src/cpu/pred/btb/btb_ittage.hh (1)

272-272: New public method declaration looks appropriate.

The tageHit() method declaration is straightforward and likely provides a way to query TAGE hit status for testing or statistics purposes.

src/cpu/pred/btb/decoupled_bpred.hh (2)

319-319: Statistics additions align with PR objectives.

The new statistics enable granular tracking of wrong-source predictions across different prediction stages (S1 and S3) and components (UBTB, ABTB, MBTB, TAGE, ITTAGE, RAS), which aligns with the PR's goal of implementing the predwrongSource method.

Also applies to: 372-378


920-922: Method declaration matches PR objectives.

The commitPredWrongSource method declaration is appropriate and directly addresses the PR title "Implement predwrongSource method." The const reference parameter is correct for read-only access to the FetchStream.

src/cpu/pred/btb/mbtb.cc (1)

813-915: Comprehensive commitBranch implementation.

The new commitBranch method provides detailed tracking of branch prediction outcomes across multiple dimensions (conditional/unconditional, direct/indirect, calls/returns), and the statistics updates are appropriate for each branch type.

src/cpu/pred/btb/decoupled_bpred_stats.cc (1)

444-526: Statistics registration looks appropriate.

The new statistics are properly registered with clear descriptions that align with the wrong-source tracking feature. The naming convention is consistent with existing statistics.

@github-actions

github-actions Bot commented Jan 5, 2026

Copy link
Copy Markdown

🚀 Coremark Smoke Test Results

Branch IPC Change
Base (xs-dev) 2.1772 -
This PR 2.1832 📈 +0.0060 (+0.27%)

✅ Difftest smoke test passed!

@XiangShanRobot

Copy link
Copy Markdown

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

Align BTB Performance

Overall Score

PR Master Diff(%)
Score 17.57 17.48 +0.49 🟢

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

Align BTB Performance

Overall Score

PR Previous Commit Diff(%)
Score 17.57 17.57 0.00

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants