Skip to content

Commit aace287

Browse files
author
Cao Jiaming
committed
cpu-o3: enhance source prediction alignment
Change-Id: Ic8a5757f4f87dbaf448df998fcd714e46f80d9a8
1 parent 901bc82 commit aace287

5 files changed

Lines changed: 33 additions & 15 deletions

File tree

src/cpu/pred/btb/abtb.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ AheadBTB::fillStagePredictions(const std::vector<TickedBTBEntry>& entries,
215215
mixed_entries = entries;
216216
for (auto &entry : mixed_entries) {
217217
if (entry.pc == ubtb_pred_entry.pc) {
218-
entry.valid = false; // invalidate duplicated entry from aBTB
218+
entry.valid = false; // invalidate duplicated entry from aBTB (only use for align counter)
219219
break;
220220
}
221221
}

src/cpu/pred/btb/btb_ittage.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,21 @@ BTBITTAGE::doUpdateHist(const boost::dynamic_bitset<> &history, bool taken, Addr
495495
}
496496
}
497497

498+
bool
499+
BTBITTAGE::tageHit()
500+
{
501+
auto meta = getPredictionMeta();
502+
auto preds = std::static_pointer_cast<TageMeta>(meta)->preds;
503+
bool hit = false;
504+
for (auto & [pc, pred] : preds) {
505+
if (pred.mainInfo.found) {
506+
hit = true;
507+
break;
508+
}
509+
}
510+
return hit;
511+
}
512+
498513
/**
499514
* @brief Updates branch history for speculative execution
500515
*

src/cpu/pred/btb/btb_ittage.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ class BTBITTAGE : public TimedBaseBTBPredictor
140140
// Update branch history
141141
void doUpdateHist(const bitset &history, bool taken, Addr pc, Addr target);
142142

143-
144143
const unsigned numPredictors;
145144

146145
std::vector<unsigned> tableSizes;
@@ -270,6 +269,7 @@ public:
270269
bool debugFlag = false;
271270

272271
void recoverFoldedHist(const bitset& history);
272+
bool tageHit();
273273

274274
// void checkFoldedHist(const bitset& history);
275275
};

src/cpu/pred/btb/decoupled_bpred.cc

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,34 +245,39 @@ DecoupledBPUWithBTB::generateFinalPredAndCreateBubbles()
245245

246246
if (predsOfEachStage[0].btbEntries.size() != 0) {
247247
for (auto entry : predsOfEachStage[0].btbEntries){
248-
if (entry.isIndirect || entry.isDirect || entry.ctr >=0 ||entry.alwaysTaken){
248+
if (entry.isIndirect || entry.isDirect || entry.ctr >= 0 ||entry.alwaysTaken){
249249
finalPred.s1Source = entry.source;
250250
break;
251251
}
252252
}
253253
}
254254

255-
if (predsOfEachStage[2].btbEntries.size() != 0) {
255+
bool found_s3_taken = false;
256+
bool na_s3_taken_but_have_cond = false;
257+
258+
for (BTBEntry entry : predsOfEachStage[2].btbEntries) {
259+
if (entry.isDirect || entry.isIndirect || entry.ctr >= 0 || entry.alwaysTaken) {
260+
found_s3_taken = true;
261+
}else if (entry.isCond){
262+
//only use when there's no taken prediction in s3
263+
na_s3_taken_but_have_cond = true;
264+
}
265+
}
266+
267+
if (found_s3_taken) {
256268
auto pred_taken_entry = finalPred.getTakenEntry();
257269
if (pred_taken_entry.valid) {
258270
if (pred_taken_entry.isReturn) {
259271
finalPred.s3Source = ras->getComponentIdx();
260-
} else if (pred_taken_entry.isIndirect) {
272+
} else if (pred_taken_entry.isIndirect && ittage->tageHit()) {
261273
finalPred.s3Source = ittage->getComponentIdx();
262274
}else if (pred_taken_entry.isCond) {
263275
finalPred.s3Source = tage->getComponentIdx();
264276
} else {
265277
finalPred.s3Source = mbtb->getComponentIdx();
266278
}
267279
}else {
268-
bool found = false;
269-
for (auto entry : predsOfEachStage[2].btbEntries) {
270-
if (entry.isCond){
271-
found = true;
272-
break;
273-
}
274-
}
275-
if (found) {
280+
if (na_s3_taken_but_have_cond) {
276281
finalPred.s3Source = tage->getComponentIdx();
277282
}else {
278283
finalPred.s3Source = -1;

src/cpu/pred/btb/decoupled_bpred_stats.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ DecoupledBPUWithBTB::commitPredWrongSource(const FetchStream &entry)
905905
dbpBtbStats.s1PredWrongFallthrough++;
906906
}
907907

908-
int s3blame = mbtbid;
909908
if (s3PredSource == rasid) {
910909
if (exeBranchInfo.isCond) {
911910
dbpBtbStats.s3PredWrongTage++;
@@ -947,7 +946,6 @@ DecoupledBPUWithBTB::commitPredWrongSource(const FetchStream &entry)
947946
}else if (s3PredSource == -1) {
948947
dbpBtbStats.s3PredWrongMbtb++;
949948
}
950-
//components[s3blame]->predwrongSource();
951949
}
952950
/**
953951
* @brief Handle instruction commits and phase-based statistics

0 commit comments

Comments
 (0)