iew_impl.hh revision 9046
11689SN/A/* 28733Sgeoffrey.blake@arm.com * Copyright (c) 2010-2011 ARM Limited 37598Sminkyu.jeong@arm.com * All rights reserved. 47598Sminkyu.jeong@arm.com * 57598Sminkyu.jeong@arm.com * The license below extends only to copyright in the software and shall 67598Sminkyu.jeong@arm.com * not be construed as granting a license to any other intellectual 77598Sminkyu.jeong@arm.com * property including but not limited to intellectual property relating 87598Sminkyu.jeong@arm.com * to a hardware implementation of the functionality of the software 97598Sminkyu.jeong@arm.com * licensed hereunder. You may use the software subject to the license 107598Sminkyu.jeong@arm.com * terms below provided that you ensure that this notice is replicated 117598Sminkyu.jeong@arm.com * unmodified and in its entirety in all distributions of the software, 127598Sminkyu.jeong@arm.com * modified or unmodified, in source code or in binary form. 137598Sminkyu.jeong@arm.com * 142326SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 271689SN/A * 281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392665Ssaidi@eecs.umich.edu * 402665Ssaidi@eecs.umich.edu * Authors: Kevin Lim 411689SN/A */ 421689SN/A 431060SN/A// @todo: Fix the instantaneous communication among all the stages within 441060SN/A// iew. There's a clear delay between issue and execute, yet backwards 451689SN/A// communication happens simultaneously. 461060SN/A 471060SN/A#include <queue> 481060SN/A 498230Snate@binkert.org#include "arch/utility.hh" 506658Snate@binkert.org#include "config/the_isa.hh" 518887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 522292SN/A#include "cpu/o3/fu_pool.hh" 531717SN/A#include "cpu/o3/iew.hh" 548229Snate@binkert.org#include "cpu/timebuf.hh" 558232Snate@binkert.org#include "debug/Activity.hh" 568232Snate@binkert.org#include "debug/Decode.hh" 578232Snate@binkert.org#include "debug/IEW.hh" 585529Snate@binkert.org#include "params/DerivO3CPU.hh" 591060SN/A 606221Snate@binkert.orgusing namespace std; 616221Snate@binkert.org 621681SN/Atemplate<class Impl> 635529Snate@binkert.orgDefaultIEW<Impl>::DefaultIEW(O3CPU *_cpu, DerivO3CPUParams *params) 642873Sktlim@umich.edu : issueToExecQueue(params->backComSize, params->forwardComSize), 654329Sktlim@umich.edu cpu(_cpu), 664329Sktlim@umich.edu instQueue(_cpu, this, params), 674329Sktlim@umich.edu ldstQueue(_cpu, this, params), 682292SN/A fuPool(params->fuPool), 692292SN/A commitToIEWDelay(params->commitToIEWDelay), 702292SN/A renameToIEWDelay(params->renameToIEWDelay), 712292SN/A issueToExecuteDelay(params->issueToExecuteDelay), 722820Sktlim@umich.edu dispatchWidth(params->dispatchWidth), 732292SN/A issueWidth(params->issueWidth), 742820Sktlim@umich.edu wbOutstanding(0), 752820Sktlim@umich.edu wbWidth(params->wbWidth), 765529Snate@binkert.org numThreads(params->numThreads), 772307SN/A switchedOut(false) 781060SN/A{ 792292SN/A _status = Active; 802292SN/A exeStatus = Running; 812292SN/A wbStatus = Idle; 821060SN/A 831060SN/A // Setup wire to read instructions coming from issue. 841060SN/A fromIssue = issueToExecQueue.getWire(-issueToExecuteDelay); 851060SN/A 861060SN/A // Instruction queue needs the queue between issue and execute. 871060SN/A instQueue.setIssueToExecuteQueue(&issueToExecQueue); 881681SN/A 896221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 906221Snate@binkert.org dispatchStatus[tid] = Running; 916221Snate@binkert.org stalls[tid].commit = false; 926221Snate@binkert.org fetchRedirect[tid] = false; 932292SN/A } 942292SN/A 952820Sktlim@umich.edu wbMax = wbWidth * params->wbDepth; 962820Sktlim@umich.edu 972292SN/A updateLSQNextCycle = false; 982292SN/A 992820Sktlim@umich.edu ableToIssue = true; 1002820Sktlim@umich.edu 1012292SN/A skidBufferMax = (3 * (renameToIEWDelay * params->renameWidth)) + issueWidth; 1022292SN/A} 1032292SN/A 1042292SN/Atemplate <class Impl> 1052292SN/Astd::string 1062292SN/ADefaultIEW<Impl>::name() const 1072292SN/A{ 1082292SN/A return cpu->name() + ".iew"; 1091060SN/A} 1101060SN/A 1111681SN/Atemplate <class Impl> 1121062SN/Avoid 1132292SN/ADefaultIEW<Impl>::regStats() 1141062SN/A{ 1152301SN/A using namespace Stats; 1162301SN/A 1171062SN/A instQueue.regStats(); 1182727Sktlim@umich.edu ldstQueue.regStats(); 1191062SN/A 1201062SN/A iewIdleCycles 1211062SN/A .name(name() + ".iewIdleCycles") 1221062SN/A .desc("Number of cycles IEW is idle"); 1231062SN/A 1241062SN/A iewSquashCycles 1251062SN/A .name(name() + ".iewSquashCycles") 1261062SN/A .desc("Number of cycles IEW is squashing"); 1271062SN/A 1281062SN/A iewBlockCycles 1291062SN/A .name(name() + ".iewBlockCycles") 1301062SN/A .desc("Number of cycles IEW is blocking"); 1311062SN/A 1321062SN/A iewUnblockCycles 1331062SN/A .name(name() + ".iewUnblockCycles") 1341062SN/A .desc("Number of cycles IEW is unblocking"); 1351062SN/A 1361062SN/A iewDispatchedInsts 1371062SN/A .name(name() + ".iewDispatchedInsts") 1381062SN/A .desc("Number of instructions dispatched to IQ"); 1391062SN/A 1401062SN/A iewDispSquashedInsts 1411062SN/A .name(name() + ".iewDispSquashedInsts") 1421062SN/A .desc("Number of squashed instructions skipped by dispatch"); 1431062SN/A 1441062SN/A iewDispLoadInsts 1451062SN/A .name(name() + ".iewDispLoadInsts") 1461062SN/A .desc("Number of dispatched load instructions"); 1471062SN/A 1481062SN/A iewDispStoreInsts 1491062SN/A .name(name() + ".iewDispStoreInsts") 1501062SN/A .desc("Number of dispatched store instructions"); 1511062SN/A 1521062SN/A iewDispNonSpecInsts 1531062SN/A .name(name() + ".iewDispNonSpecInsts") 1541062SN/A .desc("Number of dispatched non-speculative instructions"); 1551062SN/A 1561062SN/A iewIQFullEvents 1571062SN/A .name(name() + ".iewIQFullEvents") 1581062SN/A .desc("Number of times the IQ has become full, causing a stall"); 1591062SN/A 1602292SN/A iewLSQFullEvents 1612292SN/A .name(name() + ".iewLSQFullEvents") 1622292SN/A .desc("Number of times the LSQ has become full, causing a stall"); 1632292SN/A 1641062SN/A memOrderViolationEvents 1651062SN/A .name(name() + ".memOrderViolationEvents") 1661062SN/A .desc("Number of memory order violations"); 1671062SN/A 1681062SN/A predictedTakenIncorrect 1691062SN/A .name(name() + ".predictedTakenIncorrect") 1701062SN/A .desc("Number of branches that were predicted taken incorrectly"); 1712292SN/A 1722292SN/A predictedNotTakenIncorrect 1732292SN/A .name(name() + ".predictedNotTakenIncorrect") 1742292SN/A .desc("Number of branches that were predicted not taken incorrectly"); 1752292SN/A 1762292SN/A branchMispredicts 1772292SN/A .name(name() + ".branchMispredicts") 1782292SN/A .desc("Number of branch mispredicts detected at execute"); 1792292SN/A 1802292SN/A branchMispredicts = predictedTakenIncorrect + predictedNotTakenIncorrect; 1812301SN/A 1822727Sktlim@umich.edu iewExecutedInsts 1832353SN/A .name(name() + ".iewExecutedInsts") 1842727Sktlim@umich.edu .desc("Number of executed instructions"); 1852727Sktlim@umich.edu 1862727Sktlim@umich.edu iewExecLoadInsts 1876221Snate@binkert.org .init(cpu->numThreads) 1882353SN/A .name(name() + ".iewExecLoadInsts") 1892727Sktlim@umich.edu .desc("Number of load instructions executed") 1902727Sktlim@umich.edu .flags(total); 1912727Sktlim@umich.edu 1922727Sktlim@umich.edu iewExecSquashedInsts 1932353SN/A .name(name() + ".iewExecSquashedInsts") 1942727Sktlim@umich.edu .desc("Number of squashed instructions skipped in execute"); 1952727Sktlim@umich.edu 1962727Sktlim@umich.edu iewExecutedSwp 1976221Snate@binkert.org .init(cpu->numThreads) 1988240Snate@binkert.org .name(name() + ".exec_swp") 1992301SN/A .desc("number of swp insts executed") 2002727Sktlim@umich.edu .flags(total); 2012301SN/A 2022727Sktlim@umich.edu iewExecutedNop 2036221Snate@binkert.org .init(cpu->numThreads) 2048240Snate@binkert.org .name(name() + ".exec_nop") 2052301SN/A .desc("number of nop insts executed") 2062727Sktlim@umich.edu .flags(total); 2072301SN/A 2082727Sktlim@umich.edu iewExecutedRefs 2096221Snate@binkert.org .init(cpu->numThreads) 2108240Snate@binkert.org .name(name() + ".exec_refs") 2112301SN/A .desc("number of memory reference insts executed") 2122727Sktlim@umich.edu .flags(total); 2132301SN/A 2142727Sktlim@umich.edu iewExecutedBranches 2156221Snate@binkert.org .init(cpu->numThreads) 2168240Snate@binkert.org .name(name() + ".exec_branches") 2172301SN/A .desc("Number of branches executed") 2182727Sktlim@umich.edu .flags(total); 2192301SN/A 2202301SN/A iewExecStoreInsts 2218240Snate@binkert.org .name(name() + ".exec_stores") 2222301SN/A .desc("Number of stores executed") 2232727Sktlim@umich.edu .flags(total); 2242727Sktlim@umich.edu iewExecStoreInsts = iewExecutedRefs - iewExecLoadInsts; 2252727Sktlim@umich.edu 2262727Sktlim@umich.edu iewExecRate 2278240Snate@binkert.org .name(name() + ".exec_rate") 2282727Sktlim@umich.edu .desc("Inst execution rate") 2292727Sktlim@umich.edu .flags(total); 2302727Sktlim@umich.edu 2312727Sktlim@umich.edu iewExecRate = iewExecutedInsts / cpu->numCycles; 2322301SN/A 2332301SN/A iewInstsToCommit 2346221Snate@binkert.org .init(cpu->numThreads) 2358240Snate@binkert.org .name(name() + ".wb_sent") 2362301SN/A .desc("cumulative count of insts sent to commit") 2372727Sktlim@umich.edu .flags(total); 2382301SN/A 2392326SN/A writebackCount 2406221Snate@binkert.org .init(cpu->numThreads) 2418240Snate@binkert.org .name(name() + ".wb_count") 2422301SN/A .desc("cumulative count of insts written-back") 2432727Sktlim@umich.edu .flags(total); 2442301SN/A 2452326SN/A producerInst 2466221Snate@binkert.org .init(cpu->numThreads) 2478240Snate@binkert.org .name(name() + ".wb_producers") 2482301SN/A .desc("num instructions producing a value") 2492727Sktlim@umich.edu .flags(total); 2502301SN/A 2512326SN/A consumerInst 2526221Snate@binkert.org .init(cpu->numThreads) 2538240Snate@binkert.org .name(name() + ".wb_consumers") 2542301SN/A .desc("num instructions consuming a value") 2552727Sktlim@umich.edu .flags(total); 2562301SN/A 2572326SN/A wbPenalized 2586221Snate@binkert.org .init(cpu->numThreads) 2598240Snate@binkert.org .name(name() + ".wb_penalized") 2602301SN/A .desc("number of instrctions required to write to 'other' IQ") 2612727Sktlim@umich.edu .flags(total); 2622301SN/A 2632326SN/A wbPenalizedRate 2648240Snate@binkert.org .name(name() + ".wb_penalized_rate") 2652301SN/A .desc ("fraction of instructions written-back that wrote to 'other' IQ") 2662727Sktlim@umich.edu .flags(total); 2672301SN/A 2682326SN/A wbPenalizedRate = wbPenalized / writebackCount; 2692301SN/A 2702326SN/A wbFanout 2718240Snate@binkert.org .name(name() + ".wb_fanout") 2722301SN/A .desc("average fanout of values written-back") 2732727Sktlim@umich.edu .flags(total); 2742301SN/A 2752326SN/A wbFanout = producerInst / consumerInst; 2762301SN/A 2772326SN/A wbRate 2788240Snate@binkert.org .name(name() + ".wb_rate") 2792301SN/A .desc("insts written-back per cycle") 2802727Sktlim@umich.edu .flags(total); 2812326SN/A wbRate = writebackCount / cpu->numCycles; 2821062SN/A} 2831062SN/A 2841681SN/Atemplate<class Impl> 2851060SN/Avoid 2862292SN/ADefaultIEW<Impl>::initStage() 2871060SN/A{ 2886221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 2892292SN/A toRename->iewInfo[tid].usedIQ = true; 2902292SN/A toRename->iewInfo[tid].freeIQEntries = 2912292SN/A instQueue.numFreeEntries(tid); 2922292SN/A 2932292SN/A toRename->iewInfo[tid].usedLSQ = true; 2942292SN/A toRename->iewInfo[tid].freeLSQEntries = 2952292SN/A ldstQueue.numFreeEntries(tid); 2962292SN/A } 2972292SN/A 2988887Sgeoffrey.blake@arm.com // Initialize the checker's dcache port here 2998733Sgeoffrey.blake@arm.com if (cpu->checker) { 3008850Sandreas.hansson@arm.com cpu->checker->setDcachePort(&cpu->getDataPort()); 3018887Sgeoffrey.blake@arm.com } 3028733Sgeoffrey.blake@arm.com 3032733Sktlim@umich.edu cpu->activateStage(O3CPU::IEWIdx); 3041060SN/A} 3051060SN/A 3061681SN/Atemplate<class Impl> 3071060SN/Avoid 3082292SN/ADefaultIEW<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr) 3091060SN/A{ 3101060SN/A timeBuffer = tb_ptr; 3111060SN/A 3121060SN/A // Setup wire to read information from time buffer, from commit. 3131060SN/A fromCommit = timeBuffer->getWire(-commitToIEWDelay); 3141060SN/A 3151060SN/A // Setup wire to write information back to previous stages. 3161060SN/A toRename = timeBuffer->getWire(0); 3171060SN/A 3182292SN/A toFetch = timeBuffer->getWire(0); 3192292SN/A 3201060SN/A // Instruction queue also needs main time buffer. 3211060SN/A instQueue.setTimeBuffer(tb_ptr); 3221060SN/A} 3231060SN/A 3241681SN/Atemplate<class Impl> 3251060SN/Avoid 3262292SN/ADefaultIEW<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr) 3271060SN/A{ 3281060SN/A renameQueue = rq_ptr; 3291060SN/A 3301060SN/A // Setup wire to read information from rename queue. 3311060SN/A fromRename = renameQueue->getWire(-renameToIEWDelay); 3321060SN/A} 3331060SN/A 3341681SN/Atemplate<class Impl> 3351060SN/Avoid 3362292SN/ADefaultIEW<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr) 3371060SN/A{ 3381060SN/A iewQueue = iq_ptr; 3391060SN/A 3401060SN/A // Setup wire to write instructions to commit. 3411060SN/A toCommit = iewQueue->getWire(0); 3421060SN/A} 3431060SN/A 3441681SN/Atemplate<class Impl> 3451060SN/Avoid 3466221Snate@binkert.orgDefaultIEW<Impl>::setActiveThreads(list<ThreadID> *at_ptr) 3471060SN/A{ 3482292SN/A activeThreads = at_ptr; 3492292SN/A 3502292SN/A ldstQueue.setActiveThreads(at_ptr); 3512292SN/A instQueue.setActiveThreads(at_ptr); 3521060SN/A} 3531060SN/A 3541681SN/Atemplate<class Impl> 3551060SN/Avoid 3562292SN/ADefaultIEW<Impl>::setScoreboard(Scoreboard *sb_ptr) 3571060SN/A{ 3582292SN/A scoreboard = sb_ptr; 3591060SN/A} 3601060SN/A 3612307SN/Atemplate <class Impl> 3622863Sktlim@umich.edubool 3632843Sktlim@umich.eduDefaultIEW<Impl>::drain() 3642307SN/A{ 3652843Sktlim@umich.edu // IEW is ready to drain at any time. 3662843Sktlim@umich.edu cpu->signalDrained(); 3672863Sktlim@umich.edu return true; 3681681SN/A} 3691681SN/A 3702316SN/Atemplate <class Impl> 3711681SN/Avoid 3722843Sktlim@umich.eduDefaultIEW<Impl>::resume() 3732843Sktlim@umich.edu{ 3742843Sktlim@umich.edu} 3752843Sktlim@umich.edu 3762843Sktlim@umich.edutemplate <class Impl> 3772843Sktlim@umich.eduvoid 3782843Sktlim@umich.eduDefaultIEW<Impl>::switchOut() 3791681SN/A{ 3802348SN/A // Clear any state. 3812307SN/A switchedOut = true; 3822367SN/A assert(insts[0].empty()); 3832367SN/A assert(skidBuffer[0].empty()); 3841681SN/A 3852307SN/A instQueue.switchOut(); 3862307SN/A ldstQueue.switchOut(); 3872307SN/A fuPool->switchOut(); 3882307SN/A 3896221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 3906221Snate@binkert.org while (!insts[tid].empty()) 3916221Snate@binkert.org insts[tid].pop(); 3926221Snate@binkert.org while (!skidBuffer[tid].empty()) 3936221Snate@binkert.org skidBuffer[tid].pop(); 3942307SN/A } 3951681SN/A} 3961681SN/A 3972307SN/Atemplate <class Impl> 3981681SN/Avoid 3992307SN/ADefaultIEW<Impl>::takeOverFrom() 4001060SN/A{ 4012348SN/A // Reset all state. 4022307SN/A _status = Active; 4032307SN/A exeStatus = Running; 4042307SN/A wbStatus = Idle; 4052307SN/A switchedOut = false; 4061060SN/A 4072307SN/A instQueue.takeOverFrom(); 4082307SN/A ldstQueue.takeOverFrom(); 4098737Skoansin.tan@gmail.com fuPool->takeOver(); 4101060SN/A 4112307SN/A initStage(); 4122307SN/A cpu->activityThisCycle(); 4131060SN/A 4146221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) { 4156221Snate@binkert.org dispatchStatus[tid] = Running; 4166221Snate@binkert.org stalls[tid].commit = false; 4176221Snate@binkert.org fetchRedirect[tid] = false; 4182307SN/A } 4191060SN/A 4202307SN/A updateLSQNextCycle = false; 4212307SN/A 4222873Sktlim@umich.edu for (int i = 0; i < issueToExecQueue.getSize(); ++i) { 4232307SN/A issueToExecQueue.advance(); 4241060SN/A } 4251060SN/A} 4261060SN/A 4271681SN/Atemplate<class Impl> 4281060SN/Avoid 4296221Snate@binkert.orgDefaultIEW<Impl>::squash(ThreadID tid) 4302107SN/A{ 4316221Snate@binkert.org DPRINTF(IEW, "[tid:%i]: Squashing all instructions.\n", tid); 4322107SN/A 4332292SN/A // Tell the IQ to start squashing. 4342292SN/A instQueue.squash(tid); 4352107SN/A 4362292SN/A // Tell the LDSTQ to start squashing. 4372326SN/A ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid); 4382292SN/A updatedQueues = true; 4392107SN/A 4402292SN/A // Clear the skid buffer in case it has any data in it. 4412935Sksewell@umich.edu DPRINTF(IEW, "[tid:%i]: Removing skidbuffer instructions until [sn:%i].\n", 4424632Sgblack@eecs.umich.edu tid, fromCommit->commitInfo[tid].doneSeqNum); 4432935Sksewell@umich.edu 4442292SN/A while (!skidBuffer[tid].empty()) { 4452292SN/A if (skidBuffer[tid].front()->isLoad() || 4462292SN/A skidBuffer[tid].front()->isStore() ) { 4472292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 4482292SN/A } 4492107SN/A 4502292SN/A toRename->iewInfo[tid].dispatched++; 4512107SN/A 4522292SN/A skidBuffer[tid].pop(); 4532292SN/A } 4542107SN/A 4552702Sktlim@umich.edu emptyRenameInsts(tid); 4562107SN/A} 4572107SN/A 4582107SN/Atemplate<class Impl> 4592107SN/Avoid 4606221Snate@binkert.orgDefaultIEW<Impl>::squashDueToBranch(DynInstPtr &inst, ThreadID tid) 4612292SN/A{ 4627720Sgblack@eecs.umich.edu DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, PC: %s " 4637720Sgblack@eecs.umich.edu "[sn:%i].\n", tid, inst->pcState(), inst->seqNum); 4642292SN/A 4657852SMatt.Horsnell@arm.com if (toCommit->squash[tid] == false || 4667852SMatt.Horsnell@arm.com inst->seqNum < toCommit->squashedSeqNum[tid]) { 4677852SMatt.Horsnell@arm.com toCommit->squash[tid] = true; 4687852SMatt.Horsnell@arm.com toCommit->squashedSeqNum[tid] = inst->seqNum; 4697852SMatt.Horsnell@arm.com toCommit->branchTaken[tid] = inst->pcState().branching(); 4702935Sksewell@umich.edu 4717852SMatt.Horsnell@arm.com TheISA::PCState pc = inst->pcState(); 4727852SMatt.Horsnell@arm.com TheISA::advancePC(pc, inst->staticInst); 4732292SN/A 4747852SMatt.Horsnell@arm.com toCommit->pc[tid] = pc; 4757852SMatt.Horsnell@arm.com toCommit->mispredictInst[tid] = inst; 4767852SMatt.Horsnell@arm.com toCommit->includeSquashInst[tid] = false; 4772292SN/A 4787852SMatt.Horsnell@arm.com wroteToTimeBuffer = true; 4797852SMatt.Horsnell@arm.com } 4807852SMatt.Horsnell@arm.com 4812292SN/A} 4822292SN/A 4832292SN/Atemplate<class Impl> 4842292SN/Avoid 4856221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemOrder(DynInstPtr &inst, ThreadID tid) 4862292SN/A{ 4878513SGiacomo.Gabrielli@arm.com DPRINTF(IEW, "[tid:%i]: Memory violation, squashing violator and younger " 4888513SGiacomo.Gabrielli@arm.com "insts, PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum); 4898513SGiacomo.Gabrielli@arm.com // Need to include inst->seqNum in the following comparison to cover the 4908513SGiacomo.Gabrielli@arm.com // corner case when a branch misprediction and a memory violation for the 4918513SGiacomo.Gabrielli@arm.com // same instruction (e.g. load PC) are detected in the same cycle. In this 4928513SGiacomo.Gabrielli@arm.com // case the memory violator should take precedence over the branch 4938513SGiacomo.Gabrielli@arm.com // misprediction because it requires the violator itself to be included in 4948513SGiacomo.Gabrielli@arm.com // the squash. 4958513SGiacomo.Gabrielli@arm.com if (toCommit->squash[tid] == false || 4968513SGiacomo.Gabrielli@arm.com inst->seqNum <= toCommit->squashedSeqNum[tid]) { 4978513SGiacomo.Gabrielli@arm.com toCommit->squash[tid] = true; 4982292SN/A 4997852SMatt.Horsnell@arm.com toCommit->squashedSeqNum[tid] = inst->seqNum; 5008513SGiacomo.Gabrielli@arm.com toCommit->pc[tid] = inst->pcState(); 5018137SAli.Saidi@ARM.com toCommit->mispredictInst[tid] = NULL; 5022292SN/A 5038513SGiacomo.Gabrielli@arm.com // Must include the memory violator in the squash. 5048513SGiacomo.Gabrielli@arm.com toCommit->includeSquashInst[tid] = true; 5052292SN/A 5067852SMatt.Horsnell@arm.com wroteToTimeBuffer = true; 5077852SMatt.Horsnell@arm.com } 5082292SN/A} 5092292SN/A 5102292SN/Atemplate<class Impl> 5112292SN/Avoid 5126221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemBlocked(DynInstPtr &inst, ThreadID tid) 5132292SN/A{ 5142292SN/A DPRINTF(IEW, "[tid:%i]: Memory blocked, squashing load and younger insts, " 5157720Sgblack@eecs.umich.edu "PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum); 5167852SMatt.Horsnell@arm.com if (toCommit->squash[tid] == false || 5177852SMatt.Horsnell@arm.com inst->seqNum < toCommit->squashedSeqNum[tid]) { 5187852SMatt.Horsnell@arm.com toCommit->squash[tid] = true; 5192292SN/A 5207852SMatt.Horsnell@arm.com toCommit->squashedSeqNum[tid] = inst->seqNum; 5217852SMatt.Horsnell@arm.com toCommit->pc[tid] = inst->pcState(); 5228137SAli.Saidi@ARM.com toCommit->mispredictInst[tid] = NULL; 5232292SN/A 5247852SMatt.Horsnell@arm.com // Must include the broadcasted SN in the squash. 5257852SMatt.Horsnell@arm.com toCommit->includeSquashInst[tid] = true; 5262292SN/A 5277852SMatt.Horsnell@arm.com ldstQueue.setLoadBlockedHandled(tid); 5282292SN/A 5297852SMatt.Horsnell@arm.com wroteToTimeBuffer = true; 5307852SMatt.Horsnell@arm.com } 5312292SN/A} 5322292SN/A 5332292SN/Atemplate<class Impl> 5342292SN/Avoid 5356221Snate@binkert.orgDefaultIEW<Impl>::block(ThreadID tid) 5362292SN/A{ 5372292SN/A DPRINTF(IEW, "[tid:%u]: Blocking.\n", tid); 5382292SN/A 5392292SN/A if (dispatchStatus[tid] != Blocked && 5402292SN/A dispatchStatus[tid] != Unblocking) { 5412292SN/A toRename->iewBlock[tid] = true; 5422292SN/A wroteToTimeBuffer = true; 5432292SN/A } 5442292SN/A 5452292SN/A // Add the current inputs to the skid buffer so they can be 5462292SN/A // reprocessed when this stage unblocks. 5472292SN/A skidInsert(tid); 5482292SN/A 5492292SN/A dispatchStatus[tid] = Blocked; 5502292SN/A} 5512292SN/A 5522292SN/Atemplate<class Impl> 5532292SN/Avoid 5546221Snate@binkert.orgDefaultIEW<Impl>::unblock(ThreadID tid) 5552292SN/A{ 5562292SN/A DPRINTF(IEW, "[tid:%i]: Reading instructions out of the skid " 5572292SN/A "buffer %u.\n",tid, tid); 5582292SN/A 5592292SN/A // If the skid bufffer is empty, signal back to previous stages to unblock. 5602292SN/A // Also switch status to running. 5612292SN/A if (skidBuffer[tid].empty()) { 5622292SN/A toRename->iewUnblock[tid] = true; 5632292SN/A wroteToTimeBuffer = true; 5642292SN/A DPRINTF(IEW, "[tid:%i]: Done unblocking.\n",tid); 5652292SN/A dispatchStatus[tid] = Running; 5662292SN/A } 5672292SN/A} 5682292SN/A 5692292SN/Atemplate<class Impl> 5702292SN/Avoid 5712292SN/ADefaultIEW<Impl>::wakeDependents(DynInstPtr &inst) 5721060SN/A{ 5731681SN/A instQueue.wakeDependents(inst); 5741060SN/A} 5751060SN/A 5762292SN/Atemplate<class Impl> 5772292SN/Avoid 5782292SN/ADefaultIEW<Impl>::rescheduleMemInst(DynInstPtr &inst) 5792292SN/A{ 5802292SN/A instQueue.rescheduleMemInst(inst); 5812292SN/A} 5821681SN/A 5831681SN/Atemplate<class Impl> 5841060SN/Avoid 5852292SN/ADefaultIEW<Impl>::replayMemInst(DynInstPtr &inst) 5861060SN/A{ 5872292SN/A instQueue.replayMemInst(inst); 5882292SN/A} 5891060SN/A 5902292SN/Atemplate<class Impl> 5912292SN/Avoid 5922292SN/ADefaultIEW<Impl>::instToCommit(DynInstPtr &inst) 5932292SN/A{ 5943221Sktlim@umich.edu // This function should not be called after writebackInsts in a 5953221Sktlim@umich.edu // single cycle. That will cause problems with an instruction 5963221Sktlim@umich.edu // being added to the queue to commit without being processed by 5973221Sktlim@umich.edu // writebackInsts prior to being sent to commit. 5983221Sktlim@umich.edu 5992292SN/A // First check the time slot that this instruction will write 6002292SN/A // to. If there are free write ports at the time, then go ahead 6012292SN/A // and write the instruction to that time. If there are not, 6022292SN/A // keep looking back to see where's the first time there's a 6032326SN/A // free slot. 6042292SN/A while ((*iewQueue)[wbCycle].insts[wbNumInst]) { 6052292SN/A ++wbNumInst; 6062820Sktlim@umich.edu if (wbNumInst == wbWidth) { 6072292SN/A ++wbCycle; 6082292SN/A wbNumInst = 0; 6092292SN/A } 6102292SN/A 6112353SN/A assert((wbCycle * wbWidth + wbNumInst) <= wbMax); 6122292SN/A } 6132292SN/A 6142353SN/A DPRINTF(IEW, "Current wb cycle: %i, width: %i, numInst: %i\nwbActual:%i\n", 6152353SN/A wbCycle, wbWidth, wbNumInst, wbCycle * wbWidth + wbNumInst); 6162292SN/A // Add finished instruction to queue to commit. 6172292SN/A (*iewQueue)[wbCycle].insts[wbNumInst] = inst; 6182292SN/A (*iewQueue)[wbCycle].size++; 6192292SN/A} 6202292SN/A 6212292SN/Atemplate <class Impl> 6222292SN/Aunsigned 6232292SN/ADefaultIEW<Impl>::validInstsFromRename() 6242292SN/A{ 6252292SN/A unsigned inst_count = 0; 6262292SN/A 6272292SN/A for (int i=0; i<fromRename->size; i++) { 6282731Sktlim@umich.edu if (!fromRename->insts[i]->isSquashed()) 6292292SN/A inst_count++; 6302292SN/A } 6312292SN/A 6322292SN/A return inst_count; 6332292SN/A} 6342292SN/A 6352292SN/Atemplate<class Impl> 6362292SN/Avoid 6376221Snate@binkert.orgDefaultIEW<Impl>::skidInsert(ThreadID tid) 6382292SN/A{ 6392292SN/A DynInstPtr inst = NULL; 6402292SN/A 6412292SN/A while (!insts[tid].empty()) { 6422292SN/A inst = insts[tid].front(); 6432292SN/A 6442292SN/A insts[tid].pop(); 6452292SN/A 6467720Sgblack@eecs.umich.edu DPRINTF(Decode,"[tid:%i]: Inserting [sn:%lli] PC:%s into " 6472292SN/A "dispatch skidBuffer %i\n",tid, inst->seqNum, 6487720Sgblack@eecs.umich.edu inst->pcState(),tid); 6492292SN/A 6502292SN/A skidBuffer[tid].push(inst); 6512292SN/A } 6522292SN/A 6532292SN/A assert(skidBuffer[tid].size() <= skidBufferMax && 6542292SN/A "Skidbuffer Exceeded Max Size"); 6552292SN/A} 6562292SN/A 6572292SN/Atemplate<class Impl> 6582292SN/Aint 6592292SN/ADefaultIEW<Impl>::skidCount() 6602292SN/A{ 6612292SN/A int max=0; 6622292SN/A 6636221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 6646221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 6652292SN/A 6663867Sbinkertn@umich.edu while (threads != end) { 6676221Snate@binkert.org ThreadID tid = *threads++; 6683867Sbinkertn@umich.edu unsigned thread_count = skidBuffer[tid].size(); 6692292SN/A if (max < thread_count) 6702292SN/A max = thread_count; 6712292SN/A } 6722292SN/A 6732292SN/A return max; 6742292SN/A} 6752292SN/A 6762292SN/Atemplate<class Impl> 6772292SN/Abool 6782292SN/ADefaultIEW<Impl>::skidsEmpty() 6792292SN/A{ 6806221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 6816221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 6822292SN/A 6833867Sbinkertn@umich.edu while (threads != end) { 6846221Snate@binkert.org ThreadID tid = *threads++; 6853867Sbinkertn@umich.edu 6863867Sbinkertn@umich.edu if (!skidBuffer[tid].empty()) 6872292SN/A return false; 6882292SN/A } 6892292SN/A 6902292SN/A return true; 6911062SN/A} 6921062SN/A 6931681SN/Atemplate <class Impl> 6941062SN/Avoid 6952292SN/ADefaultIEW<Impl>::updateStatus() 6961062SN/A{ 6972292SN/A bool any_unblocking = false; 6981062SN/A 6996221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 7006221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 7011062SN/A 7023867Sbinkertn@umich.edu while (threads != end) { 7036221Snate@binkert.org ThreadID tid = *threads++; 7041062SN/A 7052292SN/A if (dispatchStatus[tid] == Unblocking) { 7062292SN/A any_unblocking = true; 7072292SN/A break; 7082292SN/A } 7092292SN/A } 7101062SN/A 7112292SN/A // If there are no ready instructions waiting to be scheduled by the IQ, 7122292SN/A // and there's no stores waiting to write back, and dispatch is not 7132292SN/A // unblocking, then there is no internal activity for the IEW stage. 7147897Shestness@cs.utexas.edu instQueue.intInstQueueReads++; 7152292SN/A if (_status == Active && !instQueue.hasReadyInsts() && 7162292SN/A !ldstQueue.willWB() && !any_unblocking) { 7172292SN/A DPRINTF(IEW, "IEW switching to idle\n"); 7181062SN/A 7192292SN/A deactivateStage(); 7201062SN/A 7212292SN/A _status = Inactive; 7222292SN/A } else if (_status == Inactive && (instQueue.hasReadyInsts() || 7232292SN/A ldstQueue.willWB() || 7242292SN/A any_unblocking)) { 7252292SN/A // Otherwise there is internal activity. Set to active. 7262292SN/A DPRINTF(IEW, "IEW switching to active\n"); 7271062SN/A 7282292SN/A activateStage(); 7291062SN/A 7302292SN/A _status = Active; 7311062SN/A } 7321062SN/A} 7331062SN/A 7341681SN/Atemplate <class Impl> 7351062SN/Avoid 7362292SN/ADefaultIEW<Impl>::resetEntries() 7371062SN/A{ 7382292SN/A instQueue.resetEntries(); 7392292SN/A ldstQueue.resetEntries(); 7402292SN/A} 7411062SN/A 7422292SN/Atemplate <class Impl> 7432292SN/Avoid 7446221Snate@binkert.orgDefaultIEW<Impl>::readStallSignals(ThreadID tid) 7452292SN/A{ 7462292SN/A if (fromCommit->commitBlock[tid]) { 7472292SN/A stalls[tid].commit = true; 7482292SN/A } 7491062SN/A 7502292SN/A if (fromCommit->commitUnblock[tid]) { 7512292SN/A assert(stalls[tid].commit); 7522292SN/A stalls[tid].commit = false; 7532292SN/A } 7542292SN/A} 7552292SN/A 7562292SN/Atemplate <class Impl> 7572292SN/Abool 7586221Snate@binkert.orgDefaultIEW<Impl>::checkStall(ThreadID tid) 7592292SN/A{ 7602292SN/A bool ret_val(false); 7612292SN/A 7622292SN/A if (stalls[tid].commit) { 7632292SN/A DPRINTF(IEW,"[tid:%i]: Stall from Commit stage detected.\n",tid); 7642292SN/A ret_val = true; 7652292SN/A } else if (instQueue.isFull(tid)) { 7662292SN/A DPRINTF(IEW,"[tid:%i]: Stall: IQ is full.\n",tid); 7672292SN/A ret_val = true; 7682292SN/A } else if (ldstQueue.isFull(tid)) { 7692292SN/A DPRINTF(IEW,"[tid:%i]: Stall: LSQ is full\n",tid); 7702292SN/A 7712292SN/A if (ldstQueue.numLoads(tid) > 0 ) { 7722292SN/A 7732292SN/A DPRINTF(IEW,"[tid:%i]: LSQ oldest load: [sn:%i] \n", 7742292SN/A tid,ldstQueue.getLoadHeadSeqNum(tid)); 7752292SN/A } 7762292SN/A 7772292SN/A if (ldstQueue.numStores(tid) > 0) { 7782292SN/A 7792292SN/A DPRINTF(IEW,"[tid:%i]: LSQ oldest store: [sn:%i] \n", 7802292SN/A tid,ldstQueue.getStoreHeadSeqNum(tid)); 7812292SN/A } 7822292SN/A 7832292SN/A ret_val = true; 7842292SN/A } else if (ldstQueue.isStalled(tid)) { 7852292SN/A DPRINTF(IEW,"[tid:%i]: Stall: LSQ stall detected.\n",tid); 7862292SN/A ret_val = true; 7872292SN/A } 7882292SN/A 7892292SN/A return ret_val; 7902292SN/A} 7912292SN/A 7922292SN/Atemplate <class Impl> 7932292SN/Avoid 7946221Snate@binkert.orgDefaultIEW<Impl>::checkSignalsAndUpdate(ThreadID tid) 7952292SN/A{ 7962292SN/A // Check if there's a squash signal, squash if there is 7972292SN/A // Check stall signals, block if there is. 7982292SN/A // If status was Blocked 7992292SN/A // if so then go to unblocking 8002292SN/A // If status was Squashing 8012292SN/A // check if squashing is not high. Switch to running this cycle. 8022292SN/A 8032292SN/A readStallSignals(tid); 8042292SN/A 8052292SN/A if (fromCommit->commitInfo[tid].squash) { 8062292SN/A squash(tid); 8072292SN/A 8082292SN/A if (dispatchStatus[tid] == Blocked || 8092292SN/A dispatchStatus[tid] == Unblocking) { 8102292SN/A toRename->iewUnblock[tid] = true; 8112292SN/A wroteToTimeBuffer = true; 8122292SN/A } 8132292SN/A 8142292SN/A dispatchStatus[tid] = Squashing; 8152292SN/A fetchRedirect[tid] = false; 8162292SN/A return; 8172292SN/A } 8182292SN/A 8192292SN/A if (fromCommit->commitInfo[tid].robSquashing) { 8202702Sktlim@umich.edu DPRINTF(IEW, "[tid:%i]: ROB is still squashing.\n", tid); 8212292SN/A 8222292SN/A dispatchStatus[tid] = Squashing; 8232702Sktlim@umich.edu emptyRenameInsts(tid); 8242702Sktlim@umich.edu wroteToTimeBuffer = true; 8252292SN/A return; 8262292SN/A } 8272292SN/A 8282292SN/A if (checkStall(tid)) { 8292292SN/A block(tid); 8302292SN/A dispatchStatus[tid] = Blocked; 8312292SN/A return; 8322292SN/A } 8332292SN/A 8342292SN/A if (dispatchStatus[tid] == Blocked) { 8352292SN/A // Status from previous cycle was blocked, but there are no more stall 8362292SN/A // conditions. Switch over to unblocking. 8372292SN/A DPRINTF(IEW, "[tid:%i]: Done blocking, switching to unblocking.\n", 8382292SN/A tid); 8392292SN/A 8402292SN/A dispatchStatus[tid] = Unblocking; 8412292SN/A 8422292SN/A unblock(tid); 8432292SN/A 8442292SN/A return; 8452292SN/A } 8462292SN/A 8472292SN/A if (dispatchStatus[tid] == Squashing) { 8482292SN/A // Switch status to running if rename isn't being told to block or 8492292SN/A // squash this cycle. 8502292SN/A DPRINTF(IEW, "[tid:%i]: Done squashing, switching to running.\n", 8512292SN/A tid); 8522292SN/A 8532292SN/A dispatchStatus[tid] = Running; 8542292SN/A 8552292SN/A return; 8562292SN/A } 8572292SN/A} 8582292SN/A 8592292SN/Atemplate <class Impl> 8602292SN/Avoid 8612292SN/ADefaultIEW<Impl>::sortInsts() 8622292SN/A{ 8632292SN/A int insts_from_rename = fromRename->size; 8642326SN/A#ifdef DEBUG 8656221Snate@binkert.org for (ThreadID tid = 0; tid < numThreads; tid++) 8666221Snate@binkert.org assert(insts[tid].empty()); 8672326SN/A#endif 8682292SN/A for (int i = 0; i < insts_from_rename; ++i) { 8692292SN/A insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]); 8702292SN/A } 8712292SN/A} 8722292SN/A 8732292SN/Atemplate <class Impl> 8742292SN/Avoid 8756221Snate@binkert.orgDefaultIEW<Impl>::emptyRenameInsts(ThreadID tid) 8762702Sktlim@umich.edu{ 8774632Sgblack@eecs.umich.edu DPRINTF(IEW, "[tid:%i]: Removing incoming rename instructions\n", tid); 8782935Sksewell@umich.edu 8792702Sktlim@umich.edu while (!insts[tid].empty()) { 8802935Sksewell@umich.edu 8812702Sktlim@umich.edu if (insts[tid].front()->isLoad() || 8822702Sktlim@umich.edu insts[tid].front()->isStore() ) { 8832702Sktlim@umich.edu toRename->iewInfo[tid].dispatchedToLSQ++; 8842702Sktlim@umich.edu } 8852702Sktlim@umich.edu 8862702Sktlim@umich.edu toRename->iewInfo[tid].dispatched++; 8872702Sktlim@umich.edu 8882702Sktlim@umich.edu insts[tid].pop(); 8892702Sktlim@umich.edu } 8902702Sktlim@umich.edu} 8912702Sktlim@umich.edu 8922702Sktlim@umich.edutemplate <class Impl> 8932702Sktlim@umich.eduvoid 8942292SN/ADefaultIEW<Impl>::wakeCPU() 8952292SN/A{ 8962292SN/A cpu->wakeCPU(); 8972292SN/A} 8982292SN/A 8992292SN/Atemplate <class Impl> 9002292SN/Avoid 9012292SN/ADefaultIEW<Impl>::activityThisCycle() 9022292SN/A{ 9032292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 9042292SN/A cpu->activityThisCycle(); 9052292SN/A} 9062292SN/A 9072292SN/Atemplate <class Impl> 9082292SN/Ainline void 9092292SN/ADefaultIEW<Impl>::activateStage() 9102292SN/A{ 9112292SN/A DPRINTF(Activity, "Activating stage.\n"); 9122733Sktlim@umich.edu cpu->activateStage(O3CPU::IEWIdx); 9132292SN/A} 9142292SN/A 9152292SN/Atemplate <class Impl> 9162292SN/Ainline void 9172292SN/ADefaultIEW<Impl>::deactivateStage() 9182292SN/A{ 9192292SN/A DPRINTF(Activity, "Deactivating stage.\n"); 9202733Sktlim@umich.edu cpu->deactivateStage(O3CPU::IEWIdx); 9212292SN/A} 9222292SN/A 9232292SN/Atemplate<class Impl> 9242292SN/Avoid 9256221Snate@binkert.orgDefaultIEW<Impl>::dispatch(ThreadID tid) 9262292SN/A{ 9272292SN/A // If status is Running or idle, 9282292SN/A // call dispatchInsts() 9292292SN/A // If status is Unblocking, 9302292SN/A // buffer any instructions coming from rename 9312292SN/A // continue trying to empty skid buffer 9322292SN/A // check if stall conditions have passed 9332292SN/A 9342292SN/A if (dispatchStatus[tid] == Blocked) { 9352292SN/A ++iewBlockCycles; 9362292SN/A 9372292SN/A } else if (dispatchStatus[tid] == Squashing) { 9382292SN/A ++iewSquashCycles; 9392292SN/A } 9402292SN/A 9412292SN/A // Dispatch should try to dispatch as many instructions as its bandwidth 9422292SN/A // will allow, as long as it is not currently blocked. 9432292SN/A if (dispatchStatus[tid] == Running || 9442292SN/A dispatchStatus[tid] == Idle) { 9452292SN/A DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run " 9462292SN/A "dispatch.\n", tid); 9472292SN/A 9482292SN/A dispatchInsts(tid); 9492292SN/A } else if (dispatchStatus[tid] == Unblocking) { 9502292SN/A // Make sure that the skid buffer has something in it if the 9512292SN/A // status is unblocking. 9522292SN/A assert(!skidsEmpty()); 9532292SN/A 9542292SN/A // If the status was unblocking, then instructions from the skid 9552292SN/A // buffer were used. Remove those instructions and handle 9562292SN/A // the rest of unblocking. 9572292SN/A dispatchInsts(tid); 9582292SN/A 9592292SN/A ++iewUnblockCycles; 9602292SN/A 9615215Sgblack@eecs.umich.edu if (validInstsFromRename()) { 9622292SN/A // Add the current inputs to the skid buffer so they can be 9632292SN/A // reprocessed when this stage unblocks. 9642292SN/A skidInsert(tid); 9652292SN/A } 9662292SN/A 9672292SN/A unblock(tid); 9682292SN/A } 9692292SN/A} 9702292SN/A 9712292SN/Atemplate <class Impl> 9722292SN/Avoid 9736221Snate@binkert.orgDefaultIEW<Impl>::dispatchInsts(ThreadID tid) 9742292SN/A{ 9752292SN/A // Obtain instructions from skid buffer if unblocking, or queue from rename 9762292SN/A // otherwise. 9772292SN/A std::queue<DynInstPtr> &insts_to_dispatch = 9782292SN/A dispatchStatus[tid] == Unblocking ? 9792292SN/A skidBuffer[tid] : insts[tid]; 9802292SN/A 9812292SN/A int insts_to_add = insts_to_dispatch.size(); 9822292SN/A 9832292SN/A DynInstPtr inst; 9842292SN/A bool add_to_iq = false; 9852292SN/A int dis_num_inst = 0; 9862292SN/A 9872292SN/A // Loop through the instructions, putting them in the instruction 9882292SN/A // queue. 9892292SN/A for ( ; dis_num_inst < insts_to_add && 9902820Sktlim@umich.edu dis_num_inst < dispatchWidth; 9912292SN/A ++dis_num_inst) 9922292SN/A { 9932292SN/A inst = insts_to_dispatch.front(); 9942292SN/A 9952292SN/A if (dispatchStatus[tid] == Unblocking) { 9962292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Examining instruction from skid " 9972292SN/A "buffer\n", tid); 9982292SN/A } 9992292SN/A 10002292SN/A // Make sure there's a valid instruction there. 10012292SN/A assert(inst); 10022292SN/A 10037720Sgblack@eecs.umich.edu DPRINTF(IEW, "[tid:%i]: Issue: Adding PC %s [sn:%lli] [tid:%i] to " 10042292SN/A "IQ.\n", 10057720Sgblack@eecs.umich.edu tid, inst->pcState(), inst->seqNum, inst->threadNumber); 10062292SN/A 10072292SN/A // Be sure to mark these instructions as ready so that the 10082292SN/A // commit stage can go ahead and execute them, and mark 10092292SN/A // them as issued so the IQ doesn't reprocess them. 10102292SN/A 10112292SN/A // Check for squashed instructions. 10122292SN/A if (inst->isSquashed()) { 10132292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Squashed instruction encountered, " 10142292SN/A "not adding to IQ.\n", tid); 10152292SN/A 10162292SN/A ++iewDispSquashedInsts; 10172292SN/A 10182292SN/A insts_to_dispatch.pop(); 10192292SN/A 10202292SN/A //Tell Rename That An Instruction has been processed 10212292SN/A if (inst->isLoad() || inst->isStore()) { 10222292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 10232292SN/A } 10242292SN/A toRename->iewInfo[tid].dispatched++; 10252292SN/A 10262292SN/A continue; 10272292SN/A } 10282292SN/A 10292292SN/A // Check for full conditions. 10302292SN/A if (instQueue.isFull(tid)) { 10312292SN/A DPRINTF(IEW, "[tid:%i]: Issue: IQ has become full.\n", tid); 10322292SN/A 10332292SN/A // Call function to start blocking. 10342292SN/A block(tid); 10352292SN/A 10362292SN/A // Set unblock to false. Special case where we are using 10372292SN/A // skidbuffer (unblocking) instructions but then we still 10382292SN/A // get full in the IQ. 10392292SN/A toRename->iewUnblock[tid] = false; 10402292SN/A 10412292SN/A ++iewIQFullEvents; 10422292SN/A break; 10432292SN/A } else if (ldstQueue.isFull(tid)) { 10442292SN/A DPRINTF(IEW, "[tid:%i]: Issue: LSQ has become full.\n",tid); 10452292SN/A 10462292SN/A // Call function to start blocking. 10472292SN/A block(tid); 10482292SN/A 10492292SN/A // Set unblock to false. Special case where we are using 10502292SN/A // skidbuffer (unblocking) instructions but then we still 10512292SN/A // get full in the IQ. 10522292SN/A toRename->iewUnblock[tid] = false; 10532292SN/A 10542292SN/A ++iewLSQFullEvents; 10552292SN/A break; 10562292SN/A } 10572292SN/A 10582292SN/A // Otherwise issue the instruction just fine. 10592292SN/A if (inst->isLoad()) { 10602292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10612292SN/A "encountered, adding to LSQ.\n", tid); 10622292SN/A 10632292SN/A // Reserve a spot in the load store queue for this 10642292SN/A // memory access. 10652292SN/A ldstQueue.insertLoad(inst); 10662292SN/A 10672292SN/A ++iewDispLoadInsts; 10682292SN/A 10692292SN/A add_to_iq = true; 10702292SN/A 10712292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 10722292SN/A } else if (inst->isStore()) { 10732292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction " 10742292SN/A "encountered, adding to LSQ.\n", tid); 10752292SN/A 10762292SN/A ldstQueue.insertStore(inst); 10772292SN/A 10782292SN/A ++iewDispStoreInsts; 10792292SN/A 10802336SN/A if (inst->isStoreConditional()) { 10812336SN/A // Store conditionals need to be set as "canCommit()" 10822336SN/A // so that commit can process them when they reach the 10832336SN/A // head of commit. 10842348SN/A // @todo: This is somewhat specific to Alpha. 10852292SN/A inst->setCanCommit(); 10862292SN/A instQueue.insertNonSpec(inst); 10872292SN/A add_to_iq = false; 10882292SN/A 10892292SN/A ++iewDispNonSpecInsts; 10902292SN/A } else { 10912292SN/A add_to_iq = true; 10922292SN/A } 10932292SN/A 10942292SN/A toRename->iewInfo[tid].dispatchedToLSQ++; 10952292SN/A } else if (inst->isMemBarrier() || inst->isWriteBarrier()) { 10962326SN/A // Same as non-speculative stores. 10972292SN/A inst->setCanCommit(); 10982292SN/A instQueue.insertBarrier(inst); 10992292SN/A add_to_iq = false; 11002292SN/A } else if (inst->isNop()) { 11012292SN/A DPRINTF(IEW, "[tid:%i]: Issue: Nop instruction encountered, " 11022292SN/A "skipping.\n", tid); 11032292SN/A 11042292SN/A inst->setIssued(); 11052292SN/A inst->setExecuted(); 11062292SN/A inst->setCanCommit(); 11072292SN/A 11082326SN/A instQueue.recordProducer(inst); 11092292SN/A 11102727Sktlim@umich.edu iewExecutedNop[tid]++; 11112301SN/A 11122292SN/A add_to_iq = false; 11132292SN/A } else if (inst->isExecuted()) { 11142292SN/A assert(0 && "Instruction shouldn't be executed.\n"); 11152292SN/A DPRINTF(IEW, "Issue: Executed branch encountered, " 11162292SN/A "skipping.\n"); 11172292SN/A 11182292SN/A inst->setIssued(); 11192292SN/A inst->setCanCommit(); 11202292SN/A 11212326SN/A instQueue.recordProducer(inst); 11222292SN/A 11232292SN/A add_to_iq = false; 11242292SN/A } else { 11252292SN/A add_to_iq = true; 11262292SN/A } 11274033Sktlim@umich.edu if (inst->isNonSpeculative()) { 11284033Sktlim@umich.edu DPRINTF(IEW, "[tid:%i]: Issue: Nonspeculative instruction " 11294033Sktlim@umich.edu "encountered, skipping.\n", tid); 11304033Sktlim@umich.edu 11314033Sktlim@umich.edu // Same as non-speculative stores. 11324033Sktlim@umich.edu inst->setCanCommit(); 11334033Sktlim@umich.edu 11344033Sktlim@umich.edu // Specifically insert it as nonspeculative. 11354033Sktlim@umich.edu instQueue.insertNonSpec(inst); 11364033Sktlim@umich.edu 11374033Sktlim@umich.edu ++iewDispNonSpecInsts; 11384033Sktlim@umich.edu 11394033Sktlim@umich.edu add_to_iq = false; 11404033Sktlim@umich.edu } 11412292SN/A 11422292SN/A // If the instruction queue is not full, then add the 11432292SN/A // instruction. 11442292SN/A if (add_to_iq) { 11452292SN/A instQueue.insert(inst); 11462292SN/A } 11472292SN/A 11482292SN/A insts_to_dispatch.pop(); 11492292SN/A 11502292SN/A toRename->iewInfo[tid].dispatched++; 11512292SN/A 11522292SN/A ++iewDispatchedInsts; 11538471SGiacomo.Gabrielli@arm.com 11548471SGiacomo.Gabrielli@arm.com#if TRACING_ON 11559046SAli.Saidi@ARM.com inst->dispatchTick = curTick() - inst->fetchTick; 11568471SGiacomo.Gabrielli@arm.com#endif 11572292SN/A } 11582292SN/A 11592292SN/A if (!insts_to_dispatch.empty()) { 11602935Sksewell@umich.edu DPRINTF(IEW,"[tid:%i]: Issue: Bandwidth Full. Blocking.\n", tid); 11612292SN/A block(tid); 11622292SN/A toRename->iewUnblock[tid] = false; 11632292SN/A } 11642292SN/A 11652292SN/A if (dispatchStatus[tid] == Idle && dis_num_inst) { 11662292SN/A dispatchStatus[tid] = Running; 11672292SN/A 11682292SN/A updatedQueues = true; 11692292SN/A } 11702292SN/A 11712292SN/A dis_num_inst = 0; 11722292SN/A} 11732292SN/A 11742292SN/Atemplate <class Impl> 11752292SN/Avoid 11762292SN/ADefaultIEW<Impl>::printAvailableInsts() 11772292SN/A{ 11782292SN/A int inst = 0; 11792292SN/A 11802980Sgblack@eecs.umich.edu std::cout << "Available Instructions: "; 11812292SN/A 11822292SN/A while (fromIssue->insts[inst]) { 11832292SN/A 11842980Sgblack@eecs.umich.edu if (inst%3==0) std::cout << "\n\t"; 11852292SN/A 11867720Sgblack@eecs.umich.edu std::cout << "PC: " << fromIssue->insts[inst]->pcState() 11872292SN/A << " TN: " << fromIssue->insts[inst]->threadNumber 11882292SN/A << " SN: " << fromIssue->insts[inst]->seqNum << " | "; 11892292SN/A 11902292SN/A inst++; 11912292SN/A 11922292SN/A } 11932292SN/A 11942980Sgblack@eecs.umich.edu std::cout << "\n"; 11952292SN/A} 11962292SN/A 11972292SN/Atemplate <class Impl> 11982292SN/Avoid 11992292SN/ADefaultIEW<Impl>::executeInsts() 12002292SN/A{ 12012292SN/A wbNumInst = 0; 12022292SN/A wbCycle = 0; 12032292SN/A 12046221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 12056221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 12062292SN/A 12073867Sbinkertn@umich.edu while (threads != end) { 12086221Snate@binkert.org ThreadID tid = *threads++; 12092292SN/A fetchRedirect[tid] = false; 12102292SN/A } 12112292SN/A 12122698Sktlim@umich.edu // Uncomment this if you want to see all available instructions. 12137599Sminkyu.jeong@arm.com // @todo This doesn't actually work anymore, we should fix it. 12142698Sktlim@umich.edu// printAvailableInsts(); 12151062SN/A 12161062SN/A // Execute/writeback any instructions that are available. 12172333SN/A int insts_to_execute = fromIssue->size; 12182292SN/A int inst_num = 0; 12192333SN/A for (; inst_num < insts_to_execute; 12202326SN/A ++inst_num) { 12211062SN/A 12222292SN/A DPRINTF(IEW, "Execute: Executing instructions from IQ.\n"); 12231062SN/A 12242333SN/A DynInstPtr inst = instQueue.getInstToExecute(); 12251062SN/A 12267720Sgblack@eecs.umich.edu DPRINTF(IEW, "Execute: Processing PC %s, [tid:%i] [sn:%i].\n", 12277720Sgblack@eecs.umich.edu inst->pcState(), inst->threadNumber,inst->seqNum); 12281062SN/A 12291062SN/A // Check if the instruction is squashed; if so then skip it 12301062SN/A if (inst->isSquashed()) { 12318315Sgeoffrey.blake@arm.com DPRINTF(IEW, "Execute: Instruction was squashed. PC: %s, [tid:%i]" 12328315Sgeoffrey.blake@arm.com " [sn:%i]\n", inst->pcState(), inst->threadNumber, 12338315Sgeoffrey.blake@arm.com inst->seqNum); 12341062SN/A 12351062SN/A // Consider this instruction executed so that commit can go 12361062SN/A // ahead and retire the instruction. 12371062SN/A inst->setExecuted(); 12381062SN/A 12392292SN/A // Not sure if I should set this here or just let commit try to 12402292SN/A // commit any squashed instructions. I like the latter a bit more. 12412292SN/A inst->setCanCommit(); 12421062SN/A 12431062SN/A ++iewExecSquashedInsts; 12441062SN/A 12452820Sktlim@umich.edu decrWb(inst->seqNum); 12461062SN/A continue; 12471062SN/A } 12481062SN/A 12492292SN/A Fault fault = NoFault; 12501062SN/A 12511062SN/A // Execute instruction. 12521062SN/A // Note that if the instruction faults, it will be handled 12531062SN/A // at the commit stage. 12547850SMatt.Horsnell@arm.com if (inst->isMemRef()) { 12552292SN/A DPRINTF(IEW, "Execute: Calculating address for memory " 12561062SN/A "reference.\n"); 12571062SN/A 12581062SN/A // Tell the LDSTQ to execute this instruction (if it is a load). 12591062SN/A if (inst->isLoad()) { 12602292SN/A // Loads will mark themselves as executed, and their writeback 12612292SN/A // event adds the instruction to the queue to commit 12622292SN/A fault = ldstQueue.executeLoad(inst); 12637944SGiacomo.Gabrielli@arm.com 12647944SGiacomo.Gabrielli@arm.com if (inst->isTranslationDelayed() && 12657944SGiacomo.Gabrielli@arm.com fault == NoFault) { 12667944SGiacomo.Gabrielli@arm.com // A hw page table walk is currently going on; the 12677944SGiacomo.Gabrielli@arm.com // instruction must be deferred. 12687944SGiacomo.Gabrielli@arm.com DPRINTF(IEW, "Execute: Delayed translation, deferring " 12697944SGiacomo.Gabrielli@arm.com "load.\n"); 12707944SGiacomo.Gabrielli@arm.com instQueue.deferMemInst(inst); 12717944SGiacomo.Gabrielli@arm.com continue; 12727944SGiacomo.Gabrielli@arm.com } 12737944SGiacomo.Gabrielli@arm.com 12747850SMatt.Horsnell@arm.com if (inst->isDataPrefetch() || inst->isInstPrefetch()) { 12758073SAli.Saidi@ARM.com inst->fault = NoFault; 12767850SMatt.Horsnell@arm.com } 12771062SN/A } else if (inst->isStore()) { 12782367SN/A fault = ldstQueue.executeStore(inst); 12791062SN/A 12807944SGiacomo.Gabrielli@arm.com if (inst->isTranslationDelayed() && 12817944SGiacomo.Gabrielli@arm.com fault == NoFault) { 12827944SGiacomo.Gabrielli@arm.com // A hw page table walk is currently going on; the 12837944SGiacomo.Gabrielli@arm.com // instruction must be deferred. 12847944SGiacomo.Gabrielli@arm.com DPRINTF(IEW, "Execute: Delayed translation, deferring " 12857944SGiacomo.Gabrielli@arm.com "store.\n"); 12867944SGiacomo.Gabrielli@arm.com instQueue.deferMemInst(inst); 12877944SGiacomo.Gabrielli@arm.com continue; 12887944SGiacomo.Gabrielli@arm.com } 12897944SGiacomo.Gabrielli@arm.com 12902292SN/A // If the store had a fault then it may not have a mem req 12917782Sminkyu.jeong@arm.com if (fault != NoFault || inst->readPredicate() == false || 12927782Sminkyu.jeong@arm.com !inst->isStoreConditional()) { 12937782Sminkyu.jeong@arm.com // If the instruction faulted, then we need to send it along 12947782Sminkyu.jeong@arm.com // to commit without the instruction completing. 12952367SN/A // Send this instruction to commit, also make sure iew stage 12962367SN/A // realizes there is activity. 12972367SN/A inst->setExecuted(); 12982367SN/A instToCommit(inst); 12992367SN/A activityThisCycle(); 13002292SN/A } 13012326SN/A 13022326SN/A // Store conditionals will mark themselves as 13032326SN/A // executed, and their writeback event will add the 13042326SN/A // instruction to the queue to commit. 13051062SN/A } else { 13062292SN/A panic("Unexpected memory type!\n"); 13071062SN/A } 13081062SN/A 13091062SN/A } else { 13107847Sminkyu.jeong@arm.com // If the instruction has already faulted, then skip executing it. 13117847Sminkyu.jeong@arm.com // Such case can happen when it faulted during ITLB translation. 13127847Sminkyu.jeong@arm.com // If we execute the instruction (even if it's a nop) the fault 13137847Sminkyu.jeong@arm.com // will be replaced and we will lose it. 13147847Sminkyu.jeong@arm.com if (inst->getFault() == NoFault) { 13157847Sminkyu.jeong@arm.com inst->execute(); 13167848SAli.Saidi@ARM.com if (inst->readPredicate() == false) 13177848SAli.Saidi@ARM.com inst->forwardOldRegs(); 13187847Sminkyu.jeong@arm.com } 13191062SN/A 13202292SN/A inst->setExecuted(); 13212292SN/A 13222292SN/A instToCommit(inst); 13231062SN/A } 13241062SN/A 13252301SN/A updateExeInstStats(inst); 13261681SN/A 13272326SN/A // Check if branch prediction was correct, if not then we need 13282326SN/A // to tell commit to squash in flight instructions. Only 13292326SN/A // handle this if there hasn't already been something that 13302107SN/A // redirects fetch in this group of instructions. 13311681SN/A 13322292SN/A // This probably needs to prioritize the redirects if a different 13332292SN/A // scheduler is used. Currently the scheduler schedules the oldest 13342292SN/A // instruction first, so the branch resolution order will be correct. 13356221Snate@binkert.org ThreadID tid = inst->threadNumber; 13361062SN/A 13373732Sktlim@umich.edu if (!fetchRedirect[tid] || 13387852SMatt.Horsnell@arm.com !toCommit->squash[tid] || 13393732Sktlim@umich.edu toCommit->squashedSeqNum[tid] > inst->seqNum) { 13401062SN/A 13417856SMatt.Horsnell@arm.com // Prevent testing for misprediction on load instructions, 13427856SMatt.Horsnell@arm.com // that have not been executed. 13437856SMatt.Horsnell@arm.com bool loadNotExecuted = !inst->isExecuted() && inst->isLoad(); 13447856SMatt.Horsnell@arm.com 13457856SMatt.Horsnell@arm.com if (inst->mispredicted() && !loadNotExecuted) { 13462292SN/A fetchRedirect[tid] = true; 13471062SN/A 13482292SN/A DPRINTF(IEW, "Execute: Branch mispredict detected.\n"); 13498674Snilay@cs.wisc.edu DPRINTF(IEW, "Predicted target was PC: %s.\n", 13508674Snilay@cs.wisc.edu inst->readPredTarg()); 13517720Sgblack@eecs.umich.edu DPRINTF(IEW, "Execute: Redirecting fetch to PC: %s.\n", 13528674Snilay@cs.wisc.edu inst->pcState()); 13531062SN/A // If incorrect, then signal the ROB that it must be squashed. 13542292SN/A squashDueToBranch(inst, tid); 13551062SN/A 13563795Sgblack@eecs.umich.edu if (inst->readPredTaken()) { 13571062SN/A predictedTakenIncorrect++; 13582292SN/A } else { 13592292SN/A predictedNotTakenIncorrect++; 13601062SN/A } 13612292SN/A } else if (ldstQueue.violation(tid)) { 13624033Sktlim@umich.edu assert(inst->isMemRef()); 13632326SN/A // If there was an ordering violation, then get the 13642326SN/A // DynInst that caused the violation. Note that this 13652292SN/A // clears the violation signal. 13662292SN/A DynInstPtr violator; 13672292SN/A violator = ldstQueue.getMemDepViolator(tid); 13681062SN/A 13697720Sgblack@eecs.umich.edu DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: %s " 13707720Sgblack@eecs.umich.edu "[sn:%lli], inst PC: %s [sn:%lli]. Addr is: %#x.\n", 13717720Sgblack@eecs.umich.edu violator->pcState(), violator->seqNum, 13727720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum, inst->physEffAddr); 13737720Sgblack@eecs.umich.edu 13743732Sktlim@umich.edu fetchRedirect[tid] = true; 13753732Sktlim@umich.edu 13761062SN/A // Tell the instruction queue that a violation has occured. 13771062SN/A instQueue.violation(inst, violator); 13781062SN/A 13791062SN/A // Squash. 13808513SGiacomo.Gabrielli@arm.com squashDueToMemOrder(violator, tid); 13811062SN/A 13821062SN/A ++memOrderViolationEvents; 13832292SN/A } else if (ldstQueue.loadBlocked(tid) && 13842292SN/A !ldstQueue.isLoadBlockedHandled(tid)) { 13852292SN/A fetchRedirect[tid] = true; 13862292SN/A 13872292SN/A DPRINTF(IEW, "Load operation couldn't execute because the " 13887720Sgblack@eecs.umich.edu "memory system is blocked. PC: %s [sn:%lli]\n", 13897720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum); 13902292SN/A 13912292SN/A squashDueToMemBlocked(inst, tid); 13921062SN/A } 13934033Sktlim@umich.edu } else { 13944033Sktlim@umich.edu // Reset any state associated with redirects that will not 13954033Sktlim@umich.edu // be used. 13964033Sktlim@umich.edu if (ldstQueue.violation(tid)) { 13974033Sktlim@umich.edu assert(inst->isMemRef()); 13984033Sktlim@umich.edu 13994033Sktlim@umich.edu DynInstPtr violator = ldstQueue.getMemDepViolator(tid); 14004033Sktlim@umich.edu 14014033Sktlim@umich.edu DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: " 14027720Sgblack@eecs.umich.edu "%s, inst PC: %s. Addr is: %#x.\n", 14037720Sgblack@eecs.umich.edu violator->pcState(), inst->pcState(), 14047720Sgblack@eecs.umich.edu inst->physEffAddr); 14054033Sktlim@umich.edu DPRINTF(IEW, "Violation will not be handled because " 14064033Sktlim@umich.edu "already squashing\n"); 14074033Sktlim@umich.edu 14084033Sktlim@umich.edu ++memOrderViolationEvents; 14094033Sktlim@umich.edu } 14104033Sktlim@umich.edu if (ldstQueue.loadBlocked(tid) && 14114033Sktlim@umich.edu !ldstQueue.isLoadBlockedHandled(tid)) { 14124033Sktlim@umich.edu DPRINTF(IEW, "Load operation couldn't execute because the " 14137720Sgblack@eecs.umich.edu "memory system is blocked. PC: %s [sn:%lli]\n", 14147720Sgblack@eecs.umich.edu inst->pcState(), inst->seqNum); 14154033Sktlim@umich.edu DPRINTF(IEW, "Blocked load will not be handled because " 14164033Sktlim@umich.edu "already squashing\n"); 14174033Sktlim@umich.edu 14184033Sktlim@umich.edu ldstQueue.setLoadBlockedHandled(tid); 14194033Sktlim@umich.edu } 14204033Sktlim@umich.edu 14211062SN/A } 14221062SN/A } 14232292SN/A 14242348SN/A // Update and record activity if we processed any instructions. 14252292SN/A if (inst_num) { 14262292SN/A if (exeStatus == Idle) { 14272292SN/A exeStatus = Running; 14282292SN/A } 14292292SN/A 14302292SN/A updatedQueues = true; 14312292SN/A 14322292SN/A cpu->activityThisCycle(); 14332292SN/A } 14342292SN/A 14352292SN/A // Need to reset this in case a writeback event needs to write into the 14362292SN/A // iew queue. That way the writeback event will write into the correct 14372292SN/A // spot in the queue. 14382292SN/A wbNumInst = 0; 14397852SMatt.Horsnell@arm.com 14402107SN/A} 14412107SN/A 14422292SN/Atemplate <class Impl> 14432107SN/Avoid 14442292SN/ADefaultIEW<Impl>::writebackInsts() 14452107SN/A{ 14462326SN/A // Loop through the head of the time buffer and wake any 14472326SN/A // dependents. These instructions are about to write back. Also 14482326SN/A // mark scoreboard that this instruction is finally complete. 14492326SN/A // Either have IEW have direct access to scoreboard, or have this 14502326SN/A // as part of backwards communication. 14513958Sgblack@eecs.umich.edu for (int inst_num = 0; inst_num < wbWidth && 14522292SN/A toCommit->insts[inst_num]; inst_num++) { 14532107SN/A DynInstPtr inst = toCommit->insts[inst_num]; 14546221Snate@binkert.org ThreadID tid = inst->threadNumber; 14552107SN/A 14567720Sgblack@eecs.umich.edu DPRINTF(IEW, "Sending instructions to commit, [sn:%lli] PC %s.\n", 14577720Sgblack@eecs.umich.edu inst->seqNum, inst->pcState()); 14582107SN/A 14592301SN/A iewInstsToCommit[tid]++; 14602301SN/A 14612292SN/A // Some instructions will be sent to commit without having 14622292SN/A // executed because they need commit to handle them. 14632292SN/A // E.g. Uncached loads have not actually executed when they 14642292SN/A // are first sent to commit. Instead commit must tell the LSQ 14652292SN/A // when it's ready to execute the uncached load. 14662367SN/A if (!inst->isSquashed() && inst->isExecuted() && inst->getFault() == NoFault) { 14672301SN/A int dependents = instQueue.wakeDependents(inst); 14682107SN/A 14692292SN/A for (int i = 0; i < inst->numDestRegs(); i++) { 14702292SN/A //mark as Ready 14712292SN/A DPRINTF(IEW,"Setting Destination Register %i\n", 14722292SN/A inst->renamedDestRegIdx(i)); 14732292SN/A scoreboard->setReg(inst->renamedDestRegIdx(i)); 14742107SN/A } 14752301SN/A 14762348SN/A if (dependents) { 14772348SN/A producerInst[tid]++; 14782348SN/A consumerInst[tid]+= dependents; 14792348SN/A } 14802326SN/A writebackCount[tid]++; 14812107SN/A } 14822820Sktlim@umich.edu 14832820Sktlim@umich.edu decrWb(inst->seqNum); 14842107SN/A } 14851060SN/A} 14861060SN/A 14871681SN/Atemplate<class Impl> 14881060SN/Avoid 14892292SN/ADefaultIEW<Impl>::tick() 14901060SN/A{ 14912292SN/A wbNumInst = 0; 14922292SN/A wbCycle = 0; 14931060SN/A 14942292SN/A wroteToTimeBuffer = false; 14952292SN/A updatedQueues = false; 14961060SN/A 14972292SN/A sortInsts(); 14981060SN/A 14992326SN/A // Free function units marked as being freed this cycle. 15002326SN/A fuPool->processFreeUnits(); 15011062SN/A 15026221Snate@binkert.org list<ThreadID>::iterator threads = activeThreads->begin(); 15036221Snate@binkert.org list<ThreadID>::iterator end = activeThreads->end(); 15041060SN/A 15052326SN/A // Check stall and squash signals, dispatch any instructions. 15063867Sbinkertn@umich.edu while (threads != end) { 15076221Snate@binkert.org ThreadID tid = *threads++; 15081060SN/A 15092292SN/A DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid); 15101060SN/A 15112292SN/A checkSignalsAndUpdate(tid); 15122292SN/A dispatch(tid); 15131060SN/A } 15141060SN/A 15152292SN/A if (exeStatus != Squashing) { 15162292SN/A executeInsts(); 15171060SN/A 15182292SN/A writebackInsts(); 15192292SN/A 15202292SN/A // Have the instruction queue try to schedule any ready instructions. 15212292SN/A // (In actuality, this scheduling is for instructions that will 15222292SN/A // be executed next cycle.) 15232292SN/A instQueue.scheduleReadyInsts(); 15242292SN/A 15252292SN/A // Also should advance its own time buffers if the stage ran. 15262292SN/A // Not the best place for it, but this works (hopefully). 15272292SN/A issueToExecQueue.advance(); 15282292SN/A } 15292292SN/A 15302292SN/A bool broadcast_free_entries = false; 15312292SN/A 15322292SN/A if (updatedQueues || exeStatus == Running || updateLSQNextCycle) { 15332292SN/A exeStatus = Idle; 15342292SN/A updateLSQNextCycle = false; 15352292SN/A 15362292SN/A broadcast_free_entries = true; 15372292SN/A } 15382292SN/A 15392292SN/A // Writeback any stores using any leftover bandwidth. 15401681SN/A ldstQueue.writebackStores(); 15411681SN/A 15421061SN/A // Check the committed load/store signals to see if there's a load 15431061SN/A // or store to commit. Also check if it's being told to execute a 15441061SN/A // nonspeculative instruction. 15451681SN/A // This is pretty inefficient... 15462292SN/A 15473867Sbinkertn@umich.edu threads = activeThreads->begin(); 15483867Sbinkertn@umich.edu while (threads != end) { 15496221Snate@binkert.org ThreadID tid = (*threads++); 15502292SN/A 15512292SN/A DPRINTF(IEW,"Processing [tid:%i]\n",tid); 15522292SN/A 15532348SN/A // Update structures based on instructions committed. 15542292SN/A if (fromCommit->commitInfo[tid].doneSeqNum != 0 && 15552292SN/A !fromCommit->commitInfo[tid].squash && 15562292SN/A !fromCommit->commitInfo[tid].robSquashing) { 15572292SN/A 15582292SN/A ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid); 15592292SN/A 15602292SN/A ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid); 15612292SN/A 15622292SN/A updateLSQNextCycle = true; 15632292SN/A instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid); 15642292SN/A } 15652292SN/A 15662292SN/A if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) { 15672292SN/A 15682292SN/A //DPRINTF(IEW,"NonspecInst from thread %i",tid); 15692292SN/A if (fromCommit->commitInfo[tid].uncached) { 15702292SN/A instQueue.replayMemInst(fromCommit->commitInfo[tid].uncachedLoad); 15714033Sktlim@umich.edu fromCommit->commitInfo[tid].uncachedLoad->setAtCommit(); 15722292SN/A } else { 15732292SN/A instQueue.scheduleNonSpec( 15742292SN/A fromCommit->commitInfo[tid].nonSpecSeqNum); 15752292SN/A } 15762292SN/A } 15772292SN/A 15782292SN/A if (broadcast_free_entries) { 15792292SN/A toFetch->iewInfo[tid].iqCount = 15802292SN/A instQueue.getCount(tid); 15812292SN/A toFetch->iewInfo[tid].ldstqCount = 15822292SN/A ldstQueue.getCount(tid); 15832292SN/A 15842292SN/A toRename->iewInfo[tid].usedIQ = true; 15852292SN/A toRename->iewInfo[tid].freeIQEntries = 15862292SN/A instQueue.numFreeEntries(); 15872292SN/A toRename->iewInfo[tid].usedLSQ = true; 15882292SN/A toRename->iewInfo[tid].freeLSQEntries = 15892292SN/A ldstQueue.numFreeEntries(tid); 15902292SN/A 15912292SN/A wroteToTimeBuffer = true; 15922292SN/A } 15932292SN/A 15942292SN/A DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n", 15952292SN/A tid, toRename->iewInfo[tid].dispatched); 15961061SN/A } 15971061SN/A 15982292SN/A DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i). " 15992292SN/A "LSQ has %i free entries.\n", 16002292SN/A instQueue.numFreeEntries(), instQueue.hasReadyInsts(), 16012292SN/A ldstQueue.numFreeEntries()); 16022292SN/A 16032292SN/A updateStatus(); 16042292SN/A 16052292SN/A if (wroteToTimeBuffer) { 16062292SN/A DPRINTF(Activity, "Activity this cycle.\n"); 16072292SN/A cpu->activityThisCycle(); 16081061SN/A } 16091060SN/A} 16101060SN/A 16112301SN/Atemplate <class Impl> 16121060SN/Avoid 16132301SN/ADefaultIEW<Impl>::updateExeInstStats(DynInstPtr &inst) 16141060SN/A{ 16156221Snate@binkert.org ThreadID tid = inst->threadNumber; 16161060SN/A 16172669Sktlim@umich.edu iewExecutedInsts++; 16181060SN/A 16198471SGiacomo.Gabrielli@arm.com#if TRACING_ON 16209046SAli.Saidi@ARM.com inst->completeTick = curTick() - inst->fetchTick; 16218471SGiacomo.Gabrielli@arm.com#endif 16228471SGiacomo.Gabrielli@arm.com 16232301SN/A // 16242301SN/A // Control operations 16252301SN/A // 16262301SN/A if (inst->isControl()) 16276221Snate@binkert.org iewExecutedBranches[tid]++; 16281060SN/A 16292301SN/A // 16302301SN/A // Memory operations 16312301SN/A // 16322301SN/A if (inst->isMemRef()) { 16336221Snate@binkert.org iewExecutedRefs[tid]++; 16341060SN/A 16352301SN/A if (inst->isLoad()) { 16366221Snate@binkert.org iewExecLoadInsts[tid]++; 16371060SN/A } 16381060SN/A } 16391060SN/A} 16407598Sminkyu.jeong@arm.com 16417598Sminkyu.jeong@arm.comtemplate <class Impl> 16427598Sminkyu.jeong@arm.comvoid 16437598Sminkyu.jeong@arm.comDefaultIEW<Impl>::checkMisprediction(DynInstPtr &inst) 16447598Sminkyu.jeong@arm.com{ 16457598Sminkyu.jeong@arm.com ThreadID tid = inst->threadNumber; 16467598Sminkyu.jeong@arm.com 16477598Sminkyu.jeong@arm.com if (!fetchRedirect[tid] || 16487852SMatt.Horsnell@arm.com !toCommit->squash[tid] || 16497598Sminkyu.jeong@arm.com toCommit->squashedSeqNum[tid] > inst->seqNum) { 16507598Sminkyu.jeong@arm.com 16517598Sminkyu.jeong@arm.com if (inst->mispredicted()) { 16527598Sminkyu.jeong@arm.com fetchRedirect[tid] = true; 16537598Sminkyu.jeong@arm.com 16547598Sminkyu.jeong@arm.com DPRINTF(IEW, "Execute: Branch mispredict detected.\n"); 16557598Sminkyu.jeong@arm.com DPRINTF(IEW, "Predicted target was PC:%#x, NPC:%#x.\n", 16567720Sgblack@eecs.umich.edu inst->predInstAddr(), inst->predNextInstAddr()); 16577598Sminkyu.jeong@arm.com DPRINTF(IEW, "Execute: Redirecting fetch to PC: %#x," 16587720Sgblack@eecs.umich.edu " NPC: %#x.\n", inst->nextInstAddr(), 16597720Sgblack@eecs.umich.edu inst->nextInstAddr()); 16607598Sminkyu.jeong@arm.com // If incorrect, then signal the ROB that it must be squashed. 16617598Sminkyu.jeong@arm.com squashDueToBranch(inst, tid); 16627598Sminkyu.jeong@arm.com 16637598Sminkyu.jeong@arm.com if (inst->readPredTaken()) { 16647598Sminkyu.jeong@arm.com predictedTakenIncorrect++; 16657598Sminkyu.jeong@arm.com } else { 16667598Sminkyu.jeong@arm.com predictedNotTakenIncorrect++; 16677598Sminkyu.jeong@arm.com } 16687598Sminkyu.jeong@arm.com } 16697598Sminkyu.jeong@arm.com } 16707598Sminkyu.jeong@arm.com} 1671