Skip to content

Commit 10ff8c0

Browse files
authored
cpu-pred-btb: remove fetch stream use fetch target (#744)
1 parent a1d519e commit 10ff8c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+501
-553
lines changed

src/cpu/o3/comm.hh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ struct IEWStruct
147147
DynInstPtr mispredictInst[MaxThreads];
148148
Addr mispredPC[MaxThreads];
149149
InstSeqNum squashedSeqNum[MaxThreads];
150-
uint64_t squashedStreamId[MaxThreads];
151150
uint64_t squashedTargetId[MaxThreads];
152151
uint64_t squashedLoopIter[MaxThreads];
153152
std::unique_ptr<PCStateBase> pc[MaxThreads];
@@ -196,7 +195,7 @@ struct SquashVersion
196195

197196
struct ResolveQueueEntry
198197
{
199-
uint64_t resolvedFSQId;
198+
uint64_t resolvedFTQId;
200199
std::vector<uint64_t> resolvedInstPC;
201200
};
202201

@@ -250,7 +249,7 @@ struct TimeStruct
250249

251250
struct ResolvedCFIEntry
252251
{
253-
uint64_t fsqId;
252+
uint64_t ftqId;
254253
uint64_t pc;
255254
};
256255
/** Resolved control-flow PCs produced this cycle (fetch buffers/merges). */
@@ -301,8 +300,7 @@ struct TimeStruct
301300

302301
InstSeqNum doneMemSeqNum;
303302

304-
uint64_t doneFsqId; // F
305-
uint64_t squashedStreamId; // F
303+
uint64_t doneFtqId; // F
306304
uint64_t squashedTargetId; // F
307305
unsigned squashedLoopIter; // F
308306

src/cpu/o3/commit.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ Commit::squashAll(ThreadID tid)
701701

702702
set(toIEW->commitInfo[tid].pc, pc[tid]);
703703

704-
toIEW->commitInfo[tid].squashedStreamId = committedStreamId;
705704
toIEW->commitInfo[tid].squashedTargetId = committedTargetId;
706705
toIEW->commitInfo[tid].squashedLoopIter = committedLoopIter;
707706

@@ -1074,12 +1073,9 @@ Commit::commit()
10741073
DPRINTF(Commit,
10751074
"Unable to find squashed instruction in ROB\n");
10761075
}
1077-
toIEW->commitInfo[tid].squashedStreamId = fromIEW->squashedStreamId[tid];
10781076
toIEW->commitInfo[tid].squashedTargetId = fromIEW->squashedTargetId[tid];
10791077
toIEW->commitInfo[tid].squashedLoopIter = fromIEW->squashedLoopIter[tid];
10801078

