rename_impl.hh revision 1061
11689SN/A#include <list> 29444SAndreas.Sandberg@ARM.com 37854SAli.Saidi@ARM.com#include "cpu/beta_cpu/rename.hh" 47854SAli.Saidi@ARM.com 57854SAli.Saidi@ARM.comtemplate <class Impl> 67854SAli.Saidi@ARM.comSimpleRename<Impl>::SimpleRename(Params ¶ms) 77854SAli.Saidi@ARM.com : iewToRenameDelay(params.iewToRenameDelay), 87854SAli.Saidi@ARM.com decodeToRenameDelay(params.decodeToRenameDelay), 97854SAli.Saidi@ARM.com commitToRenameDelay(params.commitToRenameDelay), 107854SAli.Saidi@ARM.com renameWidth(params.renameWidth), 117854SAli.Saidi@ARM.com commitWidth(params.commitWidth), 127854SAli.Saidi@ARM.com numInst(0) 137854SAli.Saidi@ARM.com{ 142329SN/A _status = Idle; 151689SN/A} 161689SN/A 171689SN/Atemplate <class Impl> 181689SN/Avoid 191689SN/ASimpleRename<Impl>::setCPU(FullCPU *cpu_ptr) 201689SN/A{ 211689SN/A DPRINTF(Rename, "Rename: Setting CPU pointer.\n"); 221689SN/A cpu = cpu_ptr; 231689SN/A} 241689SN/A 251689SN/Atemplate <class Impl> 261689SN/Avoid 271689SN/ASimpleRename<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 281689SN/A{ 291689SN/A DPRINTF(Rename, "Rename: Setting time buffer pointer.\n"); 301689SN/A timeBuffer = tb_ptr; 311689SN/A 321689SN/A // Setup wire to read information from time buffer, from IEW stage. 331689SN/A fromIEW = timeBuffer->getWire(-iewToRenameDelay); 341689SN/A 351689SN/A // Setup wire to read infromation from time buffer, from commit stage. 361689SN/A fromCommit = timeBuffer->getWire(-commitToRenameDelay); 371689SN/A 381689SN/A // Setup wire to write information to previous stages. 392665Ssaidi@eecs.umich.edu toDecode = timeBuffer->getWire(0); 402665Ssaidi@eecs.umich.edu} 412935Sksewell@umich.edu 421689SN/Atemplate <class Impl> 431689SN/Avoid 441060SN/ASimpleRename<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 451060SN/A{ 463773Sgblack@eecs.umich.edu DPRINTF(Rename, "Rename: Setting rename queue pointer.\n"); 476329Sgblack@eecs.umich.edu renameQueue = rq_ptr; 486658Snate@binkert.org 491717SN/A // Setup wire to write information to future stages. 508232Snate@binkert.org toIEW = renameQueue->getWire(0); 518232Snate@binkert.org} 525529Snate@binkert.org 531060SN/Atemplate <class Impl> 546221Snate@binkert.orgvoid 556221Snate@binkert.orgSimpleRename<Impl>::setDecodeQueue(TimeBuffer<DecodeStruct> *dq_ptr) 561061SN/A{ 575529Snate@binkert.org DPRINTF(Rename, "Rename: Setting decode queue pointer.\n"); 584329Sktlim@umich.edu decodeQueue = dq_ptr; 594329Sktlim@umich.edu 602292SN/A // Setup wire to get information from decode. 612292SN/A fromDecode = decodeQueue->getWire(-decodeToRenameDelay); 622292SN/A 632292SN/A} 645529Snate@binkert.org 652361SN/Atemplate <class Impl> 661060SN/Avoid 672292SN/ASimpleRename<Impl>::setRenameMap(RenameMap *rm_ptr) 688907Slukefahr@umich.edu{ 692292SN/A DPRINTF(Rename, "Rename: Setting rename map pointer.\n"); 702292SN/A renameMap = rm_ptr; 712292SN/A} 722292SN/A 732292SN/Atemplate <class Impl> 742292SN/Avoid 752292SN/ASimpleRename<Impl>::setFreeList(FreeList *fl_ptr) 761060SN/A{ 771060SN/A DPRINTF(Rename, "Rename: Setting free list pointer.\n"); 781061SN/A freeList = fl_ptr; 791060SN/A} 802292SN/A 811062SN/Atemplate <class Impl> 821062SN/Avoid 838240Snate@binkert.orgSimpleRename<Impl>::dumpHistory() 841062SN/A{ 851062SN/A typename list<RenameHistory>::iterator buf_it = historyBuffer.begin(); 861062SN/A 878240Snate@binkert.org while (buf_it != historyBuffer.end()) 881062SN/A { 891062SN/A cprintf("Seq num: %i\nArch reg: %i New phys reg: %i Old phys " 901062SN/A "reg: %i\n", (*buf_it).instSeqNum, (int)(*buf_it).archReg, 918240Snate@binkert.org (int)(*buf_it).newPhysReg, (int)(*buf_it).prevPhysReg); 921062SN/A 931062SN/A buf_it++; 942301SN/A } 958240Snate@binkert.org} 962301SN/A 972301SN/Atemplate <class Impl> 982292SN/Avoid 998240Snate@binkert.orgSimpleRename<Impl>::block() 1002292SN/A{ 1012292SN/A DPRINTF(Rename, "Rename: Blocking.\n"); 1021062SN/A // Set status to Blocked. 1038240Snate@binkert.org _status = Blocked; 1041062SN/A 1051062SN/A // Add the current inputs onto the skid buffer, so they can be 1061062SN/A // reprocessed when this stage unblocks. 1078240Snate@binkert.org skidBuffer.push(*fromDecode); 1081062SN/A 1091062SN/A // Note that this stage only signals previous stages to stall when 1101062SN/A // it is the cause of the stall originates at this stage. Otherwise 1118240Snate@binkert.org // the previous stages are expected to check all possible stall signals. 1121062SN/A} 1131062SN/A 1141062SN/Atemplate <class Impl> 1158240Snate@binkert.orginline void 1162292SN/ASimpleRename<Impl>::unblock() 1171062SN/A{ 1181062SN/A DPRINTF(Rename, "Rename: Read instructions out of skid buffer this " 1198240Snate@binkert.org "cycle.\n"); 1202292SN/A // Remove the now processed instructions from the skid buffer. 1211062SN/A skidBuffer.pop(); 1222292SN/A 1238240Snate@binkert.org // If there's still information in the skid buffer, then 1242292SN/A // continue to tell previous stages to stall. They will be 1252292SN/A // able to restart once the skid buffer is empty. 1261062SN/A if (!skidBuffer.empty()) { 1278240Snate@binkert.org toDecode->renameInfo.stall = true; 1281062SN/A } else { 1291062SN/A DPRINTF(Rename, "Rename: Done unblocking.\n"); 1301062SN/A _status = Running; 1318240Snate@binkert.org } 1321062SN/A} 1331062SN/A 1341062SN/Atemplate <class Impl> 1358240Snate@binkert.orgvoid 1361062SN/ASimpleRename<Impl>::doSquash() 1371062SN/A{ 1381062SN/A typename list<RenameHistory>::iterator hb_it = historyBuffer.begin(); 1398240Snate@binkert.org// typename list<RenameHistory>::iterator delete_it; 1401062SN/A 1411062SN/A InstSeqNum squashed_seq_num = fromCommit->commitInfo.doneSeqNum; 1421062SN/A 1438240Snate@binkert.org#ifdef FULL_SYSTEM 1441062SN/A assert(!historyBuffer.empty()); 1451062SN/A#else 1462301SN/A // After a syscall squashes everything, the history buffer may be empty 1478240Snate@binkert.org // but the ROB may still be squashing instructions. 1482301SN/A if (historyBuffer.empty()) { 1492301SN/A return; 1502301SN/A } 1512301SN/A#endif // FULL_SYSTEM 1528240Snate@binkert.org 1532301SN/A // Go through the most recent instructions, undoing the mappings 1542301SN/A // they did and freeing up the registers. 1552301SN/A while ((*hb_it).instSeqNum > squashed_seq_num) 1562307SN/A { 1578240Snate@binkert.org DPRINTF(Rename, "Rename: Removing history entry with sequence " 1582307SN/A "number %i.\n", (*hb_it).instSeqNum); 1592307SN/A 1602307SN/A // If it's not simply a place holder, then add the registers. 1617897Shestness@cs.utexas.edu if (!(*hb_it).placeHolder) { 1628240Snate@binkert.org // Tell the rename map to set the architected register to the 1637897Shestness@cs.utexas.edu // previous physical register that it was renamed to. 1647897Shestness@cs.utexas.edu renameMap->setEntry(hb_it->archReg, hb_it->prevPhysReg); 1657897Shestness@cs.utexas.edu 1668240Snate@binkert.org // Put the renamed physical register back on the free list. 1677897Shestness@cs.utexas.edu freeList->addReg(hb_it->newPhysReg); 1687897Shestness@cs.utexas.edu } 1691062SN/A 1701062SN/A// delete_it = hb_it; 1711062SN/A 1721062SN/A// hb_it++; 1732292SN/A 1741060SN/A historyBuffer.erase(hb_it++); 1751060SN/A 1761060SN/A assert(hb_it != historyBuffer.end()); 1771060SN/A } 1781060SN/A} 1791060SN/A 1801060SN/Atemplate <class Impl> 1811060SN/Avoid 1821060SN/ASimpleRename<Impl>::squash() 1831060SN/A{ 1841060SN/A DPRINTF(Rename, "Rename: Squashing instructions.\n"); 1851060SN/A // Set the status to Squashing. 1861060SN/A _status = Squashing; 1871061SN/A 1881060SN/A numInst = 0; 1892292SN/A 1901060SN/A // Clear the skid buffer in case it has any data in it. 1911060SN/A while (!skidBuffer.empty()) 1921060SN/A { 1931060SN/A skidBuffer.pop(); 1941060SN/A } 1951060SN/A 1961060SN/A doSquash(); 1971061SN/A} 1981060SN/A 1992292SN/A// In the future, when a SmartPtr is used for DynInst, then this function 2001060SN/A// itself can handle returning the instruction's physical registers to 2011060SN/A// the free list. 2021060SN/Atemplate<class Impl> 2031060SN/Avoid 2041060SN/ASimpleRename<Impl>::removeFromHistory(InstSeqNum inst_seq_num) 2051060SN/A{ 2061060SN/A DPRINTF(Rename, "Rename: Removing a committed instruction from the " 2071061SN/A "history buffer, until sequence number %lli.\n", inst_seq_num); 2081060SN/A typename list<RenameHistory>::iterator hb_it = historyBuffer.end(); 2099427SAndreas.Sandberg@ARM.com 2101060SN/A --hb_it; 2119444SAndreas.Sandberg@ARM.com 2129444SAndreas.Sandberg@ARM.com if (hb_it->instSeqNum > inst_seq_num) { 2139444SAndreas.Sandberg@ARM.com DPRINTF(Rename, "Rename: Old sequence number encountered. Ensure " 2149444SAndreas.Sandberg@ARM.com "that a syscall happened recently.\n"); 2159444SAndreas.Sandberg@ARM.com return; 2169444SAndreas.Sandberg@ARM.com } 2179444SAndreas.Sandberg@ARM.com 2189444SAndreas.Sandberg@ARM.com while ((*hb_it).instSeqNum != inst_seq_num) 2199444SAndreas.Sandberg@ARM.com { 2209444SAndreas.Sandberg@ARM.com // Make sure we haven't gone off the end of the list. 2219444SAndreas.Sandberg@ARM.com assert(hb_it != historyBuffer.end()); 2229444SAndreas.Sandberg@ARM.com 2232329SN/A // In theory instructions at the end of the history buffer 2246221Snate@binkert.org // should be older than the instruction being removed, which 2259444SAndreas.Sandberg@ARM.com // means they will have a lower sequence number. Also the 2269444SAndreas.Sandberg@ARM.com // instruction being removed from the history really should 2272292SN/A // be the last instruction in the list, as it is the instruction 2282292SN/A // that was just committed that is being removed. 2292292SN/A assert(hb_it->instSeqNum < inst_seq_num); 2302292SN/A DPRINTF(Rename, "Rename: Freeing up older rename of reg %i, sequence" 2319444SAndreas.Sandberg@ARM.com " number %i.\n", 2329444SAndreas.Sandberg@ARM.com (*hb_it).prevPhysReg, (*hb_it).instSeqNum); 2339444SAndreas.Sandberg@ARM.com 2349444SAndreas.Sandberg@ARM.com if (!(*hb_it).placeHolder) { 2359444SAndreas.Sandberg@ARM.com freeList->addReg((*hb_it).prevPhysReg); 2369444SAndreas.Sandberg@ARM.com } 2379444SAndreas.Sandberg@ARM.com 2389444SAndreas.Sandberg@ARM.com historyBuffer.erase(hb_it--); 2392292SN/A } 2401060SN/A 2411060SN/A // Finally free up the previous register of the squashed instruction 2422292SN/A // itself. 2432292SN/A if (!(*hb_it).placeHolder) { 2446221Snate@binkert.org freeList->addReg(hb_it->prevPhysReg); 2452292SN/A } 2462292SN/A 2472292SN/A historyBuffer.erase(hb_it); 2482292SN/A 2492292SN/A} 2501061SN/A 2511060SN/Atemplate <class Impl> 2522292SN/Ainline void 2531060SN/ASimpleRename<Impl>::renameSrcRegs(DynInstPtr &inst) 2546221Snate@binkert.org{ 2556221Snate@binkert.org unsigned num_src_regs = inst->numSrcRegs(); 2561060SN/A 2571060SN/A // Get the architectual register numbers from the source and 2581061SN/A // destination operands, and redirect them to the right register. 2591060SN/A // Will need to mark dependencies though. 2602292SN/A for (int src_idx = 0; src_idx < num_src_regs; src_idx++) 2611060SN/A { 2622292SN/A RegIndex src_reg = inst->srcRegIdx(src_idx); 2632292SN/A 2641060SN/A // Look up the source registers to get the phys. register they've 2652292SN/A // been renamed to, and set the sources to those registers. 2662292SN/A RegIndex renamed_reg = renameMap->lookup(src_reg); 2672292SN/A 2682292SN/A DPRINTF(Rename, "Rename: Looking up arch reg %i, got " 2692292SN/A "physical reg %i.\n", (int)src_reg, (int)renamed_reg); 2701060SN/A 2711060SN/A inst->renameSrcReg(src_idx, renamed_reg); 2721061SN/A 2732863Sktlim@umich.edu // Either incorporate it into the info passed back, 2749444SAndreas.Sandberg@ARM.com // or make another function call to see if that register is 2751060SN/A // ready or not. 2769444SAndreas.Sandberg@ARM.com if (renameMap->isReady(renamed_reg)) { 2779444SAndreas.Sandberg@ARM.com DPRINTF(Rename, "Rename: Register is ready.\n"); 2789444SAndreas.Sandberg@ARM.com 2799444SAndreas.Sandberg@ARM.com inst->markSrcRegReady(src_idx); 2809444SAndreas.Sandberg@ARM.com } 2819444SAndreas.Sandberg@ARM.com } 2829444SAndreas.Sandberg@ARM.com} 2832863Sktlim@umich.edu 2842316SN/Atemplate <class Impl> 2851060SN/Ainline void 2862316SN/ASimpleRename<Impl>::renameDestRegs(DynInstPtr &inst) 2872316SN/A{ 2882307SN/A typename SimpleRenameMap::RenameInfo rename_result; 2891060SN/A 2909444SAndreas.Sandberg@ARM.com unsigned num_dest_regs = inst->numDestRegs(); 2919444SAndreas.Sandberg@ARM.com 2921060SN/A // Rename the destination registers. 2939444SAndreas.Sandberg@ARM.com for (int dest_idx = 0; dest_idx < num_dest_regs; dest_idx++) 2949444SAndreas.Sandberg@ARM.com { 2959444SAndreas.Sandberg@ARM.com RegIndex dest_reg = inst->destRegIdx(dest_idx); 2969444SAndreas.Sandberg@ARM.com 2976221Snate@binkert.org // Get the physical register that the destination will be 2989444SAndreas.Sandberg@ARM.com // renamed to. 2999444SAndreas.Sandberg@ARM.com rename_result = renameMap->rename(dest_reg); 3009444SAndreas.Sandberg@ARM.com 3019444SAndreas.Sandberg@ARM.com DPRINTF(Rename, "Rename: Renaming arch reg %i to physical " 3022307SN/A "reg %i.\n", (int)dest_reg, 3032307SN/A (int)rename_result.first); 3042307SN/A 3052307SN/A // Record the rename information so that a history can be kept. 3062307SN/A RenameHistory hb_entry(inst->seqNum, dest_reg, 3076221Snate@binkert.org rename_result.first, 3081858SN/A rename_result.second); 3092292SN/A 3101858SN/A historyBuffer.push_front(hb_entry); 3112292SN/A 3122292SN/A DPRINTF(Rename, "Rename: Adding instruction to history buffer, " 3132292SN/A "sequence number %lli.\n", 3142292SN/A (*historyBuffer.begin()).instSeqNum); 3153788Sgblack@eecs.umich.edu 3162292SN/A // Tell the instruction to rename the appropriate destination 3172698Sktlim@umich.edu // register (dest_idx) to the new physical register 3183788Sgblack@eecs.umich.edu // (rename_result.first), and record the previous physical 3192301SN/A // register that the same logical register was renamed to 3203788Sgblack@eecs.umich.edu // (rename_result.second). 3213788Sgblack@eecs.umich.edu inst->renameDestReg(dest_idx, 3223788Sgblack@eecs.umich.edu rename_result.first, 3233788Sgblack@eecs.umich.edu rename_result.second); 3243788Sgblack@eecs.umich.edu } 3253788Sgblack@eecs.umich.edu 3263788Sgblack@eecs.umich.edu // If it's an instruction with no destination registers, then put 3273788Sgblack@eecs.umich.edu // a placeholder within the history buffer. It might be better 3283788Sgblack@eecs.umich.edu // to not put it in the history buffer at all (other than branches, 3293788Sgblack@eecs.umich.edu // which always need at least a place holder), and differentiate 3303788Sgblack@eecs.umich.edu // between instructions with and without destination registers 3312292SN/A // when getting from commit the instructions that committed. 3322292SN/A if (num_dest_regs == 0) { 3332292SN/A RenameHistory hb_entry(inst->seqNum); 3342292SN/A 3352292SN/A historyBuffer.push_front(hb_entry); 3362329SN/A 3372292SN/A DPRINTF(Rename, "Rename: Adding placeholder instruction to " 3382292SN/A "history buffer, sequence number %lli.\n", 3392292SN/A inst->seqNum); 3402935Sksewell@umich.edu } 3412935Sksewell@umich.edu} 3422731Sktlim@umich.edu 3432292SN/Atemplate <class Impl> 3442292SN/Ainline int 3452292SN/ASimpleRename<Impl>::calcFreeROBEntries() 3462935Sksewell@umich.edu{ 3472292SN/A return fromCommit->commitInfo.freeROBEntries - 3482292SN/A renameWidth * iewToRenameDelay; 3492935Sksewell@umich.edu} 3504632Sgblack@eecs.umich.edu 3513093Sksewell@umich.edutemplate <class Impl> 3522292SN/Ainline int 3532292SN/ASimpleRename<Impl>::calcFreeIQEntries() 3543093Sksewell@umich.edu{ 3554632Sgblack@eecs.umich.edu return fromIEW->iewInfo.freeIQEntries - renameWidth * iewToRenameDelay; 3562935Sksewell@umich.edu} 3572292SN/A 3582292SN/Atemplate<class Impl> 3592292SN/Avoid 3602292SN/ASimpleRename<Impl>::tick() 3612292SN/A{ 3622292SN/A // Rename will need to try to rename as many instructions as it 3632292SN/A // has bandwidth, unless it is blocked. 3642292SN/A 3652292SN/A // Check if _status is BarrierStall. If so, then check if the number 3662292SN/A // of free ROB entries is equal to the number of total ROB entries. 3672292SN/A // Once equal then wake this stage up. Set status to unblocking maybe. 3682292SN/A 3692292SN/A if (_status != Blocked && _status != Squashing) { 3702292SN/A DPRINTF(Rename, "Rename: Status is not blocked, will attempt to " 3712292SN/A "run stage.\n"); 3722292SN/A // Make sure that the skid buffer has something in it if the 3736221Snate@binkert.org // status is unblocking. 3746221Snate@binkert.org assert(_status == Unblocking ? !skidBuffer.empty() : 1); 3752292SN/A 3762292SN/A rename(); 3773867Sbinkertn@umich.edu 3786221Snate@binkert.org // If the status was unblocking, then instructions from the skid 3792292SN/A // buffer were used. Remove those instructions and handle 3802292SN/A // the rest of unblocking. 3812292SN/A if (_status == Unblocking) { 3822292SN/A if (fromDecode->size > 0) { 3832292SN/A // Add the current inputs onto the skid buffer, so they can be 3842292SN/A // reprocessed when this stage unblocks. 3852292SN/A skidBuffer.push(*fromDecode); 3862292SN/A } 3872292SN/A 3882292SN/A unblock(); 3892292SN/A } 3902292SN/A } else if (_status == Blocked) { 3912292SN/A // If stage is blocked and still receiving valid instructions, 3922292SN/A // make sure to store them in the skid buffer. 3932292SN/A if (fromDecode->size > 0) { 3942292SN/A 3952292SN/A block(); 3963867Sbinkertn@umich.edu 3972292SN/A // Continue to tell previous stage to stall. 3983867Sbinkertn@umich.edu toDecode->renameInfo.stall = true; 3996221Snate@binkert.org } 4002292SN/A 4012292SN/A if (!fromIEW->iewInfo.stall && 4022292SN/A !fromCommit->commitInfo.stall && 4032292SN/A calcFreeROBEntries() > 0 && 4042292SN/A calcFreeIQEntries() > 0 && 4052292SN/A renameMap->numFreeEntries() > 0) { 4062292SN/A 4072292SN/A // Need to be sure to check all blocking conditions above. 4082292SN/A // If they have cleared, then start unblocking. 4092292SN/A DPRINTF(Rename, "Rename: Stall signals cleared, going to " 4102292SN/A "unblock.\n"); 4112292SN/A _status = Unblocking; 4126221Snate@binkert.org 4132292SN/A // Continue to tell previous stage to block until this stage 4142292SN/A // is done unblocking. 4152292SN/A toDecode->renameInfo.stall = true; 4162292SN/A } else { 4172292SN/A // Otherwise no conditions have changed. Tell previous 4182292SN/A // stage to continue blocking. 4192292SN/A toDecode->renameInfo.stall = true; 4202292SN/A } 4212292SN/A 4226221Snate@binkert.org if (fromCommit->commitInfo.squash || 4232292SN/A fromCommit->commitInfo.robSquashing) { 4242292SN/A squash(); 4252292SN/A return; 4262292SN/A } 4272292SN/A } else if (_status == Squashing) { 4282292SN/A if (fromCommit->commitInfo.squash) { 4292292SN/A squash(); 4302292SN/A } else if (!fromCommit->commitInfo.squash && 4312292SN/A !fromCommit->commitInfo.robSquashing) { 4322292SN/A 4332292SN/A DPRINTF(Rename, "Rename: Done squashing, going to running.\n"); 4342292SN/A _status = Running; 4352301SN/A } else { 4362301SN/A doSquash(); 4373788Sgblack@eecs.umich.edu } 4383788Sgblack@eecs.umich.edu } 4393788Sgblack@eecs.umich.edu 4403788Sgblack@eecs.umich.edu // Ugly code, revamp all of the tick() functions eventually. 4413788Sgblack@eecs.umich.edu if (fromCommit->commitInfo.doneSeqNum != 0 && _status != Squashing) { 4423788Sgblack@eecs.umich.edu removeFromHistory(fromCommit->commitInfo.doneSeqNum); 4433788Sgblack@eecs.umich.edu } 4443788Sgblack@eecs.umich.edu 4453798Sgblack@eecs.umich.edu // Perhaps put this outside of this function, since this will 4463798Sgblack@eecs.umich.edu // happen regardless of whether or not the stage is blocked or 4473798Sgblack@eecs.umich.edu // squashing. 4483798Sgblack@eecs.umich.edu // Read from the time buffer any necessary data. 4493798Sgblack@eecs.umich.edu // Read registers that are freed, and add them to the freelist. 4503798Sgblack@eecs.umich.edu // This is unnecessary due to the history buffer (assuming the history 4512292SN/A // buffer works properly). 4522292SN/A/* 4532292SN/A while(!fromCommit->commitInfo.freeRegs.empty()) 4542292SN/A { 4552292SN/A PhysRegIndex freed_reg = fromCommit->commitInfo.freeRegs.back(); 4562292SN/A DPRINTF(Rename, "Rename: Adding freed register %i to freelist.\n", 4572292SN/A (int)freed_reg); 4582292SN/A freeList->addReg(freed_reg); 4592292SN/A 4602292SN/A fromCommit->commitInfo.freeRegs.pop_back(); 4612292SN/A } 4622292SN/A*/ 4632292SN/A 4642292SN/A} 4652292SN/A 4662292SN/Atemplate<class Impl> 4672292SN/Avoid 4682292SN/ASimpleRename<Impl>::rename() 4692292SN/A{ 4702292SN/A // Check if any of the stages ahead of rename are telling rename 4711858SN/A // to squash. The squash() function will also take care of fixing up 4721858SN/A // the rename map and the free list. 4731858SN/A if (fromCommit->commitInfo.squash || 4741858SN/A fromCommit->commitInfo.robSquashing) { 4751858SN/A DPRINTF(Rename, "Rename: Receiving signal from Commit to squash.\n"); 4766221Snate@binkert.org squash(); 4771858SN/A return; 4782292SN/A } 4792292SN/A 4802292SN/A // Check if time buffer is telling this stage to stall. 4812292SN/A if (fromIEW->iewInfo.stall || 4821858SN/A fromCommit->commitInfo.stall) { 4832292SN/A DPRINTF(Rename, "Rename: Receiving signal from IEW/Commit to " 4842292SN/A "stall.\n"); 4852292SN/A block(); 4862292SN/A return; 4872292SN/A } 4882292SN/A 4892292SN/A // Check if the current status is squashing. If so, set its status 4902292SN/A // to running and resume execution the next cycle. 4912292SN/A if (_status == Squashing) { 4922292SN/A DPRINTF(Rename, "Rename: Done squashing.\n"); 4932292SN/A _status = Running; 4942292SN/A return; 4952292SN/A } 4961858SN/A 4972292SN/A // Check the decode queue to see if instructions are available. 4982292SN/A // If there are no available instructions to rename, then do nothing. 4992292SN/A // Or, if the stage is currently unblocking, then go ahead and run it. 5002292SN/A if (fromDecode->size == 0 && _status != Unblocking) { 5012292SN/A DPRINTF(Rename, "Rename: Nothing to do, breaking out early.\n"); 5022292SN/A // Should I change status to idle? 5032292SN/A return; 5042292SN/A } 5052292SN/A 5062292SN/A //////////////////////////////////// 5072292SN/A // Actual rename part. 5082292SN/A //////////////////////////////////// 5092292SN/A 5102292SN/A DynInstPtr inst; 5112292SN/A 5122292SN/A // If we're unblocking, then we may be in the middle of an instruction 5132292SN/A // group. Subtract off numInst to get the proper number of instructions 5142292SN/A // left. 5152292SN/A int insts_available = _status == Unblocking ? 5162292SN/A skidBuffer.front().size - numInst : 5172292SN/A fromDecode->size; 5182292SN/A 5192292SN/A bool block_this_cycle = false; 5202292SN/A 5212292SN/A // Will have to do a different calculation for the number of free 5222292SN/A // entries. Number of free entries recorded on this cycle - 5232292SN/A // renameWidth * renameToDecodeDelay 5242292SN/A int free_rob_entries = calcFreeROBEntries(); 5252292SN/A int free_iq_entries = calcFreeIQEntries(); 5262292SN/A int min_iq_rob = min(free_rob_entries, free_iq_entries); 5272292SN/A 5282292SN/A unsigned to_iew_index = 0; 5292292SN/A 5302292SN/A // Check if there's any space left. 5312292SN/A if (min_iq_rob <= 0) { 5322292SN/A DPRINTF(Rename, "Rename: Blocking due to no free ROB or IQ " 5332292SN/A "entries.\n" 5342292SN/A "Rename: ROB has %d free entries.\n" 5352292SN/A "Rename: IQ has %d free entries.\n", 5362292SN/A free_rob_entries, 5372292SN/A free_iq_entries); 5382292SN/A block(); 5392292SN/A // Tell previous stage to stall. 5402292SN/A toDecode->renameInfo.stall = true; 5412292SN/A 5422292SN/A return; 5432292SN/A } else if (min_iq_rob < insts_available) { 5442292SN/A DPRINTF(Rename, "Rename: Will have to block this cycle. Only " 5452292SN/A "%i insts can be renamed due to IQ/ROB limits.\n", 5462292SN/A min_iq_rob); 5472292SN/A 5482292SN/A insts_available = min_iq_rob; 5492292SN/A 5502292SN/A block_this_cycle = true; 5512292SN/A } 5522292SN/A 5532292SN/A while (insts_available > 0) { 5542292SN/A DPRINTF(Rename, "Rename: Sending instructions to iew.\n"); 5552292SN/A 5562292SN/A // Get the next instruction either from the skid buffer or the 5572292SN/A // decode queue. 5582292SN/A inst = _status == Unblocking ? skidBuffer.front().insts[numInst] : 5592292SN/A fromDecode->insts[numInst]; 5602292SN/A 5612292SN/A if (inst->isSquashed()) { 5622292SN/A DPRINTF(Rename, "Rename: instruction %i with PC %#x is " 5632292SN/A "squashed, skipping.\n", 5642292SN/A inst->seqNum, inst->readPC()); 5652292SN/A 5662292SN/A // Go to the next instruction. 5672292SN/A ++numInst; 5682292SN/A 5692292SN/A // Decrement how many instructions are available. 5702292SN/A --insts_available; 5712292SN/A 5722292SN/A continue; 5732292SN/A } 5742292SN/A 5752292SN/A DPRINTF(Rename, "Rename: Processing instruction %i with PC %#x.\n", 5762292SN/A inst->seqNum, inst->readPC()); 5772292SN/A 5782292SN/A // If it's a trap instruction, then it needs to wait here within 5792292SN/A // rename until the ROB is empty. Needs a way to detect that the 5802292SN/A // ROB is empty. Maybe an event? 5812292SN/A // Would be nice if it could be avoided putting this into a 5827720Sgblack@eecs.umich.edu // specific stage and instead just put it into the AlphaFullCPU. 5837720Sgblack@eecs.umich.edu // Might not really be feasible though... 5842292SN/A // (EXCB, TRAPB) 5852292SN/A if (inst->isSerializing()) { 5862292SN/A panic("Rename: Serializing instruction encountered.\n"); 5877720Sgblack@eecs.umich.edu DPRINTF(Rename, "Rename: Serializing instruction " 5887720Sgblack@eecs.umich.edu "encountered.\n"); 5897720Sgblack@eecs.umich.edu 5902292SN/A // Change status over to BarrierStall so that other stages know 5912292SN/A // what this is blocked on. 5922292SN/A _status = BarrierStall; 5932292SN/A 5942292SN/A block_this_cycle = true; 5952292SN/A 5962292SN/A break; 5972292SN/A } 5982292SN/A 5992292SN/A // Check here to make sure there are enough destination registers 6007720Sgblack@eecs.umich.edu // to rename to. Otherwise block. 6012292SN/A if (renameMap->numFreeEntries() < inst->numDestRegs()) 6022292SN/A { 6032292SN/A DPRINTF(Rename, "Rename: Blocking due to lack of free " 6042292SN/A "physical registers to rename to.\n"); 6052292SN/A // Need some sort of event based on a register being freed. 6062336SN/A 6072336SN/A block_this_cycle = true; 6082336SN/A 6092336SN/A break; 6102336SN/A } 6112336SN/A 6122336SN/A renameSrcRegs(inst); 6132336SN/A 6142292SN/A renameDestRegs(inst); 6152292SN/A 6162301SN/A // Put instruction in rename queue. 6172301SN/A toIEW->insts[to_iew_index] = inst; 6182292SN/A ++(toIEW->size); 6192301SN/A 6202301SN/A // Decrease the number of free ROB and IQ entries. 6212301SN/A --free_rob_entries; 6222292SN/A --free_iq_entries; 6232301SN/A 6242292SN/A // Increment which instruction we're on. 6252301SN/A ++to_iew_index; 6262292SN/A ++numInst; 6272301SN/A 6282292SN/A // Decrement how many instructions are available. 6292292SN/A --insts_available; 6302292SN/A } 6312292SN/A 6322336SN/A // Check if there's any instructions left that haven't yet been renamed. 6332336SN/A // If so then block. 6342292SN/A if (block_this_cycle) { 6352292SN/A block(); 6362307SN/A 6372307SN/A toDecode->renameInfo.stall = true; 6382292SN/A } else { 6392292SN/A // If we had a successful rename and didn't have to exit early, then 6402292SN/A // reset numInst so it will refer to the correct instruction on next 6412292SN/A // run. 6422292SN/A numInst = 0; 6432292SN/A } 6442292SN/A} 6452292SN/A