-
Notifications
You must be signed in to change notification settings - Fork 68
cpu-o3: add 2Fetch features #700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: xs-dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #include "cpu/pred/btb/decoupled_bpred.hh" | ||
|
|
||
| #include <algorithm> | ||
| #include <array> | ||
|
|
||
| #include "base/debug_helper.hh" | ||
|
|
@@ -27,6 +28,7 @@ DecoupledBPUWithBTB::DecoupledBPUWithBTB(const DecoupledBPUWithBTBParams &p) | |
| enableLoopBuffer(p.enableLoopBuffer), | ||
| enableLoopPredictor(p.enableLoopPredictor), | ||
| enableJumpAheadPredictor(p.enableJumpAheadPredictor), | ||
| enable2Taken(p.enable2Taken), | ||
| fetchTargetQueue(p.ftq_size), | ||
| fetchStreamQueueSize(p.fsq_size), | ||
| predictWidth(p.predictWidth), | ||
|
|
@@ -45,7 +47,9 @@ DecoupledBPUWithBTB::DecoupledBPUWithBTB(const DecoupledBPUWithBTBParams &p) | |
| numStages(p.numStages), | ||
| historyManager(16), // TODO: fix this | ||
| resolveBlockThreshold(p.resolveBlockThreshold), | ||
| dbpBtbStats(this, p.numStages, p.fsq_size, maxInstsNum) | ||
| dbpBtbStats(this, p.numStages, p.fsq_size, maxInstsNum), | ||
| enable2Fetch(p.enable2Fetch), | ||
| maxFetchBytesPerCycle(p.maxFetchBytesPerCycle) | ||
| { | ||
| if (bpDBSwitches.size() > 0) { | ||
| initDB(); | ||
|
|
@@ -160,7 +164,7 @@ DecoupledBPUWithBTB::tick() | |
| // Clear each predictor's output | ||
| for (int i = 0; i < numStages; i++) { | ||
| predsOfEachStage[i].btbEntries.clear(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (bpuState == BpuState::PREDICTION_OUTSTANDING && numOverrideBubbles > 0) { | ||
|
|
@@ -436,7 +440,20 @@ DecoupledBPUWithBTB::decoupledPredict(const StaticInstPtr &inst, | |
| // Increment instruction counter for current FTQ entry | ||
| currentFtqEntryInstNum++; | ||
| if (run_out_of_this_entry) { | ||
| // Check if 2fetch is enabled, not fetched first FTQ yet, and if we can extend to the next FTQ | ||
| // NEW: 2Fetch extension check - before processing completion | ||
| dbpBtbStats.fetch2Attempts++; | ||
| if (enable2Fetch && !has1Fetched && canExtendToNextFTQ(pc, target_to_fetch)) { | ||
| DPRINTF(DecoupleBP, "2Fetch: extending to next FTQ in same cycle\n"); | ||
| has1Fetched = true; | ||
| processFetchTargetCompletion(target_to_fetch); | ||
| extendToNextFTQ(pc); | ||
| // first fetchBlock is always taken, do not run out of FTQ now | ||
| return std::make_pair(true, false); | ||
| } | ||
|
|
||
| processFetchTargetCompletion(target_to_fetch); | ||
| has1Fetched = false; // reset 2fetch flag | ||
| } | ||
|
|
||
| DPRINTF(DecoupleBP, "Predict it %staken to %#lx\n", taken ? "" : "not ", | ||
|
|
@@ -1372,6 +1389,93 @@ DecoupledBPUWithBTB::recoverHistoryForSquash( | |
| } | ||
|
|
||
|
|
||
| // NEW: 2Fetch support methods implementation | ||
|
|
||
| /** | ||
| * @brief Check if we can extend to next FTQ entry for 2fetch | ||
| * | ||
| * @param current_pc Current program counter | ||
| * @param current_ftq Current FTQ entry that is being completed | ||
| * @return true if 2fetch extension is possible | ||
| */ | ||
| bool | ||
| DecoupledBPUWithBTB::canExtendToNextFTQ(const PCStateBase ¤t_pc, const FtqEntry ¤t_ftq) | ||
| { | ||
| // Early exit if 2fetch is disabled | ||
| if (!enable2Fetch) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!current_ftq.taken) { | ||
| DPRINTF(DecoupleBP, "2Fetch rejected: current FTQ is not taken\n"); | ||
| dbpBtbStats.fetch2FirstNotTaken++; | ||
| return false; | ||
| } | ||
|
|
||
| // Check if next FTQ entry is available | ||
| if (!fetchTargetQueue.hasNext()) { | ||
| DPRINTF(DecoupleBP, "2Fetch rejected: no next FTQ entry available\n"); | ||
| dbpBtbStats.fetch2NoNextFTQ++; | ||
| return false; | ||
| } | ||
|
|
||
| // Get next FTQ entry (without consuming it) | ||
| const auto &next_ftq = fetchTargetQueue.peekNext(); | ||
| // current_ftq is passed as parameter | ||
|
|
||
| // Check if current PC is the jump target of the next FTQ start | ||
| if (current_pc.instAddr() != next_ftq.startPC) { | ||
| DPRINTF(DecoupleBP, "2Fetch rejected: PC %#x not at next FTQ start %#x\n", | ||
| current_pc.instAddr(), next_ftq.startPC); | ||
| dbpBtbStats.fetch2FirstNotAtStart++; | ||
| return false; | ||
| } | ||
|
|
||
| // Check if both FTQs fit in maxFetchBytesPerCycle window | ||
| Addr span = next_ftq.endPC - current_ftq.startPC; | ||
| if (span > maxFetchBytesPerCycle) { | ||
| DPRINTF(DecoupleBP, "2Fetch rejected: span %d exceeds %d bytes\n", | ||
| span, maxFetchBytesPerCycle); | ||
| dbpBtbStats.fetch2SpanTooLarge++; | ||
|
Comment on lines
+1435
to
+1439
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The 2fetch gate only checks Useful? React with 👍 / 👎. |
||
| return false; | ||
| } | ||
|
|
||
| DPRINTF(DecoupleBP, "2Fetch enabled: extending to next FTQ [%#x, %#x), total span: %d bytes\n", | ||
| next_ftq.startPC, next_ftq.endPC, span); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Extend to process next FTQ entry for 2fetch | ||
| * | ||
| * @param pc Program counter reference to update | ||
| * @param seqNum Sequence number | ||
| * @param tid Thread ID | ||
| * @param currentLoopIter Current loop iteration | ||
| */ | ||
| void | ||
| DecoupledBPUWithBTB::extendToNextFTQ(PCStateBase &pc) | ||
| { | ||
| // Move to next FTQ entry | ||
| fetchTargetQueue.advance(); | ||
| currentFtqEntryInstNum = 0; // Reset instruction counter for new FTQ | ||
|
|
||
| // Get the new FTQ entry | ||
| const auto &target_to_fetch = fetchTargetQueue.getTarget(); | ||
|
|
||
| DPRINTF(DecoupleBP, "Processing extended FTQ entry: [%#x, %#x)\n", | ||
| target_to_fetch.startPC, target_to_fetch.endPC); | ||
|
|
||
| // Set PC to start of new FTQ | ||
| auto &rpc = pc.as<GenericISA::PCStateWithNext>(); | ||
| rpc.pc(target_to_fetch.startPC); | ||
| rpc.npc(target_to_fetch.startPC + 4); | ||
| rpc.uReset(); | ||
|
|
||
| // Record successful 2fetch | ||
| dbpBtbStats.fetch2Successes++; | ||
| } | ||
|
|
||
| } // namespace btb_pred | ||
|
|
||
| } // namespace branch_prediction | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fetch2Attemptsis incremented even when 2Fetch is disabled or already used.The counter
fetch2Attemptsis incremented unconditionally at line 445, before checkingenable2Fetchand!has1Fetched. This means:enable2Fetchis falsehas1Fetched=true) also counts as an attemptConsider moving the increment inside the condition, or after the early-exit checks in
canExtendToNextFTQ.🐛 Suggested fix
if (run_out_of_this_entry) { // Check if 2fetch is enabled, not fetched first FTQ yet, and if we can extend to the next FTQ // NEW: 2Fetch extension check - before processing completion - dbpBtbStats.fetch2Attempts++; - if (enable2Fetch && !has1Fetched && canExtendToNextFTQ(pc, target_to_fetch)) { + if (enable2Fetch && !has1Fetched) { + dbpBtbStats.fetch2Attempts++; + if (canExtendToNextFTQ(pc, target_to_fetch)) { DPRINTF(DecoupleBP, "2Fetch: extending to next FTQ in same cycle\n"); has1Fetched = true; processFetchTargetCompletion(target_to_fetch); extendToNextFTQ(pc); // first fetchBlock is always taken, do not run out of FTQ now return std::make_pair(true, false); + } } processFetchTargetCompletion(target_to_fetch);