Skip to content

Commit

Permalink
cpu-o3: branchPred: parameterize predictWidth/fetchBlockSize (#227)
Browse files Browse the repository at this point in the history
Change-Id: I94561ec64feebdcebb6d8837ff9f6f64d51b09bd
  • Loading branch information
jensen-yan authored Dec 14, 2024
1 parent 9e99f64 commit 38a5253
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/cpu/pred/BranchPredictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ class TimedBaseFTBPredictor(SimObject):
cxx_header = "cpu/pred/ftb/timed_base_pred.hh"

numBr = Param.Unsigned(Parent.numBr, "Number of maximum branches per entry")
predictWidth = Param.Unsigned(Parent.predictWidth, "The width of prediction/fetch block")
# subclass are encouraged to explicitly declare latency as numDelay
numDelay = Param.Unsigned(1000, "Number of bubbles to put on a prediction")

Expand Down Expand Up @@ -943,6 +944,7 @@ class DecoupledBPUWithFTB(BranchPredictor):
fsq_size = Param.Unsigned(64, "Fetch stream queue size")
maxHistLen = Param.Unsigned(970, "The length of history")
numBr = Param.Unsigned(2, "Number of maximum branches per entry")
predictWidth = Param.Unsigned(32, "The width of prediction/fetch block")
numStages = Param.Unsigned(3, "Number of stages in the pipeline")
ftb = Param.DefaultFTB(DefaultFTB(), "FTB")
tage = Param.FTBTAGE(FTBTAGE(), "TAGE predictor")
Expand Down
1 change: 1 addition & 0 deletions src/cpu/pred/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Source('stream/stream_common.cc')
Source('ftb/decoupled_bpred.cc')
Source('ftb/ftb.cc')
Source('ftb/stream_common.cc')
Source('ftb/stream_struct.cc')
Source('ftb/timed_base_pred.cc')
Source('ftb/fetch_target_queue.cc')
Source('ftb/ftb_tage.cc')
Expand Down
10 changes: 6 additions & 4 deletions src/cpu/pred/ftb/decoupled_bpred.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DecoupledBPUWithFTB::DecoupledBPUWithFTB(const DecoupledBPUWithFTBParams &p)
fetchTargetQueue(p.ftq_size),
fetchStreamQueueSize(p.fsq_size),
numBr(p.numBr),
predictWidth(p.predictWidth),
historyBits(p.maxHistLen),
uftb(p.uftb),
ftb(p.ftb),
Expand All @@ -43,6 +44,7 @@ DecoupledBPUWithFTB::DecoupledBPUWithFTB(const DecoupledBPUWithFTBParams &p)
historyManager(p.numBr),
dbpFtbStats(this, p.numStages, p.fsq_size)
{
gem5::branch_prediction::ftb_pred::predictWidth = p.predictWidth;
if (bpDBSwitches.size() > 0) {

bpdb.init_db();
Expand Down Expand Up @@ -2098,7 +2100,7 @@ DecoupledBPUWithFTB::tryEnqFetchTarget()
ftq_enq_state.pc, end);
}

assert(ftq_enq_state.pc <= end || (end < 0x20 && (ftq_enq_state.pc + 0x20 < 0x20)));
assert(ftq_enq_state.pc <= end || (end < predictWidth && (ftq_enq_state.pc + predictWidth < predictWidth)));

// create a new target entry
FtqEntry ftq_entry;
Expand All @@ -2114,7 +2116,7 @@ DecoupledBPUWithFTB::tryEnqFetchTarget()
bool jaHit = stream_to_enq.jaHit;
if (jaHit) {
int &currentSentBlock = stream_to_enq.currentSentBlock;
thisFtqEntryShouldEndPC = stream_to_enq.startPC + (currentSentBlock + 1) * 0x20;
thisFtqEntryShouldEndPC = stream_to_enq.startPC + (currentSentBlock + 1) * predictWidth;
currentSentBlock++;
}
}
Expand Down Expand Up @@ -2289,9 +2291,9 @@ DecoupledBPUWithFTB::makeNewPrediction(bool create_new_stream)
entry.isHit = false;
entry.falseHit = true;
entry.predTaken = false;
entry.predEndPC = entry.startPC + 32;
entry.predEndPC = entry.startPC + predictWidth;
entry.predFTBEntry = FTBEntry();
s0PC = entry.startPC + 32; // TODO: parameterize
s0PC = entry.startPC + predictWidth;
// TODO: when false hit, act like a miss, do not update history
}

