rename_impl.hh revision 3788
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" 353773Sgblack@eecs.umich.edu#include "arch/regfile.hh" 361858SN/A#include "config/full_system.hh" 371717SN/A#include "cpu/o3/rename.hh" 381060SN/A 391061SN/Atemplate <class Impl> 402292SN/ADefaultRename<Impl>::DefaultRename(Params *params) 412292SN/A : iewToRenameDelay(params->iewToRenameDelay), 422292SN/A decodeToRenameDelay(params->decodeToRenameDelay), 432292SN/A commitToRenameDelay(params->commitToRenameDelay), 442292SN/A renameWidth(params->renameWidth), 452292SN/A commitWidth(params->commitWidth), 463788Sgblack@eecs.umich.edu resumeSerialize(false), 472361SN/A numThreads(params->numberOfThreads), 482361SN/A maxPhysicalRegs(params->numPhysIntRegs + params->numPhysFloatRegs) 491060SN/A{ 502292SN/A _status = Inactive; 512292SN/A 522292SN/A for (int i=0; i< numThreads; i++) { 532292SN/A renameStatus[i] = Idle; 542292SN/A 552292SN/A freeEntries[i].iqEntries = 0; 562292SN/A freeEntries[i].lsqEntries = 0; 572292SN/A freeEntries[i].robEntries = 0; 582292SN/A 592292SN/A stalls[i].iew = false; 602292SN/A stalls[i].commit = false; 612301SN/A serializeInst[i] = NULL; 622292SN/A 632292SN/A instsInProgress[i] = 0; 642292SN/A 652292SN/A emptyROB[i] = true; 662292SN/A 672292SN/A serializeOnNextInst[i] = false; 682292SN/A } 692292SN/A 702292SN/A // @todo: Make into a parameter. 712292SN/A skidBufferMax = (2 * (iewToRenameDelay * params->decodeWidth)) + renameWidth; 722292SN/A} 732292SN/A 742292SN/Atemplate <class Impl> 752292SN/Astd::string 762292SN/ADefaultRename<Impl>::name() const 772292SN/A{ 782292SN/A return cpu->name() + ".rename"; 791060SN/A} 801060SN/A 811061SN/Atemplate <class Impl> 821060SN/Avoid 832292SN/ADefaultRename<Impl>::regStats() 841062SN/A{ 851062SN/A renameSquashCycles 862301SN/A .name(name() + ".RENAME:SquashCycles") 871062SN/A .desc("Number of cycles rename is squashing") 881062SN/A .prereq(renameSquashCycles); 891062SN/A renameIdleCycles 902301SN/A .name(name() + ".RENAME:IdleCycles") 911062SN/A .desc("Number of cycles rename is idle") 921062SN/A .prereq(renameIdleCycles); 931062SN/A renameBlockCycles 942301SN/A .name(name() + ".RENAME:BlockCycles") 951062SN/A .desc("Number of cycles rename is blocking") 961062SN/A .prereq(renameBlockCycles); 972301SN/A renameSerializeStallCycles 982301SN/A .name(name() + ".RENAME:serializeStallCycles") 992301SN/A .desc("count of cycles rename stalled for serializing inst") 1002301SN/A .flags(Stats::total); 1012292SN/A renameRunCycles 1022301SN/A .name(name() + ".RENAME:RunCycles") 1032292SN/A .desc("Number of cycles rename is running") 1042292SN/A .prereq(renameIdleCycles); 1051062SN/A renameUnblockCycles 1062301SN/A .name(name() + ".RENAME:UnblockCycles") 1071062SN/A .desc("Number of cycles rename is unblocking") 1081062SN/A .prereq(renameUnblockCycles); 1091062SN/A renameRenamedInsts 1102301SN/A .name(name() + ".RENAME:RenamedInsts") 1111062SN/A .desc("Number of instructions processed by rename") 1121062SN/A .prereq(renameRenamedInsts); 1131062SN/A renameSquashedInsts 1142301SN/A .name(name() + ".RENAME:SquashedInsts") 1151062SN/A .desc("Number of squashed instructions processed by rename") 1161062SN/A .prereq(renameSquashedInsts); 1171062SN/A renameROBFullEvents 1182301SN/A .name(name() + ".RENAME:ROBFullEvents") 1192292SN/A .desc("Number of times rename has blocked due to ROB full") 1201062SN/A .prereq(renameROBFullEvents); 1211062SN/A renameIQFullEvents 1222301SN/A .name(name() + ".RENAME:IQFullEvents") 1232292SN/A .desc("Number of times rename has blocked due to IQ full") 1241062SN/A .prereq(renameIQFullEvents); 1252292SN/A renameLSQFullEvents 1262301SN/A .name(name() + ".RENAME:LSQFullEvents") 1272292SN/A .desc("Number of times rename has blocked due to LSQ full") 1282292SN/A .prereq(renameLSQFullEvents); 1291062SN/A renameFullRegistersEvents 1302301SN/A .name(name() + ".RENAME:FullRegisterEvents") 1311062SN/A .desc("Number of times there has been no free registers") 1321062SN/A .prereq(renameFullRegistersEvents); 1331062SN/A renameRenamedOperands 1342301SN/A .name(name() + ".RENAME:RenamedOperands") 1351062SN/A .desc("Number of destination operands rename has renamed") 1361062SN/A .prereq(renameRenamedOperands); 1371062SN/A renameRenameLookups 1382301SN/A .name(name() + ".RENAME:RenameLookups") 1391062SN/A .desc("Number of register rename lookups that rename has made") 1401062SN/A .prereq(renameRenameLookups); 1411062SN/A renameCommittedMaps 1422301SN/A .name(name() + ".RENAME:CommittedMaps") 1431062SN/A .desc("Number of HB maps that are committed") 1441062SN/A .prereq(renameCommittedMaps); 1451062SN/A renameUndoneMaps 1462301SN/A .name(name() + ".RENAME:UndoneMaps") 1471062SN/A .desc("Number of HB maps that are undone due to squashing") 1481062SN/A .prereq(renameUndoneMaps); 1492301SN/A renamedSerializing 1502301SN/A .name(name() + ".RENAME:serializingInsts") 1512301SN/A .desc("count of serializing insts renamed") 1522301SN/A .flags(Stats::total) 1532301SN/A ; 1542301SN/A renamedTempSerializing 1552301SN/A .name(name() + ".RENAME:tempSerializingInsts") 1562301SN/A .desc("count of temporary serializing insts renamed") 1572301SN/A .flags(Stats::total) 1582301SN/A ; 1592307SN/A renameSkidInsts 1602307SN/A .name(name() + ".RENAME:skidInsts") 1612307SN/A .desc("count of insts added to the skid buffer") 1622307SN/A .flags(Stats::total) 1632307SN/A ; 1641062SN/A} 1651062SN/A 1661062SN/Atemplate <class Impl> 1671062SN/Avoid 1682733Sktlim@umich.eduDefaultRename<Impl>::setCPU(O3CPU *cpu_ptr) 1691060SN/A{ 1702292SN/A DPRINTF(Rename, "Setting CPU pointer.\n"); 1711060SN/A cpu = cpu_ptr; 1721060SN/A} 1731060SN/A 1741061SN/Atemplate <class Impl> 1751060SN/Avoid 1762292SN/ADefaultRename<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 1771060SN/A{ 1782292SN/A DPRINTF(Rename, "Setting time buffer pointer.\n"); 1791060SN/A timeBuffer = tb_ptr; 1801060SN/A 1811060SN/A // Setup wire to read information from time buffer, from IEW stage. 1821060SN/A fromIEW = timeBuffer->getWire(-iewToRenameDelay); 1831060SN/A 1841060SN/A // Setup wire to read infromation from time buffer, from commit stage. 1851060SN/A fromCommit = timeBuffer->getWire(-commitToRenameDelay); 1861060SN/A 1871060SN/A // Setup wire to write information to previous stages. 1881060SN/A toDecode = timeBuffer->getWire(0); 1891060SN/A} 1901060SN/A 1911061SN/Atemplate <class Impl> 1921060SN/Avoid 1932292SN/ADefaultRename<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 1941060SN/A{ 1952292SN/A DPRINTF(Rename, "Setting rename queue pointer.\n"); 1961060SN/A renameQueue = rq_ptr; 1971060SN/A 1981060SN/A // Setup wire to write information to future stages. 1991060SN/A toIEW = renameQueue->getWire(0); 2001060SN/A} 2011060SN/A 2021061SN/Atemplate <class Impl> 2031060SN/Avoid 2042292SN/ADefaultRename<Impl>::setDecodeQueue(TimeBuffer<DecodeStruct> *dq_ptr) 2051060SN/A{ 2062292SN/A DPRINTF(Rename, "Setting decode queue pointer.\n"); 2071060SN/A decodeQueue = dq_ptr; 2081060SN/A 2091060SN/A // Setup wire to get information from decode. 2101060SN/A fromDecode = decodeQueue->getWire(-decodeToRenameDelay); 2111060SN/A} 2121060SN/A 2131061SN/Atemplate <class Impl> 2141060SN/Avoid 2152292SN/ADefaultRename<Impl>::initStage() 2161060SN/A{ 2172329SN/A // Grab the number of free entries directly from the stages. 2182292SN/A for (int tid=0; tid < numThreads; tid++) { 2192292SN/A freeEntries[tid].iqEntries = iew_ptr->instQueue.numFreeEntries(tid); 2202292SN/A freeEntries[tid].lsqEntries = iew_ptr->ldstQueue.numFreeEntries(tid); 2212292SN/A freeEntries[tid].robEntries = commit_ptr->numROBFreeEntries(tid); 2222292SN/A emptyROB[tid] = true; 2232292SN/A } 2241060SN/A} 2251060SN/A 2262292SN/Atemplate<class Impl> 2272292SN/Avoid 2282980Sgblack@eecs.umich.eduDefaultRename<Impl>::setActiveThreads(std::list<unsigned> *at_ptr) 2292292SN/A{ 2302292SN/A DPRINTF(Rename, "Setting active threads list pointer.\n"); 2312292SN/A activeThreads = at_ptr; 2322292SN/A} 2332292SN/A 2342292SN/A 2351061SN/Atemplate <class Impl> 2361060SN/Avoid 2372292SN/ADefaultRename<Impl>::setRenameMap(RenameMap rm_ptr[]) 2381060SN/A{ 2392292SN/A DPRINTF(Rename, "Setting rename map pointers.\n"); 2401060SN/A 2412292SN/A for (int i=0; i<numThreads; i++) { 2422292SN/A renameMap[i] = &rm_ptr[i]; 2431060SN/A } 2441060SN/A} 2451060SN/A 2461061SN/Atemplate <class Impl> 2471060SN/Avoid 2482292SN/ADefaultRename<Impl>::setFreeList(FreeList *fl_ptr) 2491060SN/A{ 2502292SN/A DPRINTF(Rename, "Setting free list pointer.\n"); 2512292SN/A freeList = fl_ptr; 2522292SN/A} 2531060SN/A 2542292SN/Atemplate<class Impl> 2552292SN/Avoid 2562292SN/ADefaultRename<Impl>::setScoreboard(Scoreboard *_scoreboard) 2572292SN/A{ 2582292SN/A DPRINTF(Rename, "Setting scoreboard pointer.\n"); 2592292SN/A scoreboard = _scoreboard; 2601060SN/A} 2611060SN/A 2621061SN/Atemplate <class Impl> 2632863Sktlim@umich.edubool 2642843Sktlim@umich.eduDefaultRename<Impl>::drain() 2651060SN/A{ 2662348SN/A // Rename is ready to switch out at any time. 2672843Sktlim@umich.edu cpu->signalDrained(); 2682863Sktlim@umich.edu return true; 2692316SN/A} 2701060SN/A 2712316SN/Atemplate <class Impl> 2722316SN/Avoid 2732843Sktlim@umich.eduDefaultRename<Impl>::switchOut() 2742316SN/A{ 2752348SN/A // Clear any state, fix up the rename map. 2762307SN/A for (int i = 0; i < numThreads; i++) { 2772980Sgblack@eecs.umich.edu typename std::list<RenameHistory>::iterator hb_it = 2782980Sgblack@eecs.umich.edu historyBuffer[i].begin(); 2792307SN/A 2802307SN/A while (!historyBuffer[i].empty()) { 2812307SN/A assert(hb_it != historyBuffer[i].end()); 2822307SN/A 2832307SN/A DPRINTF(Rename, "[tid:%u]: Removing history entry with sequence " 2842307SN/A "number %i.\n", i, (*hb_it).instSeqNum); 2852307SN/A 2862307SN/A // Tell the rename map to set the architected register to the 2872307SN/A // previous physical register that it was renamed to. 2882307SN/A renameMap[i]->setEntry(hb_it->archReg, hb_it->prevPhysReg); 2892307SN/A 2902307SN/A // Put the renamed physical register back on the free list. 2912307SN/A freeList->addReg(hb_it->newPhysReg); 2922307SN/A 2932361SN/A // Be sure to mark its register as ready if it's a misc register. 2942361SN/A if (hb_it->newPhysReg >= maxPhysicalRegs) { 2952361SN/A scoreboard->setReg(hb_it->newPhysReg); 2962361SN/A } 2972361SN/A 2982307SN/A historyBuffer[i].erase(hb_it++); 2992307SN/A } 3002307SN/A insts[i].clear(); 3012307SN/A skidBuffer[i].clear(); 3021060SN/A } 3031060SN/A} 3041060SN/A 3051061SN/Atemplate <class Impl> 3061060SN/Avoid 3072307SN/ADefaultRename<Impl>::takeOverFrom() 3081060SN/A{ 3092307SN/A _status = Inactive; 3102307SN/A initStage(); 3111060SN/A 3122329SN/A // Reset all state prior to taking over from the other CPU. 3132307SN/A for (int i=0; i< numThreads; i++) { 3142307SN/A renameStatus[i] = Idle; 3151060SN/A 3162307SN/A stalls[i].iew = false; 3172307SN/A stalls[i].commit = false; 3182307SN/A serializeInst[i] = NULL; 3192307SN/A 3202307SN/A instsInProgress[i] = 0; 3212307SN/A 3222307SN/A emptyROB[i] = true; 3232307SN/A 3242307SN/A serializeOnNextInst[i] = false; 3252307SN/A } 3262307SN/A} 3272307SN/A 3282307SN/Atemplate <class Impl> 3292307SN/Avoid 3302935Sksewell@umich.eduDefaultRename<Impl>::squash(const InstSeqNum &squash_seq_num, unsigned tid) 3311858SN/A{ 3322292SN/A DPRINTF(Rename, "[tid:%u]: Squashing instructions.\n",tid); 3331858SN/A 3342292SN/A // Clear the stall signal if rename was blocked or unblocking before. 3352292SN/A // If it still needs to block, the blocking should happen the next 3362292SN/A // cycle and there should be space to hold everything due to the squash. 3372292SN/A if (renameStatus[tid] == Blocked || 3383788Sgblack@eecs.umich.edu renameStatus[tid] == Unblocking) { 3392292SN/A toDecode->renameUnblock[tid] = 1; 3402698Sktlim@umich.edu 3413788Sgblack@eecs.umich.edu resumeSerialize = false; 3422301SN/A serializeInst[tid] = NULL; 3433788Sgblack@eecs.umich.edu } else if (renameStatus[tid] == SerializeStall) { 3443788Sgblack@eecs.umich.edu if (serializeInst[tid]->seqNum <= squash_seq_num) { 3453788Sgblack@eecs.umich.edu DPRINTF(Rename, "Rename will resume serializing after squash\n"); 3463788Sgblack@eecs.umich.edu resumeSerialize = true; 3473788Sgblack@eecs.umich.edu assert(serializeInst[tid]); 3483788Sgblack@eecs.umich.edu } else { 3493788Sgblack@eecs.umich.edu resumeSerialize = false; 3503788Sgblack@eecs.umich.edu toDecode->renameUnblock[tid] = 1; 3513788Sgblack@eecs.umich.edu 3523788Sgblack@eecs.umich.edu serializeInst[tid] = NULL; 3533788Sgblack@eecs.umich.edu } 3542292SN/A } 3552292SN/A 3562292SN/A // Set the status to Squashing. 3572292SN/A renameStatus[tid] = Squashing; 3582292SN/A 3592329SN/A // Squash any instructions from decode. 3602292SN/A unsigned squashCount = 0; 3612292SN/A 3622292SN/A for (int i=0; i<fromDecode->size; i++) { 3632935Sksewell@umich.edu if (fromDecode->insts[i]->threadNumber == tid && 3642935Sksewell@umich.edu fromDecode->insts[i]->seqNum > squash_seq_num) { 3652731Sktlim@umich.edu fromDecode->insts[i]->setSquashed(); 3662292SN/A wroteToTimeBuffer = true; 3672292SN/A squashCount++; 3682292SN/A } 3692935Sksewell@umich.edu 3702292SN/A } 3712292SN/A 3722935Sksewell@umich.edu // Clear the instruction list and skid buffer in case they have any 3732935Sksewell@umich.edu // insts in them. Since we support multiple ISAs, we cant just: 3742935Sksewell@umich.edu // "insts[tid].clear();" or "skidBuffer[tid].clear()" since there is 3752935Sksewell@umich.edu // a possible delay slot inst for different architectures 3762935Sksewell@umich.edu // insts[tid].clear(); 3773093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 3782935Sksewell@umich.edu DPRINTF(Rename, "[tid:%i] Squashing incoming decode instructions until " 3792935Sksewell@umich.edu "[sn:%i].\n",tid, squash_seq_num); 3802935Sksewell@umich.edu ListIt ilist_it = insts[tid].begin(); 3812935Sksewell@umich.edu while (ilist_it != insts[tid].end()) { 3822935Sksewell@umich.edu if ((*ilist_it)->seqNum > squash_seq_num) { 3832935Sksewell@umich.edu (*ilist_it)->setSquashed(); 3842935Sksewell@umich.edu DPRINTF(Rename, "Squashing incoming decode instruction, " 3852935Sksewell@umich.edu "[tid:%i] [sn:%i] PC %08p.\n", tid, (*ilist_it)->seqNum, (*ilist_it)->PC); 3862935Sksewell@umich.edu } 3872935Sksewell@umich.edu ilist_it++; 3882935Sksewell@umich.edu } 3893093Sksewell@umich.edu#else 3903093Sksewell@umich.edu insts[tid].clear(); 3912935Sksewell@umich.edu#endif 3922292SN/A 3932292SN/A // Clear the skid buffer in case it has any data in it. 3942935Sksewell@umich.edu // See comments above. 3952935Sksewell@umich.edu // skidBuffer[tid].clear(); 3963093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 3972935Sksewell@umich.edu DPRINTF(Rename, "[tid:%i] Squashing incoming skidbuffer instructions " 3982935Sksewell@umich.edu "until [sn:%i].\n", tid, squash_seq_num); 3992935Sksewell@umich.edu ListIt slist_it = skidBuffer[tid].begin(); 4002935Sksewell@umich.edu while (slist_it != skidBuffer[tid].end()) { 4012935Sksewell@umich.edu if ((*slist_it)->seqNum > squash_seq_num) { 4022935Sksewell@umich.edu (*slist_it)->setSquashed(); 4032935Sksewell@umich.edu DPRINTF(Rename, "Squashing skidbuffer instruction, [tid:%i] [sn:%i]" 4042935Sksewell@umich.edu "PC %08p.\n", tid, (*slist_it)->seqNum, (*slist_it)->PC); 4052935Sksewell@umich.edu } 4062935Sksewell@umich.edu slist_it++; 4072935Sksewell@umich.edu } 4083093Sksewell@umich.edu#else 4093093Sksewell@umich.edu skidBuffer[tid].clear(); 4102935Sksewell@umich.edu#endif 4112935Sksewell@umich.edu doSquash(squash_seq_num, tid); 4122292SN/A} 4132292SN/A 4142292SN/Atemplate <class Impl> 4152292SN/Avoid 4162292SN/ADefaultRename<Impl>::tick() 4172292SN/A{ 4182292SN/A wroteToTimeBuffer = false; 4192292SN/A 4202292SN/A blockThisCycle = false; 4212292SN/A 4222292SN/A bool status_change = false; 4232292SN/A 4242292SN/A toIEWIndex = 0; 4252292SN/A 4262292SN/A sortInsts(); 4272292SN/A 4282980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 4292292SN/A 4302292SN/A // Check stall and squash signals. 4312292SN/A while (threads != (*activeThreads).end()) { 4322292SN/A unsigned tid = *threads++; 4332292SN/A 4342292SN/A DPRINTF(Rename, "Processing [tid:%i]\n", tid); 4352292SN/A 4362292SN/A status_change = checkSignalsAndUpdate(tid) || status_change; 4372292SN/A 4382292SN/A rename(status_change, tid); 4392292SN/A } 4402292SN/A 4412292SN/A if (status_change) { 4422292SN/A updateStatus(); 4432292SN/A } 4442292SN/A 4452292SN/A if (wroteToTimeBuffer) { 4462292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 4472292SN/A cpu->activityThisCycle(); 4482292SN/A } 4492292SN/A 4502292SN/A threads = (*activeThreads).begin(); 4512292SN/A 4522292SN/A while (threads != (*activeThreads).end()) { 4532292SN/A unsigned tid = *threads++; 4542292SN/A 4552292SN/A // If we committed this cycle then doneSeqNum will be > 0 4562292SN/A if (fromCommit->commitInfo[tid].doneSeqNum != 0 && 4572292SN/A !fromCommit->commitInfo[tid].squash && 4582292SN/A renameStatus[tid] != Squashing) { 4592292SN/A 4602292SN/A removeFromHistory(fromCommit->commitInfo[tid].doneSeqNum, 4612292SN/A tid); 4622292SN/A } 4632292SN/A } 4642292SN/A 4652292SN/A // @todo: make into updateProgress function 4662292SN/A for (int tid=0; tid < numThreads; tid++) { 4672292SN/A instsInProgress[tid] -= fromIEW->iewInfo[tid].dispatched; 4682292SN/A 4692292SN/A assert(instsInProgress[tid] >=0); 4702292SN/A } 4712292SN/A 4722292SN/A} 4732292SN/A 4742292SN/Atemplate<class Impl> 4752292SN/Avoid 4762292SN/ADefaultRename<Impl>::rename(bool &status_change, unsigned tid) 4772292SN/A{ 4782292SN/A // If status is Running or idle, 4792292SN/A // call renameInsts() 4802292SN/A // If status is Unblocking, 4812292SN/A // buffer any instructions coming from decode 4822292SN/A // continue trying to empty skid buffer 4832292SN/A // check if stall conditions have passed 4842292SN/A 4852292SN/A if (renameStatus[tid] == Blocked) { 4862292SN/A ++renameBlockCycles; 4872292SN/A } else if (renameStatus[tid] == Squashing) { 4882292SN/A ++renameSquashCycles; 4892301SN/A } else if (renameStatus[tid] == SerializeStall) { 4902301SN/A ++renameSerializeStallCycles; 4913788Sgblack@eecs.umich.edu // If we are currently in SerializeStall and resumeSerialize 4923788Sgblack@eecs.umich.edu // was set, then that means that we are resuming serializing 4933788Sgblack@eecs.umich.edu // this cycle. Tell the previous stages to block. 4943788Sgblack@eecs.umich.edu if (resumeSerialize) { 4953788Sgblack@eecs.umich.edu resumeSerialize = false; 4963788Sgblack@eecs.umich.edu block(tid); 4973788Sgblack@eecs.umich.edu toDecode->renameUnblock[tid] = false; 4983788Sgblack@eecs.umich.edu } 4992292SN/A } 5002292SN/A 5012292SN/A if (renameStatus[tid] == Running || 5022292SN/A renameStatus[tid] == Idle) { 5032292SN/A DPRINTF(Rename, "[tid:%u]: Not blocked, so attempting to run " 5042292SN/A "stage.\n", tid); 5052292SN/A 5062292SN/A renameInsts(tid); 5072292SN/A } else if (renameStatus[tid] == Unblocking) { 5082292SN/A renameInsts(tid); 5092292SN/A 5102292SN/A if (validInsts()) { 5112292SN/A // Add the current inputs to the skid buffer so they can be 5122292SN/A // reprocessed when this stage unblocks. 5132292SN/A skidInsert(tid); 5142292SN/A } 5152292SN/A 5162292SN/A // If we switched over to blocking, then there's a potential for 5172292SN/A // an overall status change. 5182292SN/A status_change = unblock(tid) || status_change || blockThisCycle; 5191858SN/A } 5201858SN/A} 5211858SN/A 5221858SN/Atemplate <class Impl> 5231858SN/Avoid 5242292SN/ADefaultRename<Impl>::renameInsts(unsigned tid) 5251858SN/A{ 5262292SN/A // Instructions can be either in the skid buffer or the queue of 5272292SN/A // instructions coming from decode, depending on the status. 5282292SN/A int insts_available = renameStatus[tid] == Unblocking ? 5292292SN/A skidBuffer[tid].size() : insts[tid].size(); 5301858SN/A 5312292SN/A // Check the decode queue to see if instructions are available. 5322292SN/A // If there are no available instructions to rename, then do nothing. 5332292SN/A if (insts_available == 0) { 5342292SN/A DPRINTF(Rename, "[tid:%u]: Nothing to do, breaking out early.\n", 5352292SN/A tid); 5362292SN/A // Should I change status to idle? 5372292SN/A ++renameIdleCycles; 5382292SN/A return; 5392292SN/A } else if (renameStatus[tid] == Unblocking) { 5402292SN/A ++renameUnblockCycles; 5412292SN/A } else if (renameStatus[tid] == Running) { 5422292SN/A ++renameRunCycles; 5432292SN/A } 5441858SN/A 5452292SN/A DynInstPtr inst; 5462292SN/A 5472292SN/A // Will have to do a different calculation for the number of free 5482292SN/A // entries. 5492292SN/A int free_rob_entries = calcFreeROBEntries(tid); 5502292SN/A int free_iq_entries = calcFreeIQEntries(tid); 5512292SN/A int free_lsq_entries = calcFreeLSQEntries(tid); 5522292SN/A int min_free_entries = free_rob_entries; 5532292SN/A 5542292SN/A FullSource source = ROB; 5552292SN/A 5562292SN/A if (free_iq_entries < min_free_entries) { 5572292SN/A min_free_entries = free_iq_entries; 5582292SN/A source = IQ; 5592292SN/A } 5602292SN/A 5612292SN/A if (free_lsq_entries < min_free_entries) { 5622292SN/A min_free_entries = free_lsq_entries; 5632292SN/A source = LSQ; 5642292SN/A } 5652292SN/A 5662292SN/A // Check if there's any space left. 5672292SN/A if (min_free_entries <= 0) { 5682292SN/A DPRINTF(Rename, "[tid:%u]: Blocking due to no free ROB/IQ/LSQ " 5692292SN/A "entries.\n" 5702292SN/A "ROB has %i free entries.\n" 5712292SN/A "IQ has %i free entries.\n" 5722292SN/A "LSQ has %i free entries.\n", 5732292SN/A tid, 5742292SN/A free_rob_entries, 5752292SN/A free_iq_entries, 5762292SN/A free_lsq_entries); 5772292SN/A 5782292SN/A blockThisCycle = true; 5792292SN/A 5802292SN/A block(tid); 5812292SN/A 5822292SN/A incrFullStat(source); 5832292SN/A 5842292SN/A return; 5852292SN/A } else if (min_free_entries < insts_available) { 5862292SN/A DPRINTF(Rename, "[tid:%u]: Will have to block this cycle." 5872292SN/A "%i insts available, but only %i insts can be " 5882292SN/A "renamed due to ROB/IQ/LSQ limits.\n", 5892292SN/A tid, insts_available, min_free_entries); 5902292SN/A 5912292SN/A insts_available = min_free_entries; 5922292SN/A 5932292SN/A blockThisCycle = true; 5942292SN/A 5952292SN/A incrFullStat(source); 5962292SN/A } 5972292SN/A 5982292SN/A InstQueue &insts_to_rename = renameStatus[tid] == Unblocking ? 5992292SN/A skidBuffer[tid] : insts[tid]; 6002292SN/A 6012292SN/A DPRINTF(Rename, "[tid:%u]: %i available instructions to " 6022292SN/A "send iew.\n", tid, insts_available); 6032292SN/A 6042292SN/A DPRINTF(Rename, "[tid:%u]: %i insts pipelining from Rename | %i insts " 6052292SN/A "dispatched to IQ last cycle.\n", 6062292SN/A tid, instsInProgress[tid], fromIEW->iewInfo[tid].dispatched); 6072292SN/A 6082292SN/A // Handle serializing the next instruction if necessary. 6092292SN/A if (serializeOnNextInst[tid]) { 6102292SN/A if (emptyROB[tid] && instsInProgress[tid] == 0) { 6112292SN/A // ROB already empty; no need to serialize. 6122292SN/A serializeOnNextInst[tid] = false; 6132292SN/A } else if (!insts_to_rename.empty()) { 6142292SN/A insts_to_rename.front()->setSerializeBefore(); 6152292SN/A } 6162292SN/A } 6172292SN/A 6182292SN/A int renamed_insts = 0; 6192292SN/A 6202292SN/A while (insts_available > 0 && toIEWIndex < renameWidth) { 6212292SN/A DPRINTF(Rename, "[tid:%u]: Sending instructions to IEW.\n", tid); 6222292SN/A 6232292SN/A assert(!insts_to_rename.empty()); 6242292SN/A 6252292SN/A inst = insts_to_rename.front(); 6262292SN/A 6272292SN/A insts_to_rename.pop_front(); 6282292SN/A 6292292SN/A if (renameStatus[tid] == Unblocking) { 6302292SN/A DPRINTF(Rename,"[tid:%u]: Removing [sn:%lli] PC:%#x from rename " 6312292SN/A "skidBuffer\n", 6322292SN/A tid, inst->seqNum, inst->readPC()); 6332292SN/A } 6342292SN/A 6352292SN/A if (inst->isSquashed()) { 6362292SN/A DPRINTF(Rename, "[tid:%u]: instruction %i with PC %#x is " 6372292SN/A "squashed, skipping.\n", 6382935Sksewell@umich.edu tid, inst->seqNum, inst->readPC()); 6392292SN/A 6402292SN/A ++renameSquashedInsts; 6412292SN/A 6422292SN/A // Decrement how many instructions are available. 6432292SN/A --insts_available; 6442292SN/A 6452292SN/A continue; 6462292SN/A } 6472292SN/A 6482292SN/A DPRINTF(Rename, "[tid:%u]: Processing instruction [sn:%lli] with " 6492292SN/A "PC %#x.\n", 6502292SN/A tid, inst->seqNum, inst->readPC()); 6512292SN/A 6522292SN/A // Handle serializeAfter/serializeBefore instructions. 6532292SN/A // serializeAfter marks the next instruction as serializeBefore. 6542292SN/A // serializeBefore makes the instruction wait in rename until the ROB 6552292SN/A // is empty. 6562336SN/A 6572336SN/A // In this model, IPR accesses are serialize before 6582336SN/A // instructions, and store conditionals are serialize after 6592336SN/A // instructions. This is mainly due to lack of support for 6602336SN/A // out-of-order operations of either of those classes of 6612336SN/A // instructions. 6622336SN/A if ((inst->isIprAccess() || inst->isSerializeBefore()) && 6632336SN/A !inst->isSerializeHandled()) { 6642292SN/A DPRINTF(Rename, "Serialize before instruction encountered.\n"); 6652292SN/A 6662301SN/A if (!inst->isTempSerializeBefore()) { 6672301SN/A renamedSerializing++; 6682292SN/A inst->setSerializeHandled(); 6692301SN/A } else { 6702301SN/A renamedTempSerializing++; 6712301SN/A } 6722292SN/A 6732301SN/A // Change status over to SerializeStall so that other stages know 6742292SN/A // what this is blocked on. 6752301SN/A renameStatus[tid] = SerializeStall; 6762292SN/A 6772301SN/A serializeInst[tid] = inst; 6782292SN/A 6792292SN/A blockThisCycle = true; 6802292SN/A 6812292SN/A break; 6822336SN/A } else if ((inst->isStoreConditional() || inst->isSerializeAfter()) && 6832336SN/A !inst->isSerializeHandled()) { 6842292SN/A DPRINTF(Rename, "Serialize after instruction encountered.\n"); 6852292SN/A 6862307SN/A renamedSerializing++; 6872307SN/A 6882292SN/A inst->setSerializeHandled(); 6892292SN/A 6902292SN/A serializeAfter(insts_to_rename, tid); 6912292SN/A } 6922292SN/A 6932292SN/A // Check here to make sure there are enough destination registers 6942292SN/A // to rename to. Otherwise block. 6952292SN/A if (renameMap[tid]->numFreeEntries() < inst->numDestRegs()) { 6962292SN/A DPRINTF(Rename, "Blocking due to lack of free " 6972292SN/A "physical registers to rename to.\n"); 6982292SN/A blockThisCycle = true; 6992292SN/A 7002292SN/A ++renameFullRegistersEvents; 7012292SN/A 7022292SN/A break; 7032292SN/A } 7042292SN/A 7052292SN/A renameSrcRegs(inst, inst->threadNumber); 7062292SN/A 7072292SN/A renameDestRegs(inst, inst->threadNumber); 7082292SN/A 7092292SN/A ++renamed_insts; 7102292SN/A 7112292SN/A // Put instruction in rename queue. 7122292SN/A toIEW->insts[toIEWIndex] = inst; 7132292SN/A ++(toIEW->size); 7142292SN/A 7152292SN/A // Increment which instruction we're on. 7162292SN/A ++toIEWIndex; 7172292SN/A 7182292SN/A // Decrement how many instructions are available. 7192292SN/A --insts_available; 7202292SN/A } 7212292SN/A 7222292SN/A instsInProgress[tid] += renamed_insts; 7232307SN/A renameRenamedInsts += renamed_insts; 7242292SN/A 7252292SN/A // If we wrote to the time buffer, record this. 7262292SN/A if (toIEWIndex) { 7272292SN/A wroteToTimeBuffer = true; 7282292SN/A } 7292292SN/A 7302292SN/A // Check if there's any instructions left that haven't yet been renamed. 7312292SN/A // If so then block. 7322292SN/A if (insts_available) { 7332292SN/A blockThisCycle = true; 7342292SN/A } 7352292SN/A 7362292SN/A if (blockThisCycle) { 7372292SN/A block(tid); 7382292SN/A toDecode->renameUnblock[tid] = false; 7392292SN/A } 7402292SN/A} 7412292SN/A 7422292SN/Atemplate<class Impl> 7432292SN/Avoid 7442292SN/ADefaultRename<Impl>::skidInsert(unsigned tid) 7452292SN/A{ 7462292SN/A DynInstPtr inst = NULL; 7472292SN/A 7482292SN/A while (!insts[tid].empty()) { 7492292SN/A inst = insts[tid].front(); 7502292SN/A 7512292SN/A insts[tid].pop_front(); 7522292SN/A 7532292SN/A assert(tid == inst->threadNumber); 7542292SN/A 7552292SN/A DPRINTF(Rename, "[tid:%u]: Inserting [sn:%lli] PC:%#x into Rename " 7562292SN/A "skidBuffer\n", tid, inst->seqNum, inst->readPC()); 7572292SN/A 7582307SN/A ++renameSkidInsts; 7592307SN/A 7602292SN/A skidBuffer[tid].push_back(inst); 7612292SN/A } 7622292SN/A 7632292SN/A if (skidBuffer[tid].size() > skidBufferMax) 7642292SN/A panic("Skidbuffer Exceeded Max Size"); 7652292SN/A} 7662292SN/A 7672292SN/Atemplate <class Impl> 7682292SN/Avoid 7692292SN/ADefaultRename<Impl>::sortInsts() 7702292SN/A{ 7712292SN/A int insts_from_decode = fromDecode->size; 7722329SN/A#ifdef DEBUG 7733093Sksewell@umich.edu#if !ISA_HAS_DELAY_SLOT 7742292SN/A for (int i=0; i < numThreads; i++) 7752292SN/A assert(insts[i].empty()); 7762329SN/A#endif 7772935Sksewell@umich.edu#endif 7782292SN/A for (int i = 0; i < insts_from_decode; ++i) { 7792292SN/A DynInstPtr inst = fromDecode->insts[i]; 7802292SN/A insts[inst->threadNumber].push_back(inst); 7812292SN/A } 7822292SN/A} 7832292SN/A 7842292SN/Atemplate<class Impl> 7852292SN/Abool 7862292SN/ADefaultRename<Impl>::skidsEmpty() 7872292SN/A{ 7882980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 7892292SN/A 7902292SN/A while (threads != (*activeThreads).end()) { 7912292SN/A if (!skidBuffer[*threads++].empty()) 7922292SN/A return false; 7932292SN/A } 7942292SN/A 7952292SN/A return true; 7962292SN/A} 7972292SN/A 7982292SN/Atemplate<class Impl> 7992292SN/Avoid 8002292SN/ADefaultRename<Impl>::updateStatus() 8012292SN/A{ 8022292SN/A bool any_unblocking = false; 8032292SN/A 8042980Sgblack@eecs.umich.edu std::list<unsigned>::iterator threads = (*activeThreads).begin(); 8052292SN/A 8062292SN/A threads = (*activeThreads).begin(); 8072292SN/A 8082292SN/A while (threads != (*activeThreads).end()) { 8092292SN/A unsigned tid = *threads++; 8102292SN/A 8112292SN/A if (renameStatus[tid] == Unblocking) { 8122292SN/A any_unblocking = true; 8132292SN/A break; 8142292SN/A } 8152292SN/A } 8162292SN/A 8172292SN/A // Rename will have activity if it's unblocking. 8182292SN/A if (any_unblocking) { 8192292SN/A if (_status == Inactive) { 8202292SN/A _status = Active; 8212292SN/A 8222292SN/A DPRINTF(Activity, "Activating stage.\n"); 8232292SN/A 8242733Sktlim@umich.edu cpu->activateStage(O3CPU::RenameIdx); 8252292SN/A } 8262292SN/A } else { 8272292SN/A // If it's not unblocking, then rename will not have any internal 8282292SN/A // activity. Switch it to inactive. 8292292SN/A if (_status == Active) { 8302292SN/A _status = Inactive; 8312292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 8322292SN/A 8332733Sktlim@umich.edu cpu->deactivateStage(O3CPU::RenameIdx); 8342292SN/A } 8352292SN/A } 8362292SN/A} 8372292SN/A 8382292SN/Atemplate <class Impl> 8392292SN/Abool 8402292SN/ADefaultRename<Impl>::block(unsigned tid) 8412292SN/A{ 8422292SN/A DPRINTF(Rename, "[tid:%u]: Blocking.\n", tid); 8432292SN/A 8442292SN/A // Add the current inputs onto the skid buffer, so they can be 8452292SN/A // reprocessed when this stage unblocks. 8462292SN/A skidInsert(tid); 8472292SN/A 8482292SN/A // Only signal backwards to block if the previous stages do not think 8492292SN/A // rename is already blocked. 8502292SN/A if (renameStatus[tid] != Blocked) { 8512292SN/A if (renameStatus[tid] != Unblocking) { 8522292SN/A toDecode->renameBlock[tid] = true; 8532292SN/A toDecode->renameUnblock[tid] = false; 8542292SN/A wroteToTimeBuffer = true; 8552292SN/A } 8562292SN/A 8572329SN/A // Rename can not go from SerializeStall to Blocked, otherwise 8582329SN/A // it would not know to complete the serialize stall. 8592301SN/A if (renameStatus[tid] != SerializeStall) { 8602292SN/A // Set status to Blocked. 8612292SN/A renameStatus[tid] = Blocked; 8622292SN/A return true; 8632292SN/A } 8642292SN/A } 8652292SN/A 8662292SN/A return false; 8672292SN/A} 8682292SN/A 8692292SN/Atemplate <class Impl> 8702292SN/Abool 8712292SN/ADefaultRename<Impl>::unblock(unsigned tid) 8722292SN/A{ 8732292SN/A DPRINTF(Rename, "[tid:%u]: Trying to unblock.\n", tid); 8742292SN/A 8752292SN/A // Rename is done unblocking if the skid buffer is empty. 8762301SN/A if (skidBuffer[tid].empty() && renameStatus[tid] != SerializeStall) { 8772292SN/A 8782292SN/A DPRINTF(Rename, "[tid:%u]: Done unblocking.\n", tid); 8792292SN/A 8802292SN/A toDecode->renameUnblock[tid] = true; 8812292SN/A wroteToTimeBuffer = true; 8822292SN/A 8832292SN/A renameStatus[tid] = Running; 8842292SN/A return true; 8852292SN/A } 8862292SN/A 8872292SN/A return false; 8882292SN/A} 8892292SN/A 8902292SN/Atemplate <class Impl> 8912292SN/Avoid 8922935Sksewell@umich.eduDefaultRename<Impl>::doSquash(const InstSeqNum &squashed_seq_num, unsigned tid) 8932292SN/A{ 8942980Sgblack@eecs.umich.edu typename std::list<RenameHistory>::iterator hb_it = 8952980Sgblack@eecs.umich.edu historyBuffer[tid].begin(); 8962292SN/A 8971060SN/A // After a syscall squashes everything, the history buffer may be empty 8981060SN/A // but the ROB may still be squashing instructions. 8992292SN/A if (historyBuffer[tid].empty()) { 9001060SN/A return; 9011060SN/A } 9021060SN/A 9031060SN/A // Go through the most recent instructions, undoing the mappings 9041060SN/A // they did and freeing up the registers. 9052292SN/A while (!historyBuffer[tid].empty() && 9062292SN/A (*hb_it).instSeqNum > squashed_seq_num) { 9072292SN/A assert(hb_it != historyBuffer[tid].end()); 9081062SN/A 9092292SN/A DPRINTF(Rename, "[tid:%u]: Removing history entry with sequence " 9102292SN/A "number %i.\n", tid, (*hb_it).instSeqNum); 9111060SN/A 9122292SN/A // Tell the rename map to set the architected register to the 9132292SN/A // previous physical register that it was renamed to. 9142292SN/A renameMap[tid]->setEntry(hb_it->archReg, hb_it->prevPhysReg); 9151060SN/A 9162292SN/A // Put the renamed physical register back on the free list. 9172292SN/A freeList->addReg(hb_it->newPhysReg); 9181062SN/A 9192367SN/A // Be sure to mark its register as ready if it's a misc register. 9202367SN/A if (hb_it->newPhysReg >= maxPhysicalRegs) { 9212367SN/A scoreboard->setReg(hb_it->newPhysReg); 9222367SN/A } 9232367SN/A 9242292SN/A historyBuffer[tid].erase(hb_it++); 9251061SN/A 9261062SN/A ++renameUndoneMaps; 9271060SN/A } 9281060SN/A} 9291060SN/A 9301060SN/Atemplate<class Impl> 9311060SN/Avoid 9322292SN/ADefaultRename<Impl>::removeFromHistory(InstSeqNum inst_seq_num, unsigned tid) 9331060SN/A{ 9342292SN/A DPRINTF(Rename, "[tid:%u]: Removing a committed instruction from the " 9352292SN/A "history buffer %u (size=%i), until [sn:%lli].\n", 9362292SN/A tid, tid, historyBuffer[tid].size(), inst_seq_num); 9372292SN/A 9382980Sgblack@eecs.umich.edu typename std::list<RenameHistory>::iterator hb_it = 9392980Sgblack@eecs.umich.edu historyBuffer[tid].end(); 9401060SN/A 9411061SN/A --hb_it; 9421060SN/A 9432292SN/A if (historyBuffer[tid].empty()) { 9442292SN/A DPRINTF(Rename, "[tid:%u]: History buffer is empty.\n", tid); 9452292SN/A return; 9462292SN/A } else if (hb_it->instSeqNum > inst_seq_num) { 9472292SN/A DPRINTF(Rename, "[tid:%u]: Old sequence number encountered. Ensure " 9482292SN/A "that a syscall happened recently.\n", tid); 9491060SN/A return; 9501060SN/A } 9511060SN/A 9522292SN/A // Commit all the renames up until (and including) the committed sequence 9532292SN/A // number. Some or even all of the committed instructions may not have 9542292SN/A // rename histories if they did not have destination registers that were 9552292SN/A // renamed. 9562292SN/A while (!historyBuffer[tid].empty() && 9572292SN/A hb_it != historyBuffer[tid].end() && 9582292SN/A (*hb_it).instSeqNum <= inst_seq_num) { 9591060SN/A 9602329SN/A DPRINTF(Rename, "[tid:%u]: Freeing up older rename of reg %i, " 9612329SN/A "[sn:%lli].\n", 9622292SN/A tid, (*hb_it).prevPhysReg, (*hb_it).instSeqNum); 9631061SN/A 9642292SN/A freeList->addReg((*hb_it).prevPhysReg); 9652292SN/A ++renameCommittedMaps; 9661061SN/A 9672292SN/A historyBuffer[tid].erase(hb_it--); 9681060SN/A } 9691060SN/A} 9701060SN/A 9711061SN/Atemplate <class Impl> 9721061SN/Ainline void 9732292SN/ADefaultRename<Impl>::renameSrcRegs(DynInstPtr &inst,unsigned tid) 9741061SN/A{ 9752292SN/A assert(renameMap[tid] != 0); 9762292SN/A 9771061SN/A unsigned num_src_regs = inst->numSrcRegs(); 9781061SN/A 9791061SN/A // Get the architectual register numbers from the source and 9801061SN/A // destination operands, and redirect them to the right register. 9811061SN/A // Will need to mark dependencies though. 9822292SN/A for (int src_idx = 0; src_idx < num_src_regs; src_idx++) { 9831061SN/A RegIndex src_reg = inst->srcRegIdx(src_idx); 9843773Sgblack@eecs.umich.edu RegIndex flat_src_reg = src_reg; 9853773Sgblack@eecs.umich.edu if (src_reg < TheISA::FP_Base_DepTag) { 9863773Sgblack@eecs.umich.edu flat_src_reg = TheISA::flattenIntIndex(inst->tcBase(), src_reg); 9873773Sgblack@eecs.umich.edu DPRINTF(Rename, "Flattening index %d to %d.\n", (int)src_reg, (int)flat_src_reg); 9883773Sgblack@eecs.umich.edu } 9893773Sgblack@eecs.umich.edu inst->flattenSrcReg(src_idx, flat_src_reg); 9901061SN/A 9911061SN/A // Look up the source registers to get the phys. register they've 9921061SN/A // been renamed to, and set the sources to those registers. 9933773Sgblack@eecs.umich.edu PhysRegIndex renamed_reg = renameMap[tid]->lookup(flat_src_reg); 9941061SN/A 9952292SN/A DPRINTF(Rename, "[tid:%u]: Looking up arch reg %i, got " 9963773Sgblack@eecs.umich.edu "physical reg %i.\n", tid, (int)flat_src_reg, 9972292SN/A (int)renamed_reg); 9981061SN/A 9991061SN/A inst->renameSrcReg(src_idx, renamed_reg); 10001061SN/A 10012292SN/A // See if the register is ready or not. 10022292SN/A if (scoreboard->getReg(renamed_reg) == true) { 10032292SN/A DPRINTF(Rename, "[tid:%u]: Register is ready.\n", tid); 10041061SN/A 10051061SN/A inst->markSrcRegReady(src_idx); 10061061SN/A } 10071062SN/A 10081062SN/A ++renameRenameLookups; 10091061SN/A } 10101061SN/A} 10111061SN/A 10121061SN/Atemplate <class Impl> 10131061SN/Ainline void 10142292SN/ADefaultRename<Impl>::renameDestRegs(DynInstPtr &inst,unsigned tid) 10151061SN/A{ 10162292SN/A typename RenameMap::RenameInfo rename_result; 10171061SN/A 10181061SN/A unsigned num_dest_regs = inst->numDestRegs(); 10191061SN/A 10202292SN/A // Rename the destination registers. 10212292SN/A for (int dest_idx = 0; dest_idx < num_dest_regs; dest_idx++) { 10222292SN/A RegIndex dest_reg = inst->destRegIdx(dest_idx); 10233773Sgblack@eecs.umich.edu RegIndex flat_dest_reg = dest_reg; 10243773Sgblack@eecs.umich.edu if (dest_reg < TheISA::FP_Base_DepTag) { 10253773Sgblack@eecs.umich.edu flat_dest_reg = TheISA::flattenIntIndex(inst->tcBase(), dest_reg); 10263773Sgblack@eecs.umich.edu DPRINTF(Rename, "Flattening index %d to %d.\n", (int)dest_reg, (int)flat_dest_reg); 10273773Sgblack@eecs.umich.edu } 10283773Sgblack@eecs.umich.edu 10293773Sgblack@eecs.umich.edu inst->flattenDestReg(dest_idx, flat_dest_reg); 10301061SN/A 10312292SN/A // Get the physical register that the destination will be 10322292SN/A // renamed to. 10333773Sgblack@eecs.umich.edu rename_result = renameMap[tid]->rename(flat_dest_reg); 10341061SN/A 10352292SN/A //Mark Scoreboard entry as not ready 10362292SN/A scoreboard->unsetReg(rename_result.first); 10371062SN/A 10382292SN/A DPRINTF(Rename, "[tid:%u]: Renaming arch reg %i to physical " 10393773Sgblack@eecs.umich.edu "reg %i.\n", tid, (int)flat_dest_reg, 10402292SN/A (int)rename_result.first); 10411062SN/A 10422292SN/A // Record the rename information so that a history can be kept. 10433773Sgblack@eecs.umich.edu RenameHistory hb_entry(inst->seqNum, flat_dest_reg, 10442292SN/A rename_result.first, 10452292SN/A rename_result.second); 10461062SN/A 10472292SN/A historyBuffer[tid].push_front(hb_entry); 10481062SN/A 10492935Sksewell@umich.edu DPRINTF(Rename, "[tid:%u]: Adding instruction to history buffer " 10502935Sksewell@umich.edu "(size=%i), [sn:%lli].\n",tid, 10512935Sksewell@umich.edu historyBuffer[tid].size(), 10522292SN/A (*historyBuffer[tid].begin()).instSeqNum); 10531062SN/A 10542292SN/A // Tell the instruction to rename the appropriate destination 10552292SN/A // register (dest_idx) to the new physical register 10562292SN/A // (rename_result.first), and record the previous physical 10572292SN/A // register that the same logical register was renamed to 10582292SN/A // (rename_result.second). 10592292SN/A inst->renameDestReg(dest_idx, 10602292SN/A rename_result.first, 10612292SN/A rename_result.second); 10621062SN/A 10632292SN/A ++renameRenamedOperands; 10641061SN/A } 10651061SN/A} 10661061SN/A 10671061SN/Atemplate <class Impl> 10681061SN/Ainline int 10692292SN/ADefaultRename<Impl>::calcFreeROBEntries(unsigned tid) 10701061SN/A{ 10712292SN/A int num_free = freeEntries[tid].robEntries - 10722292SN/A (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched); 10732292SN/A 10742292SN/A //DPRINTF(Rename,"[tid:%i]: %i rob free\n",tid,num_free); 10752292SN/A 10762292SN/A return num_free; 10771061SN/A} 10781061SN/A 10791061SN/Atemplate <class Impl> 10801061SN/Ainline int 10812292SN/ADefaultRename<Impl>::calcFreeIQEntries(unsigned tid) 10821061SN/A{ 10832292SN/A int num_free = freeEntries[tid].iqEntries - 10842292SN/A (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatched); 10852292SN/A 10862292SN/A //DPRINTF(Rename,"[tid:%i]: %i iq free\n",tid,num_free); 10872292SN/A 10882292SN/A return num_free; 10892292SN/A} 10902292SN/A 10912292SN/Atemplate <class Impl> 10922292SN/Ainline int 10932292SN/ADefaultRename<Impl>::calcFreeLSQEntries(unsigned tid) 10942292SN/A{ 10952292SN/A int num_free = freeEntries[tid].lsqEntries - 10962292SN/A (instsInProgress[tid] - fromIEW->iewInfo[tid].dispatchedToLSQ); 10972292SN/A 10982292SN/A //DPRINTF(Rename,"[tid:%i]: %i lsq free\n",tid,num_free); 10992292SN/A 11002292SN/A return num_free; 11012292SN/A} 11022292SN/A 11032292SN/Atemplate <class Impl> 11042292SN/Aunsigned 11052292SN/ADefaultRename<Impl>::validInsts() 11062292SN/A{ 11072292SN/A unsigned inst_count = 0; 11082292SN/A 11092292SN/A for (int i=0; i<fromDecode->size; i++) { 11102731Sktlim@umich.edu if (!fromDecode->insts[i]->isSquashed()) 11112292SN/A inst_count++; 11122292SN/A } 11132292SN/A 11142292SN/A return inst_count; 11152292SN/A} 11162292SN/A 11172292SN/Atemplate <class Impl> 11182292SN/Avoid 11192292SN/ADefaultRename<Impl>::readStallSignals(unsigned tid) 11202292SN/A{ 11212292SN/A if (fromIEW->iewBlock[tid]) { 11222292SN/A stalls[tid].iew = true; 11232292SN/A } 11242292SN/A 11252292SN/A if (fromIEW->iewUnblock[tid]) { 11262292SN/A assert(stalls[tid].iew); 11272292SN/A stalls[tid].iew = false; 11282292SN/A } 11292292SN/A 11302292SN/A if (fromCommit->commitBlock[tid]) { 11312292SN/A stalls[tid].commit = true; 11322292SN/A } 11332292SN/A 11342292SN/A if (fromCommit->commitUnblock[tid]) { 11352292SN/A assert(stalls[tid].commit); 11362292SN/A stalls[tid].commit = false; 11372292SN/A } 11382292SN/A} 11392292SN/A 11402292SN/Atemplate <class Impl> 11412292SN/Abool 11422292SN/ADefaultRename<Impl>::checkStall(unsigned tid) 11432292SN/A{ 11442292SN/A bool ret_val = false; 11452292SN/A 11462292SN/A if (stalls[tid].iew) { 11472292SN/A DPRINTF(Rename,"[tid:%i]: Stall from IEW stage detected.\n", tid); 11482292SN/A ret_val = true; 11492292SN/A } else if (stalls[tid].commit) { 11502292SN/A DPRINTF(Rename,"[tid:%i]: Stall from Commit stage detected.\n", tid); 11512292SN/A ret_val = true; 11522292SN/A } else if (calcFreeROBEntries(tid) <= 0) { 11532292SN/A DPRINTF(Rename,"[tid:%i]: Stall: ROB has 0 free entries.\n", tid); 11542292SN/A ret_val = true; 11552292SN/A } else if (calcFreeIQEntries(tid) <= 0) { 11562292SN/A DPRINTF(Rename,"[tid:%i]: Stall: IQ has 0 free entries.\n", tid); 11572292SN/A ret_val = true; 11582292SN/A } else if (calcFreeLSQEntries(tid) <= 0) { 11592292SN/A DPRINTF(Rename,"[tid:%i]: Stall: LSQ has 0 free entries.\n", tid); 11602292SN/A ret_val = true; 11612292SN/A } else if (renameMap[tid]->numFreeEntries() <= 0) { 11622292SN/A DPRINTF(Rename,"[tid:%i]: Stall: RenameMap has 0 free entries.\n", tid); 11632292SN/A ret_val = true; 11642301SN/A } else if (renameStatus[tid] == SerializeStall && 11652292SN/A (!emptyROB[tid] || instsInProgress[tid])) { 11662301SN/A DPRINTF(Rename,"[tid:%i]: Stall: Serialize stall and ROB is not " 11672292SN/A "empty.\n", 11682292SN/A tid); 11692292SN/A ret_val = true; 11702292SN/A } 11712292SN/A 11722292SN/A return ret_val; 11732292SN/A} 11742292SN/A 11752292SN/Atemplate <class Impl> 11762292SN/Avoid 11772292SN/ADefaultRename<Impl>::readFreeEntries(unsigned tid) 11782292SN/A{ 11792292SN/A bool updated = false; 11802292SN/A if (fromIEW->iewInfo[tid].usedIQ) { 11812292SN/A freeEntries[tid].iqEntries = 11822292SN/A fromIEW->iewInfo[tid].freeIQEntries; 11832292SN/A updated = true; 11842292SN/A } 11852292SN/A 11862292SN/A if (fromIEW->iewInfo[tid].usedLSQ) { 11872292SN/A freeEntries[tid].lsqEntries = 11882292SN/A fromIEW->iewInfo[tid].freeLSQEntries; 11892292SN/A updated = true; 11902292SN/A } 11912292SN/A 11922292SN/A if (fromCommit->commitInfo[tid].usedROB) { 11932292SN/A freeEntries[tid].robEntries = 11942292SN/A fromCommit->commitInfo[tid].freeROBEntries; 11952292SN/A emptyROB[tid] = fromCommit->commitInfo[tid].emptyROB; 11962292SN/A updated = true; 11972292SN/A } 11982292SN/A 11992292SN/A DPRINTF(Rename, "[tid:%i]: Free IQ: %i, Free ROB: %i, Free LSQ: %i\n", 12002292SN/A tid, 12012292SN/A freeEntries[tid].iqEntries, 12022292SN/A freeEntries[tid].robEntries, 12032292SN/A freeEntries[tid].lsqEntries); 12042292SN/A 12052292SN/A DPRINTF(Rename, "[tid:%i]: %i instructions not yet in ROB\n", 12062292SN/A tid, instsInProgress[tid]); 12072292SN/A} 12082292SN/A 12092292SN/Atemplate <class Impl> 12102292SN/Abool 12112292SN/ADefaultRename<Impl>::checkSignalsAndUpdate(unsigned tid) 12122292SN/A{ 12132292SN/A // Check if there's a squash signal, squash if there is 12142292SN/A // Check stall signals, block if necessary. 12152292SN/A // If status was blocked 12162292SN/A // check if stall conditions have passed 12172292SN/A // if so then go to unblocking 12182292SN/A // If status was Squashing 12192292SN/A // check if squashing is not high. Switch to running this cycle. 12202301SN/A // If status was serialize stall 12212292SN/A // check if ROB is empty and no insts are in flight to the ROB 12222292SN/A 12232292SN/A readFreeEntries(tid); 12242292SN/A readStallSignals(tid); 12252292SN/A 12262292SN/A if (fromCommit->commitInfo[tid].squash) { 12272292SN/A DPRINTF(Rename, "[tid:%u]: Squashing instructions due to squash from " 12282292SN/A "commit.\n", tid); 12292292SN/A 12303093Sksewell@umich.edu#if ISA_HAS_DELAY_SLOT 12313093Sksewell@umich.edu InstSeqNum squashed_seq_num = fromCommit->commitInfo[tid].bdelayDoneSeqNum; 12323093Sksewell@umich.edu#else 12332935Sksewell@umich.edu InstSeqNum squashed_seq_num = fromCommit->commitInfo[tid].doneSeqNum; 12342935Sksewell@umich.edu#endif 12352935Sksewell@umich.edu 12362935Sksewell@umich.edu squash(squashed_seq_num, tid); 12372292SN/A 12382292SN/A return true; 12392292SN/A } 12402292SN/A 12412292SN/A if (fromCommit->commitInfo[tid].robSquashing) { 12422292SN/A DPRINTF(Rename, "[tid:%u]: ROB is still squashing.\n", tid); 12432292SN/A 12442292SN/A renameStatus[tid] = Squashing; 12452292SN/A 12462292SN/A return true; 12472292SN/A } 12482292SN/A 12492292SN/A if (checkStall(tid)) { 12502292SN/A return block(tid); 12512292SN/A } 12522292SN/A 12532292SN/A if (renameStatus[tid] == Blocked) { 12542292SN/A DPRINTF(Rename, "[tid:%u]: Done blocking, switching to unblocking.\n", 12552292SN/A tid); 12562292SN/A 12572292SN/A renameStatus[tid] = Unblocking; 12582292SN/A 12592292SN/A unblock(tid); 12602292SN/A 12612292SN/A return true; 12622292SN/A } 12632292SN/A 12642292SN/A if (renameStatus[tid] == Squashing) { 12652292SN/A // Switch status to running if rename isn't being told to block or 12662292SN/A // squash this cycle. 12673788Sgblack@eecs.umich.edu if (!resumeSerialize) { 12683788Sgblack@eecs.umich.edu DPRINTF(Rename, "[tid:%u]: Done squashing, switching to running.\n", 12693788Sgblack@eecs.umich.edu tid); 12702292SN/A 12713788Sgblack@eecs.umich.edu renameStatus[tid] = Running; 12723788Sgblack@eecs.umich.edu return false; 12733788Sgblack@eecs.umich.edu } else { 12743788Sgblack@eecs.umich.edu DPRINTF(Rename, "[tid:%u]: Done squashing, switching to serialize.\n", 12753788Sgblack@eecs.umich.edu tid); 12762292SN/A 12773788Sgblack@eecs.umich.edu renameStatus[tid] = SerializeStall; 12783788Sgblack@eecs.umich.edu return true; 12793788Sgblack@eecs.umich.edu } 12802292SN/A } 12812292SN/A 12822301SN/A if (renameStatus[tid] == SerializeStall) { 12832292SN/A // Stall ends once the ROB is free. 12842301SN/A DPRINTF(Rename, "[tid:%u]: Done with serialize stall, switching to " 12852292SN/A "unblocking.\n", tid); 12862292SN/A 12872301SN/A DynInstPtr serial_inst = serializeInst[tid]; 12882292SN/A 12892292SN/A renameStatus[tid] = Unblocking; 12902292SN/A 12912292SN/A unblock(tid); 12922292SN/A 12932292SN/A DPRINTF(Rename, "[tid:%u]: Processing instruction [%lli] with " 12942292SN/A "PC %#x.\n", 12952301SN/A tid, serial_inst->seqNum, serial_inst->readPC()); 12962292SN/A 12972292SN/A // Put instruction into queue here. 12982301SN/A serial_inst->clearSerializeBefore(); 12992292SN/A 13002292SN/A if (!skidBuffer[tid].empty()) { 13012301SN/A skidBuffer[tid].push_front(serial_inst); 13022292SN/A } else { 13032301SN/A insts[tid].push_front(serial_inst); 13042292SN/A } 13052292SN/A 13062292SN/A DPRINTF(Rename, "[tid:%u]: Instruction must be processed by rename." 13072703Sktlim@umich.edu " Adding to front of list.\n", tid); 13082292SN/A 13092301SN/A serializeInst[tid] = NULL; 13102292SN/A 13112292SN/A return true; 13122292SN/A } 13132292SN/A 13142292SN/A // If we've reached this point, we have not gotten any signals that 13152292SN/A // cause rename to change its status. Rename remains the same as before. 13162292SN/A return false; 13171061SN/A} 13181061SN/A 13191060SN/Atemplate<class Impl> 13201060SN/Avoid 13212292SN/ADefaultRename<Impl>::serializeAfter(InstQueue &inst_list, 13222292SN/A unsigned tid) 13231060SN/A{ 13242292SN/A if (inst_list.empty()) { 13252292SN/A // Mark a bit to say that I must serialize on the next instruction. 13262292SN/A serializeOnNextInst[tid] = true; 13271060SN/A return; 13281060SN/A } 13291060SN/A 13302292SN/A // Set the next instruction as serializing. 13312292SN/A inst_list.front()->setSerializeBefore(); 13322292SN/A} 13332292SN/A 13342292SN/Atemplate <class Impl> 13352292SN/Ainline void 13362292SN/ADefaultRename<Impl>::incrFullStat(const FullSource &source) 13372292SN/A{ 13382292SN/A switch (source) { 13392292SN/A case ROB: 13402292SN/A ++renameROBFullEvents; 13412292SN/A break; 13422292SN/A case IQ: 13432292SN/A ++renameIQFullEvents; 13442292SN/A break; 13452292SN/A case LSQ: 13462292SN/A ++renameLSQFullEvents; 13472292SN/A break; 13482292SN/A default: 13492292SN/A panic("Rename full stall stat should be incremented for a reason!"); 13502292SN/A break; 13511060SN/A } 13522292SN/A} 13531060SN/A 13542292SN/Atemplate <class Impl> 13552292SN/Avoid 13562292SN/ADefaultRename<Impl>::dumpHistory() 13572292SN/A{ 13582980Sgblack@eecs.umich.edu typename std::list<RenameHistory>::iterator buf_it; 13591060SN/A 13602292SN/A for (int i = 0; i < numThreads; i++) { 13611060SN/A 13622292SN/A buf_it = historyBuffer[i].begin(); 13631060SN/A 13642292SN/A while (buf_it != historyBuffer[i].end()) { 13652292SN/A cprintf("Seq num: %i\nArch reg: %i New phys reg: %i Old phys " 13662292SN/A "reg: %i\n", (*buf_it).instSeqNum, (int)(*buf_it).archReg, 13672292SN/A (int)(*buf_it).newPhysReg, (int)(*buf_it).prevPhysReg); 13681060SN/A 13692292SN/A buf_it++; 13701062SN/A } 13711060SN/A } 13721060SN/A} 1373