rename_impl.hh revision 2348
11689SN/A/*
212143Sanouk.vanlaer@arm.com * Copyright (c) 2004-2006 The Regents of The University of Michigan
39916Ssteve.reinhardt@amd.com * All rights reserved.
48707Sandreas.hansson@arm.com *
58707Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without
68707Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are
78707Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright
88707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer;
98707Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright
108707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the
118707Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution;
128707Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its
138707Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from
148707Sandreas.hansson@arm.com * this software without specific prior written permission.
152325SN/A *
167897Shestness@cs.utexas.edu * 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.
271689SN/A */
281689SN/A
291689SN/A#include <list>
301689SN/A
311689SN/A#include "config/full_system.hh"
321689SN/A#include "cpu/o3/rename.hh"
331689SN/A
341689SN/Ausing namespace std;
351689SN/A
361689SN/Atemplate <class Impl>
371689SN/ADefaultRename<Impl>::DefaultRename(Params *params)
381689SN/A    : iewToRenameDelay(params->iewToRenameDelay),
391689SN/A      decodeToRenameDelay(params->decodeToRenameDelay),
401689SN/A      commitToRenameDelay(params->commitToRenameDelay),
412665Ssaidi@eecs.umich.edu      renameWidth(params->renameWidth),
422665Ssaidi@eecs.umich.edu      commitWidth(params->commitWidth),
432756Sksewell@umich.edu      numThreads(params->numberOfThreads)
447897Shestness@cs.utexas.edu{
451689SN/A    _status = Inactive;
461689SN/A
4711793Sbrandon.potter@amd.com    for (int i=0; i< numThreads; i++) {
4811793Sbrandon.potter@amd.com        renameStatus[i] = Idle;
4912109SRekai.GonzalezAlberquilla@arm.com
508779Sgblack@eecs.umich.edu        freeEntries[i].iqEntries = 0;
516658Snate@binkert.org        freeEntries[i].lsqEntries = 0;
5211793Sbrandon.potter@amd.com        freeEntries[i].robEntries = 0;
538887Sgeoffrey.blake@arm.com
548887Sgeoffrey.blake@arm.com        stalls[i].iew = false;
558229Snate@binkert.org        stalls[i].commit = false;
568229Snate@binkert.org        serializeInst[i] = NULL;
578779Sgblack@eecs.umich.edu
584762Snate@binkert.org        instsInProgress[i] = 0;
594762Snate@binkert.org
608232Snate@binkert.org        emptyROB[i] = true;
619152Satgutier@umich.edu
628232Snate@binkert.org        serializeOnNextInst[i] = false;
638232Snate@binkert.org    }
644762Snate@binkert.org
654762Snate@binkert.org    // @todo: Make into a parameter.
668793Sgblack@eecs.umich.edu    skidBufferMax = (2 * (iewToRenameDelay * params->decodeWidth)) + renameWidth;
678779Sgblack@eecs.umich.edu}
684762Snate@binkert.org
698460SAli.Saidi@ARM.comtemplate <class Impl>
704762Snate@binkert.orgstd::string
715702Ssaidi@eecs.umich.eduDefaultRename<Impl>::name() const
725702Ssaidi@eecs.umich.edu{
738232Snate@binkert.org    return cpu->name() + ".rename";
7411793Sbrandon.potter@amd.com}
755702Ssaidi@eecs.umich.edu
765702Ssaidi@eecs.umich.edutemplate <class Impl>
778737Skoansin.tan@gmail.comvoid
785529Snate@binkert.orgDefaultRename<Impl>::regStats()
792669Sktlim@umich.edu{
806221Snate@binkert.org    renameSquashCycles
811060SN/A        .name(name() + ".RENAME:SquashCycles")
825529Snate@binkert.org        .desc("Number of cycles rename is squashing")
835712Shsul@eecs.umich.edu        .prereq(renameSquashCycles);
841060SN/A    renameIdleCycles
851060SN/A        .name(name() + ".RENAME:IdleCycles")
861060SN/A        .desc("Number of cycles rename is idle")
872292SN/A        .prereq(renameIdleCycles);
882733Sktlim@umich.edu    renameBlockCycles
892292SN/A        .name(name() + ".RENAME:BlockCycles")
902292SN/A        .desc("Number of cycles rename is blocking")
912292SN/A        .prereq(renameBlockCycles);
922292SN/A    renameSerializeStallCycles
938707Sandreas.hansson@arm.com        .name(name() + ".RENAME:serializeStallCycles")
948707Sandreas.hansson@arm.com        .desc("count of cycles rename stalled for serializing inst")
958975Sandreas.hansson@arm.com        .flags(Stats::total);
968707Sandreas.hansson@arm.com    renameRunCycles
978707Sandreas.hansson@arm.com        .name(name() + ".RENAME:RunCycles")
9811284Sandreas.hansson@arm.com        .desc("Number of cycles rename is running")
9910821Sandreas.hansson@arm.com        .prereq(renameIdleCycles);
10011284Sandreas.hansson@arm.com    renameUnblockCycles
1018948Sandreas.hansson@arm.com        .name(name() + ".RENAME:UnblockCycles")
1028707Sandreas.hansson@arm.com        .desc("Number of cycles rename is unblocking")
1038707Sandreas.hansson@arm.com        .prereq(renameUnblockCycles);
1048707Sandreas.hansson@arm.com    renameRenamedInsts
1058707Sandreas.hansson@arm.com        .name(name() + ".RENAME:RenamedInsts")
1068707Sandreas.hansson@arm.com        .desc("Number of instructions processed by rename")
1078707Sandreas.hansson@arm.com        .prereq(renameRenamedInsts);
10810713Sandreas.hansson@arm.com    renameSquashedInsts
1098707Sandreas.hansson@arm.com        .name(name() + ".RENAME:SquashedInsts")
11010713Sandreas.hansson@arm.com        .desc("Number of squashed instructions processed by rename")
1118707Sandreas.hansson@arm.com        .prereq(renameSquashedInsts);
1128707Sandreas.hansson@arm.com    renameROBFullEvents
1138707Sandreas.hansson@arm.com        .name(name() + ".RENAME:ROBFullEvents")
1148707Sandreas.hansson@arm.com        .desc("Number of times rename has blocked due to ROB full")
1158975Sandreas.hansson@arm.com        .prereq(renameROBFullEvents);
1168707Sandreas.hansson@arm.com    renameIQFullEvents
1178975Sandreas.hansson@arm.com        .name(name() + ".RENAME:IQFullEvents")
1188707Sandreas.hansson@arm.com        .desc("Number of times rename has blocked due to IQ full")
1198707Sandreas.hansson@arm.com        .prereq(renameIQFullEvents);
1208707Sandreas.hansson@arm.com    renameLSQFullEvents
1218975Sandreas.hansson@arm.com        .name(name() + ".RENAME:LSQFullEvents")
1228975Sandreas.hansson@arm.com        .desc("Number of times rename has blocked due to LSQ full")
1238948Sandreas.hansson@arm.com        .prereq(renameLSQFullEvents);
12411148Smitch.hayenga@arm.com    renameFullRegistersEvents
12511148Smitch.hayenga@arm.com        .name(name() + ".RENAME:FullRegisterEvents")
12611151Smitch.hayenga@arm.com        .desc("Number of times there has been no free registers")
12711148Smitch.hayenga@arm.com        .prereq(renameFullRegistersEvents);
12810529Smorr@cs.wisc.edu    renameRenamedOperands
1298975Sandreas.hansson@arm.com        .name(name() + ".RENAME:RenamedOperands")
1308948Sandreas.hansson@arm.com        .desc("Number of destination operands rename has renamed")
1318948Sandreas.hansson@arm.com        .prereq(renameRenamedOperands);
1328948Sandreas.hansson@arm.com    renameRenameLookups
1338707Sandreas.hansson@arm.com        .name(name() + ".RENAME:RenameLookups")
13410713Sandreas.hansson@arm.com        .desc("Number of register rename lookups that rename has made")
1358707Sandreas.hansson@arm.com        .prereq(renameRenameLookups);
13610713Sandreas.hansson@arm.com    renameCommittedMaps
1378707Sandreas.hansson@arm.com        .name(name() + ".RENAME:CommittedMaps")
1388707Sandreas.hansson@arm.com        .desc("Number of HB maps that are committed")
1391060SN/A        .prereq(renameCommittedMaps);
1405595Sgblack@eecs.umich.edu    renameUndoneMaps
1412733Sktlim@umich.edu        .name(name() + ".RENAME:UndoneMaps")
1423781Sgblack@eecs.umich.edu        .desc("Number of HB maps that are undone due to squashing")
1433781Sgblack@eecs.umich.edu        .prereq(renameUndoneMaps);
14412127Sspwilson2@wisc.edu    renamedSerializing
14512127Sspwilson2@wisc.edu        .name(name() + ".RENAME:serializingInsts")
1465737Scws3k@cs.virginia.edu        .desc("count of serializing insts renamed")
1475737Scws3k@cs.virginia.edu        .flags(Stats::total)
1485737Scws3k@cs.virginia.edu        ;
1492292SN/A    renamedTempSerializing
1505595Sgblack@eecs.umich.edu        .name(name() + ".RENAME:tempSerializingInsts")
1515595Sgblack@eecs.umich.edu        .desc("count of temporary serializing insts renamed")
1525595Sgblack@eecs.umich.edu        .flags(Stats::total)
1535595Sgblack@eecs.umich.edu        ;
1545595Sgblack@eecs.umich.edu    renameSkidInsts
1551060SN/A        .name(name() + ".RENAME:skidInsts")
15612109SRekai.GonzalezAlberquilla@arm.com        .desc("count of insts added to the skid buffer")
15712109SRekai.GonzalezAlberquilla@arm.com        .flags(Stats::total)
15812109SRekai.GonzalezAlberquilla@arm.com        ;
1599915Ssteve.reinhardt@amd.com}
1609920Syasuko.eckert@amd.com
16112109SRekai.GonzalezAlberquilla@arm.comtemplate <class Impl>
16212109SRekai.GonzalezAlberquilla@arm.comvoid
16312109SRekai.GonzalezAlberquilla@arm.comDefaultRename<Impl>::setCPU(FullCPU *cpu_ptr)
1641060SN/A{
1659919Ssteve.reinhardt@amd.com    DPRINTF(Rename, "Setting CPU pointer.\n");
1661060SN/A    cpu = cpu_ptr;
1679954SFaissal.Sleiman@arm.com}
1681060SN/A
1699916Ssteve.reinhardt@amd.comtemplate <class Impl>
17012105Snathanael.premillieu@arm.comvoid
1711060SN/ADefaultRename<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
1729384SAndreas.Sandberg@arm.com{
1739384SAndreas.Sandberg@arm.com    DPRINTF(Rename, "Setting time buffer pointer.\n");
1748707Sandreas.hansson@arm.com    timeBuffer = tb_ptr;
1758707Sandreas.hansson@arm.com
1768707Sandreas.hansson@arm.com    // Setup wire to read information from time buffer, from IEW stage.
1772873Sktlim@umich.edu    fromIEW = timeBuffer->getWire(-iewToRenameDelay);
1782873Sktlim@umich.edu
1792873Sktlim@umich.edu    // Setup wire to read infromation from time buffer, from commit stage.
1802873Sktlim@umich.edu    fromCommit = timeBuffer->getWire(-commitToRenameDelay);
1812873Sktlim@umich.edu
1825804Snate@binkert.org    // Setup wire to write information to previous stages.
1832873Sktlim@umich.edu    toDecode = timeBuffer->getWire(0);
1842873Sktlim@umich.edu}
1851060SN/A
1861060SN/Atemplate <class Impl>
1872292SN/Avoid
1889180Sandreas.hansson@arm.comDefaultRename<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
1891060SN/A{
1909433SAndreas.Sandberg@ARM.com    DPRINTF(Rename, "Setting rename queue pointer.\n");
1913221Sktlim@umich.edu    renameQueue = rq_ptr;
1923221Sktlim@umich.edu
1939152Satgutier@umich.edu    // Setup wire to write information to future stages.
1943221Sktlim@umich.edu    toIEW = renameQueue->getWire(0);
1951681SN/A}
1962794Sktlim@umich.edu
1972316SN/Atemplate <class Impl>
1988733Sgeoffrey.blake@arm.comvoid
1998707Sandreas.hansson@arm.comDefaultRename<Impl>::setDecodeQueue(TimeBuffer<DecodeStruct> *dq_ptr)
2002316SN/A{
2014598Sbinkertn@umich.edu    DPRINTF(Rename, "Setting decode queue pointer.\n");
2024598Sbinkertn@umich.edu    decodeQueue = dq_ptr;
2034598Sbinkertn@umich.edu
2042316SN/A    // Setup wire to get information from decode.
2058793Sgblack@eecs.umich.edu    fromDecode = decodeQueue->getWire(-decodeToRenameDelay);
2068793Sgblack@eecs.umich.edu}
2078793Sgblack@eecs.umich.edu
2088793Sgblack@eecs.umich.edutemplate <class Impl>
2091681SN/Avoid
2102325SN/ADefaultRename<Impl>::initStage()
2112325SN/A{
2122325SN/A    // Grab the number of free entries directly from the stages.
2131060SN/A    for (int tid=0; tid < numThreads; tid++) {
2142292SN/A        freeEntries[tid].iqEntries = iew_ptr->instQueue.numFreeEntries(tid);
2152292SN/A        freeEntries[tid].lsqEntries = iew_ptr->ldstQueue.numFreeEntries(tid);
2162292SN/A        freeEntries[tid].robEntries = commit_ptr->numROBFreeEntries(tid);
2172292SN/A        emptyROB[tid] = true;
2182292SN/A    }
2192292SN/A}
2201060SN/A
2211060SN/Atemplate<class Impl>
2221060SN/Avoid
2231060SN/ADefaultRename<Impl>::setActiveThreads(list<unsigned> *at_ptr)
2241060SN/A{
2251060SN/A    DPRINTF(Rename, "Setting active threads list pointer.\n");
2261060SN/A    activeThreads = at_ptr;
2271060SN/A}
2281060SN/A
2291060SN/A
2301060SN/Atemplate <class Impl>
2312292SN/Avoid
2321060SN/ADefaultRename<Impl>::setRenameMap(RenameMap rm_ptr[])
2331060SN/A{
2341060SN/A    DPRINTF(Rename, "Setting rename map pointers.\n");
2351060SN/A
2361060SN/A    for (int i=0; i<numThreads; i++) {
2371060SN/A        renameMap[i] = &rm_ptr[i];
2381060SN/A    }
2391060SN/A}
2402292SN/A
2412292SN/Atemplate <class Impl>
2422292SN/Avoid
2432292SN/ADefaultRename<Impl>::setFreeList(FreeList *fl_ptr)
2448793Sgblack@eecs.umich.edu{
2458793Sgblack@eecs.umich.edu    DPRINTF(Rename, "Setting free list pointer.\n");
2468793Sgblack@eecs.umich.edu    freeList = fl_ptr;
2478793Sgblack@eecs.umich.edu}
2488793Sgblack@eecs.umich.edu
2492831Sksewell@umich.edutemplate<class Impl>
2508793Sgblack@eecs.umich.eduvoid
2518793Sgblack@eecs.umich.eduDefaultRename<Impl>::setScoreboard(Scoreboard *_scoreboard)
2528793Sgblack@eecs.umich.edu{
2538793Sgblack@eecs.umich.edu    DPRINTF(Rename, "Setting scoreboard pointer.\n");
2548793Sgblack@eecs.umich.edu    scoreboard = _scoreboard;
2552831Sksewell@umich.edu}
2562292SN/A
2572316SN/Atemplate <class Impl>
2582292SN/Avoid
2592292SN/ADefaultRename<Impl>::switchOut()
26012109SRekai.GonzalezAlberquilla@arm.com{
2619920Syasuko.eckert@amd.com    // Rename is ready to switch out at any time.
2622292SN/A    cpu->signalSwitched();
2632292SN/A}
2642292SN/A
2652292SN/Atemplate <class Impl>
2661060SN/Avoid
2676221Snate@binkert.orgDefaultRename<Impl>::doSwitchOut()
2689384SAndreas.Sandberg@arm.com{
26912109SRekai.GonzalezAlberquilla@arm.com    // Clear any state, fix up the rename map.
2709384SAndreas.Sandberg@arm.com    for (int i = 0; i < numThreads; i++) {
2719919Ssteve.reinhardt@amd.com        typename list<RenameHistory>::iterator hb_it = historyBuffer[i].begin();
2729919Ssteve.reinhardt@amd.com
2739919Ssteve.reinhardt@amd.com        while (!historyBuffer[i].empty()) {
2749919Ssteve.reinhardt@amd.com            assert(hb_it != historyBuffer[i].end());
2759919Ssteve.reinhardt@amd.com
2769919Ssteve.reinhardt@amd.com            DPRINTF(Rename, "[tid:%u]: Removing history entry with sequence "
2772292SN/A                    "number %i.\n", i, (*hb_it).instSeqNum);
2789919Ssteve.reinhardt@amd.com
27912109SRekai.GonzalezAlberquilla@arm.com            // Tell the rename map to set the architected register to the
28012109SRekai.GonzalezAlberquilla@arm.com            // previous physical register that it was renamed to.
2812292SN/A            renameMap[i]->setEntry(hb_it->archReg, hb_it->prevPhysReg);
2829919Ssteve.reinhardt@amd.com
28312109SRekai.GonzalezAlberquilla@arm.com            // Put the renamed physical register back on the free list.
2842292SN/A            freeList->addReg(hb_it->newPhysReg);
2852292SN/A
2869919Ssteve.reinhardt@amd.com            historyBuffer[i].erase(hb_it++);
2879919Ssteve.reinhardt@amd.com        }
2889919Ssteve.reinhardt@amd.com        insts[i].clear();
2899919Ssteve.reinhardt@amd.com        skidBuffer[i].clear();
2909919Ssteve.reinhardt@amd.com    }
2919919Ssteve.reinhardt@amd.com}
29212105Snathanael.premillieu@arm.com
29312106SRekai.GonzalezAlberquilla@arm.comtemplate <class Impl>
29412106SRekai.GonzalezAlberquilla@arm.comvoid
2959919Ssteve.reinhardt@amd.comDefaultRename<Impl>::takeOverFrom()
2969919Ssteve.reinhardt@amd.com{
2979919Ssteve.reinhardt@amd.com    _status = Inactive;
29812105Snathanael.premillieu@arm.com    initStage();
29912106SRekai.GonzalezAlberquilla@arm.com
30012106SRekai.GonzalezAlberquilla@arm.com    // Reset all state prior to taking over from the other CPU.
30112106SRekai.GonzalezAlberquilla@arm.com    for (int i=0; i< numThreads; i++) {
3029919Ssteve.reinhardt@amd.com        renameStatus[i] = Idle;
3039920Syasuko.eckert@amd.com
30412109SRekai.GonzalezAlberquilla@arm.com        stalls[i].iew = false;
30512109SRekai.GonzalezAlberquilla@arm.com        stalls[i].commit = false;
30612109SRekai.GonzalezAlberquilla@arm.com        serializeInst[i] = NULL;
30712109SRekai.GonzalezAlberquilla@arm.com
30812109SRekai.GonzalezAlberquilla@arm.com        instsInProgress[i] = 0;
30912109SRekai.GonzalezAlberquilla@arm.com
31012109SRekai.GonzalezAlberquilla@arm.com        emptyROB[i] = true;
31112109SRekai.GonzalezAlberquilla@arm.com
31212109SRekai.GonzalezAlberquilla@arm.com        serializeOnNextInst[i] = false;
31312109SRekai.GonzalezAlberquilla@arm.com    }
31412109SRekai.GonzalezAlberquilla@arm.com}
31512109SRekai.GonzalezAlberquilla@arm.com
31612109SRekai.GonzalezAlberquilla@arm.comtemplate <class Impl>
31712109SRekai.GonzalezAlberquilla@arm.comvoid
31812109SRekai.GonzalezAlberquilla@arm.comDefaultRename<Impl>::squash(unsigned tid)
31912109SRekai.GonzalezAlberquilla@arm.com{
32012109SRekai.GonzalezAlberquilla@arm.com    DPRINTF(Rename, "[tid:%u]: Squashing instructions.\n",tid);
32112109SRekai.GonzalezAlberquilla@arm.com
32212109SRekai.GonzalezAlberquilla@arm.com    // Clear the stall signal if rename was blocked or unblocking before.
32312109SRekai.GonzalezAlberquilla@arm.com    // If it still needs to block, the blocking should happen the next
32412109SRekai.GonzalezAlberquilla@arm.com    // cycle and there should be space to hold everything due to the squash.
32512109SRekai.GonzalezAlberquilla@arm.com    if (renameStatus[tid] == Blocked ||
32612109SRekai.GonzalezAlberquilla@arm.com        renameStatus[tid] == Unblocking ||
32712109SRekai.GonzalezAlberquilla@arm.com        renameStatus[tid] == SerializeStall) {
3289920Syasuko.eckert@amd.com#if 0
32912105Snathanael.premillieu@arm.com        // In syscall emulation, we can have both a block and a squash due
33012106SRekai.GonzalezAlberquilla@arm.com        // to a syscall in the same cycle.  This would cause both signals to
33112106SRekai.GonzalezAlberquilla@arm.com        // be high.  This shouldn't happen in full system.
3329920Syasuko.eckert@amd.com        if (toDecode->renameBlock[tid]) {
3339919Ssteve.reinhardt@amd.com            toDecode->renameBlock[tid] = 0;
3349919Ssteve.reinhardt@amd.com        } else {
3352292SN/A            toDecode->renameUnblock[tid] = 1;
3362292SN/A        }
3371060SN/A#else
3382292SN/A        toDecode->renameUnblock[tid] = 1;
3391060SN/A#endif
3401060SN/A        serializeInst[tid] = NULL;
3412292SN/A    }
3429158Sandreas.hansson@arm.com
3436221Snate@binkert.org    // Set the status to Squashing.
3443093Sksewell@umich.edu    renameStatus[tid] = Squashing;
3456221Snate@binkert.org
3466221Snate@binkert.org    // Squash any instructions from decode.
3476221Snate@binkert.org    unsigned squashCount = 0;
3483093Sksewell@umich.edu
3495595Sgblack@eecs.umich.edu    for (int i=0; i<fromDecode->size; i++) {
3505595Sgblack@eecs.umich.edu        if (fromDecode->insts[i]->threadNumber == tid) {
3515595Sgblack@eecs.umich.edu            fromDecode->insts[i]->squashed = true;
3525595Sgblack@eecs.umich.edu            wroteToTimeBuffer = true;
3535595Sgblack@eecs.umich.edu            squashCount++;
3546221Snate@binkert.org        }
3558793Sgblack@eecs.umich.edu    }
3568793Sgblack@eecs.umich.edu
3578793Sgblack@eecs.umich.edu    insts[tid].clear();
3588793Sgblack@eecs.umich.edu
3598793Sgblack@eecs.umich.edu    // Clear the skid buffer in case it has any data in it.
3608793Sgblack@eecs.umich.edu    skidBuffer[tid].clear();
3618793Sgblack@eecs.umich.edu
3628793Sgblack@eecs.umich.edu    doSquash(tid);
3638793Sgblack@eecs.umich.edu}
3648793Sgblack@eecs.umich.edu
3658793Sgblack@eecs.umich.edutemplate <class Impl>
3665595Sgblack@eecs.umich.eduvoid
3678793Sgblack@eecs.umich.eduDefaultRename<Impl>::tick()
3688793Sgblack@eecs.umich.edu{
3698793Sgblack@eecs.umich.edu    wroteToTimeBuffer = false;
3708793Sgblack@eecs.umich.edu
3718793Sgblack@eecs.umich.edu    blockThisCycle = false;
3728793Sgblack@eecs.umich.edu
3735595Sgblack@eecs.umich.edu    bool status_change = false;
3748793Sgblack@eecs.umich.edu
3758793Sgblack@eecs.umich.edu    toIEWIndex = 0;
3768793Sgblack@eecs.umich.edu
3778793Sgblack@eecs.umich.edu    sortInsts();
3788793Sgblack@eecs.umich.edu
3795595Sgblack@eecs.umich.edu    list<unsigned>::iterator threads = (*activeThreads).begin();
3805595Sgblack@eecs.umich.edu
3815595Sgblack@eecs.umich.edu    // Check stall and squash signals.
3825595Sgblack@eecs.umich.edu    while (threads != (*activeThreads).end()) {
3835595Sgblack@eecs.umich.edu        unsigned tid = *threads++;
3845595Sgblack@eecs.umich.edu
3855595Sgblack@eecs.umich.edu        DPRINTF(Rename, "Processing [tid:%i]\n", tid);
3865595Sgblack@eecs.umich.edu
3875595Sgblack@eecs.umich.edu        status_change = checkSignalsAndUpdate(tid) || status_change;
3885595Sgblack@eecs.umich.edu
3895595Sgblack@eecs.umich.edu        rename(status_change, tid);
3905595Sgblack@eecs.umich.edu    }
3915595Sgblack@eecs.umich.edu
3925595Sgblack@eecs.umich.edu    if (status_change) {
3935595Sgblack@eecs.umich.edu        updateStatus();
3945595Sgblack@eecs.umich.edu    }
3955595Sgblack@eecs.umich.edu
3965595Sgblack@eecs.umich.edu    if (wroteToTimeBuffer) {
3976221Snate@binkert.org        DPRINTF(Activity, "Activity this cycle.\n");
3985595Sgblack@eecs.umich.edu        cpu->activityThisCycle();
39911627Smichael.lebeane@amd.com    }
40011627Smichael.lebeane@amd.com
40111627Smichael.lebeane@amd.com    threads = (*activeThreads).begin();
4025595Sgblack@eecs.umich.edu
4036221Snate@binkert.org    while (threads != (*activeThreads).end()) {
4045595Sgblack@eecs.umich.edu        unsigned tid = *threads++;
4055595Sgblack@eecs.umich.edu
4065595Sgblack@eecs.umich.edu        // If we committed this cycle then doneSeqNum will be > 0
4075595Sgblack@eecs.umich.edu        if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
4085595Sgblack@eecs.umich.edu            !fromCommit->commitInfo[tid].squash &&
4098876Sandreas.hansson@arm.com            renameStatus[tid] != Squashing) {
41011150Smitch.hayenga@arm.com
4118876Sandreas.hansson@arm.com            removeFromHistory(fromCommit->commitInfo[tid].doneSeqNum,
4128876Sandreas.hansson@arm.com                                  tid);
4138876Sandreas.hansson@arm.com        }
4148876Sandreas.hansson@arm.com    }
4156221Snate@binkert.org
4166221Snate@binkert.org    // @todo: make into updateProgress function
4171060SN/A    for (int tid=0; tid < numThreads; tid++) {
4181060SN/A        instsInProgress[tid] -= fromIEW->iewInfo[tid].dispatched;
4191060SN/A
4201755SN/A        assert(instsInProgress[tid] >=0);
4211060SN/A    }
4221060SN/A
4231060SN/A}
4241060SN/A
4251060SN/Atemplate<class Impl>
42610023Smatt.horsnell@ARM.comvoid
42710023Smatt.horsnell@ARM.comDefaultRename<Impl>::rename(bool &status_change, unsigned tid)
42810464SAndreas.Sandberg@ARM.com{
42910464SAndreas.Sandberg@ARM.com    // If status is Running or idle,
43010023Smatt.horsnell@ARM.com    //     call renameInsts()
43110023Smatt.horsnell@ARM.com    // If status is Unblocking,
43210464SAndreas.Sandberg@ARM.com    //     buffer any instructions coming from decode
43310023Smatt.horsnell@ARM.com    //     continue trying to empty skid buffer
43411246Sradhika.jagtap@ARM.com    //     check if stall conditions have passed
43510023Smatt.horsnell@ARM.com
43610023Smatt.horsnell@ARM.com    if (renameStatus[tid] == Blocked) {
43710023Smatt.horsnell@ARM.com        ++renameBlockCycles;
43810023Smatt.horsnell@ARM.com    } else if (renameStatus[tid] == Squashing) {
43910023Smatt.horsnell@ARM.com        ++renameSquashCycles;
44010023Smatt.horsnell@ARM.com    } else if (renameStatus[tid] == SerializeStall) {
4415595Sgblack@eecs.umich.edu        ++renameSerializeStallCycles;
4421062SN/A    }
4432733Sktlim@umich.edu
4442292SN/A    if (renameStatus[tid] == Running ||
4452733Sktlim@umich.edu        renameStatus[tid] == Idle) {
4462292SN/A        DPRINTF(Rename, "[tid:%u]: Not blocked, so attempting to run "
4472292SN/A                "stage.\n", tid);
4482292SN/A
4492292SN/A        renameInsts(tid);
4502292SN/A    } else if (renameStatus[tid] == Unblocking) {
4512292SN/A        renameInsts(tid);
4522292SN/A
4532292SN/A        if (validInsts()) {
4542292SN/A            // Add the current inputs to the skid buffer so they can be
4552292SN/A            // reprocessed when this stage unblocks.
4562292SN/A            skidInsert(tid);
4572292SN/A        }
4588627SAli.Saidi@ARM.com
4598627SAli.Saidi@ARM.com        // If we switched over to blocking, then there's a potential for
4608627SAli.Saidi@ARM.com        // an overall status change.
4618627SAli.Saidi@ARM.com        status_change = unblock(tid) || status_change || blockThisCycle;
4628627SAli.Saidi@ARM.com    }
4638627SAli.Saidi@ARM.com}
4642292SN/A
4652292SN/Atemplate <class Impl>
4662292SN/Avoid
4672292SN/ADefaultRename<Impl>::renameInsts(unsigned tid)
4682292SN/A{
4692292SN/A    // Instructions can be either in the skid buffer or the queue of
4702292SN/A    // instructions coming from decode, depending on the status.
47110225Snilay@cs.wisc.edu    int insts_available = renameStatus[tid] == Unblocking ?
47210225Snilay@cs.wisc.edu        skidBuffer[tid].size() : insts[tid].size();
4732292SN/A
4748834Satgutier@umich.edu    // Check the decode queue to see if instructions are available.
4758834Satgutier@umich.edu    // If there are no available instructions to rename, then do nothing.
4768834Satgutier@umich.edu    if (insts_available == 0) {
47710225Snilay@cs.wisc.edu        DPRINTF(Rename, "[tid:%u]: Nothing to do, breaking out early.\n",
47810225Snilay@cs.wisc.edu                tid);
4792292SN/A        // Should I change status to idle?
4802292SN/A        ++renameIdleCycles;
4812292SN/A        return;
4822292SN/A    } else if (renameStatus[tid] == Unblocking) {
4832292SN/A        ++renameUnblockCycles;
4844392Sktlim@umich.edu    } else if (renameStatus[tid] == Running) {
4852292SN/A        ++renameRunCycles;
4862292SN/A    }
4872292SN/A
4882292SN/A    DynInstPtr inst;
4892292SN/A
49010225Snilay@cs.wisc.edu    // Will have to do a different calculation for the number of free
4912292SN/A    // entries.
4922292SN/A    int free_rob_entries = calcFreeROBEntries(tid);
4932292SN/A    int free_iq_entries  = calcFreeIQEntries(tid);
4942292SN/A    int free_lsq_entries = calcFreeLSQEntries(tid);
4952292SN/A    int min_free_entries = free_rob_entries;
4964392Sktlim@umich.edu
4972292SN/A    FullSource source = ROB;
4982292SN/A
4992292SN/A    if (free_iq_entries < min_free_entries) {
5002292SN/A        min_free_entries = free_iq_entries;
5012292SN/A        source = IQ;
50210225Snilay@cs.wisc.edu    }
5032292SN/A
5045595Sgblack@eecs.umich.edu    if (free_lsq_entries < min_free_entries) {
5055595Sgblack@eecs.umich.edu        min_free_entries = free_lsq_entries;
5065595Sgblack@eecs.umich.edu        source = LSQ;
5075595Sgblack@eecs.umich.edu    }
5085595Sgblack@eecs.umich.edu
5097897Shestness@cs.utexas.edu    // Check if there's any space left.
5107897Shestness@cs.utexas.edu    if (min_free_entries <= 0) {
5117897Shestness@cs.utexas.edu        DPRINTF(Rename, "[tid:%u]: Blocking due to no free ROB/IQ/LSQ "
5127897Shestness@cs.utexas.edu                "entries.\n"
5137897Shestness@cs.utexas.edu                "ROB has %i free entries.\n"
5147897Shestness@cs.utexas.edu                "IQ has %i free entries.\n"
5157897Shestness@cs.utexas.edu                "LSQ has %i free entries.\n",
5167897Shestness@cs.utexas.edu                tid,
5177897Shestness@cs.utexas.edu                free_rob_entries,
5187897Shestness@cs.utexas.edu                free_iq_entries,
5197897Shestness@cs.utexas.edu                free_lsq_entries);
5207897Shestness@cs.utexas.edu
5217897Shestness@cs.utexas.edu        blockThisCycle = true;
5227897Shestness@cs.utexas.edu
5237897Shestness@cs.utexas.edu        block(tid);
5247897Shestness@cs.utexas.edu
5257897Shestness@cs.utexas.edu        incrFullStat(source);
5267897Shestness@cs.utexas.edu
5277897Shestness@cs.utexas.edu        return;
5287897Shestness@cs.utexas.edu    } else if (min_free_entries < insts_available) {
5297897Shestness@cs.utexas.edu        DPRINTF(Rename, "[tid:%u]: Will have to block this cycle."
5307897Shestness@cs.utexas.edu                "%i insts available, but only %i insts can be "
53112109SRekai.GonzalezAlberquilla@arm.com                "renamed due to ROB/IQ/LSQ limits.\n",
53212109SRekai.GonzalezAlberquilla@arm.com                tid, insts_available, min_free_entries);
53312109SRekai.GonzalezAlberquilla@arm.com
53412109SRekai.GonzalezAlberquilla@arm.com        insts_available = min_free_entries;
53512109SRekai.GonzalezAlberquilla@arm.com
53612109SRekai.GonzalezAlberquilla@arm.com        blockThisCycle = true;
53712109SRekai.GonzalezAlberquilla@arm.com
53812109SRekai.GonzalezAlberquilla@arm.com        incrFullStat(source);
53912109SRekai.GonzalezAlberquilla@arm.com    }
54012109SRekai.GonzalezAlberquilla@arm.com
5419920Syasuko.eckert@amd.com    InstQueue &insts_to_rename = renameStatus[tid] == Unblocking ?
5429920Syasuko.eckert@amd.com        skidBuffer[tid] : insts[tid];
5439920Syasuko.eckert@amd.com
5449920Syasuko.eckert@amd.com    DPRINTF(Rename, "[tid:%u]: %i available instructions to "
5459920Syasuko.eckert@amd.com            "send iew.\n", tid, insts_available);
5469920Syasuko.eckert@amd.com
5479920Syasuko.eckert@amd.com    DPRINTF(Rename, "[tid:%u]: %i insts pipelining from Rename | %i insts "
5489920Syasuko.eckert@amd.com            "dispatched to IQ last cycle.\n",
5499920Syasuko.eckert@amd.com            tid, instsInProgress[tid], fromIEW->iewInfo[tid].dispatched);
5509920Syasuko.eckert@amd.com
5517897Shestness@cs.utexas.edu    // Handle serializing the next instruction if necessary.
5527897Shestness@cs.utexas.edu    if (serializeOnNextInst[tid]) {
5537897Shestness@cs.utexas.edu        if (emptyROB[tid] && instsInProgress[tid] == 0) {
5547897Shestness@cs.utexas.edu            // ROB already empty; no need to serialize.
5557897Shestness@cs.utexas.edu            serializeOnNextInst[tid] = false;
5567897Shestness@cs.utexas.edu        } else if (!insts_to_rename.empty()) {
5577897Shestness@cs.utexas.edu            insts_to_rename.front()->setSerializeBefore();
5587897Shestness@cs.utexas.edu        }
5597897Shestness@cs.utexas.edu    }
5601062SN/A
5611062SN/A    int renamed_insts = 0;
5621062SN/A
5631062SN/A    while (insts_available > 0 &&  toIEWIndex < renameWidth) {
5641755SN/A        DPRINTF(Rename, "[tid:%u]: Sending instructions to IEW.\n", tid);
5651060SN/A
5662733Sktlim@umich.edu        assert(!insts_to_rename.empty());
5679444SAndreas.Sandberg@ARM.com
56810913Sandreas.sandberg@arm.com        inst = insts_to_rename.front();
5691060SN/A
5702292SN/A        insts_to_rename.pop_front();
57110464SAndreas.Sandberg@ARM.com
5722292SN/A        if (renameStatus[tid] == Unblocking) {
5732325SN/A            DPRINTF(Rename,"[tid:%u]: Removing [sn:%lli] PC:%#x from rename "
5742292SN/A                    "skidBuffer\n",
5752292SN/A                    tid, inst->seqNum, inst->readPC());
5761060SN/A        }
5771060SN/A
5781060SN/A        if (inst->isSquashed()) {
5791060SN/A            DPRINTF(Rename, "[tid:%u]: instruction %i with PC %#x is "
5801060SN/A                    "squashed, skipping.\n",
5811060SN/A                    tid, inst->seqNum, inst->threadNumber,inst->readPC());
5821060SN/A
5831060SN/A            ++renameSquashedInsts;
5841060SN/A
5851060SN/A            // Decrement how many instructions are available.
5862292SN/A            --insts_available;
5871060SN/A
5881060SN/A            continue;
5891060SN/A        }
5901060SN/A
5911060SN/A        DPRINTF(Rename, "[tid:%u]: Processing instruction [sn:%lli] with "
5921060SN/A                "PC %#x.\n",
5931060SN/A                tid, inst->seqNum, inst->readPC());
5942325SN/A
5952292SN/A        // Handle serializeAfter/serializeBefore instructions.
5962292SN/A        // serializeAfter marks the next instruction as serializeBefore.
5972292SN/A        // serializeBefore makes the instruction wait in rename until the ROB
5982292SN/A        // is empty.
5992292SN/A
6002325SN/A        // In this model, IPR accesses are serialize before
6019444SAndreas.Sandberg@ARM.com        // instructions, and store conditionals are serialize after
6023226Sktlim@umich.edu        // instructions.  This is mainly due to lack of support for
6032325SN/A        // out-of-order operations of either of those classes of
6049179Sandreas.hansson@arm.com        // instructions.
6053221Sktlim@umich.edu        if ((inst->isIprAccess() || inst->isSerializeBefore()) &&
6063226Sktlim@umich.edu            !inst->isSerializeHandled()) {
6079179Sandreas.hansson@arm.com            DPRINTF(Rename, "Serialize before instruction encountered.\n");
6082325SN/A
6092325SN/A            if (!inst->isTempSerializeBefore()) {
6109180Sandreas.hansson@arm.com                renamedSerializing++;
6113226Sktlim@umich.edu                inst->setSerializeHandled();
6122325SN/A            } else {
6132292SN/A                renamedTempSerializing++;
6142292SN/A            }
6158793Sgblack@eecs.umich.edu
6168793Sgblack@eecs.umich.edu            // Change status over to SerializeStall so that other stages know
6179444SAndreas.Sandberg@ARM.com            // what this is blocked on.
6189444SAndreas.Sandberg@ARM.com            renameStatus[tid] = SerializeStall;
6191060SN/A
6201060SN/A            serializeInst[tid] = inst;
6211060SN/A
6221060SN/A            blockThisCycle = true;
6231755SN/A
6241060SN/A            break;
6255714Shsul@eecs.umich.edu        } else if ((inst->isStoreConditional() || inst->isSerializeAfter()) &&
6261060SN/A                   !inst->isSerializeHandled()) {
6278921Sandreas.hansson@arm.com            DPRINTF(Rename, "Serialize after instruction encountered.\n");
6289382SAli.Saidi@ARM.com
6298921Sandreas.hansson@arm.com            renamedSerializing++;
6309382SAli.Saidi@ARM.com
6318921Sandreas.hansson@arm.com            inst->setSerializeHandled();
6328921Sandreas.hansson@arm.com
6338921Sandreas.hansson@arm.com            serializeAfter(insts_to_rename, tid);
6342292SN/A        }
6359433SAndreas.Sandberg@ARM.com
6368793Sgblack@eecs.umich.edu        // Check here to make sure there are enough destination registers
6378793Sgblack@eecs.umich.edu        // to rename to.  Otherwise block.
6388793Sgblack@eecs.umich.edu        if (renameMap[tid]->numFreeEntries() < inst->numDestRegs()) {
6398793Sgblack@eecs.umich.edu            DPRINTF(Rename, "Blocking due to lack of free "
6406034Ssteve.reinhardt@amd.com                    "physical registers to rename to.\n");
6412292SN/A            blockThisCycle = true;
6429382SAli.Saidi@ARM.com
6436221Snate@binkert.org            ++renameFullRegistersEvents;
6449382SAli.Saidi@ARM.com
6452292SN/A            break;
6469427SAndreas.Sandberg@ARM.com        }
6479427SAndreas.Sandberg@ARM.com
6482292SN/A        renameSrcRegs(inst, inst->threadNumber);
6499427SAndreas.Sandberg@ARM.com
6509427SAndreas.Sandberg@ARM.com        renameDestRegs(inst, inst->threadNumber);
6519427SAndreas.Sandberg@ARM.com
6529427SAndreas.Sandberg@ARM.com        ++renamed_insts;
6539992Snilay@cs.wisc.edu
6549461Snilay@cs.wisc.edu        // Put instruction in rename queue.
6559461Snilay@cs.wisc.edu        toIEW->insts[toIEWIndex] = inst;
6569461Snilay@cs.wisc.edu        ++(toIEW->size);
6579427SAndreas.Sandberg@ARM.com
6589444SAndreas.Sandberg@ARM.com        // Increment which instruction we're on.
6599427SAndreas.Sandberg@ARM.com        ++toIEWIndex;
6609427SAndreas.Sandberg@ARM.com
6619427SAndreas.Sandberg@ARM.com        // Decrement how many instructions are available.
6622292SN/A        --insts_available;
6632292SN/A    }
6642292SN/A
6652292SN/A    instsInProgress[tid] += renamed_insts;
6666221Snate@binkert.org    renameRenamedInsts += renamed_insts;
6672875Sksewell@umich.edu
6686221Snate@binkert.org    // If we wrote to the time buffer, record this.
6695314Sstever@gmail.com    if (toIEWIndex) {
6702875Sksewell@umich.edu        wroteToTimeBuffer = true;
6713226Sktlim@umich.edu    }
6729444SAndreas.Sandberg@ARM.com
6733226Sktlim@umich.edu    // Check if there's any instructions left that haven't yet been renamed.
6742875Sksewell@umich.edu    // If so then block.
6752875Sksewell@umich.edu    if (insts_available) {
6762875Sksewell@umich.edu        blockThisCycle = true;
6772875Sksewell@umich.edu    }
6782875Sksewell@umich.edu
6792875Sksewell@umich.edu    if (blockThisCycle) {
6802875Sksewell@umich.edu        block(tid);
6812875Sksewell@umich.edu        toDecode->renameUnblock[tid] = false;
6822875Sksewell@umich.edu    }
6832875Sksewell@umich.edu}
6846221Snate@binkert.org
6852875Sksewell@umich.edutemplate<class Impl>
6862875Sksewell@umich.eduvoid
6876221Snate@binkert.orgDefaultRename<Impl>::skidInsert(unsigned tid)
6885314Sstever@gmail.com{
6892875Sksewell@umich.edu    DynInstPtr inst = NULL;
6903226Sktlim@umich.edu
6919444SAndreas.Sandberg@ARM.com    while (!insts[tid].empty()) {
6923226Sktlim@umich.edu        inst = insts[tid].front();
6932875Sksewell@umich.edu
6942875Sksewell@umich.edu        insts[tid].pop_front();
6952875Sksewell@umich.edu
6962875Sksewell@umich.edu        assert(tid == inst->threadNumber);
6972875Sksewell@umich.edu
69810331Smitch.hayenga@arm.com        DPRINTF(Rename, "[tid:%u]: Inserting [sn:%lli] PC:%#x into Rename "
69910331Smitch.hayenga@arm.com                "skidBuffer\n", tid, inst->seqNum, inst->readPC());
70010331Smitch.hayenga@arm.com
7012875Sksewell@umich.edu        ++renameSkidInsts;
7022875Sksewell@umich.edu
7032875Sksewell@umich.edu        skidBuffer[tid].push_back(inst);
7046221Snate@binkert.org    }
7058834Satgutier@umich.edu
7066221Snate@binkert.org    if (skidBuffer[tid].size() > skidBufferMax)
7076221Snate@binkert.org        panic("Skidbuffer Exceeded Max Size");
7086221Snate@binkert.org}
7096221Snate@binkert.org
7106221Snate@binkert.orgtemplate <class Impl>
7116221Snate@binkert.orgvoid
7126221Snate@binkert.orgDefaultRename<Impl>::sortInsts()
7136221Snate@binkert.org{
7146221Snate@binkert.org    int insts_from_decode = fromDecode->size;
7156221Snate@binkert.org#ifdef DEBUG
7166221Snate@binkert.org    for (int i=0; i < numThreads; i++)
7178834Satgutier@umich.edu        assert(insts[i].empty());
7188834Satgutier@umich.edu#endif
7198834Satgutier@umich.edu    for (int i = 0; i < insts_from_decode; ++i) {
7208834Satgutier@umich.edu        DynInstPtr inst = fromDecode->insts[i];
7218834Satgutier@umich.edu        insts[inst->threadNumber].push_back(inst);
7228834Satgutier@umich.edu    }
7238834Satgutier@umich.edu}
7248834Satgutier@umich.edu
7258834Satgutier@umich.edutemplate<class Impl>
7268834Satgutier@umich.edubool
7278834Satgutier@umich.eduDefaultRename<Impl>::skidsEmpty()
7288834Satgutier@umich.edu{
7298834Satgutier@umich.edu    list<unsigned>::iterator threads = (*activeThreads).begin();
7302875Sksewell@umich.edu
73110407Smitch.hayenga@arm.com    while (threads != (*activeThreads).end()) {
7322875Sksewell@umich.edu        if (!skidBuffer[*threads++].empty())
7339444SAndreas.Sandberg@ARM.com            return false;
7349444SAndreas.Sandberg@ARM.com    }
7352875Sksewell@umich.edu
73610407Smitch.hayenga@arm.com    return true;
7372875Sksewell@umich.edu}
7389444SAndreas.Sandberg@ARM.com
7399444SAndreas.Sandberg@ARM.comtemplate<class Impl>
7409444SAndreas.Sandberg@ARM.comvoid
74110913Sandreas.sandberg@arm.comDefaultRename<Impl>::updateStatus()
7429444SAndreas.Sandberg@ARM.com{
7439444SAndreas.Sandberg@ARM.com    bool any_unblocking = false;
7449158Sandreas.hansson@arm.com
7459158Sandreas.hansson@arm.com    list<unsigned>::iterator threads = (*activeThreads).begin();
7469158Sandreas.hansson@arm.com
74710407Smitch.hayenga@arm.com    threads = (*activeThreads).begin();
7482875Sksewell@umich.edu
7492875Sksewell@umich.edu    while (threads != (*activeThreads).end()) {
7502875Sksewell@umich.edu        unsigned tid = *threads++;
7512875Sksewell@umich.edu
7522875Sksewell@umich.edu        if (renameStatus[tid] == Unblocking) {
7532875Sksewell@umich.edu            any_unblocking = true;
7549180Sandreas.hansson@arm.com            break;
7559180Sandreas.hansson@arm.com        }
7569179Sandreas.hansson@arm.com    }
7579179Sandreas.hansson@arm.com
7589179Sandreas.hansson@arm.com    // Rename will have activity if it's unblocking.
7598627SAli.Saidi@ARM.com    if (any_unblocking) {
7607823Ssteve.reinhardt@amd.com        if (_status == Inactive) {
7612875Sksewell@umich.edu            _status = Active;
7622875Sksewell@umich.edu
76311526Sdavid.guillen@arm.com            DPRINTF(Activity, "Activating stage.\n");
76411526Sdavid.guillen@arm.com
7652875Sksewell@umich.edu            cpu->activateStage(FullCPU::RenameIdx);
7662875Sksewell@umich.edu        }
7672875Sksewell@umich.edu    } else {
7682875Sksewell@umich.edu        // If it's not unblocking, then rename will not have any internal
76910407Smitch.hayenga@arm.com        // activity.  Switch it to inactive.
7706221Snate@binkert.org        if (_status == Active) {
7712875Sksewell@umich.edu            _status = Inactive;
7722875Sksewell@umich.edu            DPRINTF(Activity, "Deactivating stage.\n");
7739444SAndreas.Sandberg@ARM.com
77410408Smitch.hayenga@arm.com            cpu->deactivateStage(FullCPU::RenameIdx);
77510408Smitch.hayenga@arm.com        }
77610407Smitch.hayenga@arm.com    }
7773221Sktlim@umich.edu}
77810683Salexandru.dutu@amd.com
7792910Sksewell@umich.edutemplate <class Impl>
78010683Salexandru.dutu@amd.combool
78110683Salexandru.dutu@amd.comDefaultRename<Impl>::block(unsigned tid)
78210683Salexandru.dutu@amd.com{
7838627SAli.Saidi@ARM.com    DPRINTF(Rename, "[tid:%u]: Blocking.\n", tid);
7848627SAli.Saidi@ARM.com
78511526Sdavid.guillen@arm.com    // Add the current inputs onto the skid buffer, so they can be
78611526Sdavid.guillen@arm.com    // reprocessed when this stage unblocks.
7872875Sksewell@umich.edu    skidInsert(tid);
7882875Sksewell@umich.edu
7892875Sksewell@umich.edu    // Only signal backwards to block if the previous stages do not think
7902875Sksewell@umich.edu    // rename is already blocked.
7916221Snate@binkert.org    if (renameStatus[tid] != Blocked) {
7922875Sksewell@umich.edu        if (renameStatus[tid] != Unblocking) {
7932910Sksewell@umich.edu            toDecode->renameBlock[tid] = true;
7942910Sksewell@umich.edu            toDecode->renameUnblock[tid] = false;
7959444SAndreas.Sandberg@ARM.com            wroteToTimeBuffer = true;
79610408Smitch.hayenga@arm.com        }
79710408Smitch.hayenga@arm.com
79810408Smitch.hayenga@arm.com        // Rename can not go from SerializeStall to Blocked, otherwise
7992875Sksewell@umich.edu        // it would not know to complete the serialize stall.
8002875Sksewell@umich.edu        if (renameStatus[tid] != SerializeStall) {
8012875Sksewell@umich.edu            // Set status to Blocked.
8022875Sksewell@umich.edu            renameStatus[tid] = Blocked;
8036221Snate@binkert.org            return true;
8042292SN/A        }
8052847Sksewell@umich.edu    }
8062292SN/A
8072683Sktlim@umich.edu    return false;
8088793Sgblack@eecs.umich.edu}
8098793Sgblack@eecs.umich.edu
8108793Sgblack@eecs.umich.edutemplate <class Impl>
8118793Sgblack@eecs.umich.edubool
8128793Sgblack@eecs.umich.eduDefaultRename<Impl>::unblock(unsigned tid)
8132292SN/A{
8142292SN/A    DPRINTF(Rename, "[tid:%u]: Trying to unblock.\n", tid);
81512104Snathanael.premillieu@arm.com
81612106SRekai.GonzalezAlberquilla@arm.com    // Rename is done unblocking if the skid buffer is empty.
81712106SRekai.GonzalezAlberquilla@arm.com    if (skidBuffer[tid].empty() && renameStatus[tid] != SerializeStall) {
81812105Snathanael.premillieu@arm.com
81912104Snathanael.premillieu@arm.com        DPRINTF(Rename, "[tid:%u]: Done unblocking.\n", tid);
8202292SN/A
8212292SN/A        toDecode->renameUnblock[tid] = true;
8222292SN/A        wroteToTimeBuffer = true;
8232292SN/A
82412106SRekai.GonzalezAlberquilla@arm.com        renameStatus[tid] = Running;
82512106SRekai.GonzalezAlberquilla@arm.com        return true;
82612105Snathanael.premillieu@arm.com    }
82712104Snathanael.premillieu@arm.com
8282292SN/A    return false;
8292292SN/A}
8302292SN/A
8319920Syasuko.eckert@amd.comtemplate <class Impl>
83212106SRekai.GonzalezAlberquilla@arm.comvoid
83312106SRekai.GonzalezAlberquilla@arm.comDefaultRename<Impl>::doSquash(unsigned tid)
83412105Snathanael.premillieu@arm.com{
83512104Snathanael.premillieu@arm.com    typename list<RenameHistory>::iterator hb_it = historyBuffer[tid].begin();
8369920Syasuko.eckert@amd.com
8379920Syasuko.eckert@amd.com    InstSeqNum squashed_seq_num = fromCommit->commitInfo[tid].doneSeqNum;
8389920Syasuko.eckert@amd.com
8392292SN/A    // After a syscall squashes everything, the history buffer may be empty
8402847Sksewell@umich.edu    // but the ROB may still be squashing instructions.
8412292SN/A    if (historyBuffer[tid].empty()) {
8422847Sksewell@umich.edu        return;
8437720Sgblack@eecs.umich.edu    }
8442292SN/A
8452680Sktlim@umich.edu    // Go through the most recent instructions, undoing the mappings
8462292SN/A    // they did and freeing up the registers.
84710407Smitch.hayenga@arm.com    while (!historyBuffer[tid].empty() &&
8482292SN/A           (*hb_it).instSeqNum > squashed_seq_num) {
8492292SN/A        assert(hb_it != historyBuffer[tid].end());
8502292SN/A
8512292SN/A        DPRINTF(Rename, "[tid:%u]: Removing history entry with sequence "
8522292SN/A                "number %i.\n", tid, (*hb_it).instSeqNum);
8532292SN/A
8542292SN/A        // Tell the rename map to set the architected register to the
8552292SN/A        // previous physical register that it was renamed to.
8566221Snate@binkert.org        renameMap[tid]->setEntry(hb_it->archReg, hb_it->prevPhysReg);
8572292SN/A
8582877Sksewell@umich.edu        // Put the renamed physical register back on the free list.
8592847Sksewell@umich.edu        freeList->addReg(hb_it->newPhysReg);
8602847Sksewell@umich.edu
8612847Sksewell@umich.edu        historyBuffer[tid].erase(hb_it++);
8625364Sksewell@umich.edu
8635364Sksewell@umich.edu        ++renameUndoneMaps;
8645364Sksewell@umich.edu    }
8655364Sksewell@umich.edu}
8665364Sksewell@umich.edu
8675364Sksewell@umich.edutemplate<class Impl>
8682847Sksewell@umich.eduvoid
8692847Sksewell@umich.eduDefaultRename<Impl>::removeFromHistory(InstSeqNum inst_seq_num, unsigned tid)
87012106SRekai.GonzalezAlberquilla@arm.com{
87112106SRekai.GonzalezAlberquilla@arm.com    DPRINTF(Rename, "[tid:%u]: Removing a committed instruction from the "
87212105Snathanael.premillieu@arm.com            "history buffer %u (size=%i), until [sn:%lli].\n",
8732292SN/A            tid, tid, historyBuffer[tid].size(), inst_seq_num);
8742292SN/A
8752292SN/A    typename list<RenameHistory>::iterator hb_it = historyBuffer[tid].end();
8762292SN/A
8772847Sksewell@umich.edu    --hb_it;
87812106SRekai.GonzalezAlberquilla@arm.com
87912106SRekai.GonzalezAlberquilla@arm.com    if (historyBuffer[tid].empty()) {
88012105Snathanael.premillieu@arm.com        DPRINTF(Rename, "[tid:%u]: History buffer is empty.\n", tid);
8812292SN/A        return;
8822292SN/A    } else if (hb_it->instSeqNum > inst_seq_num) {
8832292SN/A        DPRINTF(Rename, "[tid:%u]: Old sequence number encountered.  Ensure "
8842292SN/A                "that a syscall happened recently.\n", tid);
8859920Syasuko.eckert@amd.com        return;
88612106SRekai.GonzalezAlberquilla@arm.com    }
88712106SRekai.GonzalezAlberquilla@arm.com
88812105Snathanael.premillieu@arm.com    // Commit all the renames up until (and including) the committed sequence
8899920Syasuko.eckert@amd.com    // number. Some or even all of the committed instructions may not have
8909920Syasuko.eckert@amd.com    // rename histories if they did not have destination registers that were
8919920Syasuko.eckert@amd.com    // renamed.
8929920Syasuko.eckert@amd.com    while (!historyBuffer[tid].empty() &&
8932847Sksewell@umich.edu           hb_it != historyBuffer[tid].end() &&
8948138SAli.Saidi@ARM.com           (*hb_it).instSeqNum <= inst_seq_num) {
8958138SAli.Saidi@ARM.com
8968138SAli.Saidi@ARM.com        DPRINTF(Rename, "[tid:%u]: Freeing up older rename of reg %i, "
8972292SN/A                "[sn:%lli].\n",
8982935Sksewell@umich.edu                tid, (*hb_it).prevPhysReg, (*hb_it).instSeqNum);
8992875Sksewell@umich.edu
9005363Sksewell@umich.edu        freeList->addReg((*hb_it).prevPhysReg);
9012935Sksewell@umich.edu        ++renameCommittedMaps;
9022292SN/A
9035362Sksewell@umich.edu        historyBuffer[tid].erase(hb_it--);
9045362Sksewell@umich.edu    }
9052292SN/A}
9062292SN/A
9072847Sksewell@umich.edutemplate <class Impl>
9083229Sktlim@umich.eduinline void
9093229Sktlim@umich.eduDefaultRename<Impl>::renameSrcRegs(DynInstPtr &inst,unsigned tid)
9103229Sktlim@umich.edu{
9113229Sktlim@umich.edu    assert(renameMap[tid] != 0);
9123229Sktlim@umich.edu
9133229Sktlim@umich.edu    unsigned num_src_regs = inst->numSrcRegs();
9142292SN/A
9152292SN/A    // Get the architectual register numbers from the source and
9162292SN/A    // destination operands, and redirect them to the right register.
9172292SN/A    // Will need to mark dependencies though.
9183229Sktlim@umich.edu    for (int src_idx = 0; src_idx < num_src_regs; src_idx++) {
9192292SN/A        RegIndex src_reg = inst->srcRegIdx(src_idx);
9202292SN/A
9214192Sktlim@umich.edu        // Look up the source registers to get the phys. register they've
9225595Sgblack@eecs.umich.edu        // been renamed to, and set the sources to those registers.
9236221Snate@binkert.org        PhysRegIndex renamed_reg = renameMap[tid]->lookup(src_reg);
9245702Ssaidi@eecs.umich.edu
9255702Ssaidi@eecs.umich.edu        DPRINTF(Rename, "[tid:%u]: Looking up arch reg %i, got "
9265702Ssaidi@eecs.umich.edu                "physical reg %i.\n", tid, (int)src_reg,
9275702Ssaidi@eecs.umich.edu                (int)renamed_reg);
9285702Ssaidi@eecs.umich.edu
9295702Ssaidi@eecs.umich.edu        inst->renameSrcReg(src_idx, renamed_reg);
9305702Ssaidi@eecs.umich.edu
9315702Ssaidi@eecs.umich.edu        // See if the register is ready or not.
9325702Ssaidi@eecs.umich.edu        if (scoreboard->getReg(renamed_reg) == true) {
9335702Ssaidi@eecs.umich.edu            DPRINTF(Rename, "[tid:%u]: Register is ready.\n", tid);
9345702Ssaidi@eecs.umich.edu
9355702Ssaidi@eecs.umich.edu            inst->markSrcRegReady(src_idx);
9365702Ssaidi@eecs.umich.edu        }
9375702Ssaidi@eecs.umich.edu
9386221Snate@binkert.org        ++renameRenameLookups;
9395702Ssaidi@eecs.umich.edu    }
9405702Ssaidi@eecs.umich.edu}
9415702Ssaidi@eecs.umich.edu
9425702Ssaidi@eecs.umich.edutemplate <class Impl>
9435702Ssaidi@eecs.umich.eduinline void
9445702Ssaidi@eecs.umich.eduDefaultRename<Impl>::renameDestRegs(DynInstPtr &inst,unsigned tid)
9455702Ssaidi@eecs.umich.edu{
9465702Ssaidi@eecs.umich.edu    typename RenameMap::RenameInfo rename_result;
9475702Ssaidi@eecs.umich.edu
9485702Ssaidi@eecs.umich.edu    unsigned num_dest_regs = inst->numDestRegs();
9495702Ssaidi@eecs.umich.edu
9505702Ssaidi@eecs.umich.edu    // Rename the destination registers.
9515702Ssaidi@eecs.umich.edu    for (int dest_idx = 0; dest_idx < num_dest_regs; dest_idx++) {
9525702Ssaidi@eecs.umich.edu        RegIndex dest_reg = inst->destRegIdx(dest_idx);
9535702Ssaidi@eecs.umich.edu
9545702Ssaidi@eecs.umich.edu        // Get the physical register that the destination will be
9555702Ssaidi@eecs.umich.edu        // renamed to.
9565702Ssaidi@eecs.umich.edu        rename_result = renameMap[tid]->rename(dest_reg);
9575702Ssaidi@eecs.umich.edu
9585702Ssaidi@eecs.umich.edu        //Mark Scoreboard entry as not ready
9595702Ssaidi@eecs.umich.edu        scoreboard->unsetReg(rename_result.first);
9605702Ssaidi@eecs.umich.edu
9615702Ssaidi@eecs.umich.edu        DPRINTF(Rename, "[tid:%u]: Renaming arch reg %i to physical "
9625702Ssaidi@eecs.umich.edu                "reg %i.\n", tid, (int)dest_reg,
9635702Ssaidi@eecs.umich.edu                (int)rename_result.first);
9645595Sgblack@eecs.umich.edu
9655595Sgblack@eecs.umich.edu        // Record the rename information so that a history can be kept.
9665595Sgblack@eecs.umich.edu        RenameHistory hb_entry(inst->seqNum, dest_reg,
96711150Smitch.hayenga@arm.com                               rename_result.first,
9685595Sgblack@eecs.umich.edu                               rename_result.second);
9695595Sgblack@eecs.umich.edu
9705595Sgblack@eecs.umich.edu        historyBuffer[tid].push_front(hb_entry);
9715595Sgblack@eecs.umich.edu
97210379Sandreas.hansson@arm.com        DPRINTF(Rename, "[tid:%u]: Adding instruction to history buffer, "
9735595Sgblack@eecs.umich.edu                "[sn:%lli].\n",tid,
9745595Sgblack@eecs.umich.edu                (*historyBuffer[tid].begin()).instSeqNum);
9755595Sgblack@eecs.umich.edu
9765595Sgblack@eecs.umich.edu        // Tell the instruction to rename the appropriate destination
9775595Sgblack@eecs.umich.edu        // register (dest_idx) to the new physical register
9785595Sgblack@eecs.umich.edu        // (rename_result.first), and record the previous physical
9795595Sgblack@eecs.umich.edu        // register that the same logical register was renamed to
9805595Sgblack@eecs.umich.edu        // (rename_result.second).
98111150Smitch.hayenga@arm.com        inst->renameDestReg(dest_idx,
9825595Sgblack@eecs.umich.edu                            rename_result.first,
9835595Sgblack@eecs.umich.edu                            rename_result.second);
98410417Sandreas.hansson@arm.com
9855595Sgblack@eecs.umich.edu        ++renameRenamedOperands;
9865595Sgblack@eecs.umich.edu    }
9871060SN/A}
9882852Sktlim@umich.edu
98910417Sandreas.hansson@arm.comtemplate <class Impl>
99010417Sandreas.hansson@arm.cominline int
9915595Sgblack@eecs.umich.eduDefaultRename<Impl>::calcFreeROBEntries(unsigned tid)
9925595Sgblack@eecs.umich.edu{
9937684Sgblack@eecs.umich.edu    int num_free = freeEntries[tid].robEntries -
9945595Sgblack@eecs.umich.edu                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
9955595Sgblack@eecs.umich.edu
9965595Sgblack@eecs.umich.edu    //DPRINTF(Rename,"[tid:%i]: %i rob free\n",tid,num_free);
9975595Sgblack@eecs.umich.edu
99811877Sbrandon.potter@amd.com    return num_free;
9995595Sgblack@eecs.umich.edu}
10005595Sgblack@eecs.umich.edu
10015595Sgblack@eecs.umich.edutemplate <class Impl>
10025595Sgblack@eecs.umich.eduinline int
10035595Sgblack@eecs.umich.eduDefaultRename<Impl>::calcFreeIQEntries(unsigned tid)
10045595Sgblack@eecs.umich.edu{
10055595Sgblack@eecs.umich.edu    int num_free = freeEntries[tid].iqEntries -
10065595Sgblack@eecs.umich.edu                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched);
10075595Sgblack@eecs.umich.edu
10085595Sgblack@eecs.umich.edu    //DPRINTF(Rename,"[tid:%i]: %i iq free\n",tid,num_free);
100911877Sbrandon.potter@amd.com
10105595Sgblack@eecs.umich.edu    return num_free;
10115595Sgblack@eecs.umich.edu}
10125595Sgblack@eecs.umich.edu
10135595Sgblack@eecs.umich.edutemplate <class Impl>
10145595Sgblack@eecs.umich.eduinline int
10155595Sgblack@eecs.umich.eduDefaultRename<Impl>::calcFreeLSQEntries(unsigned tid)
10165595Sgblack@eecs.umich.edu{
10175595Sgblack@eecs.umich.edu    int num_free = freeEntries[tid].lsqEntries -
101810905Sandreas.sandberg@arm.com                  (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatchedToLSQ);
10192864Sktlim@umich.edu
102010905Sandreas.sandberg@arm.com    //DPRINTF(Rename,"[tid:%i]: %i lsq free\n",tid,num_free);
10212864Sktlim@umich.edu
10222864Sktlim@umich.edu    return num_free;
10232864Sktlim@umich.edu}
10242864Sktlim@umich.edu
102510905Sandreas.sandberg@arm.comtemplate <class Impl>
10262864Sktlim@umich.eduunsigned
102710905Sandreas.sandberg@arm.comDefaultRename<Impl>::validInsts()
10282864Sktlim@umich.edu{
10292864Sktlim@umich.edu    unsigned inst_count = 0;
10302864Sktlim@umich.edu
103110913Sandreas.sandberg@arm.com    for (int i=0; i<fromDecode->size; i++) {
103210913Sandreas.sandberg@arm.com        if (!fromDecode->insts[i]->squashed)
10331060SN/A            inst_count++;
10349444SAndreas.Sandberg@ARM.com    }
103510913Sandreas.sandberg@arm.com
103610913Sandreas.sandberg@arm.com    return inst_count;
10373512Sktlim@umich.edu}
10389444SAndreas.Sandberg@ARM.com
10393512Sktlim@umich.edutemplate <class Impl>
10409444SAndreas.Sandberg@ARM.comvoid
10419444SAndreas.Sandberg@ARM.comDefaultRename<Impl>::readStallSignals(unsigned tid)
10429444SAndreas.Sandberg@ARM.com{
10439444SAndreas.Sandberg@ARM.com    if (fromIEW->iewBlock[tid]) {
10449444SAndreas.Sandberg@ARM.com        stalls[tid].iew = true;
10459444SAndreas.Sandberg@ARM.com    }
10462843Sktlim@umich.edu
10472325SN/A    if (fromIEW->iewUnblock[tid]) {
10482325SN/A        assert(stalls[tid].iew);
10492863Sktlim@umich.edu        stalls[tid].iew = false;
10509444SAndreas.Sandberg@ARM.com    }
105112143Sanouk.vanlaer@arm.com
105212143Sanouk.vanlaer@arm.com    if (fromCommit->commitBlock[tid]) {
105312143Sanouk.vanlaer@arm.com        stalls[tid].commit = true;
105412143Sanouk.vanlaer@arm.com    }
105512143Sanouk.vanlaer@arm.com
105612143Sanouk.vanlaer@arm.com    if (fromCommit->commitUnblock[tid]) {
105712143Sanouk.vanlaer@arm.com        assert(stalls[tid].commit);
105812143Sanouk.vanlaer@arm.com        stalls[tid].commit = false;
105912143Sanouk.vanlaer@arm.com    }
106012143Sanouk.vanlaer@arm.com}
106112143Sanouk.vanlaer@arm.com
10622863Sktlim@umich.edutemplate <class Impl>
10632863Sktlim@umich.edubool
10642852Sktlim@umich.eduDefaultRename<Impl>::checkStall(unsigned tid)
10659152Satgutier@umich.edu{
10669152Satgutier@umich.edu    bool ret_val = false;
106710913Sandreas.sandberg@arm.com
10682863Sktlim@umich.edu    if (stalls[tid].iew) {
10699444SAndreas.Sandberg@ARM.com        DPRINTF(Rename,"[tid:%i]: Stall from IEW stage detected.\n", tid);
10709444SAndreas.Sandberg@ARM.com        ret_val = true;
10719444SAndreas.Sandberg@ARM.com    } else if (stalls[tid].commit) {
10729444SAndreas.Sandberg@ARM.com        DPRINTF(Rename,"[tid:%i]: Stall from Commit stage detected.\n", tid);
10739444SAndreas.Sandberg@ARM.com        ret_val = true;
10749444SAndreas.Sandberg@ARM.com    } else if (calcFreeROBEntries(tid) <= 0) {
10759444SAndreas.Sandberg@ARM.com        DPRINTF(Rename,"[tid:%i]: Stall: ROB has 0 free entries.\n", tid);
10769444SAndreas.Sandberg@ARM.com        ret_val = true;
10779444SAndreas.Sandberg@ARM.com    } else if (calcFreeIQEntries(tid) <= 0) {
10789444SAndreas.Sandberg@ARM.com        DPRINTF(Rename,"[tid:%i]: Stall: IQ has 0 free entries.\n", tid);
10799444SAndreas.Sandberg@ARM.com        ret_val = true;
10809444SAndreas.Sandberg@ARM.com    } else if (calcFreeLSQEntries(tid) <= 0) {
10819444SAndreas.Sandberg@ARM.com        DPRINTF(Rename,"[tid:%i]: Stall: LSQ has 0 free entries.\n", tid);
10829444SAndreas.Sandberg@ARM.com        ret_val = true;
10839444SAndreas.Sandberg@ARM.com    } else if (renameMap[tid]->numFreeEntries() <= 0) {
10849444SAndreas.Sandberg@ARM.com        DPRINTF(Rename,"[tid:%i]: Stall: RenameMap has 0 free entries.\n", tid);
10859444SAndreas.Sandberg@ARM.com        ret_val = true;
108610913Sandreas.sandberg@arm.com    } else if (renameStatus[tid] == SerializeStall &&
10872863Sktlim@umich.edu               (!emptyROB[tid] || instsInProgress[tid])) {
10882316SN/A        DPRINTF(Rename,"[tid:%i]: Stall: Serialize stall and ROB is not "
10892310SN/A                "empty.\n",
10902316SN/A                tid);
10919444SAndreas.Sandberg@ARM.com        ret_val = true;
10929444SAndreas.Sandberg@ARM.com    }
10939444SAndreas.Sandberg@ARM.com
109410913Sandreas.sandberg@arm.com    return ret_val;
10959444SAndreas.Sandberg@ARM.com}
10969444SAndreas.Sandberg@ARM.com
10979444SAndreas.Sandberg@ARM.comtemplate <class Impl>
10989444SAndreas.Sandberg@ARM.comvoid
10999444SAndreas.Sandberg@ARM.comDefaultRename<Impl>::readFreeEntries(unsigned tid)
11009444SAndreas.Sandberg@ARM.com{
110110913Sandreas.sandberg@arm.com    bool updated = false;
11029444SAndreas.Sandberg@ARM.com    if (fromIEW->iewInfo[tid].usedIQ) {
11039444SAndreas.Sandberg@ARM.com        freeEntries[tid].iqEntries =
11049444SAndreas.Sandberg@ARM.com            fromIEW->iewInfo[tid].freeIQEntries;
11059444SAndreas.Sandberg@ARM.com        updated = true;
11069444SAndreas.Sandberg@ARM.com    }
11079444SAndreas.Sandberg@ARM.com
11089444SAndreas.Sandberg@ARM.com    if (fromIEW->iewInfo[tid].usedLSQ) {
11099444SAndreas.Sandberg@ARM.com        freeEntries[tid].lsqEntries =
11109444SAndreas.Sandberg@ARM.com            fromIEW->iewInfo[tid].freeLSQEntries;
11119444SAndreas.Sandberg@ARM.com        updated = true;
11129444SAndreas.Sandberg@ARM.com    }
11139444SAndreas.Sandberg@ARM.com
11149444SAndreas.Sandberg@ARM.com    if (fromCommit->commitInfo[tid].usedROB) {
11159444SAndreas.Sandberg@ARM.com        freeEntries[tid].robEntries =
11169444SAndreas.Sandberg@ARM.com            fromCommit->commitInfo[tid].freeROBEntries;
11179444SAndreas.Sandberg@ARM.com        emptyROB[tid] = fromCommit->commitInfo[tid].emptyROB;
11189444SAndreas.Sandberg@ARM.com        updated = true;
11199444SAndreas.Sandberg@ARM.com    }
11209444SAndreas.Sandberg@ARM.com
11219444SAndreas.Sandberg@ARM.com    DPRINTF(Rename, "[tid:%i]: Free IQ: %i, Free ROB: %i, Free LSQ: %i\n",
11229444SAndreas.Sandberg@ARM.com            tid,
11239444SAndreas.Sandberg@ARM.com            freeEntries[tid].iqEntries,
11249444SAndreas.Sandberg@ARM.com            freeEntries[tid].robEntries,
11259444SAndreas.Sandberg@ARM.com            freeEntries[tid].lsqEntries);
11269444SAndreas.Sandberg@ARM.com
11279444SAndreas.Sandberg@ARM.com    DPRINTF(Rename, "[tid:%i]: %i instructions not yet in ROB\n",
11289444SAndreas.Sandberg@ARM.com            tid, instsInProgress[tid]);
11299444SAndreas.Sandberg@ARM.com}
11309444SAndreas.Sandberg@ARM.com
11319444SAndreas.Sandberg@ARM.comtemplate <class Impl>
11329444SAndreas.Sandberg@ARM.combool
11339444SAndreas.Sandberg@ARM.comDefaultRename<Impl>::checkSignalsAndUpdate(unsigned tid)
11349444SAndreas.Sandberg@ARM.com{
11359444SAndreas.Sandberg@ARM.com    // Check if there's a squash signal, squash if there is
11369444SAndreas.Sandberg@ARM.com    // Check stall signals, block if necessary.
11379444SAndreas.Sandberg@ARM.com    // If status was blocked
11389444SAndreas.Sandberg@ARM.com    //     check if stall conditions have passed
11399444SAndreas.Sandberg@ARM.com    //         if so then go to unblocking
11409444SAndreas.Sandberg@ARM.com    // If status was Squashing
11419444SAndreas.Sandberg@ARM.com    //     check if squashing is not high.  Switch to running this cycle.
11429444SAndreas.Sandberg@ARM.com    // If status was serialize stall
11439444SAndreas.Sandberg@ARM.com    //     check if ROB is empty and no insts are in flight to the ROB
11449444SAndreas.Sandberg@ARM.com
11459444SAndreas.Sandberg@ARM.com    readFreeEntries(tid);
11469444SAndreas.Sandberg@ARM.com    readStallSignals(tid);
11479444SAndreas.Sandberg@ARM.com
11489444SAndreas.Sandberg@ARM.com    if (fromCommit->commitInfo[tid].squash) {
11499444SAndreas.Sandberg@ARM.com        DPRINTF(Rename, "[tid:%u]: Squashing instructions due to squash from "
11509444SAndreas.Sandberg@ARM.com                "commit.\n", tid);
11519444SAndreas.Sandberg@ARM.com
11529444SAndreas.Sandberg@ARM.com        squash(tid);
11539444SAndreas.Sandberg@ARM.com
11549444SAndreas.Sandberg@ARM.com        return true;
11559444SAndreas.Sandberg@ARM.com    }
11569444SAndreas.Sandberg@ARM.com
11579444SAndreas.Sandberg@ARM.com    if (fromCommit->commitInfo[tid].robSquashing) {
11589444SAndreas.Sandberg@ARM.com        DPRINTF(Rename, "[tid:%u]: ROB is still squashing.\n", tid);
11599444SAndreas.Sandberg@ARM.com
11609444SAndreas.Sandberg@ARM.com        renameStatus[tid] = Squashing;
11619444SAndreas.Sandberg@ARM.com
11629444SAndreas.Sandberg@ARM.com        return true;
11639444SAndreas.Sandberg@ARM.com    }
11649444SAndreas.Sandberg@ARM.com
11652316SN/A    if (checkStall(tid)) {
11669342SAndreas.Sandberg@arm.com        return block(tid);
11672316SN/A    }
11689444SAndreas.Sandberg@ARM.com
11699444SAndreas.Sandberg@ARM.com    if (renameStatus[tid] == Blocked) {
11702316SN/A        DPRINTF(Rename, "[tid:%u]: Done blocking, switching to unblocking.\n",
11719444SAndreas.Sandberg@ARM.com                tid);
11729523SAndreas.Sandberg@ARM.com
11733319Shsul@eecs.umich.edu        renameStatus[tid] = Unblocking;
11749444SAndreas.Sandberg@ARM.com
11759444SAndreas.Sandberg@ARM.com        unblock(tid);
11762316SN/A
11779444SAndreas.Sandberg@ARM.com        return true;
11789444SAndreas.Sandberg@ARM.com    }
11799444SAndreas.Sandberg@ARM.com
11809444SAndreas.Sandberg@ARM.com    if (renameStatus[tid] == Squashing) {
11819444SAndreas.Sandberg@ARM.com        // Switch status to running if rename isn't being told to block or
11829444SAndreas.Sandberg@ARM.com        // squash this cycle.
11832863Sktlim@umich.edu        DPRINTF(Rename, "[tid:%u]: Done squashing, switching to running.\n",
11842310SN/A                tid);
11859444SAndreas.Sandberg@ARM.com
11869444SAndreas.Sandberg@ARM.com        renameStatus[tid] = Running;
11879444SAndreas.Sandberg@ARM.com
11889444SAndreas.Sandberg@ARM.com        return false;
11892843Sktlim@umich.edu    }
11902843Sktlim@umich.edu
11912843Sktlim@umich.edu    if (renameStatus[tid] == SerializeStall) {
11922843Sktlim@umich.edu        // Stall ends once the ROB is free.
11932843Sktlim@umich.edu        DPRINTF(Rename, "[tid:%u]: Done with serialize stall, switching to "
11942843Sktlim@umich.edu                "unblocking.\n", tid);
11959444SAndreas.Sandberg@ARM.com
11969429SAndreas.Sandberg@ARM.com        DynInstPtr serial_inst = serializeInst[tid];
11979429SAndreas.Sandberg@ARM.com
11989444SAndreas.Sandberg@ARM.com        renameStatus[tid] = Unblocking;
11992843Sktlim@umich.edu
12002843Sktlim@umich.edu        unblock(tid);
12018887Sgeoffrey.blake@arm.com
12022843Sktlim@umich.edu        DPRINTF(Rename, "[tid:%u]: Processing instruction [%lli] with "
12032843Sktlim@umich.edu                "PC %#x.\n",
12041060SN/A                tid, serial_inst->seqNum, serial_inst->readPC());
12051060SN/A
12061060SN/A        // Put instruction into queue here.
12071060SN/A        serial_inst->clearSerializeBefore();
12081755SN/A
12091060SN/A        if (!skidBuffer[tid].empty()) {
12108737Skoansin.tan@gmail.com            skidBuffer[tid].push_front(serial_inst);
12111060SN/A        } else {
12122307SN/A            insts[tid].push_front(serial_inst);
12132307SN/A        }
12142307SN/A
12152307SN/A        DPRINTF(Rename, "[tid:%u]: Instruction must be processed by rename."
12162307SN/A                " Adding to front of list.", tid);
12172307SN/A
12189444SAndreas.Sandberg@ARM.com        serializeInst[tid] = NULL;
12191060SN/A
12209152Satgutier@umich.edu        return true;
12219152Satgutier@umich.edu    }
12229152Satgutier@umich.edu
12239152Satgutier@umich.edu    // If we've reached this point, we have not gotten any signals that
12249179Sandreas.hansson@arm.com    // cause rename to change its status.  Rename remains the same as before.
12259444SAndreas.Sandberg@ARM.com    return false;
12261060SN/A}
12271060SN/A
12281060SN/Atemplate<class Impl>
12299523SAndreas.Sandberg@ARM.comvoid
12309523SAndreas.Sandberg@ARM.comDefaultRename<Impl>::serializeAfter(InstQueue &inst_list,
12319523SAndreas.Sandberg@ARM.com                                   unsigned tid)
12329524SAndreas.Sandberg@ARM.com{
12339523SAndreas.Sandberg@ARM.com    if (inst_list.empty()) {
12349523SAndreas.Sandberg@ARM.com        // Mark a bit to say that I must serialize on the next instruction.
12359523SAndreas.Sandberg@ARM.com        serializeOnNextInst[tid] = true;
12369523SAndreas.Sandberg@ARM.com        return;
12379523SAndreas.Sandberg@ARM.com    }
12389523SAndreas.Sandberg@ARM.com
12395595Sgblack@eecs.umich.edu    // Set the next instruction as serializing.
124010698Sandreas.hansson@arm.com    inst_list.front()->setSerializeBefore();
12415595Sgblack@eecs.umich.edu}
12429384SAndreas.Sandberg@arm.com
12435595Sgblack@eecs.umich.edutemplate <class Impl>
12445595Sgblack@eecs.umich.eduinline void
12455595Sgblack@eecs.umich.eduDefaultRename<Impl>::incrFullStat(const FullSource &source)
12465595Sgblack@eecs.umich.edu{
12476221Snate@binkert.org    switch (source) {
12485595Sgblack@eecs.umich.edu      case ROB:
12497897Shestness@cs.utexas.edu        ++renameROBFullEvents;
12509384SAndreas.Sandberg@arm.com        break;
12515595Sgblack@eecs.umich.edu      case IQ:
12525595Sgblack@eecs.umich.edu        ++renameIQFullEvents;
12535595Sgblack@eecs.umich.edu        break;
12545595Sgblack@eecs.umich.edu      case LSQ:
12555595Sgblack@eecs.umich.edu        ++renameLSQFullEvents;
12566221Snate@binkert.org        break;
12575595Sgblack@eecs.umich.edu      default:
12589384SAndreas.Sandberg@arm.com        panic("Rename full stall stat should be incremented for a reason!");
12595595Sgblack@eecs.umich.edu        break;
12605595Sgblack@eecs.umich.edu    }
12615595Sgblack@eecs.umich.edu}
12625595Sgblack@eecs.umich.edu
12635595Sgblack@eecs.umich.edutemplate <class Impl>
12646221Snate@binkert.orgvoid
12655595Sgblack@eecs.umich.eduDefaultRename<Impl>::dumpHistory()
12667897Shestness@cs.utexas.edu{
12679384SAndreas.Sandberg@arm.com    typename list<RenameHistory>::iterator buf_it;
12685595Sgblack@eecs.umich.edu
12695595Sgblack@eecs.umich.edu    for (int i = 0; i < numThreads; i++) {
12705595Sgblack@eecs.umich.edu
12711060SN/A        buf_it = historyBuffer[i].begin();
127212105Snathanael.premillieu@arm.com
12731060SN/A        while (buf_it != historyBuffer[i].end()) {
12747897Shestness@cs.utexas.edu            cprintf("Seq num: %i\nArch reg: %i New phys reg: %i Old phys "
127512105Snathanael.premillieu@arm.com                    "reg: %i\n", (*buf_it).instSeqNum, (int)(*buf_it).archReg,
12761060SN/A                    (int)(*buf_it).newPhysReg, (int)(*buf_it).prevPhysReg);
12771060SN/A
12781060SN/A            buf_it++;
12792455SN/A        }
128012105Snathanael.premillieu@arm.com    }
12811060SN/A}
12827897Shestness@cs.utexas.edu