1081-
// toIEW->commitInfo[tid].doneFsqId =
1082-
// toIEW->commitInfo[tid].squashInst->getFsqId();
10831079
if (toIEW->commitInfo[tid].mispredictInst) {
10841080
if (toIEW->commitInfo[tid].mispredictInst->isUncondCtrl()) {
10851081
toIEW->commitInfo[tid].branchTaken = true;
@@ -1322,11 +1318,9 @@ Commit::commitInsts()
13221318
// Set the doneSeqNum to the youngest committed instruction.
13231319
toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum;
13241320

1325-
if (head_inst->getFsqId() > 1) {
1326-
toIEW->commitInfo[tid].doneFsqId =
1327-
head_inst->getFsqId() - 1;
1321+
if (head_inst->getFtqId() > 1) {
1322+
toIEW->commitInfo[tid].doneFtqId = head_inst->getFtqId() - 1;
13281323
}
1329-
committedStreamId = head_inst->getFsqId();
13301324
committedTargetId = head_inst->getFtqId();
13311325
committedLoopIter = head_inst->getLoopIteration();
13321326

src/cpu/o3/commit.hh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,7 @@ private:
554554

555555
// committed Stream and Target
556556

557-
uint64_t committedStreamId{1};
558-
uint64_t committedTargetId{0};
557+
uint64_t committedTargetId{1};
559558
uint64_t committedLoopIter{};
560559

561560
struct CommitStats : public statistics::Group

src/cpu/o3/decode.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,6 @@ Decode::checkAndFuseInsts(std::vector<DynInstPtr> &vec, DynInstPtr& cur)
10121012
instruction->setVersion(inst_pair[1]->getVersion());
10131013
instruction->setTid(inst_pair[1]->threadNumber);
10141014
instruction->thread = inst_pair[1]->thread;
1015-
instruction->setFsqId(inst_pair[1]->fsqId);
10161015
instruction->setFtqId(inst_pair[1]->ftqId);
10171016

10181017
instruction->instListIt = cpu->instList.insert(inst_pair[0]->instListIt, instruction);

src/cpu/o3/dyn_inst.hh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,8 @@ class DynInst : public ExecContext, public RefCounted
395395

396396
Addr fallThruPC;
397397

398-
/** fsqId and ftqId are used for squashing and committing */
398+
/** ftqId is used for squashing and committing */
399399
/** The fetch stream queue ID of the instruction. */
400-
unsigned fsqId;
401-
/** The fetch target queue ID of the instruction. */
402400
unsigned ftqId;
403401
/** The number of loop iteration within an fsq entry of the instruction. */
404402
unsigned loopIteration;
@@ -1558,18 +1556,6 @@ class DynInst : public ExecContext, public RefCounted
15581556
}
15591557

15601558

1561-
void
1562-
setFsqId(unsigned id)
1563-
{
1564-
fsqId = id;
1565-
}
1566-
1567-
unsigned
1568-
getFsqId()
1569-
{
1570-
return fsqId;
1571-
}
1572-
15731559
void
15741560
setFtqId(unsigned id)
15751561
{

src/cpu/o3/fetch.cc

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ Fetch::processCacheCompletion(PacketPtr pkt)
629629
}
630630

631631
// Verify fetchBufferPC alignment with the supplying FSQ entry.
632-
if (fetchBuffer[tid].valid && dbpbtb->fsqHasHead()) {
633-
const auto &stream = dbpbtb->fsqHead();
632+
if (fetchBuffer[tid].valid && dbpbtb->ftqHasHead()) {
633+
const auto &stream = dbpbtb->ftqHead();
634634
if (fetchBuffer[tid].startPC != stream.startPC) {
635635
panic("fetchBufferPC %#x should be aligned with FSQ startPC %#x",
636636
fetchBuffer[tid].startPC, stream.startPC);
@@ -782,10 +782,8 @@ Fetch::lookupAndUpdateNextPC(const DynInstPtr &inst, PCStateBase &next_pc)
782782
// Decoupled+BTB-only: compute next PC directly from the supplying FSQ entry.
783783
ThreadID tid = inst->threadNumber;
784784
assert(dbpbtb);
785-
assert(dbpbtb->fsqHasHead());
786-
const auto &stream = dbpbtb->fsqHead();
787-
const auto fsq_id = dbpbtb->fsqHeadId();
788-
const auto ftq_id = dbpbtb->fsqHeadFtqId();
785+
assert(dbpbtb->ftqHasHead());
786+
const auto &stream = dbpbtb->ftqHead();
789787

790788
const Addr curr_pc = next_pc.instAddr();
791789
assert(stream.startPC <= curr_pc && curr_pc < stream.predEndPC);
@@ -818,7 +816,7 @@ Fetch::lookupAndUpdateNextPC(const DynInstPtr &inst, PCStateBase &next_pc)
818816
// Track how many dynamic instructions were fetched for this (legacy) FTQ/FSQ entry.
819817
ftqEntryFetchedInsts[tid]++;
820818
if (run_out) {
821-
dbpbtb->consumeFetchTarget(ftq_id, fsq_id, ftqEntryFetchedInsts[tid]);
819+
dbpbtb->consumeFetchTarget(ftqEntryFetchedInsts[tid]);
822820
ftqEntryFetchedInsts[tid] = 0;
823821
fetchBuffer[tid].valid = false;
824822
DPRINTF(DecoupleBP, "Used up fetch targets.\n");
@@ -1519,7 +1517,7 @@ Fetch::handleIEWSignals()
15191517
for (const auto &resolved : incoming) {
15201518
bool merged = false;
15211519
for (auto &queued : resolveQueue) {
1522-
if (queued.resolvedFSQId == resolved.fsqId) {
1520+
if (queued.resolvedFTQId == resolved.ftqId) {
15231521
queued.resolvedInstPC.push_back(resolved.pc);
15241522
merged = true;
15251523
break;
@@ -1531,7 +1529,7 @@ Fetch::handleIEWSignals()
15311529
}
15321530

15331531
ResolveQueueEntry new_entry;
1534-
new_entry.resolvedFSQId = resolved.fsqId;
1532+
new_entry.resolvedFTQId = resolved.ftqId;
15351533
new_entry.resolvedInstPC.push_back(resolved.pc);
15361534
resolveQueue.push_back(std::move(new_entry));
15371535
enqueueCount++;
@@ -1543,7 +1541,7 @@ Fetch::handleIEWSignals()
15431541

15441542
if (!resolveQueue.empty()) {
15451543
auto &entry = resolveQueue.front();
1546-
unsigned int stream_id = entry.resolvedFSQId;
1544+
unsigned int stream_id = entry.resolvedFTQId;
15471545
dbpbtb->prepareResolveUpdateEntries(stream_id);
15481546
for (const auto resolvedInstPC : entry.resolvedInstPC) {
15491547
dbpbtb->markCFIResolved(stream_id, resolvedInstPC);
@@ -1564,10 +1562,10 @@ Fetch::handleCommitSignals(ThreadID tid)
15641562
{
15651563
// Check squash signals from commit.
15661564
if (!fromCommit->commitInfo[tid].squash) {
1567-
if (fromCommit->commitInfo[tid].doneSeqNum) {
1568-
DPRINTF(DecoupleBP, "Commit stream Id: %lu\n", fromCommit->commitInfo[tid].doneFsqId);
1565+
if (fromCommit->commitInfo[tid].doneFtqId) {
1566+
DPRINTF(DecoupleBP, "Commit stream Id: %lu\n", fromCommit->commitInfo[tid].doneFtqId);
15691567
assert(dbpbtb);
1570-
dbpbtb->update(fromCommit->commitInfo[tid].doneFsqId, tid);
1568+
dbpbtb->update(fromCommit->commitInfo[tid].doneFtqId, tid);
15711569
}
15721570
return false;
15731571
}
@@ -1602,24 +1600,22 @@ Fetch::handleCommitSignals(ThreadID tid)
16021600
DPRINTF(Fetch, "Use mispred inst to redirect, treating as control squash\n");
16031601
const auto corr_pc = fromCommit->commitInfo[tid].pc->as<RiscvISA::PCState>();
16041602
assert(dbpbtb);
1605-
dbpbtb->controlSquash(mispred_inst->getFtqId(), mispred_inst->getFsqId(), mispred_inst->pcState(),
1603+
dbpbtb->controlSquash(mispred_inst->getFtqId(), mispred_inst->pcState(),
16061604
corr_pc, mispred_inst->staticInst,
16071605
mispred_inst->getInstBytes(), fromCommit->commitInfo[tid].branchTaken,
16081606
mispred_inst->seqNum, tid, mispred_inst->getLoopIteration(), true);
16091607
} else if (fromCommit->commitInfo[tid].isTrapSquash) {
16101608
DPRINTF(Fetch, "Treating as trap squash\n", tid);
16111609
const auto trap_pc = fromCommit->commitInfo[tid].pc->as<RiscvISA::PCState>();
16121610
assert(dbpbtb);
1613-
dbpbtb->trapSquash(fromCommit->commitInfo[tid].squashedTargetId,
1614-
fromCommit->commitInfo[tid].squashedStreamId, fromCommit->commitInfo[tid].committedPC,
1611+
dbpbtb->trapSquash(fromCommit->commitInfo[tid].squashedTargetId, fromCommit->commitInfo[tid].committedPC,
16151612
trap_pc, tid, fromCommit->commitInfo[tid].squashedLoopIter);
16161613
} else {
1617-
if (fromCommit->commitInfo[tid].pc && fromCommit->commitInfo[tid].squashedStreamId != 0) {
1614+
if (fromCommit->commitInfo[tid].pc && fromCommit->commitInfo[tid].squashedTargetId != 0) {
16181615
DPRINTF(Fetch, "Squash with stream id and target id from IEW\n");
16191616
const auto nc_pc = fromCommit->commitInfo[tid].pc->as<RiscvISA::PCState>();
16201617
assert(dbpbtb);
1621-
dbpbtb->nonControlSquash(fromCommit->commitInfo[tid].squashedTargetId,
1622-
fromCommit->commitInfo[tid].squashedStreamId, nc_pc,
1618+
dbpbtb->nonControlSquash(fromCommit->commitInfo[tid].squashedTargetId, nc_pc,
16231619
0, tid, fromCommit->commitInfo[tid].squashedLoopIter);
16241620
} else {
16251621
DPRINTF(Fetch, "Dont squash dbq because no meaningful stream\n");
@@ -1643,7 +1639,7 @@ Fetch::handleDecodeSquash(ThreadID tid)
16431639
const auto next_pc =
16441640
fromDecode->decodeInfo[tid].nextPC->as<RiscvISA::PCState>();
16451641
dbpbtb->controlSquash(
1646-
mispred_inst->getFtqId(), mispred_inst->getFsqId(),
1642+
mispred_inst->getFtqId(),
16471643
mispred_inst->pcState(),
16481644
next_pc,
16491645
mispred_inst->staticInst, mispred_inst->getInstBytes(),
@@ -1703,11 +1699,9 @@ Fetch::buildInst(ThreadID tid, StaticInstPtr staticInst,
17031699
DPRINTF(Fetch, "Is nop: %i, is move: %i\n", instruction->isNop(),
17041700
instruction->isMov());
17051701
assert(dbpbtb);
1706-
DPRINTF(DecoupleBP, "Set instruction %lu with stream id %lu, fetch id %lu\n",
1707-
instruction->seqNum, dbpbtb->fsqHeadId(),
1708-
dbpbtb->fsqHeadFtqId());
1709-
instruction->setFsqId(dbpbtb->fsqHeadId());
1710-
instruction->setFtqId(dbpbtb->fsqHeadFtqId());
1702+
DPRINTF(DecoupleBP, "Set instruction %lu with fetch id %lu\n",
1703+
instruction->seqNum, dbpbtb->ftqHeadId());
1704+
instruction->setFtqId(dbpbtb->ftqHeadId());
17111705

17121706
#if TRACING_ON
17131707
if (trace) {
@@ -1763,7 +1757,7 @@ bool
17631757
Fetch::checkDecoupledFrontend(ThreadID tid)
17641758
{
17651759
assert(dbpbtb);
1766-
if (!isTraceMode() && !dbpbtb->fsqHasHead()) {
1760+
if (!isTraceMode() && !dbpbtb->ftqHasHead()) {
17671761
dbpbtb->addFtqNotValid();
17681762
DPRINTF(Fetch, "Skip fetch when FSQ head is not available\n");
17691763
setAllFetchStalls(StallReason::FTQBubble);
@@ -1991,7 +1985,7 @@ Fetch::performInstructionFetch(ThreadID tid)
19911985
// For decoupled frontend (including trace mode), check FTQ availability
19921986
StallReason stall = StallReason::NoStall;
19931987
while (numInst < fetchWidth && fetchQueue[tid].size() < fetchQueueSize &&
1994-
!predictedBranch && !fsqEmpty() && !waitForVsetvl) {
1988+
!predictedBranch && !ftqEmpty() && !waitForVsetvl) {
19951989

19961990
// Check memory needs and supply bytes to decoder if required
19971991
stall = checkMemoryNeeds(tid, pc_state, curMacroop);
@@ -2051,13 +2045,13 @@ Fetch::sendNextCacheRequest(ThreadID tid, const PCStateBase &pc_state) {
20512045
return;
20522046
}
20532047

2054-
if (fsqEmpty()) {
2048+
if (ftqEmpty()) {
20552049
DPRINTF(Fetch, "[tid:%i] No FSQ entry available for next fetch\n", tid);
20562050
return;
20572051
}
20582052

20592053
assert(dbpbtb);
2060-
const auto &stream = dbpbtb->fsqHead();
2054+
const auto &stream = dbpbtb->ftqHead();
20612055
const Addr start_pc = stream.startPC;
20622056
fetchBuffer[tid].startPC = start_pc;
20632057

src/cpu/o3/fetch.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ class Fetch
968968

969969
// Decoupled+BTB-only: fetch consumes the supplying FSQ entry directly.
970970
// If no head is available, fetch stalls (no extra "supply" state machine).
971-
bool fsqEmpty() const { return !dbpbtb || !dbpbtb->fsqHasHead(); }
971+
bool ftqEmpty() const { return !dbpbtb || !dbpbtb->ftqHasHead(); }
972972

973973
// Number of dynamic instructions fetched within the current FTQ entry.
974974
// Used to explicitly notify the BPU when an entry is consumed (Phase5 prep).

src/cpu/o3/iew.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ IEW::squashDueToBranch(const DynInstPtr& inst, ThreadID tid)
567567
inst->seqNum < toCommit->squashedSeqNum[tid]) {
568568
toCommit->squash[tid] = true;
569569
toCommit->squashedSeqNum[tid] = inst->seqNum;
570-
toCommit->squashedStreamId[tid] = inst->getFsqId();
571570
toCommit->squashedTargetId[tid] = inst->getFtqId();
572571
toCommit->squashedLoopIter[tid] = inst->getLoopIteration();
573572
toCommit->branchTaken[tid] = inst->pcState().branching();
@@ -581,10 +580,9 @@ IEW::squashDueToBranch(const DynInstPtr& inst, ThreadID tid)
581580
wroteToTimeBuffer = true;
582581

583582
DPRINTF(DecoupleBP,
584-
"Branch misprediction (pc=%#lx) set stream id to %lu, target "
583+
"Branch misprediction (pc=%#lx) set target "
585584
"id to %lu, loop iter to %u\n",
586585
toCommit->pc[tid]->instAddr(),
587-
toCommit->squashedStreamId[tid],
588586
toCommit->squashedTargetId[tid],
589587
toCommit->squashedLoopIter[tid]);
590588
}
@@ -607,7 +605,6 @@ IEW::squashDueToMemOrder(const DynInstPtr& inst, ThreadID tid)
607605
toCommit->squash[tid] = true;
608606

609607
toCommit->squashedSeqNum[tid] = inst->seqNum;
610-
toCommit->squashedStreamId[tid] = inst->getFsqId();
611608
toCommit->squashedTargetId[tid] = inst->getFtqId();
612609
toCommit->squashedLoopIter[tid] = inst->getLoopIteration();
613610
set(toCommit->pc[tid], inst->pcState());
@@ -619,10 +616,9 @@ IEW::squashDueToMemOrder(const DynInstPtr& inst, ThreadID tid)
619616
wroteToTimeBuffer = true;
620617

621618
DPRINTF(DecoupleBP,
622-
"Memory violation (pc=%#lx) set stream id to %lu, target id "
619+
"Memory violation (pc=%#lx) set target id "
623620
"to %lu, loop iter to %u\n",
624621
toCommit->pc[tid]->instAddr(),
625-
toCommit->squashedStreamId[tid],
626622
toCommit->squashedTargetId[tid],
627623
toCommit->squashedLoopIter[tid]);
628624

@@ -1570,7 +1566,7 @@ IEW::SquashCheckAfterExe(DynInstPtr inst)
15701566
if (inst->isControl()) {
15711567
auto &resolved_cfis = toFetch->iewInfo[tid].resolvedCFIs;
15721568
TimeStruct::IewComm::ResolvedCFIEntry entry;
1573-
entry.fsqId = inst->getFsqId();
1569+
entry.ftqId = inst->getFtqId();
15741570
entry.pc = inst->getPC();
15751571
resolved_cfis.push_back(entry);
15761572
}

src/cpu/o3/trace/TraceFetch.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,8 @@ TraceFetch::chooseWrongPathNopSize(ThreadID tid, Addr pc)
536536
bool taken = false;
537537
if (fetch.isBTBPred()) {
538538
assert(fetch.dbpbtb);
539-
if (fetch.dbpbtb->fsqHasHead()) {
540-
const auto &stream = fetch.dbpbtb->fsqHead();
539+
if (fetch.dbpbtb->ftqHasHead()) {
540+
const auto &stream = fetch.dbpbtb->ftqHead();
541541
block_end = stream.predEndPC;
542542
taken_pc = stream.predBranchInfo.pc;
543543
taken = stream.predTaken;

0 commit comments

Comments
 (0)