iew_impl.hh revision 8240
11689SN/A/*
27598Sminkyu.jeong@arm.com * Copyright (c) 2010 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"
512292SN/A#include "cpu/o3/fu_pool.hh"
521717SN/A#include "cpu/o3/iew.hh"
538229Snate@binkert.org#include "cpu/timebuf.hh"
548232Snate@binkert.org#include "debug/Activity.hh"
558232Snate@binkert.org#include "debug/Decode.hh"
568232Snate@binkert.org#include "debug/IEW.hh"
575529Snate@binkert.org#include "params/DerivO3CPU.hh"
581060SN/A
596221Snate@binkert.orgusing namespace std;
606221Snate@binkert.org
611681SN/Atemplate<class Impl>
625529Snate@binkert.orgDefaultIEW<Impl>::DefaultIEW(O3CPU *_cpu, DerivO3CPUParams *params)
632873Sktlim@umich.edu    : issueToExecQueue(params->backComSize, params->forwardComSize),
644329Sktlim@umich.edu      cpu(_cpu),
654329Sktlim@umich.edu      instQueue(_cpu, this, params),
664329Sktlim@umich.edu      ldstQueue(_cpu, this, params),
672292SN/A      fuPool(params->fuPool),
682292SN/A      commitToIEWDelay(params->commitToIEWDelay),
692292SN/A      renameToIEWDelay(params->renameToIEWDelay),
702292SN/A      issueToExecuteDelay(params->issueToExecuteDelay),
712820Sktlim@umich.edu      dispatchWidth(params->dispatchWidth),
722292SN/A      issueWidth(params->issueWidth),
732820Sktlim@umich.edu      wbOutstanding(0),
742820Sktlim@umich.edu      wbWidth(params->wbWidth),
755529Snate@binkert.org      numThreads(params->numThreads),
762307SN/A      switchedOut(false)
771060SN/A{
782292SN/A    _status = Active;
792292SN/A    exeStatus = Running;
802292SN/A    wbStatus = Idle;
811060SN/A
821060SN/A    // Setup wire to read instructions coming from issue.
831060SN/A    fromIssue = issueToExecQueue.getWire(-issueToExecuteDelay);
841060SN/A
851060SN/A    // Instruction queue needs the queue between issue and execute.
861060SN/A    instQueue.setIssueToExecuteQueue(&issueToExecQueue);
871681SN/A
886221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
896221Snate@binkert.org        dispatchStatus[tid] = Running;
906221Snate@binkert.org        stalls[tid].commit = false;
916221Snate@binkert.org        fetchRedirect[tid] = false;
922292SN/A    }
932292SN/A
942820Sktlim@umich.edu    wbMax = wbWidth * params->wbDepth;
952820Sktlim@umich.edu
962292SN/A    updateLSQNextCycle = false;
972292SN/A
982820Sktlim@umich.edu    ableToIssue = true;
992820Sktlim@umich.edu
1002292SN/A    skidBufferMax = (3 * (renameToIEWDelay * params->renameWidth)) + issueWidth;
1012292SN/A}
1022292SN/A
1032292SN/Atemplate <class Impl>
1042292SN/Astd::string
1052292SN/ADefaultIEW<Impl>::name() const
1062292SN/A{
1072292SN/A    return cpu->name() + ".iew";
1081060SN/A}
1091060SN/A
1101681SN/Atemplate <class Impl>
1111062SN/Avoid
1122292SN/ADefaultIEW<Impl>::regStats()
1131062SN/A{
1142301SN/A    using namespace Stats;
1152301SN/A
1161062SN/A    instQueue.regStats();
1172727Sktlim@umich.edu    ldstQueue.regStats();
1181062SN/A
1191062SN/A    iewIdleCycles
1201062SN/A        .name(name() + ".iewIdleCycles")
1211062SN/A        .desc("Number of cycles IEW is idle");
1221062SN/A
1231062SN/A    iewSquashCycles
1241062SN/A        .name(name() + ".iewSquashCycles")
1251062SN/A        .desc("Number of cycles IEW is squashing");
1261062SN/A
1271062SN/A    iewBlockCycles
1281062SN/A        .name(name() + ".iewBlockCycles")
1291062SN/A        .desc("Number of cycles IEW is blocking");
1301062SN/A
1311062SN/A    iewUnblockCycles
1321062SN/A        .name(name() + ".iewUnblockCycles")
1331062SN/A        .desc("Number of cycles IEW is unblocking");
1341062SN/A
1351062SN/A    iewDispatchedInsts
1361062SN/A        .name(name() + ".iewDispatchedInsts")
1371062SN/A        .desc("Number of instructions dispatched to IQ");
1381062SN/A
1391062SN/A    iewDispSquashedInsts
1401062SN/A        .name(name() + ".iewDispSquashedInsts")
1411062SN/A        .desc("Number of squashed instructions skipped by dispatch");
1421062SN/A
1431062SN/A    iewDispLoadInsts
1441062SN/A        .name(name() + ".iewDispLoadInsts")
1451062SN/A        .desc("Number of dispatched load instructions");
1461062SN/A
1471062SN/A    iewDispStoreInsts
1481062SN/A        .name(name() + ".iewDispStoreInsts")
1491062SN/A        .desc("Number of dispatched store instructions");
1501062SN/A
1511062SN/A    iewDispNonSpecInsts
1521062SN/A        .name(name() + ".iewDispNonSpecInsts")
1531062SN/A        .desc("Number of dispatched non-speculative instructions");
1541062SN/A
1551062SN/A    iewIQFullEvents
1561062SN/A        .name(name() + ".iewIQFullEvents")
1571062SN/A        .desc("Number of times the IQ has become full, causing a stall");
1581062SN/A
1592292SN/A    iewLSQFullEvents
1602292SN/A        .name(name() + ".iewLSQFullEvents")
1612292SN/A        .desc("Number of times the LSQ has become full, causing a stall");
1622292SN/A
1631062SN/A    memOrderViolationEvents
1641062SN/A        .name(name() + ".memOrderViolationEvents")
1651062SN/A        .desc("Number of memory order violations");
1661062SN/A
1671062SN/A    predictedTakenIncorrect
1681062SN/A        .name(name() + ".predictedTakenIncorrect")
1691062SN/A        .desc("Number of branches that were predicted taken incorrectly");
1702292SN/A
1712292SN/A    predictedNotTakenIncorrect
1722292SN/A        .name(name() + ".predictedNotTakenIncorrect")
1732292SN/A        .desc("Number of branches that were predicted not taken incorrectly");
1742292SN/A
1752292SN/A    branchMispredicts
1762292SN/A        .name(name() + ".branchMispredicts")
1772292SN/A        .desc("Number of branch mispredicts detected at execute");
1782292SN/A
1792292SN/A    branchMispredicts = predictedTakenIncorrect + predictedNotTakenIncorrect;
1802301SN/A
1812727Sktlim@umich.edu    iewExecutedInsts
1822353SN/A        .name(name() + ".iewExecutedInsts")
1832727Sktlim@umich.edu        .desc("Number of executed instructions");
1842727Sktlim@umich.edu
1852727Sktlim@umich.edu    iewExecLoadInsts
1866221Snate@binkert.org        .init(cpu->numThreads)
1872353SN/A        .name(name() + ".iewExecLoadInsts")
1882727Sktlim@umich.edu        .desc("Number of load instructions executed")
1892727Sktlim@umich.edu        .flags(total);
1902727Sktlim@umich.edu
1912727Sktlim@umich.edu    iewExecSquashedInsts
1922353SN/A        .name(name() + ".iewExecSquashedInsts")
1932727Sktlim@umich.edu        .desc("Number of squashed instructions skipped in execute");
1942727Sktlim@umich.edu
1952727Sktlim@umich.edu    iewExecutedSwp
1966221Snate@binkert.org        .init(cpu->numThreads)
1978240Snate@binkert.org        .name(name() + ".exec_swp")
1982301SN/A        .desc("number of swp insts executed")
1992727Sktlim@umich.edu        .flags(total);
2002301SN/A
2012727Sktlim@umich.edu    iewExecutedNop
2026221Snate@binkert.org        .init(cpu->numThreads)
2038240Snate@binkert.org        .name(name() + ".exec_nop")
2042301SN/A        .desc("number of nop insts executed")
2052727Sktlim@umich.edu        .flags(total);
2062301SN/A
2072727Sktlim@umich.edu    iewExecutedRefs
2086221Snate@binkert.org        .init(cpu->numThreads)
2098240Snate@binkert.org        .name(name() + ".exec_refs")
2102301SN/A        .desc("number of memory reference insts executed")
2112727Sktlim@umich.edu        .flags(total);
2122301SN/A
2132727Sktlim@umich.edu    iewExecutedBranches
2146221Snate@binkert.org        .init(cpu->numThreads)
2158240Snate@binkert.org        .name(name() + ".exec_branches")
2162301SN/A        .desc("Number of branches executed")
2172727Sktlim@umich.edu        .flags(total);
2182301SN/A
2192301SN/A    iewExecStoreInsts
2208240Snate@binkert.org        .name(name() + ".exec_stores")
2212301SN/A        .desc("Number of stores executed")
2222727Sktlim@umich.edu        .flags(total);
2232727Sktlim@umich.edu    iewExecStoreInsts = iewExecutedRefs - iewExecLoadInsts;
2242727Sktlim@umich.edu
2252727Sktlim@umich.edu    iewExecRate
2268240Snate@binkert.org        .name(name() + ".exec_rate")
2272727Sktlim@umich.edu        .desc("Inst execution rate")
2282727Sktlim@umich.edu        .flags(total);
2292727Sktlim@umich.edu
2302727Sktlim@umich.edu    iewExecRate = iewExecutedInsts / cpu->numCycles;
2312301SN/A
2322301SN/A    iewInstsToCommit
2336221Snate@binkert.org        .init(cpu->numThreads)
2348240Snate@binkert.org        .name(name() + ".wb_sent")
2352301SN/A        .desc("cumulative count of insts sent to commit")
2362727Sktlim@umich.edu        .flags(total);
2372301SN/A
2382326SN/A    writebackCount
2396221Snate@binkert.org        .init(cpu->numThreads)
2408240Snate@binkert.org        .name(name() + ".wb_count")
2412301SN/A        .desc("cumulative count of insts written-back")
2422727Sktlim@umich.edu        .flags(total);
2432301SN/A
2442326SN/A    producerInst
2456221Snate@binkert.org        .init(cpu->numThreads)
2468240Snate@binkert.org        .name(name() + ".wb_producers")
2472301SN/A        .desc("num instructions producing a value")
2482727Sktlim@umich.edu        .flags(total);
2492301SN/A
2502326SN/A    consumerInst
2516221Snate@binkert.org        .init(cpu->numThreads)
2528240Snate@binkert.org        .name(name() + ".wb_consumers")
2532301SN/A        .desc("num instructions consuming a value")
2542727Sktlim@umich.edu        .flags(total);
2552301SN/A
2562326SN/A    wbPenalized
2576221Snate@binkert.org        .init(cpu->numThreads)
2588240Snate@binkert.org        .name(name() + ".wb_penalized")
2592301SN/A        .desc("number of instrctions required to write to 'other' IQ")
2602727Sktlim@umich.edu        .flags(total);
2612301SN/A
2622326SN/A    wbPenalizedRate
2638240Snate@binkert.org        .name(name() + ".wb_penalized_rate")
2642301SN/A        .desc ("fraction of instructions written-back that wrote to 'other' IQ")
2652727Sktlim@umich.edu        .flags(total);
2662301SN/A
2672326SN/A    wbPenalizedRate = wbPenalized / writebackCount;
2682301SN/A
2692326SN/A    wbFanout
2708240Snate@binkert.org        .name(name() + ".wb_fanout")
2712301SN/A        .desc("average fanout of values written-back")
2722727Sktlim@umich.edu        .flags(total);
2732301SN/A
2742326SN/A    wbFanout = producerInst / consumerInst;
2752301SN/A
2762326SN/A    wbRate
2778240Snate@binkert.org        .name(name() + ".wb_rate")
2782301SN/A        .desc("insts written-back per cycle")
2792727Sktlim@umich.edu        .flags(total);
2802326SN/A    wbRate = writebackCount / cpu->numCycles;
2811062SN/A}
2821062SN/A
2831681SN/Atemplate<class Impl>
2841060SN/Avoid
2852292SN/ADefaultIEW<Impl>::initStage()
2861060SN/A{
2876221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
2882292SN/A        toRename->iewInfo[tid].usedIQ = true;
2892292SN/A        toRename->iewInfo[tid].freeIQEntries =
2902292SN/A            instQueue.numFreeEntries(tid);
2912292SN/A
2922292SN/A        toRename->iewInfo[tid].usedLSQ = true;
2932292SN/A        toRename->iewInfo[tid].freeLSQEntries =
2942292SN/A            ldstQueue.numFreeEntries(tid);
2952292SN/A    }
2962292SN/A
2972733Sktlim@umich.edu    cpu->activateStage(O3CPU::IEWIdx);
2981060SN/A}
2991060SN/A
3001681SN/Atemplate<class Impl>
3011060SN/Avoid
3022292SN/ADefaultIEW<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
3031060SN/A{
3041060SN/A    timeBuffer = tb_ptr;
3051060SN/A
3061060SN/A    // Setup wire to read information from time buffer, from commit.
3071060SN/A    fromCommit = timeBuffer->getWire(-commitToIEWDelay);
3081060SN/A
3091060SN/A    // Setup wire to write information back to previous stages.
3101060SN/A    toRename = timeBuffer->getWire(0);
3111060SN/A
3122292SN/A    toFetch = timeBuffer->getWire(0);
3132292SN/A
3141060SN/A    // Instruction queue also needs main time buffer.
3151060SN/A    instQueue.setTimeBuffer(tb_ptr);
3161060SN/A}
3171060SN/A
3181681SN/Atemplate<class Impl>
3191060SN/Avoid
3202292SN/ADefaultIEW<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
3211060SN/A{
3221060SN/A    renameQueue = rq_ptr;
3231060SN/A
3241060SN/A    // Setup wire to read information from rename queue.
3251060SN/A    fromRename = renameQueue->getWire(-renameToIEWDelay);
3261060SN/A}
3271060SN/A
3281681SN/Atemplate<class Impl>
3291060SN/Avoid
3302292SN/ADefaultIEW<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr)
3311060SN/A{
3321060SN/A    iewQueue = iq_ptr;
3331060SN/A
3341060SN/A    // Setup wire to write instructions to commit.
3351060SN/A    toCommit = iewQueue->getWire(0);
3361060SN/A}
3371060SN/A
3381681SN/Atemplate<class Impl>
3391060SN/Avoid
3406221Snate@binkert.orgDefaultIEW<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
3411060SN/A{
3422292SN/A    activeThreads = at_ptr;
3432292SN/A
3442292SN/A    ldstQueue.setActiveThreads(at_ptr);
3452292SN/A    instQueue.setActiveThreads(at_ptr);
3461060SN/A}
3471060SN/A
3481681SN/Atemplate<class Impl>
3491060SN/Avoid
3502292SN/ADefaultIEW<Impl>::setScoreboard(Scoreboard *sb_ptr)
3511060SN/A{
3522292SN/A    scoreboard = sb_ptr;
3531060SN/A}
3541060SN/A
3552307SN/Atemplate <class Impl>
3562863Sktlim@umich.edubool
3572843Sktlim@umich.eduDefaultIEW<Impl>::drain()
3582307SN/A{
3592843Sktlim@umich.edu    // IEW is ready to drain at any time.
3602843Sktlim@umich.edu    cpu->signalDrained();
3612863Sktlim@umich.edu    return true;
3621681SN/A}
3631681SN/A
3642316SN/Atemplate <class Impl>
3651681SN/Avoid
3662843Sktlim@umich.eduDefaultIEW<Impl>::resume()
3672843Sktlim@umich.edu{
3682843Sktlim@umich.edu}
3692843Sktlim@umich.edu
3702843Sktlim@umich.edutemplate <class Impl>
3712843Sktlim@umich.eduvoid
3722843Sktlim@umich.eduDefaultIEW<Impl>::switchOut()
3731681SN/A{
3742348SN/A    // Clear any state.
3752307SN/A    switchedOut = true;
3762367SN/A    assert(insts[0].empty());
3772367SN/A    assert(skidBuffer[0].empty());
3781681SN/A
3792307SN/A    instQueue.switchOut();
3802307SN/A    ldstQueue.switchOut();
3812307SN/A    fuPool->switchOut();
3822307SN/A
3836221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
3846221Snate@binkert.org        while (!insts[tid].empty())
3856221Snate@binkert.org            insts[tid].pop();
3866221Snate@binkert.org        while (!skidBuffer[tid].empty())
3876221Snate@binkert.org            skidBuffer[tid].pop();
3882307SN/A    }
3891681SN/A}
3901681SN/A
3912307SN/Atemplate <class Impl>
3921681SN/Avoid
3932307SN/ADefaultIEW<Impl>::takeOverFrom()
3941060SN/A{
3952348SN/A    // Reset all state.
3962307SN/A    _status = Active;
3972307SN/A    exeStatus = Running;
3982307SN/A    wbStatus = Idle;
3992307SN/A    switchedOut = false;
4001060SN/A
4012307SN/A    instQueue.takeOverFrom();
4022307SN/A    ldstQueue.takeOverFrom();
4032307SN/A    fuPool->takeOverFrom();
4041060SN/A
4052307SN/A    initStage();
4062307SN/A    cpu->activityThisCycle();
4071060SN/A
4086221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
4096221Snate@binkert.org        dispatchStatus[tid] = Running;
4106221Snate@binkert.org        stalls[tid].commit = false;
4116221Snate@binkert.org        fetchRedirect[tid] = false;
4122307SN/A    }
4131060SN/A
4142307SN/A    updateLSQNextCycle = false;
4152307SN/A
4162873Sktlim@umich.edu    for (int i = 0; i < issueToExecQueue.getSize(); ++i) {
4172307SN/A        issueToExecQueue.advance();
4181060SN/A    }
4191060SN/A}
4201060SN/A
4211681SN/Atemplate<class Impl>
4221060SN/Avoid
4236221Snate@binkert.orgDefaultIEW<Impl>::squash(ThreadID tid)
4242107SN/A{
4256221Snate@binkert.org    DPRINTF(IEW, "[tid:%i]: Squashing all instructions.\n", tid);
4262107SN/A
4272292SN/A    // Tell the IQ to start squashing.
4282292SN/A    instQueue.squash(tid);
4292107SN/A
4302292SN/A    // Tell the LDSTQ to start squashing.
4312326SN/A    ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid);
4322292SN/A    updatedQueues = true;
4332107SN/A
4342292SN/A    // Clear the skid buffer in case it has any data in it.
4352935Sksewell@umich.edu    DPRINTF(IEW, "[tid:%i]: Removing skidbuffer instructions until [sn:%i].\n",
4364632Sgblack@eecs.umich.edu            tid, fromCommit->commitInfo[tid].doneSeqNum);
4372935Sksewell@umich.edu
4382292SN/A    while (!skidBuffer[tid].empty()) {
4392292SN/A        if (skidBuffer[tid].front()->isLoad() ||
4402292SN/A            skidBuffer[tid].front()->isStore() ) {
4412292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
4422292SN/A        }
4432107SN/A
4442292SN/A        toRename->iewInfo[tid].dispatched++;
4452107SN/A
4462292SN/A        skidBuffer[tid].pop();
4472292SN/A    }
4482107SN/A
4492702Sktlim@umich.edu    emptyRenameInsts(tid);
4502107SN/A}
4512107SN/A
4522107SN/Atemplate<class Impl>
4532107SN/Avoid
4546221Snate@binkert.orgDefaultIEW<Impl>::squashDueToBranch(DynInstPtr &inst, ThreadID tid)
4552292SN/A{
4567720Sgblack@eecs.umich.edu    DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, PC: %s "
4577720Sgblack@eecs.umich.edu            "[sn:%i].\n", tid, inst->pcState(), inst->seqNum);
4582292SN/A
4597852SMatt.Horsnell@arm.com    if (toCommit->squash[tid] == false ||
4607852SMatt.Horsnell@arm.com            inst->seqNum < toCommit->squashedSeqNum[tid]) {
4617852SMatt.Horsnell@arm.com        toCommit->squash[tid] = true;
4627852SMatt.Horsnell@arm.com        toCommit->squashedSeqNum[tid] = inst->seqNum;
4637852SMatt.Horsnell@arm.com        toCommit->branchTaken[tid] = inst->pcState().branching();
4642935Sksewell@umich.edu
4657852SMatt.Horsnell@arm.com        TheISA::PCState pc = inst->pcState();
4667852SMatt.Horsnell@arm.com        TheISA::advancePC(pc, inst->staticInst);
4672292SN/A
4687852SMatt.Horsnell@arm.com        toCommit->pc[tid] = pc;
4697852SMatt.Horsnell@arm.com        toCommit->mispredictInst[tid] = inst;
4707852SMatt.Horsnell@arm.com        toCommit->includeSquashInst[tid] = false;
4712292SN/A
4727852SMatt.Horsnell@arm.com        wroteToTimeBuffer = true;
4737852SMatt.Horsnell@arm.com    }
4747852SMatt.Horsnell@arm.com
4752292SN/A}
4762292SN/A
4772292SN/Atemplate<class Impl>
4782292SN/Avoid
4796221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemOrder(DynInstPtr &inst, ThreadID tid)
4802292SN/A{
4812292SN/A    DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, "
4827720Sgblack@eecs.umich.edu            "PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum);
4832292SN/A
4847852SMatt.Horsnell@arm.com    if (toCommit->squash[tid] == false ||
4857852SMatt.Horsnell@arm.com            inst->seqNum < toCommit->squashedSeqNum[tid]) {
4867852SMatt.Horsnell@arm.com        toCommit->squash[tid] = true;
4877852SMatt.Horsnell@arm.com        toCommit->squashedSeqNum[tid] = inst->seqNum;
4887852SMatt.Horsnell@arm.com        TheISA::PCState pc = inst->pcState();
4897852SMatt.Horsnell@arm.com        TheISA::advancePC(pc, inst->staticInst);
4907852SMatt.Horsnell@arm.com        toCommit->pc[tid] = pc;
4918137SAli.Saidi@ARM.com        toCommit->mispredictInst[tid] = NULL;
4922292SN/A
4937852SMatt.Horsnell@arm.com        toCommit->includeSquashInst[tid] = false;
4942292SN/A
4957852SMatt.Horsnell@arm.com        wroteToTimeBuffer = true;
4967852SMatt.Horsnell@arm.com    }
4972292SN/A}
4982292SN/A
4992292SN/Atemplate<class Impl>
5002292SN/Avoid
5016221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemBlocked(DynInstPtr &inst, ThreadID tid)
5022292SN/A{
5032292SN/A    DPRINTF(IEW, "[tid:%i]: Memory blocked, squashing load and younger insts, "
5047720Sgblack@eecs.umich.edu            "PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum);
5057852SMatt.Horsnell@arm.com    if (toCommit->squash[tid] == false ||
5067852SMatt.Horsnell@arm.com            inst->seqNum < toCommit->squashedSeqNum[tid]) {
5077852SMatt.Horsnell@arm.com        toCommit->squash[tid] = true;
5082292SN/A
5097852SMatt.Horsnell@arm.com        toCommit->squashedSeqNum[tid] = inst->seqNum;
5107852SMatt.Horsnell@arm.com        toCommit->pc[tid] = inst->pcState();
5118137SAli.Saidi@ARM.com        toCommit->mispredictInst[tid] = NULL;
5122292SN/A
5137852SMatt.Horsnell@arm.com        // Must include the broadcasted SN in the squash.
5147852SMatt.Horsnell@arm.com        toCommit->includeSquashInst[tid] = true;
5152292SN/A
5167852SMatt.Horsnell@arm.com        ldstQueue.setLoadBlockedHandled(tid);
5172292SN/A
5187852SMatt.Horsnell@arm.com        wroteToTimeBuffer = true;
5197852SMatt.Horsnell@arm.com    }
5202292SN/A}
5212292SN/A
5222292SN/Atemplate<class Impl>
5232292SN/Avoid
5246221Snate@binkert.orgDefaultIEW<Impl>::block(ThreadID tid)
5252292SN/A{
5262292SN/A    DPRINTF(IEW, "[tid:%u]: Blocking.\n", tid);
5272292SN/A
5282292SN/A    if (dispatchStatus[tid] != Blocked &&
5292292SN/A        dispatchStatus[tid] != Unblocking) {
5302292SN/A        toRename->iewBlock[tid] = true;
5312292SN/A        wroteToTimeBuffer = true;
5322292SN/A    }
5332292SN/A
5342292SN/A    // Add the current inputs to the skid buffer so they can be
5352292SN/A    // reprocessed when this stage unblocks.
5362292SN/A    skidInsert(tid);
5372292SN/A
5382292SN/A    dispatchStatus[tid] = Blocked;
5392292SN/A}
5402292SN/A
5412292SN/Atemplate<class Impl>
5422292SN/Avoid
5436221Snate@binkert.orgDefaultIEW<Impl>::unblock(ThreadID tid)
5442292SN/A{
5452292SN/A    DPRINTF(IEW, "[tid:%i]: Reading instructions out of the skid "
5462292SN/A            "buffer %u.\n",tid, tid);
5472292SN/A
5482292SN/A    // If the skid bufffer is empty, signal back to previous stages to unblock.
5492292SN/A    // Also switch status to running.
5502292SN/A    if (skidBuffer[tid].empty()) {
5512292SN/A        toRename->iewUnblock[tid] = true;
5522292SN/A        wroteToTimeBuffer = true;
5532292SN/A        DPRINTF(IEW, "[tid:%i]: Done unblocking.\n",tid);
5542292SN/A        dispatchStatus[tid] = Running;
5552292SN/A    }
5562292SN/A}
5572292SN/A
5582292SN/Atemplate<class Impl>
5592292SN/Avoid
5602292SN/ADefaultIEW<Impl>::wakeDependents(DynInstPtr &inst)
5611060SN/A{
5621681SN/A    instQueue.wakeDependents(inst);
5631060SN/A}
5641060SN/A
5652292SN/Atemplate<class Impl>
5662292SN/Avoid
5672292SN/ADefaultIEW<Impl>::rescheduleMemInst(DynInstPtr &inst)
5682292SN/A{
5692292SN/A    instQueue.rescheduleMemInst(inst);
5702292SN/A}
5711681SN/A
5721681SN/Atemplate<class Impl>
5731060SN/Avoid
5742292SN/ADefaultIEW<Impl>::replayMemInst(DynInstPtr &inst)
5751060SN/A{
5762292SN/A    instQueue.replayMemInst(inst);
5772292SN/A}
5781060SN/A
5792292SN/Atemplate<class Impl>
5802292SN/Avoid
5812292SN/ADefaultIEW<Impl>::instToCommit(DynInstPtr &inst)
5822292SN/A{
5833221Sktlim@umich.edu    // This function should not be called after writebackInsts in a
5843221Sktlim@umich.edu    // single cycle.  That will cause problems with an instruction
5853221Sktlim@umich.edu    // being added to the queue to commit without being processed by
5863221Sktlim@umich.edu    // writebackInsts prior to being sent to commit.
5873221Sktlim@umich.edu
5882292SN/A    // First check the time slot that this instruction will write
5892292SN/A    // to.  If there are free write ports at the time, then go ahead
5902292SN/A    // and write the instruction to that time.  If there are not,
5912292SN/A    // keep looking back to see where's the first time there's a
5922326SN/A    // free slot.
5932292SN/A    while ((*iewQueue)[wbCycle].insts[wbNumInst]) {
5942292SN/A        ++wbNumInst;
5952820Sktlim@umich.edu        if (wbNumInst == wbWidth) {
5962292SN/A            ++wbCycle;
5972292SN/A            wbNumInst = 0;
5982292SN/A        }
5992292SN/A
6002353SN/A        assert((wbCycle * wbWidth + wbNumInst) <= wbMax);
6012292SN/A    }
6022292SN/A
6032353SN/A    DPRINTF(IEW, "Current wb cycle: %i, width: %i, numInst: %i\nwbActual:%i\n",
6042353SN/A            wbCycle, wbWidth, wbNumInst, wbCycle * wbWidth + wbNumInst);
6052292SN/A    // Add finished instruction to queue to commit.
6062292SN/A    (*iewQueue)[wbCycle].insts[wbNumInst] = inst;
6072292SN/A    (*iewQueue)[wbCycle].size++;
6082292SN/A}
6092292SN/A
6102292SN/Atemplate <class Impl>
6112292SN/Aunsigned
6122292SN/ADefaultIEW<Impl>::validInstsFromRename()
6132292SN/A{
6142292SN/A    unsigned inst_count = 0;
6152292SN/A
6162292SN/A    for (int i=0; i<fromRename->size; i++) {
6172731Sktlim@umich.edu        if (!fromRename->insts[i]->isSquashed())
6182292SN/A            inst_count++;
6192292SN/A    }
6202292SN/A
6212292SN/A    return inst_count;
6222292SN/A}
6232292SN/A
6242292SN/Atemplate<class Impl>
6252292SN/Avoid
6266221Snate@binkert.orgDefaultIEW<Impl>::skidInsert(ThreadID tid)
6272292SN/A{
6282292SN/A    DynInstPtr inst = NULL;
6292292SN/A
6302292SN/A    while (!insts[tid].empty()) {
6312292SN/A        inst = insts[tid].front();
6322292SN/A
6332292SN/A        insts[tid].pop();
6342292SN/A
6357720Sgblack@eecs.umich.edu        DPRINTF(Decode,"[tid:%i]: Inserting [sn:%lli] PC:%s into "
6362292SN/A                "dispatch skidBuffer %i\n",tid, inst->seqNum,
6377720Sgblack@eecs.umich.edu                inst->pcState(),tid);
6382292SN/A
6392292SN/A        skidBuffer[tid].push(inst);
6402292SN/A    }
6412292SN/A
6422292SN/A    assert(skidBuffer[tid].size() <= skidBufferMax &&
6432292SN/A           "Skidbuffer Exceeded Max Size");
6442292SN/A}
6452292SN/A
6462292SN/Atemplate<class Impl>
6472292SN/Aint
6482292SN/ADefaultIEW<Impl>::skidCount()
6492292SN/A{
6502292SN/A    int max=0;
6512292SN/A
6526221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6536221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6542292SN/A
6553867Sbinkertn@umich.edu    while (threads != end) {
6566221Snate@binkert.org        ThreadID tid = *threads++;
6573867Sbinkertn@umich.edu        unsigned thread_count = skidBuffer[tid].size();
6582292SN/A        if (max < thread_count)
6592292SN/A            max = thread_count;
6602292SN/A    }
6612292SN/A
6622292SN/A    return max;
6632292SN/A}
6642292SN/A
6652292SN/Atemplate<class Impl>
6662292SN/Abool
6672292SN/ADefaultIEW<Impl>::skidsEmpty()
6682292SN/A{
6696221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6706221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6712292SN/A
6723867Sbinkertn@umich.edu    while (threads != end) {
6736221Snate@binkert.org        ThreadID tid = *threads++;
6743867Sbinkertn@umich.edu
6753867Sbinkertn@umich.edu        if (!skidBuffer[tid].empty())
6762292SN/A            return false;
6772292SN/A    }
6782292SN/A
6792292SN/A    return true;
6801062SN/A}
6811062SN/A
6821681SN/Atemplate <class Impl>
6831062SN/Avoid
6842292SN/ADefaultIEW<Impl>::updateStatus()
6851062SN/A{
6862292SN/A    bool any_unblocking = false;
6871062SN/A
6886221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6896221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6901062SN/A
6913867Sbinkertn@umich.edu    while (threads != end) {
6926221Snate@binkert.org        ThreadID tid = *threads++;
6931062SN/A
6942292SN/A        if (dispatchStatus[tid] == Unblocking) {
6952292SN/A            any_unblocking = true;
6962292SN/A            break;
6972292SN/A        }
6982292SN/A    }
6991062SN/A
7002292SN/A    // If there are no ready instructions waiting to be scheduled by the IQ,
7012292SN/A    // and there's no stores waiting to write back, and dispatch is not
7022292SN/A    // unblocking, then there is no internal activity for the IEW stage.
7037897Shestness@cs.utexas.edu    instQueue.intInstQueueReads++;
7042292SN/A    if (_status == Active && !instQueue.hasReadyInsts() &&
7052292SN/A        !ldstQueue.willWB() && !any_unblocking) {
7062292SN/A        DPRINTF(IEW, "IEW switching to idle\n");
7071062SN/A
7082292SN/A        deactivateStage();
7091062SN/A
7102292SN/A        _status = Inactive;
7112292SN/A    } else if (_status == Inactive && (instQueue.hasReadyInsts() ||
7122292SN/A                                       ldstQueue.willWB() ||
7132292SN/A                                       any_unblocking)) {
7142292SN/A        // Otherwise there is internal activity.  Set to active.
7152292SN/A        DPRINTF(IEW, "IEW switching to active\n");
7161062SN/A
7172292SN/A        activateStage();
7181062SN/A
7192292SN/A        _status = Active;
7201062SN/A    }
7211062SN/A}
7221062SN/A
7231681SN/Atemplate <class Impl>
7241062SN/Avoid
7252292SN/ADefaultIEW<Impl>::resetEntries()
7261062SN/A{
7272292SN/A    instQueue.resetEntries();
7282292SN/A    ldstQueue.resetEntries();
7292292SN/A}
7301062SN/A
7312292SN/Atemplate <class Impl>
7322292SN/Avoid
7336221Snate@binkert.orgDefaultIEW<Impl>::readStallSignals(ThreadID tid)
7342292SN/A{
7352292SN/A    if (fromCommit->commitBlock[tid]) {
7362292SN/A        stalls[tid].commit = true;
7372292SN/A    }
7381062SN/A
7392292SN/A    if (fromCommit->commitUnblock[tid]) {
7402292SN/A        assert(stalls[tid].commit);
7412292SN/A        stalls[tid].commit = false;
7422292SN/A    }
7432292SN/A}
7442292SN/A
7452292SN/Atemplate <class Impl>
7462292SN/Abool
7476221Snate@binkert.orgDefaultIEW<Impl>::checkStall(ThreadID tid)
7482292SN/A{
7492292SN/A    bool ret_val(false);
7502292SN/A
7512292SN/A    if (stalls[tid].commit) {
7522292SN/A        DPRINTF(IEW,"[tid:%i]: Stall from Commit stage detected.\n",tid);
7532292SN/A        ret_val = true;
7542292SN/A    } else if (instQueue.isFull(tid)) {
7552292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: IQ  is full.\n",tid);
7562292SN/A        ret_val = true;
7572292SN/A    } else if (ldstQueue.isFull(tid)) {
7582292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: LSQ is full\n",tid);
7592292SN/A
7602292SN/A        if (ldstQueue.numLoads(tid) > 0 ) {
7612292SN/A
7622292SN/A            DPRINTF(IEW,"[tid:%i]: LSQ oldest load: [sn:%i] \n",
7632292SN/A                    tid,ldstQueue.getLoadHeadSeqNum(tid));
7642292SN/A        }
7652292SN/A
7662292SN/A        if (ldstQueue.numStores(tid) > 0) {
7672292SN/A
7682292SN/A            DPRINTF(IEW,"[tid:%i]: LSQ oldest store: [sn:%i] \n",
7692292SN/A                    tid,ldstQueue.getStoreHeadSeqNum(tid));
7702292SN/A        }
7712292SN/A
7722292SN/A        ret_val = true;
7732292SN/A    } else if (ldstQueue.isStalled(tid)) {
7742292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: LSQ stall detected.\n",tid);
7752292SN/A        ret_val = true;
7762292SN/A    }
7772292SN/A
7782292SN/A    return ret_val;
7792292SN/A}
7802292SN/A
7812292SN/Atemplate <class Impl>
7822292SN/Avoid
7836221Snate@binkert.orgDefaultIEW<Impl>::checkSignalsAndUpdate(ThreadID tid)
7842292SN/A{
7852292SN/A    // Check if there's a squash signal, squash if there is
7862292SN/A    // Check stall signals, block if there is.
7872292SN/A    // If status was Blocked
7882292SN/A    //     if so then go to unblocking
7892292SN/A    // If status was Squashing
7902292SN/A    //     check if squashing is not high.  Switch to running this cycle.
7912292SN/A
7922292SN/A    readStallSignals(tid);
7932292SN/A
7942292SN/A    if (fromCommit->commitInfo[tid].squash) {
7952292SN/A        squash(tid);
7962292SN/A
7972292SN/A        if (dispatchStatus[tid] == Blocked ||
7982292SN/A            dispatchStatus[tid] == Unblocking) {
7992292SN/A            toRename->iewUnblock[tid] = true;
8002292SN/A            wroteToTimeBuffer = true;
8012292SN/A        }
8022292SN/A
8032292SN/A        dispatchStatus[tid] = Squashing;
8042292SN/A        fetchRedirect[tid] = false;
8052292SN/A        return;
8062292SN/A    }
8072292SN/A
8082292SN/A    if (fromCommit->commitInfo[tid].robSquashing) {
8092702Sktlim@umich.edu        DPRINTF(IEW, "[tid:%i]: ROB is still squashing.\n", tid);
8102292SN/A
8112292SN/A        dispatchStatus[tid] = Squashing;
8122702Sktlim@umich.edu        emptyRenameInsts(tid);
8132702Sktlim@umich.edu        wroteToTimeBuffer = true;
8142292SN/A        return;
8152292SN/A    }
8162292SN/A
8172292SN/A    if (checkStall(tid)) {
8182292SN/A        block(tid);
8192292SN/A        dispatchStatus[tid] = Blocked;
8202292SN/A        return;
8212292SN/A    }
8222292SN/A
8232292SN/A    if (dispatchStatus[tid] == Blocked) {
8242292SN/A        // Status from previous cycle was blocked, but there are no more stall
8252292SN/A        // conditions.  Switch over to unblocking.
8262292SN/A        DPRINTF(IEW, "[tid:%i]: Done blocking, switching to unblocking.\n",
8272292SN/A                tid);
8282292SN/A
8292292SN/A        dispatchStatus[tid] = Unblocking;
8302292SN/A
8312292SN/A        unblock(tid);
8322292SN/A
8332292SN/A        return;
8342292SN/A    }
8352292SN/A
8362292SN/A    if (dispatchStatus[tid] == Squashing) {
8372292SN/A        // Switch status to running if rename isn't being told to block or
8382292SN/A        // squash this cycle.
8392292SN/A        DPRINTF(IEW, "[tid:%i]: Done squashing, switching to running.\n",
8402292SN/A                tid);
8412292SN/A
8422292SN/A        dispatchStatus[tid] = Running;
8432292SN/A
8442292SN/A        return;
8452292SN/A    }
8462292SN/A}
8472292SN/A
8482292SN/Atemplate <class Impl>
8492292SN/Avoid
8502292SN/ADefaultIEW<Impl>::sortInsts()
8512292SN/A{
8522292SN/A    int insts_from_rename = fromRename->size;
8532326SN/A#ifdef DEBUG
8546221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++)
8556221Snate@binkert.org        assert(insts[tid].empty());
8562326SN/A#endif
8572292SN/A    for (int i = 0; i < insts_from_rename; ++i) {
8582292SN/A        insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]);
8592292SN/A    }
8602292SN/A}
8612292SN/A
8622292SN/Atemplate <class Impl>
8632292SN/Avoid
8646221Snate@binkert.orgDefaultIEW<Impl>::emptyRenameInsts(ThreadID tid)
8652702Sktlim@umich.edu{
8664632Sgblack@eecs.umich.edu    DPRINTF(IEW, "[tid:%i]: Removing incoming rename instructions\n", tid);
8672935Sksewell@umich.edu
8682702Sktlim@umich.edu    while (!insts[tid].empty()) {
8692935Sksewell@umich.edu
8702702Sktlim@umich.edu        if (insts[tid].front()->isLoad() ||
8712702Sktlim@umich.edu            insts[tid].front()->isStore() ) {
8722702Sktlim@umich.edu            toRename->iewInfo[tid].dispatchedToLSQ++;
8732702Sktlim@umich.edu        }
8742702Sktlim@umich.edu
8752702Sktlim@umich.edu        toRename->iewInfo[tid].dispatched++;
8762702Sktlim@umich.edu
8772702Sktlim@umich.edu        insts[tid].pop();
8782702Sktlim@umich.edu    }
8792702Sktlim@umich.edu}
8802702Sktlim@umich.edu
8812702Sktlim@umich.edutemplate <class Impl>
8822702Sktlim@umich.eduvoid
8832292SN/ADefaultIEW<Impl>::wakeCPU()
8842292SN/A{
8852292SN/A    cpu->wakeCPU();
8862292SN/A}
8872292SN/A
8882292SN/Atemplate <class Impl>
8892292SN/Avoid
8902292SN/ADefaultIEW<Impl>::activityThisCycle()
8912292SN/A{
8922292SN/A    DPRINTF(Activity, "Activity this cycle.\n");
8932292SN/A    cpu->activityThisCycle();
8942292SN/A}
8952292SN/A
8962292SN/Atemplate <class Impl>
8972292SN/Ainline void
8982292SN/ADefaultIEW<Impl>::activateStage()
8992292SN/A{
9002292SN/A    DPRINTF(Activity, "Activating stage.\n");
9012733Sktlim@umich.edu    cpu->activateStage(O3CPU::IEWIdx);
9022292SN/A}
9032292SN/A
9042292SN/Atemplate <class Impl>
9052292SN/Ainline void
9062292SN/ADefaultIEW<Impl>::deactivateStage()
9072292SN/A{
9082292SN/A    DPRINTF(Activity, "Deactivating stage.\n");
9092733Sktlim@umich.edu    cpu->deactivateStage(O3CPU::IEWIdx);
9102292SN/A}
9112292SN/A
9122292SN/Atemplate<class Impl>
9132292SN/Avoid
9146221Snate@binkert.orgDefaultIEW<Impl>::dispatch(ThreadID tid)
9152292SN/A{
9162292SN/A    // If status is Running or idle,
9172292SN/A    //     call dispatchInsts()
9182292SN/A    // If status is Unblocking,
9192292SN/A    //     buffer any instructions coming from rename
9202292SN/A    //     continue trying to empty skid buffer
9212292SN/A    //     check if stall conditions have passed
9222292SN/A
9232292SN/A    if (dispatchStatus[tid] == Blocked) {
9242292SN/A        ++iewBlockCycles;
9252292SN/A
9262292SN/A    } else if (dispatchStatus[tid] == Squashing) {
9272292SN/A        ++iewSquashCycles;
9282292SN/A    }
9292292SN/A
9302292SN/A    // Dispatch should try to dispatch as many instructions as its bandwidth
9312292SN/A    // will allow, as long as it is not currently blocked.
9322292SN/A    if (dispatchStatus[tid] == Running ||
9332292SN/A        dispatchStatus[tid] == Idle) {
9342292SN/A        DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run "
9352292SN/A                "dispatch.\n", tid);
9362292SN/A
9372292SN/A        dispatchInsts(tid);
9382292SN/A    } else if (dispatchStatus[tid] == Unblocking) {
9392292SN/A        // Make sure that the skid buffer has something in it if the
9402292SN/A        // status is unblocking.
9412292SN/A        assert(!skidsEmpty());
9422292SN/A
9432292SN/A        // If the status was unblocking, then instructions from the skid
9442292SN/A        // buffer were used.  Remove those instructions and handle
9452292SN/A        // the rest of unblocking.
9462292SN/A        dispatchInsts(tid);
9472292SN/A
9482292SN/A        ++iewUnblockCycles;
9492292SN/A
9505215Sgblack@eecs.umich.edu        if (validInstsFromRename()) {
9512292SN/A            // Add the current inputs to the skid buffer so they can be
9522292SN/A            // reprocessed when this stage unblocks.
9532292SN/A            skidInsert(tid);
9542292SN/A        }
9552292SN/A
9562292SN/A        unblock(tid);
9572292SN/A    }
9582292SN/A}
9592292SN/A
9602292SN/Atemplate <class Impl>
9612292SN/Avoid
9626221Snate@binkert.orgDefaultIEW<Impl>::dispatchInsts(ThreadID tid)
9632292SN/A{
9642292SN/A    // Obtain instructions from skid buffer if unblocking, or queue from rename
9652292SN/A    // otherwise.
9662292SN/A    std::queue<DynInstPtr> &insts_to_dispatch =
9672292SN/A        dispatchStatus[tid] == Unblocking ?
9682292SN/A        skidBuffer[tid] : insts[tid];
9692292SN/A
9702292SN/A    int insts_to_add = insts_to_dispatch.size();
9712292SN/A
9722292SN/A    DynInstPtr inst;
9732292SN/A    bool add_to_iq = false;
9742292SN/A    int dis_num_inst = 0;
9752292SN/A
9762292SN/A    // Loop through the instructions, putting them in the instruction
9772292SN/A    // queue.
9782292SN/A    for ( ; dis_num_inst < insts_to_add &&
9792820Sktlim@umich.edu              dis_num_inst < dispatchWidth;
9802292SN/A          ++dis_num_inst)
9812292SN/A    {
9822292SN/A        inst = insts_to_dispatch.front();
9832292SN/A
9842292SN/A        if (dispatchStatus[tid] == Unblocking) {
9852292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Examining instruction from skid "
9862292SN/A                    "buffer\n", tid);
9872292SN/A        }
9882292SN/A
9892292SN/A        // Make sure there's a valid instruction there.
9902292SN/A        assert(inst);
9912292SN/A
9927720Sgblack@eecs.umich.edu        DPRINTF(IEW, "[tid:%i]: Issue: Adding PC %s [sn:%lli] [tid:%i] to "
9932292SN/A                "IQ.\n",
9947720Sgblack@eecs.umich.edu                tid, inst->pcState(), inst->seqNum, inst->threadNumber);
9952292SN/A
9962292SN/A        // Be sure to mark these instructions as ready so that the
9972292SN/A        // commit stage can go ahead and execute them, and mark
9982292SN/A        // them as issued so the IQ doesn't reprocess them.
9992292SN/A
10002292SN/A        // Check for squashed instructions.
10012292SN/A        if (inst->isSquashed()) {
10022292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Squashed instruction encountered, "
10032292SN/A                    "not adding to IQ.\n", tid);
10042292SN/A
10052292SN/A            ++iewDispSquashedInsts;
10062292SN/A
10072292SN/A            insts_to_dispatch.pop();
10082292SN/A
10092292SN/A            //Tell Rename That An Instruction has been processed
10102292SN/A            if (inst->isLoad() || inst->isStore()) {
10112292SN/A                toRename->iewInfo[tid].dispatchedToLSQ++;
10122292SN/A            }
10132292SN/A            toRename->iewInfo[tid].dispatched++;
10142292SN/A
10152292SN/A            continue;
10162292SN/A        }
10172292SN/A
10182292SN/A        // Check for full conditions.
10192292SN/A        if (instQueue.isFull(tid)) {
10202292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: IQ has become full.\n", tid);
10212292SN/A
10222292SN/A            // Call function to start blocking.
10232292SN/A            block(tid);
10242292SN/A
10252292SN/A            // Set unblock to false. Special case where we are using
10262292SN/A            // skidbuffer (unblocking) instructions but then we still
10272292SN/A            // get full in the IQ.
10282292SN/A            toRename->iewUnblock[tid] = false;
10292292SN/A
10302292SN/A            ++iewIQFullEvents;
10312292SN/A            break;
10322292SN/A        } else if (ldstQueue.isFull(tid)) {
10332292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: LSQ has become full.\n",tid);
10342292SN/A
10352292SN/A            // Call function to start blocking.
10362292SN/A            block(tid);
10372292SN/A
10382292SN/A            // Set unblock to false. Special case where we are using
10392292SN/A            // skidbuffer (unblocking) instructions but then we still
10402292SN/A            // get full in the IQ.
10412292SN/A            toRename->iewUnblock[tid] = false;
10422292SN/A
10432292SN/A            ++iewLSQFullEvents;
10442292SN/A            break;
10452292SN/A        }
10462292SN/A
10472292SN/A        // Otherwise issue the instruction just fine.
10482292SN/A        if (inst->isLoad()) {
10492292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction "
10502292SN/A                    "encountered, adding to LSQ.\n", tid);
10512292SN/A
10522292SN/A            // Reserve a spot in the load store queue for this
10532292SN/A            // memory access.
10542292SN/A            ldstQueue.insertLoad(inst);
10552292SN/A
10562292SN/A            ++iewDispLoadInsts;
10572292SN/A
10582292SN/A            add_to_iq = true;
10592292SN/A
10602292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
10612292SN/A        } else if (inst->isStore()) {
10622292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction "
10632292SN/A                    "encountered, adding to LSQ.\n", tid);
10642292SN/A
10652292SN/A            ldstQueue.insertStore(inst);
10662292SN/A
10672292SN/A            ++iewDispStoreInsts;
10682292SN/A
10692336SN/A            if (inst->isStoreConditional()) {
10702336SN/A                // Store conditionals need to be set as "canCommit()"
10712336SN/A                // so that commit can process them when they reach the
10722336SN/A                // head of commit.
10732348SN/A                // @todo: This is somewhat specific to Alpha.
10742292SN/A                inst->setCanCommit();
10752292SN/A                instQueue.insertNonSpec(inst);
10762292SN/A                add_to_iq = false;
10772292SN/A
10782292SN/A                ++iewDispNonSpecInsts;
10792292SN/A            } else {
10802292SN/A                add_to_iq = true;
10812292SN/A            }
10822292SN/A
10832292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
10842292SN/A        } else if (inst->isMemBarrier() || inst->isWriteBarrier()) {
10852326SN/A            // Same as non-speculative stores.
10862292SN/A            inst->setCanCommit();
10872292SN/A            instQueue.insertBarrier(inst);
10882292SN/A            add_to_iq = false;
10892292SN/A        } else if (inst->isNop()) {
10902292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Nop instruction encountered, "
10912292SN/A                    "skipping.\n", tid);
10922292SN/A
10932292SN/A            inst->setIssued();
10942292SN/A            inst->setExecuted();
10952292SN/A            inst->setCanCommit();
10962292SN/A
10972326SN/A            instQueue.recordProducer(inst);
10982292SN/A
10992727Sktlim@umich.edu            iewExecutedNop[tid]++;
11002301SN/A
11012292SN/A            add_to_iq = false;
11022292SN/A        } else if (inst->isExecuted()) {
11032292SN/A            assert(0 && "Instruction shouldn't be executed.\n");
11042292SN/A            DPRINTF(IEW, "Issue: Executed branch encountered, "
11052292SN/A                    "skipping.\n");
11062292SN/A
11072292SN/A            inst->setIssued();
11082292SN/A            inst->setCanCommit();
11092292SN/A
11102326SN/A            instQueue.recordProducer(inst);
11112292SN/A
11122292SN/A            add_to_iq = false;
11132292SN/A        } else {
11142292SN/A            add_to_iq = true;
11152292SN/A        }
11164033Sktlim@umich.edu        if (inst->isNonSpeculative()) {
11174033Sktlim@umich.edu            DPRINTF(IEW, "[tid:%i]: Issue: Nonspeculative instruction "
11184033Sktlim@umich.edu                    "encountered, skipping.\n", tid);
11194033Sktlim@umich.edu
11204033Sktlim@umich.edu            // Same as non-speculative stores.
11214033Sktlim@umich.edu            inst->setCanCommit();
11224033Sktlim@umich.edu
11234033Sktlim@umich.edu            // Specifically insert it as nonspeculative.
11244033Sktlim@umich.edu            instQueue.insertNonSpec(inst);
11254033Sktlim@umich.edu
11264033Sktlim@umich.edu            ++iewDispNonSpecInsts;
11274033Sktlim@umich.edu
11284033Sktlim@umich.edu            add_to_iq = false;
11294033Sktlim@umich.edu        }
11302292SN/A
11312292SN/A        // If the instruction queue is not full, then add the
11322292SN/A        // instruction.
11332292SN/A        if (add_to_iq) {
11342292SN/A            instQueue.insert(inst);
11352292SN/A        }
11362292SN/A
11372292SN/A        insts_to_dispatch.pop();
11382292SN/A
11392292SN/A        toRename->iewInfo[tid].dispatched++;
11402292SN/A
11412292SN/A        ++iewDispatchedInsts;
11422292SN/A    }
11432292SN/A
11442292SN/A    if (!insts_to_dispatch.empty()) {
11452935Sksewell@umich.edu        DPRINTF(IEW,"[tid:%i]: Issue: Bandwidth Full. Blocking.\n", tid);
11462292SN/A        block(tid);
11472292SN/A        toRename->iewUnblock[tid] = false;
11482292SN/A    }
11492292SN/A
11502292SN/A    if (dispatchStatus[tid] == Idle && dis_num_inst) {
11512292SN/A        dispatchStatus[tid] = Running;
11522292SN/A
11532292SN/A        updatedQueues = true;
11542292SN/A    }
11552292SN/A
11562292SN/A    dis_num_inst = 0;
11572292SN/A}
11582292SN/A
11592292SN/Atemplate <class Impl>
11602292SN/Avoid
11612292SN/ADefaultIEW<Impl>::printAvailableInsts()
11622292SN/A{
11632292SN/A    int inst = 0;
11642292SN/A
11652980Sgblack@eecs.umich.edu    std::cout << "Available Instructions: ";
11662292SN/A
11672292SN/A    while (fromIssue->insts[inst]) {
11682292SN/A
11692980Sgblack@eecs.umich.edu        if (inst%3==0) std::cout << "\n\t";
11702292SN/A
11717720Sgblack@eecs.umich.edu        std::cout << "PC: " << fromIssue->insts[inst]->pcState()
11722292SN/A             << " TN: " << fromIssue->insts[inst]->threadNumber
11732292SN/A             << " SN: " << fromIssue->insts[inst]->seqNum << " | ";
11742292SN/A
11752292SN/A        inst++;
11762292SN/A
11772292SN/A    }
11782292SN/A
11792980Sgblack@eecs.umich.edu    std::cout << "\n";
11802292SN/A}
11812292SN/A
11822292SN/Atemplate <class Impl>
11832292SN/Avoid
11842292SN/ADefaultIEW<Impl>::executeInsts()
11852292SN/A{
11862292SN/A    wbNumInst = 0;
11872292SN/A    wbCycle = 0;
11882292SN/A
11896221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
11906221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
11912292SN/A
11923867Sbinkertn@umich.edu    while (threads != end) {
11936221Snate@binkert.org        ThreadID tid = *threads++;
11942292SN/A        fetchRedirect[tid] = false;
11952292SN/A    }
11962292SN/A
11972698Sktlim@umich.edu    // Uncomment this if you want to see all available instructions.
11987599Sminkyu.jeong@arm.com    // @todo This doesn't actually work anymore, we should fix it.
11992698Sktlim@umich.edu//    printAvailableInsts();
12001062SN/A
12011062SN/A    // Execute/writeback any instructions that are available.
12022333SN/A    int insts_to_execute = fromIssue->size;
12032292SN/A    int inst_num = 0;
12042333SN/A    for (; inst_num < insts_to_execute;
12052326SN/A          ++inst_num) {
12061062SN/A
12072292SN/A        DPRINTF(IEW, "Execute: Executing instructions from IQ.\n");
12081062SN/A
12092333SN/A        DynInstPtr inst = instQueue.getInstToExecute();
12101062SN/A
12117720Sgblack@eecs.umich.edu        DPRINTF(IEW, "Execute: Processing PC %s, [tid:%i] [sn:%i].\n",
12127720Sgblack@eecs.umich.edu                inst->pcState(), inst->threadNumber,inst->seqNum);
12131062SN/A
12141062SN/A        // Check if the instruction is squashed; if so then skip it
12151062SN/A        if (inst->isSquashed()) {
12162292SN/A            DPRINTF(IEW, "Execute: Instruction was squashed.\n");
12171062SN/A
12181062SN/A            // Consider this instruction executed so that commit can go
12191062SN/A            // ahead and retire the instruction.
12201062SN/A            inst->setExecuted();
12211062SN/A
12222292SN/A            // Not sure if I should set this here or just let commit try to
12232292SN/A            // commit any squashed instructions.  I like the latter a bit more.
12242292SN/A            inst->setCanCommit();
12251062SN/A
12261062SN/A            ++iewExecSquashedInsts;
12271062SN/A
12282820Sktlim@umich.edu            decrWb(inst->seqNum);
12291062SN/A            continue;
12301062SN/A        }
12311062SN/A
12322292SN/A        Fault fault = NoFault;
12331062SN/A
12341062SN/A        // Execute instruction.
12351062SN/A        // Note that if the instruction faults, it will be handled
12361062SN/A        // at the commit stage.
12377850SMatt.Horsnell@arm.com        if (inst->isMemRef()) {
12382292SN/A            DPRINTF(IEW, "Execute: Calculating address for memory "
12391062SN/A                    "reference.\n");
12401062SN/A
12411062SN/A            // Tell the LDSTQ to execute this instruction (if it is a load).
12421062SN/A            if (inst->isLoad()) {
12432292SN/A                // Loads will mark themselves as executed, and their writeback
12442292SN/A                // event adds the instruction to the queue to commit
12452292SN/A                fault = ldstQueue.executeLoad(inst);
12467944SGiacomo.Gabrielli@arm.com
12477944SGiacomo.Gabrielli@arm.com                if (inst->isTranslationDelayed() &&
12487944SGiacomo.Gabrielli@arm.com                    fault == NoFault) {
12497944SGiacomo.Gabrielli@arm.com                    // A hw page table walk is currently going on; the
12507944SGiacomo.Gabrielli@arm.com                    // instruction must be deferred.
12517944SGiacomo.Gabrielli@arm.com                    DPRINTF(IEW, "Execute: Delayed translation, deferring "
12527944SGiacomo.Gabrielli@arm.com                            "load.\n");
12537944SGiacomo.Gabrielli@arm.com                    instQueue.deferMemInst(inst);
12547944SGiacomo.Gabrielli@arm.com                    continue;
12557944SGiacomo.Gabrielli@arm.com                }
12567944SGiacomo.Gabrielli@arm.com
12577850SMatt.Horsnell@arm.com                if (inst->isDataPrefetch() || inst->isInstPrefetch()) {
12588073SAli.Saidi@ARM.com                    inst->fault = NoFault;
12597850SMatt.Horsnell@arm.com                }
12601062SN/A            } else if (inst->isStore()) {
12612367SN/A                fault = ldstQueue.executeStore(inst);
12621062SN/A
12637944SGiacomo.Gabrielli@arm.com                if (inst->isTranslationDelayed() &&
12647944SGiacomo.Gabrielli@arm.com                    fault == NoFault) {
12657944SGiacomo.Gabrielli@arm.com                    // A hw page table walk is currently going on; the
12667944SGiacomo.Gabrielli@arm.com                    // instruction must be deferred.
12677944SGiacomo.Gabrielli@arm.com                    DPRINTF(IEW, "Execute: Delayed translation, deferring "
12687944SGiacomo.Gabrielli@arm.com                            "store.\n");
12697944SGiacomo.Gabrielli@arm.com                    instQueue.deferMemInst(inst);
12707944SGiacomo.Gabrielli@arm.com                    continue;
12717944SGiacomo.Gabrielli@arm.com                }
12727944SGiacomo.Gabrielli@arm.com
12732292SN/A                // If the store had a fault then it may not have a mem req
12747782Sminkyu.jeong@arm.com                if (fault != NoFault || inst->readPredicate() == false ||
12757782Sminkyu.jeong@arm.com                        !inst->isStoreConditional()) {
12767782Sminkyu.jeong@arm.com                    // If the instruction faulted, then we need to send it along
12777782Sminkyu.jeong@arm.com                    // to commit without the instruction completing.
12782367SN/A                    // Send this instruction to commit, also make sure iew stage
12792367SN/A                    // realizes there is activity.
12802367SN/A                    inst->setExecuted();
12812367SN/A                    instToCommit(inst);
12822367SN/A                    activityThisCycle();
12832292SN/A                }
12842326SN/A
12852326SN/A                // Store conditionals will mark themselves as
12862326SN/A                // executed, and their writeback event will add the
12872326SN/A                // instruction to the queue to commit.
12881062SN/A            } else {
12892292SN/A                panic("Unexpected memory type!\n");
12901062SN/A            }
12911062SN/A
12921062SN/A        } else {
12937847Sminkyu.jeong@arm.com            // If the instruction has already faulted, then skip executing it.
12947847Sminkyu.jeong@arm.com            // Such case can happen when it faulted during ITLB translation.
12957847Sminkyu.jeong@arm.com            // If we execute the instruction (even if it's a nop) the fault
12967847Sminkyu.jeong@arm.com            // will be replaced and we will lose it.
12977847Sminkyu.jeong@arm.com            if (inst->getFault() == NoFault) {
12987847Sminkyu.jeong@arm.com                inst->execute();
12997848SAli.Saidi@ARM.com                if (inst->readPredicate() == false)
13007848SAli.Saidi@ARM.com                    inst->forwardOldRegs();
13017847Sminkyu.jeong@arm.com            }
13021062SN/A
13032292SN/A            inst->setExecuted();
13042292SN/A
13052292SN/A            instToCommit(inst);
13061062SN/A        }
13071062SN/A
13082301SN/A        updateExeInstStats(inst);
13091681SN/A
13102326SN/A        // Check if branch prediction was correct, if not then we need
13112326SN/A        // to tell commit to squash in flight instructions.  Only
13122326SN/A        // handle this if there hasn't already been something that
13132107SN/A        // redirects fetch in this group of instructions.
13141681SN/A
13152292SN/A        // This probably needs to prioritize the redirects if a different
13162292SN/A        // scheduler is used.  Currently the scheduler schedules the oldest
13172292SN/A        // instruction first, so the branch resolution order will be correct.
13186221Snate@binkert.org        ThreadID tid = inst->threadNumber;
13191062SN/A
13203732Sktlim@umich.edu        if (!fetchRedirect[tid] ||
13217852SMatt.Horsnell@arm.com            !toCommit->squash[tid] ||
13223732Sktlim@umich.edu            toCommit->squashedSeqNum[tid] > inst->seqNum) {
13231062SN/A
13247856SMatt.Horsnell@arm.com            // Prevent testing for misprediction on load instructions,
13257856SMatt.Horsnell@arm.com            // that have not been executed.
13267856SMatt.Horsnell@arm.com            bool loadNotExecuted = !inst->isExecuted() && inst->isLoad();
13277856SMatt.Horsnell@arm.com
13287856SMatt.Horsnell@arm.com            if (inst->mispredicted() && !loadNotExecuted) {
13292292SN/A                fetchRedirect[tid] = true;
13301062SN/A
13312292SN/A                DPRINTF(IEW, "Execute: Branch mispredict detected.\n");
13326036Sksewell@umich.edu                DPRINTF(IEW, "Predicted target was PC:%#x, NPC:%#x.\n",
13337720Sgblack@eecs.umich.edu                        inst->predInstAddr(), inst->predNextInstAddr());
13347720Sgblack@eecs.umich.edu                DPRINTF(IEW, "Execute: Redirecting fetch to PC: %s.\n",
13357720Sgblack@eecs.umich.edu                        inst->pcState(), inst->nextInstAddr());
13361062SN/A                // If incorrect, then signal the ROB that it must be squashed.
13372292SN/A                squashDueToBranch(inst, tid);
13381062SN/A
13393795Sgblack@eecs.umich.edu                if (inst->readPredTaken()) {
13401062SN/A                    predictedTakenIncorrect++;
13412292SN/A                } else {
13422292SN/A                    predictedNotTakenIncorrect++;
13431062SN/A                }
13442292SN/A            } else if (ldstQueue.violation(tid)) {
13454033Sktlim@umich.edu                assert(inst->isMemRef());
13462326SN/A                // If there was an ordering violation, then get the
13472326SN/A                // DynInst that caused the violation.  Note that this
13482292SN/A                // clears the violation signal.
13492292SN/A                DynInstPtr violator;
13502292SN/A                violator = ldstQueue.getMemDepViolator(tid);
13511062SN/A
13527720Sgblack@eecs.umich.edu                DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: %s "
13537720Sgblack@eecs.umich.edu                        "[sn:%lli], inst PC: %s [sn:%lli]. Addr is: %#x.\n",
13547720Sgblack@eecs.umich.edu                        violator->pcState(), violator->seqNum,
13557720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum, inst->physEffAddr);
13567720Sgblack@eecs.umich.edu
13573732Sktlim@umich.edu                fetchRedirect[tid] = true;
13583732Sktlim@umich.edu
13591062SN/A                // Tell the instruction queue that a violation has occured.
13601062SN/A                instQueue.violation(inst, violator);
13611062SN/A
13621062SN/A                // Squash.
13632292SN/A                squashDueToMemOrder(inst,tid);
13641062SN/A
13651062SN/A                ++memOrderViolationEvents;
13662292SN/A            } else if (ldstQueue.loadBlocked(tid) &&
13672292SN/A                       !ldstQueue.isLoadBlockedHandled(tid)) {
13682292SN/A                fetchRedirect[tid] = true;
13692292SN/A
13702292SN/A                DPRINTF(IEW, "Load operation couldn't execute because the "
13717720Sgblack@eecs.umich.edu                        "memory system is blocked.  PC: %s [sn:%lli]\n",
13727720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum);
13732292SN/A
13742292SN/A                squashDueToMemBlocked(inst, tid);
13751062SN/A            }
13764033Sktlim@umich.edu        } else {
13774033Sktlim@umich.edu            // Reset any state associated with redirects that will not
13784033Sktlim@umich.edu            // be used.
13794033Sktlim@umich.edu            if (ldstQueue.violation(tid)) {
13804033Sktlim@umich.edu                assert(inst->isMemRef());
13814033Sktlim@umich.edu
13824033Sktlim@umich.edu                DynInstPtr violator = ldstQueue.getMemDepViolator(tid);
13834033Sktlim@umich.edu
13844033Sktlim@umich.edu                DPRINTF(IEW, "LDSTQ detected a violation.  Violator PC: "
13857720Sgblack@eecs.umich.edu                        "%s, inst PC: %s.  Addr is: %#x.\n",
13867720Sgblack@eecs.umich.edu                        violator->pcState(), inst->pcState(),
13877720Sgblack@eecs.umich.edu                        inst->physEffAddr);
13884033Sktlim@umich.edu                DPRINTF(IEW, "Violation will not be handled because "
13894033Sktlim@umich.edu                        "already squashing\n");
13904033Sktlim@umich.edu
13914033Sktlim@umich.edu                ++memOrderViolationEvents;
13924033Sktlim@umich.edu            }
13934033Sktlim@umich.edu            if (ldstQueue.loadBlocked(tid) &&
13944033Sktlim@umich.edu                !ldstQueue.isLoadBlockedHandled(tid)) {
13954033Sktlim@umich.edu                DPRINTF(IEW, "Load operation couldn't execute because the "
13967720Sgblack@eecs.umich.edu                        "memory system is blocked.  PC: %s [sn:%lli]\n",
13977720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum);
13984033Sktlim@umich.edu                DPRINTF(IEW, "Blocked load will not be handled because "
13994033Sktlim@umich.edu                        "already squashing\n");
14004033Sktlim@umich.edu
14014033Sktlim@umich.edu                ldstQueue.setLoadBlockedHandled(tid);
14024033Sktlim@umich.edu            }
14034033Sktlim@umich.edu
14041062SN/A        }
14051062SN/A    }
14062292SN/A
14072348SN/A    // Update and record activity if we processed any instructions.
14082292SN/A    if (inst_num) {
14092292SN/A        if (exeStatus == Idle) {
14102292SN/A            exeStatus = Running;
14112292SN/A        }
14122292SN/A
14132292SN/A        updatedQueues = true;
14142292SN/A
14152292SN/A        cpu->activityThisCycle();
14162292SN/A    }
14172292SN/A
14182292SN/A    // Need to reset this in case a writeback event needs to write into the
14192292SN/A    // iew queue.  That way the writeback event will write into the correct
14202292SN/A    // spot in the queue.
14212292SN/A    wbNumInst = 0;
14227852SMatt.Horsnell@arm.com
14232107SN/A}
14242107SN/A
14252292SN/Atemplate <class Impl>
14262107SN/Avoid
14272292SN/ADefaultIEW<Impl>::writebackInsts()
14282107SN/A{
14292326SN/A    // Loop through the head of the time buffer and wake any
14302326SN/A    // dependents.  These instructions are about to write back.  Also
14312326SN/A    // mark scoreboard that this instruction is finally complete.
14322326SN/A    // Either have IEW have direct access to scoreboard, or have this
14332326SN/A    // as part of backwards communication.
14343958Sgblack@eecs.umich.edu    for (int inst_num = 0; inst_num < wbWidth &&
14352292SN/A             toCommit->insts[inst_num]; inst_num++) {
14362107SN/A        DynInstPtr inst = toCommit->insts[inst_num];
14376221Snate@binkert.org        ThreadID tid = inst->threadNumber;
14382107SN/A
14397720Sgblack@eecs.umich.edu        DPRINTF(IEW, "Sending instructions to commit, [sn:%lli] PC %s.\n",
14407720Sgblack@eecs.umich.edu                inst->seqNum, inst->pcState());
14412107SN/A
14422301SN/A        iewInstsToCommit[tid]++;
14432301SN/A
14442292SN/A        // Some instructions will be sent to commit without having
14452292SN/A        // executed because they need commit to handle them.
14462292SN/A        // E.g. Uncached loads have not actually executed when they
14472292SN/A        // are first sent to commit.  Instead commit must tell the LSQ
14482292SN/A        // when it's ready to execute the uncached load.
14492367SN/A        if (!inst->isSquashed() && inst->isExecuted() && inst->getFault() == NoFault) {
14502301SN/A            int dependents = instQueue.wakeDependents(inst);
14512107SN/A
14522292SN/A            for (int i = 0; i < inst->numDestRegs(); i++) {
14532292SN/A                //mark as Ready
14542292SN/A                DPRINTF(IEW,"Setting Destination Register %i\n",
14552292SN/A                        inst->renamedDestRegIdx(i));
14562292SN/A                scoreboard->setReg(inst->renamedDestRegIdx(i));
14572107SN/A            }
14582301SN/A
14592348SN/A            if (dependents) {
14602348SN/A                producerInst[tid]++;
14612348SN/A                consumerInst[tid]+= dependents;
14622348SN/A            }
14632326SN/A            writebackCount[tid]++;
14642107SN/A        }
14652820Sktlim@umich.edu
14662820Sktlim@umich.edu        decrWb(inst->seqNum);
14672107SN/A    }
14681060SN/A}
14691060SN/A
14701681SN/Atemplate<class Impl>
14711060SN/Avoid
14722292SN/ADefaultIEW<Impl>::tick()
14731060SN/A{
14742292SN/A    wbNumInst = 0;
14752292SN/A    wbCycle = 0;
14761060SN/A
14772292SN/A    wroteToTimeBuffer = false;
14782292SN/A    updatedQueues = false;
14791060SN/A
14802292SN/A    sortInsts();
14811060SN/A
14822326SN/A    // Free function units marked as being freed this cycle.
14832326SN/A    fuPool->processFreeUnits();
14841062SN/A
14856221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
14866221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
14871060SN/A
14882326SN/A    // Check stall and squash signals, dispatch any instructions.
14893867Sbinkertn@umich.edu    while (threads != end) {
14906221Snate@binkert.org        ThreadID tid = *threads++;
14911060SN/A
14922292SN/A        DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid);
14931060SN/A
14942292SN/A        checkSignalsAndUpdate(tid);
14952292SN/A        dispatch(tid);
14961060SN/A    }
14971060SN/A
14982292SN/A    if (exeStatus != Squashing) {
14992292SN/A        executeInsts();
15001060SN/A
15012292SN/A        writebackInsts();
15022292SN/A
15032292SN/A        // Have the instruction queue try to schedule any ready instructions.
15042292SN/A        // (In actuality, this scheduling is for instructions that will
15052292SN/A        // be executed next cycle.)
15062292SN/A        instQueue.scheduleReadyInsts();
15072292SN/A
15082292SN/A        // Also should advance its own time buffers if the stage ran.
15092292SN/A        // Not the best place for it, but this works (hopefully).
15102292SN/A        issueToExecQueue.advance();
15112292SN/A    }
15122292SN/A
15132292SN/A    bool broadcast_free_entries = false;
15142292SN/A
15152292SN/A    if (updatedQueues || exeStatus == Running || updateLSQNextCycle) {
15162292SN/A        exeStatus = Idle;
15172292SN/A        updateLSQNextCycle = false;
15182292SN/A
15192292SN/A        broadcast_free_entries = true;
15202292SN/A    }
15212292SN/A
15222292SN/A    // Writeback any stores using any leftover bandwidth.
15231681SN/A    ldstQueue.writebackStores();
15241681SN/A
15251061SN/A    // Check the committed load/store signals to see if there's a load
15261061SN/A    // or store to commit.  Also check if it's being told to execute a
15271061SN/A    // nonspeculative instruction.
15281681SN/A    // This is pretty inefficient...
15292292SN/A
15303867Sbinkertn@umich.edu    threads = activeThreads->begin();
15313867Sbinkertn@umich.edu    while (threads != end) {
15326221Snate@binkert.org        ThreadID tid = (*threads++);
15332292SN/A
15342292SN/A        DPRINTF(IEW,"Processing [tid:%i]\n",tid);
15352292SN/A
15362348SN/A        // Update structures based on instructions committed.
15372292SN/A        if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
15382292SN/A            !fromCommit->commitInfo[tid].squash &&
15392292SN/A            !fromCommit->commitInfo[tid].robSquashing) {
15402292SN/A
15412292SN/A            ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid);
15422292SN/A
15432292SN/A            ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid);
15442292SN/A
15452292SN/A            updateLSQNextCycle = true;
15462292SN/A            instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid);
15472292SN/A        }
15482292SN/A
15492292SN/A        if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) {
15502292SN/A
15512292SN/A            //DPRINTF(IEW,"NonspecInst from thread %i",tid);
15522292SN/A            if (fromCommit->commitInfo[tid].uncached) {
15532292SN/A                instQueue.replayMemInst(fromCommit->commitInfo[tid].uncachedLoad);
15544033Sktlim@umich.edu                fromCommit->commitInfo[tid].uncachedLoad->setAtCommit();
15552292SN/A            } else {
15562292SN/A                instQueue.scheduleNonSpec(
15572292SN/A                    fromCommit->commitInfo[tid].nonSpecSeqNum);
15582292SN/A            }
15592292SN/A        }
15602292SN/A
15612292SN/A        if (broadcast_free_entries) {
15622292SN/A            toFetch->iewInfo[tid].iqCount =
15632292SN/A                instQueue.getCount(tid);
15642292SN/A            toFetch->iewInfo[tid].ldstqCount =
15652292SN/A                ldstQueue.getCount(tid);
15662292SN/A
15672292SN/A            toRename->iewInfo[tid].usedIQ = true;
15682292SN/A            toRename->iewInfo[tid].freeIQEntries =
15692292SN/A                instQueue.numFreeEntries();
15702292SN/A            toRename->iewInfo[tid].usedLSQ = true;
15712292SN/A            toRename->iewInfo[tid].freeLSQEntries =
15722292SN/A                ldstQueue.numFreeEntries(tid);
15732292SN/A
15742292SN/A            wroteToTimeBuffer = true;
15752292SN/A        }
15762292SN/A
15772292SN/A        DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n",
15782292SN/A                tid, toRename->iewInfo[tid].dispatched);
15791061SN/A    }
15801061SN/A
15812292SN/A    DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i).  "
15822292SN/A            "LSQ has %i free entries.\n",
15832292SN/A            instQueue.numFreeEntries(), instQueue.hasReadyInsts(),
15842292SN/A            ldstQueue.numFreeEntries());
15852292SN/A
15862292SN/A    updateStatus();
15872292SN/A
15882292SN/A    if (wroteToTimeBuffer) {
15892292SN/A        DPRINTF(Activity, "Activity this cycle.\n");
15902292SN/A        cpu->activityThisCycle();
15911061SN/A    }
15921060SN/A}
15931060SN/A
15942301SN/Atemplate <class Impl>
15951060SN/Avoid
15962301SN/ADefaultIEW<Impl>::updateExeInstStats(DynInstPtr &inst)
15971060SN/A{
15986221Snate@binkert.org    ThreadID tid = inst->threadNumber;
15991060SN/A
16002301SN/A    //
16012301SN/A    //  Pick off the software prefetches
16022301SN/A    //
16032301SN/A#ifdef TARGET_ALPHA
16042301SN/A    if (inst->isDataPrefetch())
16056221Snate@binkert.org        iewExecutedSwp[tid]++;
16062301SN/A    else
16072727Sktlim@umich.edu        iewIewExecutedcutedInsts++;
16082301SN/A#else
16092669Sktlim@umich.edu    iewExecutedInsts++;
16102301SN/A#endif
16111060SN/A
16122301SN/A    //
16132301SN/A    //  Control operations
16142301SN/A    //
16152301SN/A    if (inst->isControl())
16166221Snate@binkert.org        iewExecutedBranches[tid]++;
16171060SN/A
16182301SN/A    //
16192301SN/A    //  Memory operations
16202301SN/A    //
16212301SN/A    if (inst->isMemRef()) {
16226221Snate@binkert.org        iewExecutedRefs[tid]++;
16231060SN/A
16242301SN/A        if (inst->isLoad()) {
16256221Snate@binkert.org            iewExecLoadInsts[tid]++;
16261060SN/A        }
16271060SN/A    }
16281060SN/A}
16297598Sminkyu.jeong@arm.com
16307598Sminkyu.jeong@arm.comtemplate <class Impl>
16317598Sminkyu.jeong@arm.comvoid
16327598Sminkyu.jeong@arm.comDefaultIEW<Impl>::checkMisprediction(DynInstPtr &inst)
16337598Sminkyu.jeong@arm.com{
16347598Sminkyu.jeong@arm.com    ThreadID tid = inst->threadNumber;
16357598Sminkyu.jeong@arm.com
16367598Sminkyu.jeong@arm.com    if (!fetchRedirect[tid] ||
16377852SMatt.Horsnell@arm.com        !toCommit->squash[tid] ||
16387598Sminkyu.jeong@arm.com        toCommit->squashedSeqNum[tid] > inst->seqNum) {
16397598Sminkyu.jeong@arm.com
16407598Sminkyu.jeong@arm.com        if (inst->mispredicted()) {
16417598Sminkyu.jeong@arm.com            fetchRedirect[tid] = true;
16427598Sminkyu.jeong@arm.com
16437598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Execute: Branch mispredict detected.\n");
16447598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Predicted target was PC:%#x, NPC:%#x.\n",
16457720Sgblack@eecs.umich.edu                    inst->predInstAddr(), inst->predNextInstAddr());
16467598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Execute: Redirecting fetch to PC: %#x,"
16477720Sgblack@eecs.umich.edu                    " NPC: %#x.\n", inst->nextInstAddr(),
16487720Sgblack@eecs.umich.edu                    inst->nextInstAddr());
16497598Sminkyu.jeong@arm.com            // If incorrect, then signal the ROB that it must be squashed.
16507598Sminkyu.jeong@arm.com            squashDueToBranch(inst, tid);
16517598Sminkyu.jeong@arm.com
16527598Sminkyu.jeong@arm.com            if (inst->readPredTaken()) {
16537598Sminkyu.jeong@arm.com                predictedTakenIncorrect++;
16547598Sminkyu.jeong@arm.com            } else {
16557598Sminkyu.jeong@arm.com                predictedNotTakenIncorrect++;
16567598Sminkyu.jeong@arm.com            }
16577598Sminkyu.jeong@arm.com        }
16587598Sminkyu.jeong@arm.com    }
16597598Sminkyu.jeong@arm.com}
1660