Expand Down
2 changes: 2 additions & 0 deletions src/cpu/pred/ftb/decoupled_bpred.hh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ class DecoupledBPUWithFTB : public BPredUnit

unsigned numBr;

unsigned predictWidth;

unsigned cacheLineOffsetBits{6}; // TODO: parameterize this
unsigned cacheLineSize{64};

Expand Down
3 changes: 2 additions & 1 deletion src/cpu/pred/ftb/ftb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ DefaultFTB::DefaultFTB(const Params &p)
tagBits(p.tagBits),
instShiftAmt(p.instShiftAmt),
log2NumThreads(floorLog2(p.numThreads)),
predictWidth(p.predictWidth),
numBr(p.numBr),
numWays(p.numWays),
numSets(numEntries / numWays),
Expand Down Expand Up @@ -264,7 +265,7 @@ DefaultFTB::getAndSetNewFTBEntry(FetchStream &stream)
new_entry.fallThruAddr = branch_info.getEnd();
incNonL0Stat(ftbStats.newEntryWithUncond);
} else {
new_entry.fallThruAddr = startPC + 32;
new_entry.fallThruAddr = startPC + predictWidth;
incNonL0Stat(ftbStats.newEntryWithCond);
}
entry_to_write = new_entry;
Expand Down
2 changes: 2 additions & 0 deletions src/cpu/pred/ftb/ftb.hh
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ class DefaultFTB : public TimedBaseFTBPredictor
/** Log2 NumThreads used for hashing threadid */
unsigned log2NumThreads;

unsigned predictWidth;

unsigned numBr;

unsigned numWays;
Expand Down
17 changes: 17 additions & 0 deletions src/cpu/pred/ftb/stream_struct.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "cpu/pred/ftb/stream_struct.hh"

namespace gem5 {

namespace branch_prediction {

namespace ftb_pred {

unsigned predictWidth{0};
// global variable, set in decoupled_bpred.cc
// used in stream_struct.hh

}

}

}
12 changes: 7 additions & 5 deletions src/cpu/pred/ftb/stream_struct.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace branch_prediction {

namespace ftb_pred {

extern unsigned predictWidth;

enum EndType {
END_CALL=0,
END_RET,
Expand Down Expand Up @@ -189,7 +191,7 @@ typedef struct FTBEntry
// every
bool isReasonable(Addr start) {
Addr min = start;
Addr max = start+34;
Addr max = start + predictWidth + 2;
bool reasonable = true;
for (auto &slot : slots) {
if (slot.pc < min || slot.pc > max) {
Expand Down Expand Up @@ -375,8 +377,8 @@ struct FetchStream
if (jaHit && squashType == SQUASH_CTRL) {
Addr realStart = startPC;
Addr squashBranchPC = exeBranchInfo.pc;
while (realStart + 0x20 <= squashBranchPC) {
realStart += 0x20;
while (realStart + predictWidth <= squashBranchPC) {
realStart += predictWidth;
}
return realStart;
} else {
Expand Down Expand Up @@ -473,7 +475,7 @@ typedef struct FullFTBPrediction
}

} else {
target = bbStart + 32; //TODO: +predictWidth
target = bbStart + predictWidth;
}
return target;
}
Expand All @@ -493,7 +495,7 @@ typedef struct FullFTBPrediction
if (valid) {
return ftbEntry.fallThruAddr;
} else {
return bbStart + 32; //TODO: +predictWidth
return bbStart + predictWidth;
}
}

Expand Down

0 comments on commit 38a5253

Please sign in to comment.