Go to the documentation of this file.
41 #ifndef __CPU_O3_DECODE_IMPL_HH__
42 #define __CPU_O3_DECODE_IMPL_HH__
44 #include "arch/types.hh"
46 #include "config/the_isa.hh"
49 #include "debug/Activity.hh"
50 #include "debug/Decode.hh"
51 #include "debug/O3PipeView.hh"
52 #include "params/DerivO3CPU.hh"
62 renameToDecodeDelay(params->renameToDecodeDelay),
63 iewToDecodeDelay(params->iewToDecodeDelay),
64 commitToDecodeDelay(params->commitToDecodeDelay),
65 fetchToDecodeDelay(params->fetchToDecodeDelay),
66 decodeWidth(params->decodeWidth),
67 numThreads(params->numThreads),
71 fatal(
"decodeWidth (%d) is larger than compiled limit (%d),\n"
72 "\tincrease MaxWidth in src/cpu/o3/impl.hh\n",
77 for (
int tid = 0; tid < Impl::MaxThreads; tid++) {
97 decodeStatus[tid] = Idle;
98 stalls[tid].rename =
false;
108 for (
ThreadID tid = 0; tid < numThreads; ++tid) {
109 decodeStatus[tid] = Idle;
111 stalls[tid].rename =
false;
115 template <
class Impl>
119 return cpu->name() +
".decode";
122 template <
class Impl>
124 :
Stats::Group(cpu,
"decode"),
125 ADD_STAT(idleCycles,
"Number of cycles decode is idle"),
126 ADD_STAT(blockedCycles,
"Number of cycles decode is blocked"),
127 ADD_STAT(runCycles,
"Number of cycles decode is running"),
128 ADD_STAT(unblockCycles,
"Number of cycles decode is unblocking"),
129 ADD_STAT(squashCycles,
"Number of cycles decode is squashing"),
130 ADD_STAT(branchResolved,
"Number of times decode resolved a "
132 ADD_STAT(branchMispred,
"Number of times decode detected a branch"
134 ADD_STAT(controlMispred,
"Number of times decode detected an"
135 " instruction incorrectly predicted as a control"),
136 ADD_STAT(decodedInsts,
"Number of instructions handled by decode"),
137 ADD_STAT(squashedInsts,
"Number of squashed instructions handled"
194 template <
class Impl>
199 assert(
insts[tid].empty());
204 template <
class Impl>
220 bool ret_val =
false;
223 DPRINTF(Decode,
"[tid:%i] Stall fom Rename stage detected.\n", tid);
241 DPRINTF(Decode,
"[tid:%i] Blocking.\n", tid);
254 if (
toFetch->decodeUnblock[tid]) {
255 toFetch->decodeUnblock[tid] =
false;
257 toFetch->decodeBlock[tid] =
true;
273 DPRINTF(Decode,
"[tid:%i] Done unblocking.\n", tid);
274 toFetch->decodeUnblock[tid] =
true;
281 DPRINTF(Decode,
"[tid:%i] Currently unblocking.\n", tid);
290 DPRINTF(Decode,
"[tid:%i] [sn:%llu] Squashing due to incorrect branch "
291 "prediction detected at decode.\n", tid, inst->seqNum);
294 toFetch->decodeInfo[tid].branchMispredict =
true;
295 toFetch->decodeInfo[tid].predIncorrect =
true;
296 toFetch->decodeInfo[tid].mispredictInst = inst;
297 toFetch->decodeInfo[tid].squash =
true;
298 toFetch->decodeInfo[tid].doneSeqNum = inst->seqNum;
299 toFetch->decodeInfo[tid].nextPC = inst->branchTarget();
300 toFetch->decodeInfo[tid].branchTaken = inst->pcState().branching();
301 toFetch->decodeInfo[tid].squashInst = inst;
302 if (
toFetch->decodeInfo[tid].mispredictInst->isUncondCtrl()) {
303 toFetch->decodeInfo[tid].branchTaken =
true;
311 toFetch->decodeUnblock[tid] = 1;
318 if (
fromFetch->insts[
i]->threadNumber == tid &&
319 fromFetch->insts[
i]->seqNum > squash_seq_num) {
326 while (!
insts[tid].empty()) {
335 cpu->removeInstsUntil(squash_seq_num, tid);
342 DPRINTF(Decode,
"[tid:%i] Squashing.\n",tid);
347 toFetch->decodeUnblock[tid] = 1;
356 toFetch->decodeUnblock[tid] = 1;
364 unsigned squash_count = 0;
367 if (
fromFetch->insts[
i]->threadNumber == tid) {
375 while (!
insts[tid].empty()) {
392 while (!
insts[tid].empty()) {
393 inst =
insts[tid].front();
397 assert(tid == inst->threadNumber);
401 DPRINTF(Decode,
"Inserting [tid:%d][sn:%lli] PC: %s into decode skidBuffer %i\n",
402 inst->threadNumber, inst->seqNum, inst->pcState(),
skidBuffer[tid].size());
417 while (threads != end) {
430 bool any_unblocking =
false;
435 while (threads != end) {
439 any_unblocking =
true;
445 if (any_unblocking) {
449 DPRINTF(Activity,
"Activating stage.\n");
451 cpu->activateStage(O3CPU::DecodeIdx);
458 DPRINTF(Activity,
"Deactivating stage.\n");
460 cpu->deactivateStage(O3CPU::DecodeIdx);
465 template <
class Impl>
470 for (
int i = 0;
i < insts_from_fetch; ++
i) {
484 assert(
stalls[tid].rename);
489 template <
class Impl>
507 DPRINTF(Decode,
"[tid:%i] Squashing instructions due to squash "
508 "from commit.\n", tid);
520 DPRINTF(Decode,
"[tid:%i] Done blocking, switching to unblocking.\n",
533 DPRINTF(Decode,
"[tid:%i] Done squashing, switching to running.\n",
552 bool status_change =
false;
562 while (threads != end) {
565 DPRINTF(Decode,
"Processing [tid:%i]\n",tid);
568 decode(status_change, tid);
576 DPRINTF(Activity,
"Activity this cycle.\n");
578 cpu->activityThisCycle();
603 DPRINTF(Decode,
"[tid:%i] Not blocked, so attempting to run "
623 status_change =
unblock(tid) || status_change;
627 template <
class Impl>
636 if (insts_available == 0) {
637 DPRINTF(Decode,
"[tid:%i] Nothing to do, breaking out"
643 DPRINTF(Decode,
"[tid:%i] Unblocking, removing insts from skid "
650 std::queue<DynInstPtr>
654 DPRINTF(Decode,
"[tid:%i] Sending instruction to rename.\n",tid);
657 assert(!insts_to_decode.empty());
659 DynInstPtr inst = std::move(insts_to_decode.front());
661 insts_to_decode.pop();
663 DPRINTF(Decode,
"[tid:%i] Processing instruction [sn:%lli] with "
664 "PC %s\n", tid, inst->seqNum, inst->pcState());
666 if (inst->isSquashed()) {
667 DPRINTF(Decode,
"[tid:%i] Instruction %i with PC %s is "
668 "squashed, skipping.\n",
669 tid, inst->seqNum, inst->pcState());
682 if (inst->numSrcRegs() == 0) {
698 inst->decodeTick =
curTick() - inst->fetchTick;
704 if (inst->readPredTaken() && !inst->isControl()) {
705 panic(
"Instruction predicted as a branch!");
711 squash(inst, inst->threadNumber);
719 if (inst->isDirectCtrl() &&
720 (inst->isUncondCtrl() || inst->readPredTaken()))
724 if (!(inst->branchTarget() == inst->readPredTarg())) {
729 squash(inst, inst->threadNumber);
733 "[tid:%i] [sn:%llu] "
734 "Updating predictions: Wrong predicted target: %s \
736 tid, inst->seqNum, inst->readPredTarg(), target);
738 inst->setPredTarg(target);
746 if (!insts_to_decode.empty()) {
757 #endif//__CPU_O3_DECODE_IMPL_HH__
void squash(const DynInstPtr &inst, ThreadID tid)
Squashes if there is a PC-relative branch that was predicted incorrectly.
Stats::Scalar squashCycles
Stat for total number of squashing cycles.
#define fatal(...)
This implements a cprintf based fatal() function.
Addr bdelayDoneSeqNum[Impl::MaxThreads]
SeqNum of Squashing Branch Delay Instruction (used for MIPS)
TimeBuffer< TimeStruct > * timeBuffer
Time buffer interface.
Cycles renameToDecodeDelay
Rename to decode delay.
bool checkStall(ThreadID tid) const
Checks all stall signals, and returns if any are true.
Stats::Scalar decodedInsts
Stat for total number of decoded instructions.
bool checkSignalsAndUpdate(ThreadID tid)
Checks all input signals and updates decode's status appropriately.
int16_t ThreadID
Thread index/ID type.
std::queue< DynInstPtr > insts[Impl::MaxThreads]
Queue of all instructions coming from fetch this cycle.
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets pointer to list of active threads.
static scfx_rep_node * list
ThreadStatus decodeStatus[Impl::MaxThreads]
Per-thread status.
Stats::Scalar runCycles
Stat for total number of normal running cycles.
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Cycles iewToDecodeDelay
IEW to decode delay.
bool squashAfterDelaySlot[Impl::MaxThreads]
Tells when their is a pending delay slot inst.
TimeBuffer< TimeStruct >::wire fromRename
Wire to get rename's output from backwards time buffer.
Impl::DynInstPtr DynInstPtr
std::string name() const
Returns the name of decode.
void drainSanityCheck() const
Perform sanity checks after a drain.
unsigned toRenameIndex
Index of instructions being sent to rename.
void setTimeBuffer(TimeBuffer< TimeStruct > *tb_ptr)
Sets the main backwards communication time buffer pointer.
Stats::Scalar unblockCycles
Stat for total number of unblocking cycles.
TimeBuffer< TimeStruct >::wire fromCommit
Wire to get commit's information from backwards time buffer.
void skidInsert(ThreadID tid)
Inserts a thread's instructions into the skid buffer, to be decoded once decode unblocks.
bool block(ThreadID tid)
Switches decode to blocking, and signals back that decode has become blocked.
Derived & prereq(const Stat &prereq)
Set the prerequisite stat and marks this stat to print at the end of simulation.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Stats::Scalar blockedCycles
Stat for total number of blocked cycles.
Stats::Scalar controlMispred
Stat for number of times decode detected a non-control instruction incorrectly predicted as a branch.
std::list< ThreadID > * activeThreads
List of active thread ids.
std::queue< DynInstPtr > skidBuffer[Impl::MaxThreads]
Skid buffer between fetch and decode.
Stats::Scalar idleCycles
Stat for total number of idle cycles.
TimeBuffer< TimeStruct >::wire toFetch
Wire to write information heading to previous stages.
Stats::Scalar branchMispred
Stat for number of times a branch mispredict is detected.
O3CPU * cpu
CPU interface.
Stalls stalls[Impl::MaxThreads]
Tracks which stages are telling decode to stall.
DecodeStatus _status
Decode status.
TimeBuffer< FetchStruct >::wire fromFetch
Wire to get fetch's output from fetch queue.
bool fetchInstsValid()
Returns if there any instructions from fetch on this cycle.
void clearStates(ThreadID tid)
Clear all thread-specific states.
TimeBuffer< DecodeStruct >::wire toRename
Wire used to write any information heading to rename.
void updateStatus()
Updates overall decode status based on all of the threads' statuses.
void sortInsts()
Separates instructions from fetch into individual lists of instructions sorted by thread.
void decodeInsts(ThreadID tid)
Processes instructions from fetch and passes them on to rename.
void tick()
Ticks decode, processing all input signals and decoding as many instructions as possible.
Stats::Scalar squashedInsts
Stat for total number of squashed instructions.
unsigned decodeWidth
The width of decode, in instructions.
DefaultDecode::DecodeStats stats
bool skidsEmpty()
Returns if all of the skid buffers are empty.
GenericISA::DelaySlotPCState< MachInst > PCState
TimeBuffer< DecodeStruct > * decodeQueue
Decode instruction queue.
bool wroteToTimeBuffer
Variable that tracks if decode has written to the time buffer this cycle.
TimeBuffer< FetchStruct > * fetchQueue
Fetch instruction queue interface.
DynInstPtr squashInst[Impl::MaxThreads]
Instruction used for squashing branch (used for MIPS)
void setFetchQueue(TimeBuffer< FetchStruct > *fq_ptr)
Sets pointer to time buffer coming from fetch.
void setDecodeQueue(TimeBuffer< DecodeStruct > *dq_ptr)
Sets pointer to time buffer used to communicate to the next stage.
bool isDrained() const
Has the stage drained?
Stats::Scalar branchResolved
Stat for number of times a branch is resolved at decode.
void decode(bool &status_change, ThreadID tid)
Determines what to do based on decode's current status.
ThreadID numThreads
number of Active Threads
DefaultDecode(O3CPU *_cpu, DerivO3CPUParams *params)
DefaultDecode constructor.
bool unblock(ThreadID tid)
Switches decode to unblocking if the skid buffer is empty, and signals back that decode has unblocked...
unsigned skidBufferMax
Maximum size of the skid buffer.
Cycles commitToDecodeDelay
Commit to decode delay.
TimeBuffer< TimeStruct >::wire fromIEW
Wire to get iew's information from backwards time buffer.
#define panic(...)
This implements a cprintf based panic() function.
Cycles fetchToDecodeDelay
Fetch to decode delay.
Tick curTick()
The current simulated tick.
void readStallSignals(ThreadID tid)
Reads all stall signals from the backwards communication timebuffer.
Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17