Skip to content

Commit

Permalink
improve bpred stats and fix prints
Browse files Browse the repository at this point in the history
  • Loading branch information
renau committed Jan 11, 2025
1 parent 9be72f6 commit 1e6da1a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 432 deletions.
10 changes: 7 additions & 3 deletions emul/emul_dromajo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,19 @@ Dinst *Emul_dromajo::peek(Hartid_t fid) {
I(dst1 != RegType::LREG_INVALID);

uint64_t paddr = 0u;
uint64_t pc = last[fid].pc;
if (opcode == Opcode::iLALU_LD || opcode == Opcode::iSALU_ST) {
paddr = last[fid].addr;
} else if (opcode == Opcode::iBALU_LBRANCH || opcode == Opcode::iBALU_RBRANCH || opcode == Opcode::iBALU_LJUMP
|| opcode == Opcode::iBALU_RJUMP || opcode == Opcode::iBALU_LCALL || opcode == Opcode::iBALU_RCALL
} else if (opcode == Opcode::iBALU_LBRANCH || opcode == Opcode::iBALU_RBRANCH) {
paddr = last[fid].next_pc;
if ((paddr == pc+2) || paddr == pc+4) {
paddr = 0; // Not taken Control flow instruction
}
} else if (opcode == Opcode::iBALU_LJUMP || opcode == Opcode::iBALU_RJUMP || opcode == Opcode::iBALU_LCALL || opcode == Opcode::iBALU_RCALL
|| opcode == Opcode::iBALU_RET) {
paddr = last[fid].next_pc;
}

uint64_t pc = last[fid].pc;
if (detail > 0) {
--detail;
return Dinst::create(Instruction(opcode, src1, src2, dst1, dst2), pc, paddr, fid, false);
Expand Down
76 changes: 41 additions & 35 deletions simu/BPred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ Outcome BPBTB::predict(Dinst *dinst, bool doUpdate, bool doStats) {
key ^= dolc->getSign(btbHistorySize, btbHistorySize);
}


I(doUpdate);

// The branch is taken. Update the cache
Expand Down Expand Up @@ -1408,18 +1407,31 @@ BPredictor::BPredictor(int32_t i, MemObj *iobj, MemObj *dobj, std::shared_ptr<BP
, il1(iobj)
, dl1(dobj)
, nBTAC(fmt::format("P({})_BPred:nBTAC", id))
, nBranches(fmt::format("P({})_BPred:nBranches", id))

, nControl(fmt::format("P({})_BPred:nControl", id))
, nBranch(fmt::format("P({})_BPred:nBranch", id))
, nNoPredict(fmt::format("P({})_BPred:nNoPredict", id))
, nTaken(fmt::format("P({})_BPred:nTaken", id))
, nMiss(fmt::format("P({})_BPred:nMiss", id))
, nBranches2(fmt::format("P({})_BPred:nBranches2", id))
, nControlMiss(fmt::format("P({})_BPred:nControlMiss", id))
, nBranchMiss(fmt::format("P({})_BPred:nBranchMiss", id))
, nBranchBTBMiss(fmt::format("P({})_BPred:nBranchBTBMiss", id))

, nControl2(fmt::format("P({})_BPred:nControl2", id))
, nBranch2(fmt::format("P({})_BPred:nBranch2", id))
, nTaken2(fmt::format("P({})_BPred:nTaken2", id))
, nMiss2(fmt::format("P({})_BPred:nMiss2", id))
, nBranches3(fmt::format("P({})_BPred:nBranches3", id))
, nControlMiss2(fmt::format("P({})_BPred:nControlMiss2", id))
, nBranchMiss2(fmt::format("P({})_BPred:nBranchMiss2", id))
, nBranchBTBMiss2(fmt::format("P({})_BPred:nBranchBTBMiss2", id))

, nControl3(fmt::format("P({})_BPred:nControl3", id))
, nBranch3(fmt::format("P({})_BPred:nBranch3", id))
, nNoPredict3(fmt::format("P({})_BPred:nNoPredict3", id))
, nHit3_miss2(fmt::format("P({})_BPred:nHit3_miss2", id))
, nTaken3(fmt::format("P({})_BPred:nTaken3", id))
, nMiss3(fmt::format("P({})_BPred:nMiss3", id))
, nControlMiss3(fmt::format("P({})_BPred:nControlMiss3", id))
, nBranchMiss3(fmt::format("P({})_BPred:nBranchMiss3", id))
, nBranchBTBMiss3(fmt::format("P({})_BPred:nBranchBTBMiss3", id))

, nFixes1(fmt::format("P({})_BPred:nFixes1", id))
, nFixes2(fmt::format("P({})_BPred:nFixes2", id))
, nFixes3(fmt::format("P({})_BPred:nFixes3", id))
Expand Down Expand Up @@ -1514,12 +1526,18 @@ void BPredictor::fetchBoundaryEnd() {
Outcome BPredictor::predict1(Dinst *dinst) {
I(dinst->getInst()->isControl());

nBranches.inc(dinst->has_stats());
nControl.inc(dinst->has_stats());
nTaken.inc(dinst->isTaken() && dinst->has_stats());

Outcome p = pred1->doPredict(dinst);

nMiss.inc(p == Outcome::Miss && dinst->has_stats());
if (dinst->getInst()->isBranch()) {
nBranch.inc(dinst->has_stats());
nBranchMiss.inc(p == Outcome::Miss && dinst->has_stats());
nBranchBTBMiss.inc(p == Outcome::NoBTB && dinst->has_stats());
}
nControlMiss.inc((p == Outcome::Miss || p == Outcome::NoBTB) && dinst->has_stats());

nNoPredict.inc(p == Outcome::None && dinst->has_stats());

return p;
Expand All @@ -1528,49 +1546,37 @@ Outcome BPredictor::predict1(Dinst *dinst) {
Outcome BPredictor::predict2(Dinst *dinst) {
I(dinst->getInst()->isControl());

nBranches2.inc(dinst->has_stats());
nControl2.inc(dinst->has_stats());
nTaken2.inc(dinst->isTaken() && dinst->has_stats());
// No RAS in L2

Outcome p = pred2->doPredict(dinst);

// nMiss2.inc(p != Outcome::Correct && dinst->has_stats());
nMiss2.inc(p == Outcome::Miss && dinst->has_stats());
if (dinst->getInst()->isBranch()) {
nBranch2.inc(dinst->has_stats());
nBranchMiss2.inc(p == Outcome::Miss && dinst->has_stats());
nBranchBTBMiss2.inc(p == Outcome::NoBTB && dinst->has_stats());
}
nControlMiss2.inc((p == Outcome::Miss || p == Outcome::NoBTB) && dinst->has_stats());

return p;
}

Outcome BPredictor::predict3(Dinst *dinst) {
I(dinst->getInst()->isControl());

#if 0
if (dinst->isBiasBranch())
return Outcome::None;
#endif

#if 0
if(dinst->getDataSign() == DS_NoData)
return Outcome::None;
#endif

#if 0
if(!dinst->isBranchMiss_level2()) {
return Outcome::None;
}
#endif

nBranches3.inc(dinst->has_stats());
nControl3.inc(dinst->has_stats());
nTaken3.inc(dinst->isTaken() && dinst->has_stats());
// No RAS in L2

Outcome p = pred3->doPredict(dinst);
#if 0
if(p == Outcome::None)
return p;
#endif

// nMiss3.inc(p != Outcome::Correct && dinst->has_stats());
nMiss3.inc(p == Outcome::Miss && dinst->has_stats());
if (dinst->getInst()->isBranch()) {
nBranch3.inc(dinst->has_stats());
nBranchMiss3.inc(p == Outcome::Miss && dinst->has_stats());
nBranchBTBMiss3.inc(p == Outcome::NoBTB && dinst->has_stats());
}
nControlMiss3.inc((p == Outcome::Miss || p == Outcome::NoBTB) && dinst->has_stats());
nNoPredict3.inc(p == Outcome::None && dinst->has_stats());

return p;
Expand Down
21 changes: 15 additions & 6 deletions simu/bpred.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,29 @@ class BPredictor {
bool Miss_Pred_Bool;
Stats_cntr nBTAC;

Stats_cntr nBranches;
Stats_cntr nControl;
Stats_cntr nBranch;
Stats_cntr nNoPredict;
Stats_cntr nTaken;
Stats_cntr nMiss; // hits == nBranches - nMiss
Stats_cntr nControlMiss;
Stats_cntr nBranchMiss; // Miss predict due to T/NT predictor = nBranchMiss / nBranch
Stats_cntr nBranchBTBMiss; // Extra miss due to additional BTB mistake

Stats_cntr nBranches2;
Stats_cntr nControl2;
Stats_cntr nBranch2;
Stats_cntr nTaken2;
Stats_cntr nMiss2; // hits == nBranches - nMiss
Stats_cntr nControlMiss2;
Stats_cntr nBranchMiss2;
Stats_cntr nBranchBTBMiss2;

Stats_cntr nBranches3;
Stats_cntr nControl3;
Stats_cntr nBranch3;
Stats_cntr nNoPredict3;
Stats_cntr nHit3_miss2; // Mispred of Level 2 which are fixed by level 3 BPred
Stats_cntr nTaken3;
Stats_cntr nMiss3; // hits == nBranches - nMiss
Stats_cntr nControlMiss3;
Stats_cntr nBranchMiss3;
Stats_cntr nBranchBTBMiss3;

Stats_cntr nFixes1;
Stats_cntr nFixes2;
Expand Down
Loading

0 comments on commit 1e6da1a

Please sign in to comment.