rename_impl.hh revision 6329
11689SN/A/*
22329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
31689SN/A * All rights reserved.
41689SN/A *
51689SN/A * Redistribution and use in source and binary forms, with or without
61689SN/A * modification, are permitted provided that the following conditions are
71689SN/A * met: redistributions of source code must retain the above copyright
81689SN/A * notice, this list of conditions and the following disclaimer;
91689SN/A * redistributions in binary form must reproduce the above copyright
101689SN/A * notice, this list of conditions and the following disclaimer in the
111689SN/A * documentation and/or other materials provided with the distribution;
121689SN/A * neither the name of the copyright holders nor the names of its
131689SN/A * contributors may be used to endorse or promote products derived from
141689SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
292935Sksewell@umich.edu *          Korey Sewell
301689SN/A */
311689SN/A
321060SN/A#include <list>
331060SN/A
343773Sgblack@eecs.umich.edu#include "arch/isa_traits.hh"
356329Sgblack@eecs.umich.edu#include "arch/registers.hh"
361858SN/A#include "config/full_system.hh"
371717SN/A#include "cpu/o3/rename.hh"
385529Snate@binkert.org#include "params/DerivO3CPU.hh"
391060SN/A
406221Snate@binkert.orgusing namespace std;
416221Snate@binkert.org
421061SN/Atemplate <class Impl>
435529Snate@binkert.orgDefaultRename<Impl>::DefaultRename(O3CPU *_cpu, DerivO3CPUParams *params)
444329Sktlim@umich.edu    : cpu(_cpu),
454329Sktlim@umich.edu      iewToRenameDelay(params->iewToRenameDelay),
462292SN/A      decodeToRenameDelay(params->decodeToRenameDelay),
472292SN/A      commitToRenameDelay(params->commitToRenameDelay),
482292SN/A      renameWidth(params->renameWidth),
492292SN/A      commitWidth(params->commitWidth),
503788Sgblack@eecs.umich.edu      resumeSerialize(false),
513798Sgblack@eecs.umich.edu      resumeUnblocking(false),
525529Snate@binkert.org      numThreads(params->numThreads),
532361SN/A      maxPhysicalRegs(params->numPhysIntRegs + params->numPhysFloatRegs)
541060SN/A{
552292SN/A    _status = Inactive;
562292SN/A
576221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
586221Snate@binkert.org        renameStatus[tid] = Idle;
592292SN/A
606221Snate@binkert.org        freeEntries[tid].iqEntries = 0;
616221Snate@binkert.org        freeEntries[tid].lsqEntries = 0;
626221Snate@binkert.org        freeEntries[tid].robEntries = 0;
632292SN/A
646221Snate@binkert.org        stalls[tid].iew = false;
656221Snate@binkert.org        stalls[tid].commit = false;
666221Snate@binkert.org        serializeInst[tid] = NULL;
672292SN/A
686221Snate@binkert.org        instsInProgress[tid] = 0;
692292SN/A
706221Snate@binkert.org        emptyROB[tid] = true;
712292SN/A
726221Snate@binkert.org        serializeOnNextInst[tid] = false;
732292SN/A    }
742292SN/A
752292SN/A    // @todo: Make into a parameter.
762292SN/A    skidBufferMax = (2 * (iewToRenameDelay * params->decodeWidth)) + renameWidth;
772292SN/A}
782292SN/A
792292SN/Atemplate <class Impl>
802292SN/Astd::string
812292SN/ADefaultRename<Impl>::name() const
822292SN/A{
832292SN/A    return cpu->name() + ".rename";
841060SN/A}
851060SN/A
861061SN/Atemplate <class Impl>
871060SN/Avoid
882292SN/ADefaultRename<Impl>::regStats()
891062SN/A{
901062SN/A    renameSquashCycles
912301SN/A        .name(name() + ".RENAME:SquashCycles")
921062SN/A        .desc("Number of cycles rename is squashing")
931062SN/A        .prereq(renameSquashCycles);
941062SN/A    renameIdleCycles
952301SN/A        .name(name() + ".RENAME:IdleCycles")
961062SN/A        .desc("Number of cycles rename is idle")
971062SN/A        .prereq(renameIdleCycles);
981062SN/A    renameBlockCycles
992301SN/A        .name(name() + ".RENAME:BlockCycles")
1001062SN/A        .desc("Number of cycles rename is blocking")
1011062SN/A        .prereq(renameBlockCycles);
1022301SN/A    renameSerializeStallCycles
1032301SN/A        .name(name() + ".RENAME:serializeStallCycles")
1042301SN/A        .desc("count of cycles rename stalled for serializing inst")
1052301SN/A        .flags(Stats::total);
1062292SN/A    renameRunCycles
1072301SN/A        .name(name() + ".RENAME:RunCycles")
1082292SN/A        .desc("Number of cycles rename is running")
1092292SN/A        .prereq(renameIdleCycles);
1101062SN/A    renameUnblockCycles
1112301SN/A        .name(name() + ".RENAME:UnblockCycles")
1121062SN/A        .desc("Number of cycles rename is unblocking")
1131062SN/A        .prereq(renameUnblockCycles);
1141062SN/A    renameRenamedInsts
1152301SN/A        .name(name() + ".RENAME:RenamedInsts")
1161062SN/A        .desc("Number of instructions processed by rename")
1171062SN/A        .prereq(renameRenamedInsts);
1181062SN/A    renameSquashedInsts
1192301SN/A        .name(name() + ".RENAME:SquashedInsts")
1201062SN/A        .desc("Number of squashed instructions processed by rename")
1211062SN/A        .prereq(renameSquashedInsts);
1221062SN/A    renameROBFullEvents
1232301SN/A        .name(name() + ".RENAME:ROBFullEvents")
1242292SN/A        .desc("Number of times rename has blocked due to ROB full")
1251062SN/A        .prereq(renameROBFullEvents);
1261062SN/A    renameIQFullEvents
1272301SN/A        .name(name() + ".RENAME:IQFullEvents")
1282292SN/A        .desc("Number of times rename has blocked due to IQ full")
1291062SN/A        .prereq(renameIQFullEvents);
1302292SN/A    renameLSQFullEvents
1312301SN/A        .name(name() + ".RENAME:LSQFullEvents")
1322292SN/A        .desc("Number of times rename has blocked due to LSQ full")
1332292SN/A        .prereq(renameLSQFullEvents);
1341062SN/A    renameFullRegistersEvents
1352301SN/A        .name(name() + ".RENAME:FullRegisterEvents")
1361062SN/A        .desc("Number of times there has been no free registers")
1371062SN/A        .prereq(renameFullRegistersEvents);
1381062SN/A    renameRenamedOperands
1392301SN/A        .name(name() + ".RENAME:RenamedOperands")
1401062SN/A        .desc("Number of destination operands rename has renamed")
1411062SN/A        .prereq(renameRenamedOperands);
1421062SN/A    renameRenameLookups
1432301SN/A        .name(name() + ".RENAME:RenameLookups")
1441062SN/A        .desc("Number of register rename lookups that rename has made")
1451062SN/A        .prereq(renameRenameLookups);
1461062SN/A    renameCommittedMaps
1472301SN/A        .name(name() + ".RENAME:CommittedMaps")
1481062SN/A        .desc("Number of HB maps that are committed")
1491062SN/A        .prereq(renameCommittedMaps);
1501062SN/A    renameUndoneMaps
1512301SN/A        .name(name() + ".RENAME:UndoneMaps")
1521062SN/A        .desc("Number of HB maps that are undone due to squashing")
1531062SN/A        .prereq(renameUndoneMaps);
1542301SN/A    renamedSerializing
1552301SN/A        .name(name() + ".RENAME:serializingInsts")
1562301SN/A        .desc("count of serializing insts renamed")
1572301SN/A        .flags(Stats::total)
1582301SN/A        ;
1592301SN/A    renamedTempSerializing
1602301SN/A        .name(name() + ".RENAME:tempSerializingInsts")
1612301SN/A        .desc("count of temporary serializing insts renamed")
1622301SN/A        .flags(Stats::total)
1632301SN/A        ;
1642307SN/A    renameSkidInsts
1652307SN/A        .name(name() + ".RENAME:skidInsts")
1662307SN/A        .desc("count of insts added to the skid buffer")
1672307SN/A        .flags(Stats::total)
1682307SN/A        ;
1691062SN/A}
1701062SN/A
1711062SN/Atemplate <class Impl>
1721062SN/Avoid
1732292SN/ADefaultRename<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
1741060SN/A{
1751060SN/A    timeBuffer = tb_ptr;
1761060SN/A
1771060SN/A    // Setup wire to read information from time buffer, from IEW stage.
1781060SN/A    fromIEW = timeBuffer->getWire(-iewToRenameDelay);
1791060SN/A
1801060SN/A    // Setup wire to read infromation from time buffer, from commit stage.
1811060SN/A    fromCommit = timeBuffer->getWire(-commitToRenameDelay);
1821060SN/A
1831060SN/A    // Setup wire to write information to previous stages.
1841060SN/A    toDecode = timeBuffer->getWire(0);
1851060SN/A}
1861060SN/A
1871061SN/Atemplate <class Impl>
1881060SN/Avoid
1892292SN/ADefaultRename<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
1901060SN/A{
1911060SN/A    renameQueue = rq_ptr;
1921060SN/A
1931060SN/A    // Setup wire to write information to future stages.
1941060SN/A    toIEW = renameQueue->getWire(0);
1951060SN/A}
1961060SN/A
1971061SN/Atemplate <class Impl>
1981060SN/Avoid
1992292SN/ADefaultRename<Impl>::setDecodeQueue(TimeBuffer<DecodeStruct> *dq_ptr)
2001060SN/A{
2011060SN/A    decodeQueue = dq_ptr;
2021060SN/A
2031060SN/A    // Setup wire to get information from decode.
2041060SN/A    fromDecode = decodeQueue->getWire(-decodeToRenameDelay);
2051060SN/A}
2061060SN/A
2071061SN/Atemplate <class Impl>
2081060SN/Avoid
2092292SN/ADefaultRename<Impl>::initStage()
2101060SN/A{
2112329SN/A    // Grab the number of free entries directly from the stages.
2126221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
2132292SN/A        freeEntries[tid].iqEntries = iew_ptr->instQueue.numFreeEntries(tid);
2142292SN/A        freeEntries[tid].lsqEntries = iew_ptr->ldstQueue.numFreeEntries(tid);
2152292SN/A        freeEntries[tid].robEntries = commit_ptr->numROBFreeEntries(tid);
2162292SN/A        emptyROB[tid] = true;
2172292SN/A    }
2181060SN/A}
2191060SN/A
2202292SN/Atemplate<class Impl>
2212292SN/Avoid
2226221Snate@binkert.orgDefaultRename<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
2232292SN/A{
2242292SN/A    activeThreads = at_ptr;
2252292SN/A}
2262292SN/A
2272292SN/A
2281061SN/Atemplate <class Impl>
2291060SN/Avoid
2302292SN/ADefaultRename<Impl>::setRenameMap(RenameMap rm_ptr[])
2311060SN/A{
2326221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++)
2336221Snate@binkert.org        renameMap[tid] = &rm_ptr[tid];
2341060SN/A}
2351060SN/A
2361061SN/Atemplate <class Impl>
2371060SN/Avoid
2382292SN/ADefaultRename<Impl>::setFreeList(FreeList *fl_ptr)
2391060SN/A{
2402292SN/A    freeList = fl_ptr;
2412292SN/A}
2421060SN/A
2432292SN/Atemplate<class Impl>
2442292SN/Avoid
2452292SN/ADefaultRename<Impl>::setScoreboard(Scoreboard *_scoreboard)
2462292SN/A{
2472292SN/A    scoreboard = _scoreboard;
2481060SN/A}
2491060SN/A
2501061SN/Atemplate <class Impl>
2512863Sktlim@umich.edubool
2522843Sktlim@umich.eduDefaultRename<Impl>::drain()
2531060SN/A{
2542348SN/A    // Rename is ready to switch out at any time.
2552843Sktlim@umich.edu    cpu->signalDrained();
2562863Sktlim@umich.edu    return true;
2572316SN/A}
2581060SN/A
2592316SN/Atemplate <class Impl>
2602316SN/Avoid
2612843Sktlim@umich.eduDefaultRename<Impl>::switchOut()
2622316SN/A{
2632348SN/A    // Clear any state, fix up the rename map.
2646221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
2652980Sgblack@eecs.umich.edu        typename std::list<RenameHistory>::iterator hb_it =
2666221Snate@binkert.org            historyBuffer[tid].begin();
2672307SN/A
2686221Snate@binkert.org        while (!historyBuffer[tid].empty()) {
2696221Snate@binkert.org            assert(hb_it != historyBuffer[tid].end());
2702307SN/A
2712307SN/A            DPRINTF(Rename, "[tid:%u]: Removing history entry with sequence "
2726221Snate@binkert.org                    "number %i.\n", tid, (*hb_it).instSeqNum);
2732307SN/A
2742307SN/A            // Tell the rename map to set the architected register to the
2752307SN/A            // previous physical register that it was renamed to.
2766221Snate@binkert.org            renameMap[tid]->setEntry(hb_it->archReg, hb_it->prevPhysReg);
2772307SN/A
2782307SN/A            // Put the renamed physical register back on the free list.
2792307SN/A            freeList->addReg(hb_it->newPhysReg);
2802307SN/A
2812361SN/A            // Be sure to mark its register as ready if it's a misc register.
2822361SN/A            if (hb_it->newPhysReg >= maxPhysicalRegs) {
2832361SN/A                scoreboard->setReg(hb_it->newPhysReg);
2842361SN/A            }
2852361SN/A
2866221Snate@binkert.org            historyBuffer[tid].erase(hb_it++);
2872307SN/A        }
2886221Snate@binkert.org        insts[tid].clear();
2896221Snate@binkert.org        skidBuffer[tid].clear();
2901060SN/A    }
2911060SN/A}
2921060SN/A
2931061SN/Atemplate <class Impl>
2941060SN/Avoid
2952307SN/ADefaultRename<Impl>::takeOverFrom()
2961060SN/A{
2972307SN/A    _status = Inactive;
2982307SN/A    initStage();
2991060SN/A
3002329SN/A    // Reset all state prior to taking over from the other CPU.
3016221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
3026221Snate@binkert.org        renameStatus[tid] = Idle;
3031060SN/A
3046221Snate@binkert.org        stalls[tid].iew = false;
3056221Snate@binkert.org        stalls[tid].commit = false;
3066221Snate@binkert.org        serializeInst[tid] = NULL;
3072307SN/A
3086221Snate@binkert.org        instsInProgress[tid] = 0;
3092307SN/A
3106221Snate@binkert.org        emptyROB[tid] = true;
3112307SN/A
3126221Snate@binkert.org        serializeOnNextInst[tid] = false;
3132307SN/A    }
3142307SN/A}
3152307SN/A
3162307SN/Atemplate <class Impl>
3172307SN/Avoid
3186221Snate@binkert.orgDefaultRename<Impl>::squash(const InstSeqNum &squash_seq_num, ThreadID tid)
3191858SN/A{
3202292SN/A    DPRINTF(Rename, "[tid:%u]: Squashing instructions.\n",tid);
3211858SN/A
3222292SN/A    // Clear the stall signal if rename was blocked or unblocking before.
3232292SN/A    // If it still needs to block, the blocking should happen the next
3242292SN/A    // cycle and there should be space to hold everything due to the squash.
3252292SN/A    if (renameStatus[tid] == Blocked ||
3263788Sgblack@eecs.umich.edu        renameStatus[tid] == Unblocking) {
3272292SN/A        toDecode->renameUnblock[tid] = 1;
3282698Sktlim@umich.edu
3293788Sgblack@eecs.umich.edu        resumeSerialize = false;
3302301SN/A        serializeInst[tid] = NULL;
3313788Sgblack@eecs.umich.edu    } else if (renameStatus[tid] == SerializeStall) {
3323788Sgblack@eecs.umich.edu        if (serializeInst[tid]->seqNum <= squash_seq_num) {
3333788Sgblack@eecs.umich.edu            DPRINTF(Rename, "Rename will resume serializing after squash\n");
3343788Sgblack@eecs.umich.edu            resumeSerialize = true;
3353788Sgblack@eecs.umich.edu            assert(serializeInst[tid]);
3363788Sgblack@eecs.umich.edu        } else {
3373788Sgblack@eecs.umich.edu            resumeSerialize = false;
3383788Sgblack@eecs.umich.edu            toDecode->renameUnblock[tid] = 1;
3393788Sgblack@eecs.umich.edu
3403788Sgblack@eecs.umich.edu            serializeInst[tid] = NULL;
3413788Sgblack@eecs.umich.edu        }
3422292SN/A    }
3432292SN/A
3442292SN/A    // Set the status to Squashing.
3452292SN/A    renameStatus[tid] = Squashing;
3462292SN/A
3472329SN/A    // Squash any instructions from decode.
3482292SN/A    unsigned squashCount = 0;
3492292SN/A
3502292SN/A    for (int i=0; i<fromDecode->size; i++) {
3512935Sksewell@umich.edu        if (fromDecode->insts[i]->threadNumber == tid &&
3522935Sksewell@umich.edu            fromDecode->insts[i]->seqNum > squash_seq_num) {
3532731Sktlim@umich.edu            fromDecode->insts[i]->setSquashed();
3542292SN/A            wroteToTimeBuffer = true;
3552292SN/A            squashCount++;
3562292SN/A        }
3572935Sksewell@umich.edu
3582292SN/A    }
3592292SN/A
3602935Sksewell@umich.edu    // Clear the instruction list and skid buffer in case they have any
3614632Sgblack@eecs.umich.edu    // insts in them.
3623093Sksewell@umich.edu    insts[tid].clear();
3632292SN/A
3642292SN/A    // Clear the skid buffer in case it has any data in it.
3653093Sksewell@umich.edu    skidBuffer[tid].clear();
3664632Sgblack@eecs.umich.edu
3672935Sksewell@umich.edu    doSquash(squash_seq_num, tid);
3682292SN/A}
3692292SN/A
3702292SN/Atemplate <class Impl>
3712292SN/Avoid
3722292SN/ADefaultRename<Impl>::tick()
3732292SN/A{
3742292SN/A    wroteToTimeBuffer = false;
3752292SN/A
3762292SN/A    blockThisCycle = false;
3772292SN/A
3782292SN/A    bool status_change = false;
3792292SN/A
3802292SN/A    toIEWIndex = 0;
3812292SN/A
3822292SN/A    sortInsts();
3832292SN/A
3846221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
3856221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
3862292SN/A
3872292SN/A    // Check stall and squash signals.
3883867Sbinkertn@umich.edu    while (threads != end) {
3896221Snate@binkert.org        ThreadID tid = *threads++;
3902292SN/A
3912292SN/A        DPRINTF(Rename, "Processing [tid:%i]\n", tid);
3922292SN/A
3932292SN/A        status_change = checkSignalsAndUpdate(tid) || status_change;
3942292SN/A
3952292SN/A        rename(status_change, tid);
3962292SN/A    }
3972292SN/A
3982292SN/A    if (status_change) {
3992292SN/A        updateStatus();
4002292SN/A    }
4012292SN/A
4022292SN/A    if (wroteToTimeBuffer) {
4032292SN/A        DPRINTF(Activity, "Activity this cycle.\n");
4042292SN/A        cpu->activityThisCycle();
4052292SN/A    }
4062292SN/A
4073867Sbinkertn@umich.edu    threads = activeThreads->begin();
4082292SN/A
4093867Sbinkertn@umich.edu    while (threads != end) {
4106221Snate@binkert.org        ThreadID tid = *threads++;
4112292SN/A
4122292SN/A        // If we committed this cycle then doneSeqNum will be > 0
4132292SN/A        if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
4142292SN/A            !fromCommit->commitInfo[tid].squash &&
4152292SN/A            renameStatus[tid] != Squashing) {
4162292SN/A
4172292SN/A            removeFromHistory(fromCommit->commitInfo[tid].doneSeqNum,
4182292SN/A                                  tid);
4192292SN/A        }
4202292SN/A    }
4212292SN/A
4222292SN/A    // @todo: make into updateProgress function
4236221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
4242292SN/A        instsInProgress[tid] -= fromIEW->iewInfo[tid].dispatched;
4252292SN/A
4262292SN/A        assert(instsInProgress[tid] >=0);
4272292SN/A    }
4282292SN/A
4292292SN/A}
4302292SN/A
4312292SN/Atemplate<class Impl>
4322292SN/Avoid
4336221Snate@binkert.orgDefaultRename<Impl>::rename(bool &status_change, ThreadID tid)
4342292SN/A{
4352292SN/A    // If status is Running or idle,
4362292SN/A    //     call renameInsts()
4372292SN/A    // If status is Unblocking,
4382292SN/A    //     buffer any instructions coming from decode
4392292SN/A    //     continue trying to empty skid buffer
4402292SN/A    //     check if stall conditions have passed
4412292SN/A
4422292SN/A    if (renameStatus[tid] == Blocked) {
4432292SN/A        ++renameBlockCycles;
4442292SN/A    } else if (renameStatus[tid] == Squashing) {
4452292SN/A        ++renameSquashCycles;
4462301SN/A    } else if (renameStatus[tid] == SerializeStall) {
4472301SN/A        ++renameSerializeStallCycles;
4483788Sgblack@eecs.umich.edu        // If we are currently in SerializeStall and resumeSerialize
4493788Sgblack@eecs.umich.edu        // was set, then that means that we are resuming serializing
4503788Sgblack@eecs.umich.edu        // this cycle.  Tell the previous stages to block.
4513788Sgblack@eecs.umich.edu        if (resumeSerialize) {
4523788Sgblack@eecs.umich.edu            resumeSerialize = false;
4533788Sgblack@eecs.umich.edu            block(tid);
4543788Sgblack@eecs.umich.edu            toDecode->renameUnblock[tid] = false;
4553788Sgblack@eecs.umich.edu        }
4563798Sgblack@eecs.umich.edu    } else if (renameStatus[tid] == Unblocking) {
4573798Sgblack@eecs.umich.edu        if (resumeUnblocking) {
4583798Sgblack@eecs.umich.edu            block(tid);
4593798Sgblack@eecs.umich.edu            resumeUnblocking = false;
4603798Sgblack@eecs.umich.edu            toDecode->renameUnblock[tid] = false;
4613798Sgblack@eecs.umich.edu        }
4622292SN/A    }
4632292SN/A
4642292SN/A    if (renameStatus[tid] == Running ||
4652292SN/A        renameStatus[tid] == Idle) {
4662292SN/A        DPRINTF(Rename, "[tid:%u]: Not blocked, so attempting to run "
4672292SN/A                "stage.\n", tid);
4682292SN/A
4692292SN/A        renameInsts(tid);
4702292SN/A    } else if (renameStatus[tid] == Unblocking) {
4712292SN/A        renameInsts(tid);
4722292SN/A
4732292SN/A        if (validInsts()) {
4742292SN/A            // Add the current inputs to the skid buffer so they can be
4752292SN/A            // reprocessed when this stage unblocks.
4762292SN/A            skidInsert(tid);
4772292SN/A        }
4782292SN/A
4792292SN/A        // If we switched over to blocking, then there's a potential for
4802292SN/A        // an overall status change.
4812292SN/A        status_change = unblock(tid) || status_change || blockThisCycle;
4821858SN/A    }
4831858SN/A}
4841858SN/A
4851858SN/Atemplate <class Impl>
4861858SN/Avoid
4876221Snate@binkert.orgDefaultRename<Impl>::renameInsts(ThreadID tid)
4881858SN/A{
4892292SN/A    // Instructions can be either in the skid buffer or the queue of
4902292SN/A    // instructions coming from decode, depending on the status.
4912292SN/A    int insts_available = renameStatus[tid] == Unblocking ?
4922292SN/A        skidBuffer[tid].size() : insts[tid].size();
4931858SN/A
4942292SN/A    // Check the decode queue to see if instructions are available.
4952292SN/A    // If there are no available instructions to rename, then do nothing.
4962292SN/A    if (insts_available == 0) {
4972292SN/A        DPRINTF(Rename, "[tid:%u]: Nothing to do, breaking out early.\n",
4982292SN/A                tid);
4992292SN/A        // Should I change status to idle?
5002292SN/A        ++renameIdleCycles;
5012292SN/A        return;
5022292SN/A    } else if (renameStatus[tid] == Unblocking) {
5032292SN/A        ++renameUnblockCycles;
5042292SN/A    } else if (renameStatus[tid] == Running) {
5052292SN/A        ++renameRunCycles;
5062292SN/A    }
5071858SN/A
5082292SN/A    DynInstPtr inst;
5092292SN/A
5102292SN/A    // Will have to do a different calculation for the number of free
5112292SN/A    // entries.
5122292SN/A    int free_rob_entries = calcFreeROBEntries(tid);
5132292SN/A    int free_iq_entries  = calcFreeIQEntries(tid);
5142292SN/A    int free_lsq_entries = calcFreeLSQEntries(tid);
5152292SN/A    int min_free_entries = free_rob_entries;
5162292SN/A
5172292SN/A    FullSource source = ROB;
5182292SN/A
5192292SN/A    if (free_iq_entries < min_free_entries) {
5202292SN/A        min_free_entries = free_iq_entries;
5212292SN/A        source = IQ;
5222292SN/A    }
5232292SN/A
5242292SN/A    if (free_lsq_entries < min_free_entries) {
5252292SN/A        min_free_entries = free_lsq_entries;
5262292SN/A        source = LSQ;
5272292SN/A    }
5282292SN/A
5292292SN/A    // Check if there's any space left.
5302292SN/A    if (min_free_entries <= 0) {
5312292SN/A        DPRINTF(Rename, "[tid:%u]: Blocking due to no free ROB/IQ/LSQ "
5322292SN/A                "entries.\n"
5332292SN/A                "ROB has %i free entries.\n"
5342292SN/A                "IQ has %i free entries.\n"
5352292SN/A                "LSQ has %i free entries.\n",
5362292SN/A                tid,
5372292SN/A                free_rob_entries,
5382292SN/A                free_iq_entries,
5392292SN/A                free_lsq_entries);
5402292SN/A
5412292SN/A        blockThisCycle = true;
5422292SN/A
5432292SN/A        block(tid);
5442292SN/A
5452292SN/A        incrFullStat(source);
5462292SN/A
5472292SN/A        return;
5482292SN/A    } else if (min_free_entries < insts_available) {
5492292SN/A        DPRINTF(Rename, "[tid:%u]: Will have to block this cycle."
5502292SN/A                "%i insts available, but only %i insts can be "
5512292SN/A                "renamed due to ROB/IQ/LSQ limits.\n",
5522292SN/A                tid, insts_available, min_free_entries);
5532292SN/A
5542292SN/A        insts_available = min_free_entries;
5552292SN/A
5562292SN/A        blockThisCycle = true;
5572292SN/A
5582292SN/A        incrFullStat(source);
5592292SN/A    }
5602292SN/A
5612292SN/A    InstQueue &insts_to_rename = renameStatus[tid] == Unblocking ?
5622292SN/A        skidBuffer[tid] : insts[tid];
5632292SN/A
5642292SN/A    DPRINTF(Rename, "[tid:%u]: %i available instructions to "
5652292SN/A            "send iew.\n", tid, insts_available);
5662292SN/A
5672292SN/A    DPRINTF(Rename, "[tid:%u]: %i insts pipelining from Rename | %i insts "
5682292SN/A            "dispatched to IQ last cycle.\n",
5692292SN/A            tid, instsInProgress[tid], fromIEW->iewInfo[tid].dispatched);
5702292SN/A
5712292SN/A    // Handle serializing the next instruction if necessary.
5722292SN/A    if (serializeOnNextInst[tid]) {
5732292SN/A        if (emptyROB[tid] && instsInProgress[tid] == 0) {
5742292SN/A            // ROB already empty; no need to serialize.
5752292SN/A            serializeOnNextInst[tid] = false;
5762292SN/A        } else if (!insts_to_rename.empty()) {
5772292SN/A            insts_to_rename.front()->setSerializeBefore();
5782292SN/A        }
5792292SN/A    }
5802292SN/A
5812292SN/A    int renamed_insts = 0;
5822292SN/A
5832292SN/A    while (insts_available > 0 &&  toIEWIndex < renameWidth) {
5842292SN/A        DPRINTF(Rename, "[tid:%u]: Sending instructions to IEW.\n", tid);
5852292SN/A
5862292SN/A        assert(!insts_to_rename.empty());
5872292SN/A
5882292SN/A        inst = insts_to_rename.front();
5892292SN/A
5902292SN/A        insts_to_rename.pop_front();
5912292SN/A
5922292SN/A        if (renameStatus[tid] == Unblocking) {
5932292SN/A            DPRINTF(Rename,"[tid:%u]: Removing [sn:%lli] PC:%#x from rename "
5942292SN/A                    "skidBuffer\n",
5952292SN/A                    tid, inst->seqNum, inst->readPC());
5962292SN/A        }
5972292SN/A
5982292SN/A        if (inst->isSquashed()) {
5992292SN/A            DPRINTF(Rename, "[tid:%u]: instruction %i with PC %#x is "
6002292SN/A                    "squashed, skipping.\n",
6012935Sksewell@umich.edu                    tid, inst->seqNum, inst->readPC());
6022292SN/A
6032292SN/A            ++renameSquashedInsts;
6042292SN/A
6052292SN/A            // Decrement how many instructions are available.
6062292SN/A            --insts_available;
6072292SN/A
6082292SN/A            continue;
6092292SN/A        }
6102292SN/A
6112292SN/A        DPRINTF(Rename, "[tid:%u]: Processing instruction [sn:%lli] with "
6122292SN/A                "PC %#x.\n",
6132292SN/A                tid, inst->seqNum, inst->readPC());
6142292SN/A
6152292SN/A        // Handle serializeAfter/serializeBefore instructions.
6162292SN/A        // serializeAfter marks the next instruction as serializeBefore.
6172292SN/A        // serializeBefore makes the instruction wait in rename until the ROB
6182292SN/A        // is empty.
6192336SN/A
6202336SN/A        // In this model, IPR accesses are serialize before
6212336SN/A        // instructions, and store conditionals are serialize after
6222336SN/A        // instructions.  This is mainly due to lack of support for
6232336SN/A        // out-of-order operations of either of those classes of
6242336SN/A        // instructions.
6252336SN/A        if ((inst->isIprAccess() || inst->isSerializeBefore()) &&
6262336SN/A            !inst->isSerializeHandled()) {
6272292SN/A            DPRINTF(Rename, "Serialize before instruction encountered.\n");
6282292SN/A
6292301SN/A            if (!inst->isTempSerializeBefore()) {
6302301SN/A                renamedSerializing++;
6312292SN/A                inst->setSerializeHandled();
6322301SN/A            } else {
6332301SN/A                renamedTempSerializing++;
6342301SN/A            }
6352292SN/A
6362301SN/A            // Change status over to SerializeStall so that other stages know
6372292SN/A            // what this is blocked on.
6382301SN/A            renameStatus[tid] = SerializeStall;
6392292SN/A
6402301SN/A            serializeInst[tid] = inst;
6412292SN/A
6422292SN/A            blockThisCycle = true;
6432292SN/A
6442292SN/A            break;
6452336SN/A        } else if ((inst->isStoreConditional() || inst->isSerializeAfter()) &&
6462336SN/A                   !inst->isSerializeHandled()) {
6472292SN/A            DPRINTF(Rename, "Serialize after instruction encountered.\n");
6482292SN/A
6492307SN/A            renamedSerializing++;
6502307SN/A
6512292SN/A            inst->setSerializeHandled();
6522292SN/A
6532292SN/A            serializeAfter(insts_to_rename, tid);
6542292SN/A        }
6552292SN/A
6562292SN/A        // Check here to make sure there are enough destination registers
6572292SN/A        // to rename to.  Otherwise block.
6582292SN/A        if (renameMap[tid]->numFreeEntries() < inst->numDestRegs()) {
6592292SN/A            DPRINTF(Rename, "Blocking due to lack of free "
6602292SN/A                    "physical registers to rename to.\n");
6612292SN/A            blockThisCycle = true;
6624345Sktlim@umich.edu            insts_to_rename.push_front(inst);
6632292SN/A            ++renameFullRegistersEvents;
6642292SN/A
6652292SN/A            break;
6662292SN/A        }
6672292SN/A
6682292SN/A        renameSrcRegs(inst, inst->threadNumber);
6692292SN/A
6702292SN/A        renameDestRegs(inst, inst->threadNumber);
6712292SN/A
6722292SN/A        ++renamed_insts;
6732292SN/A
6742292SN/A        // Put instruction in rename queue.
6752292SN/A        toIEW->insts[toIEWIndex] = inst;
6762292SN/A        ++(toIEW->size);
6772292SN/A
6782292SN/A        // Increment which instruction we're on.
6792292SN/A        ++toIEWIndex;
6802292SN/A
6812292SN/A        // Decrement how many instructions are available.
6822292SN/A        --insts_available;
6832292SN/A    }
6842292SN/A
6852292SN/A    instsInProgress[tid] += renamed_insts;
6862307SN/A    renameRenamedInsts += renamed_insts;
6872292SN/A
6882292SN/A    // If we wrote to the time buffer, record this.
6892292SN/A    if (toIEWIndex) {
6902292SN/A        wroteToTimeBuffer = true;
6912292SN/A    }
6922292SN/A
6932292SN/A    // Check if there's any instructions left that haven't yet been renamed.
6942292SN/A    // If so then block.
6952292SN/A    if (insts_available) {
6962292SN/A        blockThisCycle = true;
6972292SN/A    }
6982292SN/A
6992292SN/A    if (blockThisCycle) {
7002292SN/A        block(tid);
7012292SN/A        toDecode->renameUnblock[tid] = false;
7022292SN/A    }
7032292SN/A}
7042292SN/A
7052292SN/Atemplate<class Impl>
7062292SN/Avoid
7076221Snate@binkert.orgDefaultRename<Impl>::skidInsert(ThreadID tid)
7082292SN/A{
7092292SN/A    DynInstPtr inst = NULL;
7102292SN/A
7112292SN/A    while (!insts[tid].empty()) {
7122292SN/A        inst = insts[tid].front();
7132292SN/A
7142292SN/A        insts[tid].pop_front();
7152292SN/A
7162292SN/A        assert(tid == inst->threadNumber);
7172292SN/A
7182292SN/A        DPRINTF(Rename, "[tid:%u]: Inserting [sn:%lli] PC:%#x into Rename "
7192292SN/A                "skidBuffer\n", tid, inst->seqNum, inst->readPC());
7202292SN/A
7212307SN/A        ++renameSkidInsts;
7222307SN/A
7232292SN/A        skidBuffer[tid].push_back(inst);
7242292SN/A    }
7252292SN/A
7262292SN/A    if (skidBuffer[tid].size() > skidBufferMax)
7273798Sgblack@eecs.umich.edu    {
7283798Sgblack@eecs.umich.edu        typename InstQueue::iterator it;
7293798Sgblack@eecs.umich.edu        warn("Skidbuffer contents:\n");
7303798Sgblack@eecs.umich.edu        for(it = skidBuffer[tid].begin(); it != skidBuffer[tid].end(); it++)
7313798Sgblack@eecs.umich.edu        {
7323798Sgblack@eecs.umich.edu            warn("[tid:%u]: %s [sn:%i].\n", tid,
7333798Sgblack@eecs.umich.edu                    (*it)->staticInst->disassemble(inst->readPC()),
7343798Sgblack@eecs.umich.edu                    (*it)->seqNum);
7353798Sgblack@eecs.umich.edu        }
7362292SN/A        panic("Skidbuffer Exceeded Max Size");
7373798Sgblack@eecs.umich.edu    }
7382292SN/A}
7392292SN/A
7402292SN/Atemplate <class Impl>
7412292SN/Avoid
7422292SN/ADefaultRename<Impl>::sortInsts()
7432292SN/A{
7442292SN/A    int insts_from_decode = fromDecode->size;
7452329SN/A#ifdef DEBUG
7466221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++)
7476221Snate@binkert.org        assert(insts[tid].empty());
7482329SN/A#endif
7492292SN/A    for (int i = 0; i < insts_from_decode; ++i) {
7502292SN/A        DynInstPtr inst = fromDecode->insts[i];
7512292SN/A        insts[inst->threadNumber].push_back(inst);
7522292SN/A    }
7532292SN/A}
7542292SN/A
7552292SN/Atemplate<class Impl>
7562292SN/Abool
7572292SN/ADefaultRename<Impl>::skidsEmpty()
7582292SN/A{
7596221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
7606221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
7612292SN/A
7623867Sbinkertn@umich.edu    while (threads != end) {
7636221Snate@binkert.org        ThreadID tid = *threads++;
7643867Sbinkertn@umich.edu
7653867Sbinkertn@umich.edu        if (!skidBuffer[tid].empty())
7662292SN/A            return false;
7672292SN/A    }
7682292SN/A
7692292SN/A    return true;
7702292SN/A}
7712292SN/A
7722292SN/Atemplate<class Impl>
7732292SN/Avoid
7742292SN/ADefaultRename<Impl>::updateStatus()
7752292SN/A{
7762292SN/A    bool any_unblocking = false;
7772292SN/A
7786221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
7796221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
7802292SN/A
7813867Sbinkertn@umich.edu    while (threads != end) {
7826221Snate@binkert.org        ThreadID tid = *threads++;
7832292SN/A
7842292SN/A        if (renameStatus[tid] == Unblocking) {
7852292SN/A            any_unblocking = true;
7862292SN/A            break;
7872292SN/A        }
7882292SN/A    }
7892292SN/A
7902292SN/A    // Rename will have activity if it's unblocking.
7912292SN/A    if (any_unblocking) {
7922292SN/A        if (_status == Inactive) {
7932292SN/A            _status = Active;
7942292SN/A
7952292SN/A            DPRINTF(Activity, "Activating stage.\n");
7962292SN/A
7972733Sktlim@umich.edu            cpu->activateStage(O3CPU::RenameIdx);
7982292SN/A        }
7992292SN/A    } else {
8002292SN/A        // If it's not unblocking, then rename will not have any internal
8012292SN/A        // activity.  Switch it to inactive.
8022292SN/A        if (_status == Active) {
8032292SN/A            _status = Inactive;
8042292SN/A            DPRINTF(Activity, "Deactivating stage.\n");
8052292SN/A
8062733Sktlim@umich.edu            cpu->deactivateStage(O3CPU::RenameIdx);
8072292SN/A        }
8082292SN/A    }
8092292SN/A}
8102292SN/A
8112292SN/Atemplate <class Impl>
8122292SN/Abool
8136221Snate@binkert.orgDefaultRename<Impl>::block(ThreadID tid)
8142292SN/A{
8152292SN/A    DPRINTF(Rename, "[tid:%u]: Blocking.\n", tid);
8162292SN/A
8172292SN/A    // Add the current inputs onto the skid buffer, so they can be
8182292SN/A    // reprocessed when this stage unblocks.
8192292SN/A    skidInsert(tid);
8202292SN/A
8212292SN/A    // Only signal backwards to block if the previous stages do not think
8222292SN/A    // rename is already blocked.
8232292SN/A    if (renameStatus[tid] != Blocked) {
8243798Sgblack@eecs.umich.edu        // If resumeUnblocking is set, we unblocked during the squash,
8253798Sgblack@eecs.umich.edu        // but now we're have unblocking status. We need to tell earlier
8263798Sgblack@eecs.umich.edu        // stages to block.
8273798Sgblack@eecs.umich.edu        if (resumeUnblocking || renameStatus[tid] != Unblocking) {
8282292SN/A            toDecode->renameBlock[tid] = true;
8292292SN/A            toDecode->renameUnblock[tid] = false;
8302292SN/A            wroteToTimeBuffer = true;
8312292SN/A        }
8322292SN/A
8332329SN/A        // Rename can not go from SerializeStall to Blocked, otherwise
8342329SN/A        // it would not know to complete the serialize stall.
8352301SN/A        if (renameStatus[tid] != SerializeStall) {
8362292SN/A            // Set status to Blocked.
8372292SN/A            renameStatus[tid] = Blocked;
8382292SN/A            return true;
8392292SN/A        }
8402292SN/A    }
8412292SN/A
8422292SN/A    return false;
8432292SN/A}
8442292SN/A
8452292SN/Atemplate <class Impl>
8462292SN/Abool
8476221Snate@binkert.orgDefaultRename<Impl>::unblock(ThreadID tid)
8482292SN/A{
8492292SN/A    DPRINTF(Rename, "[tid:%u]: Trying to unblock.\n", tid);
8502292SN/A
8512292SN/A    // Rename is done unblocking if the skid buffer is empty.
8522301SN/A    if (skidBuffer[tid].empty() && renameStatus[tid] != SerializeStall) {
8532292SN/A
8542292SN/A        DPRINTF(Rename, "[tid:%u]: Done unblocking.\n", tid);
8552292SN/A
8562292SN/A        toDecode->renameUnblock[tid] = true;
8572292SN/A        wroteToTimeBuffer = true;
8582292SN/A
8592292SN/A        renameStatus[tid] = Running;
8602292SN/A        return true;
8612292SN/A    }
8622292SN/A
8632292SN/A    return false;
8642292SN/A}
8652292SN/A
8662292SN/Atemplate <class Impl>
8672292SN/Avoid
8686221Snate@binkert.orgDefaultRename<Impl>::doSquash(const InstSeqNum &squashed_seq_num, ThreadID tid)
8692292SN/A{
8702980Sgblack@eecs.umich.edu    typename std::list<RenameHistory>::iterator hb_it =
8712980Sgblack@eecs.umich.edu        historyBuffer[tid].begin();
8722292SN/A
8731060SN/A    // After a syscall squashes everything, the history buffer may be empty
8741060SN/A    // but the ROB may still be squashing instructions.
8752292SN/A    if (historyBuffer[tid].empty()) {
8761060SN/A        return;
8771060SN/A    }
8781060SN/A
8791060SN/A    // Go through the most recent instructions, undoing the mappings
8801060SN/A    // they did and freeing up the registers.
8812292SN/A    while (!historyBuffer[tid].empty() &&
8822292SN/A           (*hb_it).instSeqNum > squashed_seq_num) {
8832292SN/A        assert(hb_it != historyBuffer[tid].end());
8841062SN/A
8852292SN/A        DPRINTF(Rename, "[tid:%u]: Removing history entry with sequence "
8862292SN/A                "number %i.\n", tid, (*hb_it).instSeqNum);
8871060SN/A
8882292SN/A        // Tell the rename map to set the architected register to the
8892292SN/A        // previous physical register that it was renamed to.
8902292SN/A        renameMap[tid]->setEntry(hb_it->archReg, hb_it->prevPhysReg);
8911060SN/A
8922292SN/A        // Put the renamed physical register back on the free list.
8932292SN/A        freeList->addReg(hb_it->newPhysReg);
8941062SN/A
8952367SN/A        // Be sure to mark its register as ready if it's a misc register.
8962367SN/A        if (hb_it->newPhysReg >= maxPhysicalRegs) {
8972367SN/A            scoreboard->setReg(hb_it->newPhysReg);
8982367SN/A        }
8992367SN/A
9002292SN/A        historyBuffer[tid].erase(hb_it++);
9011061SN/A
9021062SN/A        ++renameUndoneMaps;
9031060SN/A    }
9041060SN/A}
9051060SN/A
9061060SN/Atemplate<class Impl>
9071060SN/Avoid
9086221Snate@binkert.orgDefaultRename<Impl>::removeFromHistory(InstSeqNum inst_seq_num, ThreadID tid)
9091060SN/A{
9102292SN/A    DPRINTF(Rename, "[tid:%u]: Removing a committed instruction from the "
9112292SN/A            "history buffer %u (size=%i), until [sn:%lli].\n",
9122292SN/A            tid, tid, historyBuffer[tid].size(), inst_seq_num);
9132292SN/A
9142980Sgblack@eecs.umich.edu    typename std::list<RenameHistory>::iterator hb_it =
9152980Sgblack@eecs.umich.edu        historyBuffer[tid].end();
9161060SN/A
9171061SN/A    --hb_it;
9181060SN/A
9192292SN/A    if (historyBuffer[tid].empty()) {
9202292SN/A        DPRINTF(Rename, "[tid:%u]: History buffer is empty.\n", tid);
9212292SN/A        return;
9222292SN/A    } else if (hb_it->instSeqNum > inst_seq_num) {
9232292SN/A        DPRINTF(Rename, "[tid:%u]: Old sequence number encountered.  Ensure "
9242292SN/A                "that a syscall happened recently.\n", tid);
9251060SN/A        return;
9261060SN/A    }
9271060SN/A
9282292SN/A    // Commit all the renames up until (and including) the committed sequence
9292292SN/A    // number. Some or even all of the committed instructions may not have
9302292SN/A    // rename histories if they did not have destination registers that were
9312292SN/A    // renamed.
9322292SN/A    while (!historyBuffer[tid].empty() &&
9332292SN/A           hb_it != historyBuffer[tid].end() &&
9342292SN/A           (*hb_it).instSeqNum <= inst_seq_num) {
9351060SN/A
9362329SN/A        DPRINTF(Rename, "[tid:%u]: Freeing up older rename of reg %i, "
9372329SN/A                "[sn:%lli].\n",
9382292SN/A                tid, (*hb_it).prevPhysReg, (*hb_it).instSeqNum);
9391061SN/A
9402292SN/A        freeList->addReg((*hb_it).prevPhysReg);
9412292SN/A        ++renameCommittedMaps;
9421061SN/A
9432292SN/A        historyBuffer[tid].erase(hb_it--);
9441060SN/A    }
9451060SN/A}
9461060SN/A
9471061SN/Atemplate <class Impl>
9481061SN/Ainline void
9496221Snate@binkert.orgDefaultRename<Impl>::renameSrcRegs(DynInstPtr &inst, ThreadID tid)
9501061SN/A{
9512292SN/A    assert(renameMap[tid] != 0);
9522292SN/A
9531061SN/A    unsigned num_src_regs = inst->numSrcRegs();
9541061SN/A
9551061SN/A    // Get the architectual register numbers from the source and
9561061SN/A    // destination operands, and redirect them to the right register.
9571061SN/A    // Will need to mark dependencies though.
9582292SN/A    for (int src_idx = 0; src_idx < num_src_regs; src_idx++) {
9591061SN/A        RegIndex src_reg = inst->srcRegIdx(src_idx);
9603773Sgblack@eecs.umich.edu        RegIndex flat_src_reg = src_reg;
9613773Sgblack@eecs.umich.edu        if (src_reg < TheISA::FP_Base_DepTag) {
9626313Sgblack@eecs.umich.edu            flat_src_reg = inst->tcBase()->flattenIntIndex(src_reg);
9633773Sgblack@eecs.umich.edu            DPRINTF(Rename, "Flattening index %d to %d.\n", (int)src_reg, (int)flat_src_reg);
9645082Sgblack@eecs.umich.edu        } else if (src_reg < TheISA::Ctrl_Base_DepTag) {
9655082Sgblack@eecs.umich.edu            src_reg = src_reg - TheISA::FP_Base_DepTag;
9666313Sgblack@eecs.umich.edu            flat_src_reg = inst->tcBase()->flattenFloatIndex(src_reg);
9675082Sgblack@eecs.umich.edu            flat_src_reg += TheISA::NumIntRegs;
9684352Sgblack@eecs.umich.edu        } else {
9694352Sgblack@eecs.umich.edu            flat_src_reg = src_reg - TheISA::FP_Base_DepTag + TheISA::NumIntRegs;
9704636Sgblack@eecs.umich.edu            DPRINTF(Rename, "Adjusting reg index from %d to %d.\n", src_reg, flat_src_reg);
9713773Sgblack@eecs.umich.edu        }
9724352Sgblack@eecs.umich.edu
9733773Sgblack@eecs.umich.edu        inst->flattenSrcReg(src_idx, flat_src_reg);
9741061SN/A
9751061SN/A        // Look up the source registers to get the phys. register they've
9761061SN/A        // been renamed to, and set the sources to those registers.
9773773Sgblack@eecs.umich.edu        PhysRegIndex renamed_reg = renameMap[tid]->lookup(flat_src_reg);
9781061SN/A
9792292SN/A        DPRINTF(Rename, "[tid:%u]: Looking up arch reg %i, got "
9803773Sgblack@eecs.umich.edu                "physical reg %i.\n", tid, (int)flat_src_reg,
9812292SN/A                (int)renamed_reg);
9821061SN/A
9831061SN/A        inst->renameSrcReg(src_idx, renamed_reg);
9841061SN/A
9852292SN/A        // See if the register is ready or not.
9862292SN/A        if (scoreboard->getReg(renamed_reg) == true) {
9874636Sgblack@eecs.umich.edu            DPRINTF(Rename, "[tid:%u]: Register %d is ready.\n", tid, renamed_reg);
9881061SN/A
9891061SN/A            inst->markSrcRegReady(src_idx);
9904636Sgblack@eecs.umich.edu        } else {
9914636Sgblack@eecs.umich.edu            DPRINTF(Rename, "[tid:%u]: Register %d is not ready.\n", tid, renamed_reg);
9921061SN/A        }
9931062SN/A
9941062SN/A        ++renameRenameLookups;
9951061SN/A    }
9961061SN/A}
9971061SN/A
9981061SN/Atemplate <class Impl>
9991061SN/Ainline void
10006221Snate@binkert.orgDefaultRename<Impl>::renameDestRegs(DynInstPtr &inst, ThreadID tid)
10011061SN/A{
10022292SN/A    typename RenameMap::RenameInfo rename_result;
10031061SN/A
10041061SN/A    unsigned num_dest_regs = inst->numDestRegs();
10051061SN/A
10062292SN/A    // Rename the destination registers.
10072292SN/A    for (int dest_idx = 0; dest_idx < num_dest_regs; dest_idx++) {
10082292SN/A        RegIndex dest_reg = inst->destRegIdx(dest_idx);
10093773Sgblack@eecs.umich.edu        RegIndex flat_dest_reg = dest_reg;
10103773Sgblack@eecs.umich.edu        if (dest_reg < TheISA::FP_Base_DepTag) {
10114352Sgblack@eecs.umich.edu            // Integer registers are flattened.
10126313Sgblack@eecs.umich.edu            flat_dest_reg = inst->tcBase()->flattenIntIndex(dest_reg);
10133773Sgblack@eecs.umich.edu            DPRINTF(Rename, "Flattening index %d to %d.\n", (int)dest_reg, (int)flat_dest_reg);
10144352Sgblack@eecs.umich.edu        } else {
10154352Sgblack@eecs.umich.edu            // Floating point and Miscellaneous registers need their indexes
10164352Sgblack@eecs.umich.edu            // adjusted to account for the expanded number of flattened int regs.
10174352Sgblack@eecs.umich.edu            flat_dest_reg = dest_reg - TheISA::FP_Base_DepTag + TheISA::NumIntRegs;
10184636Sgblack@eecs.umich.edu            DPRINTF(Rename, "Adjusting reg index from %d to %d.\n", dest_reg, flat_dest_reg);
10193773Sgblack@eecs.umich.edu        }
10203773Sgblack@eecs.umich.edu
10213773Sgblack@eecs.umich.edu        inst->flattenDestReg(dest_idx, flat_dest_reg);
10221061SN/A
10232292SN/A        // Get the physical register that the destination will be
10242292SN/A        // renamed to.
10253773Sgblack@eecs.umich.edu        rename_result = renameMap[tid]->rename(flat_dest_reg);
10261061SN/A
10272292SN/A        //Mark Scoreboard entry as not ready
10282292SN/A        scoreboard->unsetReg(rename_result.first);
10291062SN/A
10302292SN/A        DPRINTF(Rename, "[tid:%u]: Renaming arch reg %i to physical "
10313773Sgblack@eecs.umich.edu                "reg %i.\n", tid, (int)flat_dest_reg,
10322292SN/A                (int)rename_result.first);
10331062SN/A
10342292SN/A        // Record the rename information so that a history can be kept.
10353773Sgblack@eecs.umich.edu        RenameHistory hb_entry(inst->seqNum, flat_dest_reg,
10362292SN/A                               rename_result.first,
10372292SN/A                               rename_result.second);
10381062SN/A
10392292SN/A        historyBuffer[tid].push_front(hb_entry);
10401062SN/A
10412935Sksewell@umich.edu        DPRINTF(Rename, "[tid:%u]: Adding instruction to history buffer "
10422935Sksewell@umich.edu                "(size=%i), [sn:%lli].\n",tid,
10432935Sksewell@umich.edu                historyBuffer[tid].size(),
10442292SN/A                (*historyBuffer[tid].begin()).instSeqNum);
10451062SN/A
10462292SN/A        // Tell the instruction to rename the appropriate destination
10472292SN/A        // register (dest_idx) to the new physical register
10482292SN/A        // (rename_result.first), and record the previous physical
10492292SN/A        // register that the same logical register was renamed to
10502292SN/A        // (rename_result.second).
10512292SN/A        inst->renameDestReg(dest_idx,
10522292SN/A                            rename_result.first,
10532292SN/A                            rename_result.second);
10541062SN/A
10552292SN/A        ++renameRenamedOperands;
10561061SN/A    }
10571061SN/A}
10581061SN/A
10591061SN/Atemplate <class Impl>
10601061SN/Ainline int
10616221Snate@binkert.orgDefaultRename<Impl>::calcFreeROBEntries(ThreadID tid)
10621061SN/A{
10632292SN/A    int num_free = freeEntries[tid].robEntries -
10642292SN/A                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
10652292SN/A
10662292SN/A    //DPRINTF(Rename,"[tid:%i]: %i rob free\n",tid,num_free);
10672292SN/A
10682292SN/A    return num_free;
10691061SN/A}
10701061SN/A
10711061SN/Atemplate <class Impl>
10721061SN/Ainline int
10736221Snate@binkert.orgDefaultRename<Impl>::calcFreeIQEntries(ThreadID tid)
10741061SN/A{
10752292SN/A    int num_free = freeEntries[tid].iqEntries -
10762292SN/A                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
10772292SN/A
10782292SN/A    //DPRINTF(Rename,"[tid:%i]: %i iq free\n",tid,num_free);
10792292SN/A
10802292SN/A    return num_free;
10812292SN/A}
10822292SN/A
10832292SN/Atemplate <class Impl>
10842292SN/Ainline int
10856221Snate@binkert.orgDefaultRename<Impl>::calcFreeLSQEntries(ThreadID tid)
10862292SN/A{
10872292SN/A    int num_free = freeEntries[tid].lsqEntries -
10882292SN/A                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatchedToLSQ);
10892292SN/A
10902292SN/A    //DPRINTF(Rename,"[tid:%i]: %i lsq free\n",tid,num_free);
10912292SN/A
10922292SN/A    return num_free;
10932292SN/A}
10942292SN/A
10952292SN/Atemplate <class Impl>
10962292SN/Aunsigned
10972292SN/ADefaultRename<Impl>::validInsts()
10982292SN/A{
10992292SN/A    unsigned inst_count = 0;
11002292SN/A
11012292SN/A    for (int i=0; i<fromDecode->size; i++) {
11022731Sktlim@umich.edu        if (!fromDecode->insts[i]->isSquashed())
11032292SN/A            inst_count++;
11042292SN/A    }
11052292SN/A
11062292SN/A    return inst_count;
11072292SN/A}
11082292SN/A
11092292SN/Atemplate <class Impl>
11102292SN/Avoid
11116221Snate@binkert.orgDefaultRename<Impl>::readStallSignals(ThreadID tid)
11122292SN/A{
11132292SN/A    if (fromIEW->iewBlock[tid]) {
11142292SN/A        stalls[tid].iew = true;
11152292SN/A    }
11162292SN/A
11172292SN/A    if (fromIEW->iewUnblock[tid]) {
11182292SN/A        assert(stalls[tid].iew);
11192292SN/A        stalls[tid].iew = false;
11202292SN/A    }
11212292SN/A
11222292SN/A    if (fromCommit->commitBlock[tid]) {
11232292SN/A        stalls[tid].commit = true;
11242292SN/A    }
11252292SN/A
11262292SN/A    if (fromCommit->commitUnblock[tid]) {
11272292SN/A        assert(stalls[tid].commit);
11282292SN/A        stalls[tid].commit = false;
11292292SN/A    }
11302292SN/A}
11312292SN/A
11322292SN/Atemplate <class Impl>
11332292SN/Abool
11346221Snate@binkert.orgDefaultRename<Impl>::checkStall(ThreadID tid)
11352292SN/A{
11362292SN/A    bool ret_val = false;
11372292SN/A
11382292SN/A    if (stalls[tid].iew) {
11392292SN/A        DPRINTF(Rename,"[tid:%i]: Stall from IEW stage detected.\n", tid);
11402292SN/A        ret_val = true;
11412292SN/A    } else if (stalls[tid].commit) {
11422292SN/A        DPRINTF(Rename,"[tid:%i]: Stall from Commit stage detected.\n", tid);
11432292SN/A        ret_val = true;
11442292SN/A    } else if (calcFreeROBEntries(tid) <= 0) {
11452292SN/A        DPRINTF(Rename,"[tid:%i]: Stall: ROB has 0 free entries.\n", tid);
11462292SN/A        ret_val = true;
11472292SN/A    } else if (calcFreeIQEntries(tid) <= 0) {
11482292SN/A        DPRINTF(Rename,"[tid:%i]: Stall: IQ has 0 free entries.\n", tid);
11492292SN/A        ret_val = true;
11502292SN/A    } else if (calcFreeLSQEntries(tid) <= 0) {
11512292SN/A        DPRINTF(Rename,"[tid:%i]: Stall: LSQ has 0 free entries.\n", tid);
11522292SN/A        ret_val = true;
11532292SN/A    } else if (renameMap[tid]->numFreeEntries() <= 0) {
11542292SN/A        DPRINTF(Rename,"[tid:%i]: Stall: RenameMap has 0 free entries.\n", tid);
11552292SN/A        ret_val = true;
11562301SN/A    } else if (renameStatus[tid] == SerializeStall &&
11572292SN/A               (!emptyROB[tid] || instsInProgress[tid])) {
11582301SN/A        DPRINTF(Rename,"[tid:%i]: Stall: Serialize stall and ROB is not "
11592292SN/A                "empty.\n",
11602292SN/A                tid);
11612292SN/A        ret_val = true;
11622292SN/A    }
11632292SN/A
11642292SN/A    return ret_val;
11652292SN/A}
11662292SN/A
11672292SN/Atemplate <class Impl>
11682292SN/Avoid
11696221Snate@binkert.orgDefaultRename<Impl>::readFreeEntries(ThreadID tid)
11702292SN/A{
11712292SN/A    bool updated = false;
11722292SN/A    if (fromIEW->iewInfo[tid].usedIQ) {
11732292SN/A        freeEntries[tid].iqEntries =
11742292SN/A            fromIEW->iewInfo[tid].freeIQEntries;
11752292SN/A        updated = true;
11762292SN/A    }
11772292SN/A
11782292SN/A    if (fromIEW->iewInfo[tid].usedLSQ) {
11792292SN/A        freeEntries[tid].lsqEntries =
11802292SN/A            fromIEW->iewInfo[tid].freeLSQEntries;
11812292SN/A        updated = true;
11822292SN/A    }
11832292SN/A
11842292SN/A    if (fromCommit->commitInfo[tid].usedROB) {
11852292SN/A        freeEntries[tid].robEntries =
11862292SN/A            fromCommit->commitInfo[tid].freeROBEntries;
11872292SN/A        emptyROB[tid] = fromCommit->commitInfo[tid].emptyROB;
11882292SN/A        updated = true;
11892292SN/A    }
11902292SN/A
11912292SN/A    DPRINTF(Rename, "[tid:%i]: Free IQ: %i, Free ROB: %i, Free LSQ: %i\n",
11922292SN/A            tid,
11932292SN/A            freeEntries[tid].iqEntries,
11942292SN/A            freeEntries[tid].robEntries,
11952292SN/A            freeEntries[tid].lsqEntries);
11962292SN/A
11972292SN/A    DPRINTF(Rename, "[tid:%i]: %i instructions not yet in ROB\n",
11982292SN/A            tid, instsInProgress[tid]);
11992292SN/A}
12002292SN/A
12012292SN/Atemplate <class Impl>
12022292SN/Abool
12036221Snate@binkert.orgDefaultRename<Impl>::checkSignalsAndUpdate(ThreadID tid)
12042292SN/A{
12052292SN/A    // Check if there's a squash signal, squash if there is
12062292SN/A    // Check stall signals, block if necessary.
12072292SN/A    // If status was blocked
12082292SN/A    //     check if stall conditions have passed
12092292SN/A    //         if so then go to unblocking
12102292SN/A    // If status was Squashing
12112292SN/A    //     check if squashing is not high.  Switch to running this cycle.
12122301SN/A    // If status was serialize stall
12132292SN/A    //     check if ROB is empty and no insts are in flight to the ROB
12142292SN/A
12152292SN/A    readFreeEntries(tid);
12162292SN/A    readStallSignals(tid);
12172292SN/A
12182292SN/A    if (fromCommit->commitInfo[tid].squash) {
12192292SN/A        DPRINTF(Rename, "[tid:%u]: Squashing instructions due to squash from "
12202292SN/A                "commit.\n", tid);
12212292SN/A
12224632Sgblack@eecs.umich.edu        squash(fromCommit->commitInfo[tid].doneSeqNum, tid);
12232292SN/A
12242292SN/A        return true;
12252292SN/A    }
12262292SN/A
12272292SN/A    if (fromCommit->commitInfo[tid].robSquashing) {
12282292SN/A        DPRINTF(Rename, "[tid:%u]: ROB is still squashing.\n", tid);
12292292SN/A
12302292SN/A        renameStatus[tid] = Squashing;
12312292SN/A
12322292SN/A        return true;
12332292SN/A    }
12342292SN/A
12352292SN/A    if (checkStall(tid)) {
12362292SN/A        return block(tid);
12372292SN/A    }
12382292SN/A
12392292SN/A    if (renameStatus[tid] == Blocked) {
12402292SN/A        DPRINTF(Rename, "[tid:%u]: Done blocking, switching to unblocking.\n",
12412292SN/A                tid);
12422292SN/A
12432292SN/A        renameStatus[tid] = Unblocking;
12442292SN/A
12452292SN/A        unblock(tid);
12462292SN/A
12472292SN/A        return true;
12482292SN/A    }
12492292SN/A
12502292SN/A    if (renameStatus[tid] == Squashing) {
12512292SN/A        // Switch status to running if rename isn't being told to block or
12522292SN/A        // squash this cycle.
12533798Sgblack@eecs.umich.edu        if (resumeSerialize) {
12543798Sgblack@eecs.umich.edu            DPRINTF(Rename, "[tid:%u]: Done squashing, switching to serialize.\n",
12553798Sgblack@eecs.umich.edu                    tid);
12562292SN/A
12573798Sgblack@eecs.umich.edu            renameStatus[tid] = SerializeStall;
12583798Sgblack@eecs.umich.edu            return true;
12593798Sgblack@eecs.umich.edu        } else if (resumeUnblocking) {
12603798Sgblack@eecs.umich.edu            DPRINTF(Rename, "[tid:%u]: Done squashing, switching to unblocking.\n",
12613798Sgblack@eecs.umich.edu                    tid);
12623798Sgblack@eecs.umich.edu            renameStatus[tid] = Unblocking;
12633798Sgblack@eecs.umich.edu            return true;
12643798Sgblack@eecs.umich.edu        } else {
12653788Sgblack@eecs.umich.edu            DPRINTF(Rename, "[tid:%u]: Done squashing, switching to running.\n",
12663788Sgblack@eecs.umich.edu                    tid);
12672292SN/A
12683788Sgblack@eecs.umich.edu            renameStatus[tid] = Running;
12693788Sgblack@eecs.umich.edu            return false;
12703788Sgblack@eecs.umich.edu        }
12712292SN/A    }
12722292SN/A
12732301SN/A    if (renameStatus[tid] == SerializeStall) {
12742292SN/A        // Stall ends once the ROB is free.
12752301SN/A        DPRINTF(Rename, "[tid:%u]: Done with serialize stall, switching to "
12762292SN/A                "unblocking.\n", tid);
12772292SN/A
12782301SN/A        DynInstPtr serial_inst = serializeInst[tid];
12792292SN/A
12802292SN/A        renameStatus[tid] = Unblocking;
12812292SN/A
12822292SN/A        unblock(tid);
12832292SN/A
12842292SN/A        DPRINTF(Rename, "[tid:%u]: Processing instruction [%lli] with "
12852292SN/A                "PC %#x.\n",
12862301SN/A                tid, serial_inst->seqNum, serial_inst->readPC());
12872292SN/A
12882292SN/A        // Put instruction into queue here.
12892301SN/A        serial_inst->clearSerializeBefore();
12902292SN/A
12912292SN/A        if (!skidBuffer[tid].empty()) {
12922301SN/A            skidBuffer[tid].push_front(serial_inst);
12932292SN/A        } else {
12942301SN/A            insts[tid].push_front(serial_inst);
12952292SN/A        }
12962292SN/A
12972292SN/A        DPRINTF(Rename, "[tid:%u]: Instruction must be processed by rename."
12982703Sktlim@umich.edu                " Adding to front of list.\n", tid);
12992292SN/A
13002301SN/A        serializeInst[tid] = NULL;
13012292SN/A
13022292SN/A        return true;
13032292SN/A    }
13042292SN/A
13052292SN/A    // If we've reached this point, we have not gotten any signals that
13062292SN/A    // cause rename to change its status.  Rename remains the same as before.
13072292SN/A    return false;
13081061SN/A}
13091061SN/A
13101060SN/Atemplate<class Impl>
13111060SN/Avoid
13126221Snate@binkert.orgDefaultRename<Impl>::serializeAfter(InstQueue &inst_list, ThreadID tid)
13131060SN/A{
13142292SN/A    if (inst_list.empty()) {
13152292SN/A        // Mark a bit to say that I must serialize on the next instruction.
13162292SN/A        serializeOnNextInst[tid] = true;
13171060SN/A        return;
13181060SN/A    }
13191060SN/A
13202292SN/A    // Set the next instruction as serializing.
13212292SN/A    inst_list.front()->setSerializeBefore();
13222292SN/A}
13232292SN/A
13242292SN/Atemplate <class Impl>
13252292SN/Ainline void
13262292SN/ADefaultRename<Impl>::incrFullStat(const FullSource &source)
13272292SN/A{
13282292SN/A    switch (source) {
13292292SN/A      case ROB:
13302292SN/A        ++renameROBFullEvents;
13312292SN/A        break;
13322292SN/A      case IQ:
13332292SN/A        ++renameIQFullEvents;
13342292SN/A        break;
13352292SN/A      case LSQ:
13362292SN/A        ++renameLSQFullEvents;
13372292SN/A        break;
13382292SN/A      default:
13392292SN/A        panic("Rename full stall stat should be incremented for a reason!");
13402292SN/A        break;
13411060SN/A    }
13422292SN/A}
13431060SN/A
13442292SN/Atemplate <class Impl>
13452292SN/Avoid
13462292SN/ADefaultRename<Impl>::dumpHistory()
13472292SN/A{
13482980Sgblack@eecs.umich.edu    typename std::list<RenameHistory>::iterator buf_it;
13491060SN/A
13506221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
13511060SN/A
13526221Snate@binkert.org        buf_it = historyBuffer[tid].begin();
13531060SN/A
13546221Snate@binkert.org        while (buf_it != historyBuffer[tid].end()) {
13552292SN/A            cprintf("Seq num: %i\nArch reg: %i New phys reg: %i Old phys "
13562292SN/A                    "reg: %i\n", (*buf_it).instSeqNum, (int)(*buf_it).archReg,
13572292SN/A                    (int)(*buf_it).newPhysReg, (int)(*buf_it).prevPhysReg);
13581060SN/A
13592292SN/A            buf_it++;
13601062SN/A        }
13611060SN/A    }
13621060SN/A}
1363