iew_impl.hh revision 7850
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
497813Ssteve.reinhardt@amd.com#include "cpu/timebuf.hh"
506658Snate@binkert.org#include "config/the_isa.hh"
512292SN/A#include "cpu/o3/fu_pool.hh"
521717SN/A#include "cpu/o3/iew.hh"
535529Snate@binkert.org#include "params/DerivO3CPU.hh"
541060SN/A
556221Snate@binkert.orgusing namespace std;
566221Snate@binkert.org
571681SN/Atemplate<class Impl>
585529Snate@binkert.orgDefaultIEW<Impl>::DefaultIEW(O3CPU *_cpu, DerivO3CPUParams *params)
592873Sktlim@umich.edu    : issueToExecQueue(params->backComSize, params->forwardComSize),
604329Sktlim@umich.edu      cpu(_cpu),
614329Sktlim@umich.edu      instQueue(_cpu, this, params),
624329Sktlim@umich.edu      ldstQueue(_cpu, this, params),
632292SN/A      fuPool(params->fuPool),
642292SN/A      commitToIEWDelay(params->commitToIEWDelay),
652292SN/A      renameToIEWDelay(params->renameToIEWDelay),
662292SN/A      issueToExecuteDelay(params->issueToExecuteDelay),
672820Sktlim@umich.edu      dispatchWidth(params->dispatchWidth),
682292SN/A      issueWidth(params->issueWidth),
692820Sktlim@umich.edu      wbOutstanding(0),
702820Sktlim@umich.edu      wbWidth(params->wbWidth),
715529Snate@binkert.org      numThreads(params->numThreads),
722307SN/A      switchedOut(false)
731060SN/A{
742292SN/A    _status = Active;
752292SN/A    exeStatus = Running;
762292SN/A    wbStatus = Idle;
771060SN/A
781060SN/A    // Setup wire to read instructions coming from issue.
791060SN/A    fromIssue = issueToExecQueue.getWire(-issueToExecuteDelay);
801060SN/A
811060SN/A    // Instruction queue needs the queue between issue and execute.
821060SN/A    instQueue.setIssueToExecuteQueue(&issueToExecQueue);
831681SN/A
846221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
856221Snate@binkert.org        dispatchStatus[tid] = Running;
866221Snate@binkert.org        stalls[tid].commit = false;
876221Snate@binkert.org        fetchRedirect[tid] = false;
882292SN/A    }
892292SN/A
902820Sktlim@umich.edu    wbMax = wbWidth * params->wbDepth;
912820Sktlim@umich.edu
922292SN/A    updateLSQNextCycle = false;
932292SN/A
942820Sktlim@umich.edu    ableToIssue = true;
952820Sktlim@umich.edu
962292SN/A    skidBufferMax = (3 * (renameToIEWDelay * params->renameWidth)) + issueWidth;
972292SN/A}
982292SN/A
992292SN/Atemplate <class Impl>
1002292SN/Astd::string
1012292SN/ADefaultIEW<Impl>::name() const
1022292SN/A{
1032292SN/A    return cpu->name() + ".iew";
1041060SN/A}
1051060SN/A
1061681SN/Atemplate <class Impl>
1071062SN/Avoid
1082292SN/ADefaultIEW<Impl>::regStats()
1091062SN/A{
1102301SN/A    using namespace Stats;
1112301SN/A
1121062SN/A    instQueue.regStats();
1132727Sktlim@umich.edu    ldstQueue.regStats();
1141062SN/A
1151062SN/A    iewIdleCycles
1161062SN/A        .name(name() + ".iewIdleCycles")
1171062SN/A        .desc("Number of cycles IEW is idle");
1181062SN/A
1191062SN/A    iewSquashCycles
1201062SN/A        .name(name() + ".iewSquashCycles")
1211062SN/A        .desc("Number of cycles IEW is squashing");
1221062SN/A
1231062SN/A    iewBlockCycles
1241062SN/A        .name(name() + ".iewBlockCycles")
1251062SN/A        .desc("Number of cycles IEW is blocking");
1261062SN/A
1271062SN/A    iewUnblockCycles
1281062SN/A        .name(name() + ".iewUnblockCycles")
1291062SN/A        .desc("Number of cycles IEW is unblocking");
1301062SN/A
1311062SN/A    iewDispatchedInsts
1321062SN/A        .name(name() + ".iewDispatchedInsts")
1331062SN/A        .desc("Number of instructions dispatched to IQ");
1341062SN/A
1351062SN/A    iewDispSquashedInsts
1361062SN/A        .name(name() + ".iewDispSquashedInsts")
1371062SN/A        .desc("Number of squashed instructions skipped by dispatch");
1381062SN/A
1391062SN/A    iewDispLoadInsts
1401062SN/A        .name(name() + ".iewDispLoadInsts")
1411062SN/A        .desc("Number of dispatched load instructions");
1421062SN/A
1431062SN/A    iewDispStoreInsts
1441062SN/A        .name(name() + ".iewDispStoreInsts")
1451062SN/A        .desc("Number of dispatched store instructions");
1461062SN/A
1471062SN/A    iewDispNonSpecInsts
1481062SN/A        .name(name() + ".iewDispNonSpecInsts")
1491062SN/A        .desc("Number of dispatched non-speculative instructions");
1501062SN/A
1511062SN/A    iewIQFullEvents
1521062SN/A        .name(name() + ".iewIQFullEvents")
1531062SN/A        .desc("Number of times the IQ has become full, causing a stall");
1541062SN/A
1552292SN/A    iewLSQFullEvents
1562292SN/A        .name(name() + ".iewLSQFullEvents")
1572292SN/A        .desc("Number of times the LSQ has become full, causing a stall");
1582292SN/A
1591062SN/A    memOrderViolationEvents
1601062SN/A        .name(name() + ".memOrderViolationEvents")
1611062SN/A        .desc("Number of memory order violations");
1621062SN/A
1631062SN/A    predictedTakenIncorrect
1641062SN/A        .name(name() + ".predictedTakenIncorrect")
1651062SN/A        .desc("Number of branches that were predicted taken incorrectly");
1662292SN/A
1672292SN/A    predictedNotTakenIncorrect
1682292SN/A        .name(name() + ".predictedNotTakenIncorrect")
1692292SN/A        .desc("Number of branches that were predicted not taken incorrectly");
1702292SN/A
1712292SN/A    branchMispredicts
1722292SN/A        .name(name() + ".branchMispredicts")
1732292SN/A        .desc("Number of branch mispredicts detected at execute");
1742292SN/A
1752292SN/A    branchMispredicts = predictedTakenIncorrect + predictedNotTakenIncorrect;
1762301SN/A
1772727Sktlim@umich.edu    iewExecutedInsts
1782353SN/A        .name(name() + ".iewExecutedInsts")
1792727Sktlim@umich.edu        .desc("Number of executed instructions");
1802727Sktlim@umich.edu
1812727Sktlim@umich.edu    iewExecLoadInsts
1826221Snate@binkert.org        .init(cpu->numThreads)
1832353SN/A        .name(name() + ".iewExecLoadInsts")
1842727Sktlim@umich.edu        .desc("Number of load instructions executed")
1852727Sktlim@umich.edu        .flags(total);
1862727Sktlim@umich.edu
1872727Sktlim@umich.edu    iewExecSquashedInsts
1882353SN/A        .name(name() + ".iewExecSquashedInsts")
1892727Sktlim@umich.edu        .desc("Number of squashed instructions skipped in execute");
1902727Sktlim@umich.edu
1912727Sktlim@umich.edu    iewExecutedSwp
1926221Snate@binkert.org        .init(cpu->numThreads)
1932301SN/A        .name(name() + ".EXEC:swp")
1942301SN/A        .desc("number of swp insts executed")
1952727Sktlim@umich.edu        .flags(total);
1962301SN/A
1972727Sktlim@umich.edu    iewExecutedNop
1986221Snate@binkert.org        .init(cpu->numThreads)
1992301SN/A        .name(name() + ".EXEC:nop")
2002301SN/A        .desc("number of nop insts executed")
2012727Sktlim@umich.edu        .flags(total);
2022301SN/A
2032727Sktlim@umich.edu    iewExecutedRefs
2046221Snate@binkert.org        .init(cpu->numThreads)
2052301SN/A        .name(name() + ".EXEC:refs")
2062301SN/A        .desc("number of memory reference insts executed")
2072727Sktlim@umich.edu        .flags(total);
2082301SN/A
2092727Sktlim@umich.edu    iewExecutedBranches
2106221Snate@binkert.org        .init(cpu->numThreads)
2112301SN/A        .name(name() + ".EXEC:branches")
2122301SN/A        .desc("Number of branches executed")
2132727Sktlim@umich.edu        .flags(total);
2142301SN/A
2152301SN/A    iewExecStoreInsts
2162301SN/A        .name(name() + ".EXEC:stores")
2172301SN/A        .desc("Number of stores executed")
2182727Sktlim@umich.edu        .flags(total);
2192727Sktlim@umich.edu    iewExecStoreInsts = iewExecutedRefs - iewExecLoadInsts;
2202727Sktlim@umich.edu
2212727Sktlim@umich.edu    iewExecRate
2222727Sktlim@umich.edu        .name(name() + ".EXEC:rate")
2232727Sktlim@umich.edu        .desc("Inst execution rate")
2242727Sktlim@umich.edu        .flags(total);
2252727Sktlim@umich.edu
2262727Sktlim@umich.edu    iewExecRate = iewExecutedInsts / cpu->numCycles;
2272301SN/A
2282301SN/A    iewInstsToCommit
2296221Snate@binkert.org        .init(cpu->numThreads)
2302301SN/A        .name(name() + ".WB:sent")
2312301SN/A        .desc("cumulative count of insts sent to commit")
2322727Sktlim@umich.edu        .flags(total);
2332301SN/A
2342326SN/A    writebackCount
2356221Snate@binkert.org        .init(cpu->numThreads)
2362301SN/A        .name(name() + ".WB:count")
2372301SN/A        .desc("cumulative count of insts written-back")
2382727Sktlim@umich.edu        .flags(total);
2392301SN/A
2402326SN/A    producerInst
2416221Snate@binkert.org        .init(cpu->numThreads)
2422301SN/A        .name(name() + ".WB:producers")
2432301SN/A        .desc("num instructions producing a value")
2442727Sktlim@umich.edu        .flags(total);
2452301SN/A
2462326SN/A    consumerInst
2476221Snate@binkert.org        .init(cpu->numThreads)
2482301SN/A        .name(name() + ".WB:consumers")
2492301SN/A        .desc("num instructions consuming a value")
2502727Sktlim@umich.edu        .flags(total);
2512301SN/A
2522326SN/A    wbPenalized
2536221Snate@binkert.org        .init(cpu->numThreads)
2542301SN/A        .name(name() + ".WB:penalized")
2552301SN/A        .desc("number of instrctions required to write to 'other' IQ")
2562727Sktlim@umich.edu        .flags(total);
2572301SN/A
2582326SN/A    wbPenalizedRate
2592301SN/A        .name(name() + ".WB:penalized_rate")
2602301SN/A        .desc ("fraction of instructions written-back that wrote to 'other' IQ")
2612727Sktlim@umich.edu        .flags(total);
2622301SN/A
2632326SN/A    wbPenalizedRate = wbPenalized / writebackCount;
2642301SN/A
2652326SN/A    wbFanout
2662301SN/A        .name(name() + ".WB:fanout")
2672301SN/A        .desc("average fanout of values written-back")
2682727Sktlim@umich.edu        .flags(total);
2692301SN/A
2702326SN/A    wbFanout = producerInst / consumerInst;
2712301SN/A
2722326SN/A    wbRate
2732301SN/A        .name(name() + ".WB:rate")
2742301SN/A        .desc("insts written-back per cycle")
2752727Sktlim@umich.edu        .flags(total);
2762326SN/A    wbRate = writebackCount / cpu->numCycles;
2771062SN/A}
2781062SN/A
2791681SN/Atemplate<class Impl>
2801060SN/Avoid
2812292SN/ADefaultIEW<Impl>::initStage()
2821060SN/A{
2836221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
2842292SN/A        toRename->iewInfo[tid].usedIQ = true;
2852292SN/A        toRename->iewInfo[tid].freeIQEntries =
2862292SN/A            instQueue.numFreeEntries(tid);
2872292SN/A
2882292SN/A        toRename->iewInfo[tid].usedLSQ = true;
2892292SN/A        toRename->iewInfo[tid].freeLSQEntries =
2902292SN/A            ldstQueue.numFreeEntries(tid);
2912292SN/A    }
2922292SN/A
2932733Sktlim@umich.edu    cpu->activateStage(O3CPU::IEWIdx);
2941060SN/A}
2951060SN/A
2961681SN/Atemplate<class Impl>
2971060SN/Avoid
2982292SN/ADefaultIEW<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
2991060SN/A{
3001060SN/A    timeBuffer = tb_ptr;
3011060SN/A
3021060SN/A    // Setup wire to read information from time buffer, from commit.
3031060SN/A    fromCommit = timeBuffer->getWire(-commitToIEWDelay);
3041060SN/A
3051060SN/A    // Setup wire to write information back to previous stages.
3061060SN/A    toRename = timeBuffer->getWire(0);
3071060SN/A
3082292SN/A    toFetch = timeBuffer->getWire(0);
3092292SN/A
3101060SN/A    // Instruction queue also needs main time buffer.
3111060SN/A    instQueue.setTimeBuffer(tb_ptr);
3121060SN/A}
3131060SN/A
3141681SN/Atemplate<class Impl>
3151060SN/Avoid
3162292SN/ADefaultIEW<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
3171060SN/A{
3181060SN/A    renameQueue = rq_ptr;
3191060SN/A
3201060SN/A    // Setup wire to read information from rename queue.
3211060SN/A    fromRename = renameQueue->getWire(-renameToIEWDelay);
3221060SN/A}
3231060SN/A
3241681SN/Atemplate<class Impl>
3251060SN/Avoid
3262292SN/ADefaultIEW<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr)
3271060SN/A{
3281060SN/A    iewQueue = iq_ptr;
3291060SN/A
3301060SN/A    // Setup wire to write instructions to commit.
3311060SN/A    toCommit = iewQueue->getWire(0);
3321060SN/A}
3331060SN/A
3341681SN/Atemplate<class Impl>
3351060SN/Avoid
3366221Snate@binkert.orgDefaultIEW<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
3371060SN/A{
3382292SN/A    activeThreads = at_ptr;
3392292SN/A
3402292SN/A    ldstQueue.setActiveThreads(at_ptr);
3412292SN/A    instQueue.setActiveThreads(at_ptr);
3421060SN/A}
3431060SN/A
3441681SN/Atemplate<class Impl>
3451060SN/Avoid
3462292SN/ADefaultIEW<Impl>::setScoreboard(Scoreboard *sb_ptr)
3471060SN/A{
3482292SN/A    scoreboard = sb_ptr;
3491060SN/A}
3501060SN/A
3512307SN/Atemplate <class Impl>
3522863Sktlim@umich.edubool
3532843Sktlim@umich.eduDefaultIEW<Impl>::drain()
3542307SN/A{
3552843Sktlim@umich.edu    // IEW is ready to drain at any time.
3562843Sktlim@umich.edu    cpu->signalDrained();
3572863Sktlim@umich.edu    return true;
3581681SN/A}
3591681SN/A
3602316SN/Atemplate <class Impl>
3611681SN/Avoid
3622843Sktlim@umich.eduDefaultIEW<Impl>::resume()
3632843Sktlim@umich.edu{
3642843Sktlim@umich.edu}
3652843Sktlim@umich.edu
3662843Sktlim@umich.edutemplate <class Impl>
3672843Sktlim@umich.eduvoid
3682843Sktlim@umich.eduDefaultIEW<Impl>::switchOut()
3691681SN/A{
3702348SN/A    // Clear any state.
3712307SN/A    switchedOut = true;
3722367SN/A    assert(insts[0].empty());
3732367SN/A    assert(skidBuffer[0].empty());
3741681SN/A
3752307SN/A    instQueue.switchOut();
3762307SN/A    ldstQueue.switchOut();
3772307SN/A    fuPool->switchOut();
3782307SN/A
3796221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
3806221Snate@binkert.org        while (!insts[tid].empty())
3816221Snate@binkert.org            insts[tid].pop();
3826221Snate@binkert.org        while (!skidBuffer[tid].empty())
3836221Snate@binkert.org            skidBuffer[tid].pop();
3842307SN/A    }
3851681SN/A}
3861681SN/A
3872307SN/Atemplate <class Impl>
3881681SN/Avoid
3892307SN/ADefaultIEW<Impl>::takeOverFrom()
3901060SN/A{
3912348SN/A    // Reset all state.
3922307SN/A    _status = Active;
3932307SN/A    exeStatus = Running;
3942307SN/A    wbStatus = Idle;
3952307SN/A    switchedOut = false;
3961060SN/A
3972307SN/A    instQueue.takeOverFrom();
3982307SN/A    ldstQueue.takeOverFrom();
3992307SN/A    fuPool->takeOverFrom();
4001060SN/A
4012307SN/A    initStage();
4022307SN/A    cpu->activityThisCycle();
4031060SN/A
4046221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
4056221Snate@binkert.org        dispatchStatus[tid] = Running;
4066221Snate@binkert.org        stalls[tid].commit = false;
4076221Snate@binkert.org        fetchRedirect[tid] = false;
4082307SN/A    }
4091060SN/A
4102307SN/A    updateLSQNextCycle = false;
4112307SN/A
4122873Sktlim@umich.edu    for (int i = 0; i < issueToExecQueue.getSize(); ++i) {
4132307SN/A        issueToExecQueue.advance();
4141060SN/A    }
4151060SN/A}
4161060SN/A
4171681SN/Atemplate<class Impl>
4181060SN/Avoid
4196221Snate@binkert.orgDefaultIEW<Impl>::squash(ThreadID tid)
4202107SN/A{
4216221Snate@binkert.org    DPRINTF(IEW, "[tid:%i]: Squashing all instructions.\n", tid);
4222107SN/A
4232292SN/A    // Tell the IQ to start squashing.
4242292SN/A    instQueue.squash(tid);
4252107SN/A
4262292SN/A    // Tell the LDSTQ to start squashing.
4272326SN/A    ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid);
4282292SN/A    updatedQueues = true;
4292107SN/A
4302292SN/A    // Clear the skid buffer in case it has any data in it.
4312935Sksewell@umich.edu    DPRINTF(IEW, "[tid:%i]: Removing skidbuffer instructions until [sn:%i].\n",
4324632Sgblack@eecs.umich.edu            tid, fromCommit->commitInfo[tid].doneSeqNum);
4332935Sksewell@umich.edu
4342292SN/A    while (!skidBuffer[tid].empty()) {
4352292SN/A        if (skidBuffer[tid].front()->isLoad() ||
4362292SN/A            skidBuffer[tid].front()->isStore() ) {
4372292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
4382292SN/A        }
4392107SN/A
4402292SN/A        toRename->iewInfo[tid].dispatched++;
4412107SN/A
4422292SN/A        skidBuffer[tid].pop();
4432292SN/A    }
4442107SN/A
4452702Sktlim@umich.edu    emptyRenameInsts(tid);
4462107SN/A}
4472107SN/A
4482107SN/Atemplate<class Impl>
4492107SN/Avoid
4506221Snate@binkert.orgDefaultIEW<Impl>::squashDueToBranch(DynInstPtr &inst, ThreadID tid)
4512292SN/A{
4527720Sgblack@eecs.umich.edu    DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, PC: %s "
4537720Sgblack@eecs.umich.edu            "[sn:%i].\n", tid, inst->pcState(), inst->seqNum);
4542292SN/A
4552292SN/A    toCommit->squash[tid] = true;
4562292SN/A    toCommit->squashedSeqNum[tid] = inst->seqNum;
4577720Sgblack@eecs.umich.edu    toCommit->mispredPC[tid] = inst->instAddr();
4582292SN/A    toCommit->branchMispredict[tid] = true;
4592935Sksewell@umich.edu
4607720Sgblack@eecs.umich.edu    toCommit->branchTaken[tid] = inst->pcState().branching();
4617720Sgblack@eecs.umich.edu    TheISA::PCState pc = inst->pcState();
4627720Sgblack@eecs.umich.edu    TheISA::advancePC(pc, inst->staticInst);
4637720Sgblack@eecs.umich.edu    toCommit->pc[tid] = pc;
4642292SN/A
4652292SN/A    toCommit->includeSquashInst[tid] = false;
4662292SN/A
4672292SN/A    wroteToTimeBuffer = true;
4682292SN/A}
4692292SN/A
4702292SN/Atemplate<class Impl>
4712292SN/Avoid
4726221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemOrder(DynInstPtr &inst, ThreadID tid)
4732292SN/A{
4742292SN/A    DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, "
4757720Sgblack@eecs.umich.edu            "PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum);
4762292SN/A
4772292SN/A    toCommit->squash[tid] = true;
4782292SN/A    toCommit->squashedSeqNum[tid] = inst->seqNum;
4797720Sgblack@eecs.umich.edu    TheISA::PCState pc = inst->pcState();
4807720Sgblack@eecs.umich.edu    TheISA::advancePC(pc, inst->staticInst);
4817720Sgblack@eecs.umich.edu    toCommit->pc[tid] = pc;
4823732Sktlim@umich.edu    toCommit->branchMispredict[tid] = false;
4832292SN/A
4842292SN/A    toCommit->includeSquashInst[tid] = false;
4852292SN/A
4862292SN/A    wroteToTimeBuffer = true;
4872292SN/A}
4882292SN/A
4892292SN/Atemplate<class Impl>
4902292SN/Avoid
4916221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemBlocked(DynInstPtr &inst, ThreadID tid)
4922292SN/A{
4932292SN/A    DPRINTF(IEW, "[tid:%i]: Memory blocked, squashing load and younger insts, "
4947720Sgblack@eecs.umich.edu            "PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum);
4952292SN/A
4962292SN/A    toCommit->squash[tid] = true;
4972292SN/A    toCommit->squashedSeqNum[tid] = inst->seqNum;
4987720Sgblack@eecs.umich.edu    toCommit->pc[tid] = inst->pcState();
4993732Sktlim@umich.edu    toCommit->branchMispredict[tid] = false;
5002292SN/A
5012348SN/A    // Must include the broadcasted SN in the squash.
5022292SN/A    toCommit->includeSquashInst[tid] = true;
5032292SN/A
5042292SN/A    ldstQueue.setLoadBlockedHandled(tid);
5052292SN/A
5062292SN/A    wroteToTimeBuffer = true;
5072292SN/A}
5082292SN/A
5092292SN/Atemplate<class Impl>
5102292SN/Avoid
5116221Snate@binkert.orgDefaultIEW<Impl>::block(ThreadID tid)
5122292SN/A{
5132292SN/A    DPRINTF(IEW, "[tid:%u]: Blocking.\n", tid);
5142292SN/A
5152292SN/A    if (dispatchStatus[tid] != Blocked &&
5162292SN/A        dispatchStatus[tid] != Unblocking) {
5172292SN/A        toRename->iewBlock[tid] = true;
5182292SN/A        wroteToTimeBuffer = true;
5192292SN/A    }
5202292SN/A
5212292SN/A    // Add the current inputs to the skid buffer so they can be
5222292SN/A    // reprocessed when this stage unblocks.
5232292SN/A    skidInsert(tid);
5242292SN/A
5252292SN/A    dispatchStatus[tid] = Blocked;
5262292SN/A}
5272292SN/A
5282292SN/Atemplate<class Impl>
5292292SN/Avoid
5306221Snate@binkert.orgDefaultIEW<Impl>::unblock(ThreadID tid)
5312292SN/A{
5322292SN/A    DPRINTF(IEW, "[tid:%i]: Reading instructions out of the skid "
5332292SN/A            "buffer %u.\n",tid, tid);
5342292SN/A
5352292SN/A    // If the skid bufffer is empty, signal back to previous stages to unblock.
5362292SN/A    // Also switch status to running.
5372292SN/A    if (skidBuffer[tid].empty()) {
5382292SN/A        toRename->iewUnblock[tid] = true;
5392292SN/A        wroteToTimeBuffer = true;
5402292SN/A        DPRINTF(IEW, "[tid:%i]: Done unblocking.\n",tid);
5412292SN/A        dispatchStatus[tid] = Running;
5422292SN/A    }
5432292SN/A}
5442292SN/A
5452292SN/Atemplate<class Impl>
5462292SN/Avoid
5472292SN/ADefaultIEW<Impl>::wakeDependents(DynInstPtr &inst)
5481060SN/A{
5491681SN/A    instQueue.wakeDependents(inst);
5501060SN/A}
5511060SN/A
5522292SN/Atemplate<class Impl>
5532292SN/Avoid
5542292SN/ADefaultIEW<Impl>::rescheduleMemInst(DynInstPtr &inst)
5552292SN/A{
5562292SN/A    instQueue.rescheduleMemInst(inst);
5572292SN/A}
5581681SN/A
5591681SN/Atemplate<class Impl>
5601060SN/Avoid
5612292SN/ADefaultIEW<Impl>::replayMemInst(DynInstPtr &inst)
5621060SN/A{
5632292SN/A    instQueue.replayMemInst(inst);
5642292SN/A}
5651060SN/A
5662292SN/Atemplate<class Impl>
5672292SN/Avoid
5682292SN/ADefaultIEW<Impl>::instToCommit(DynInstPtr &inst)
5692292SN/A{
5703221Sktlim@umich.edu    // This function should not be called after writebackInsts in a
5713221Sktlim@umich.edu    // single cycle.  That will cause problems with an instruction
5723221Sktlim@umich.edu    // being added to the queue to commit without being processed by
5733221Sktlim@umich.edu    // writebackInsts prior to being sent to commit.
5743221Sktlim@umich.edu
5752292SN/A    // First check the time slot that this instruction will write
5762292SN/A    // to.  If there are free write ports at the time, then go ahead
5772292SN/A    // and write the instruction to that time.  If there are not,
5782292SN/A    // keep looking back to see where's the first time there's a
5792326SN/A    // free slot.
5802292SN/A    while ((*iewQueue)[wbCycle].insts[wbNumInst]) {
5812292SN/A        ++wbNumInst;
5822820Sktlim@umich.edu        if (wbNumInst == wbWidth) {
5832292SN/A            ++wbCycle;
5842292SN/A            wbNumInst = 0;
5852292SN/A        }
5862292SN/A
5872353SN/A        assert((wbCycle * wbWidth + wbNumInst) <= wbMax);
5882292SN/A    }
5892292SN/A
5902353SN/A    DPRINTF(IEW, "Current wb cycle: %i, width: %i, numInst: %i\nwbActual:%i\n",
5912353SN/A            wbCycle, wbWidth, wbNumInst, wbCycle * wbWidth + wbNumInst);
5922292SN/A    // Add finished instruction to queue to commit.
5932292SN/A    (*iewQueue)[wbCycle].insts[wbNumInst] = inst;
5942292SN/A    (*iewQueue)[wbCycle].size++;
5952292SN/A}
5962292SN/A
5972292SN/Atemplate <class Impl>
5982292SN/Aunsigned
5992292SN/ADefaultIEW<Impl>::validInstsFromRename()
6002292SN/A{
6012292SN/A    unsigned inst_count = 0;
6022292SN/A
6032292SN/A    for (int i=0; i<fromRename->size; i++) {
6042731Sktlim@umich.edu        if (!fromRename->insts[i]->isSquashed())
6052292SN/A            inst_count++;
6062292SN/A    }
6072292SN/A
6082292SN/A    return inst_count;
6092292SN/A}
6102292SN/A
6112292SN/Atemplate<class Impl>
6122292SN/Avoid
6136221Snate@binkert.orgDefaultIEW<Impl>::skidInsert(ThreadID tid)
6142292SN/A{
6152292SN/A    DynInstPtr inst = NULL;
6162292SN/A
6172292SN/A    while (!insts[tid].empty()) {
6182292SN/A        inst = insts[tid].front();
6192292SN/A
6202292SN/A        insts[tid].pop();
6212292SN/A
6227720Sgblack@eecs.umich.edu        DPRINTF(Decode,"[tid:%i]: Inserting [sn:%lli] PC:%s into "
6232292SN/A                "dispatch skidBuffer %i\n",tid, inst->seqNum,
6247720Sgblack@eecs.umich.edu                inst->pcState(),tid);
6252292SN/A
6262292SN/A        skidBuffer[tid].push(inst);
6272292SN/A    }
6282292SN/A
6292292SN/A    assert(skidBuffer[tid].size() <= skidBufferMax &&
6302292SN/A           "Skidbuffer Exceeded Max Size");
6312292SN/A}
6322292SN/A
6332292SN/Atemplate<class Impl>
6342292SN/Aint
6352292SN/ADefaultIEW<Impl>::skidCount()
6362292SN/A{
6372292SN/A    int max=0;
6382292SN/A
6396221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6406221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6412292SN/A
6423867Sbinkertn@umich.edu    while (threads != end) {
6436221Snate@binkert.org        ThreadID tid = *threads++;
6443867Sbinkertn@umich.edu        unsigned thread_count = skidBuffer[tid].size();
6452292SN/A        if (max < thread_count)
6462292SN/A            max = thread_count;
6472292SN/A    }
6482292SN/A
6492292SN/A    return max;
6502292SN/A}
6512292SN/A
6522292SN/Atemplate<class Impl>
6532292SN/Abool
6542292SN/ADefaultIEW<Impl>::skidsEmpty()
6552292SN/A{
6566221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6576221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6582292SN/A
6593867Sbinkertn@umich.edu    while (threads != end) {
6606221Snate@binkert.org        ThreadID tid = *threads++;
6613867Sbinkertn@umich.edu
6623867Sbinkertn@umich.edu        if (!skidBuffer[tid].empty())
6632292SN/A            return false;
6642292SN/A    }
6652292SN/A
6662292SN/A    return true;
6671062SN/A}
6681062SN/A
6691681SN/Atemplate <class Impl>
6701062SN/Avoid
6712292SN/ADefaultIEW<Impl>::updateStatus()
6721062SN/A{
6732292SN/A    bool any_unblocking = false;
6741062SN/A
6756221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6766221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6771062SN/A
6783867Sbinkertn@umich.edu    while (threads != end) {
6796221Snate@binkert.org        ThreadID tid = *threads++;
6801062SN/A
6812292SN/A        if (dispatchStatus[tid] == Unblocking) {
6822292SN/A            any_unblocking = true;
6832292SN/A            break;
6842292SN/A        }
6852292SN/A    }
6861062SN/A
6872292SN/A    // If there are no ready instructions waiting to be scheduled by the IQ,
6882292SN/A    // and there's no stores waiting to write back, and dispatch is not
6892292SN/A    // unblocking, then there is no internal activity for the IEW stage.
6902292SN/A    if (_status == Active && !instQueue.hasReadyInsts() &&
6912292SN/A        !ldstQueue.willWB() && !any_unblocking) {
6922292SN/A        DPRINTF(IEW, "IEW switching to idle\n");
6931062SN/A
6942292SN/A        deactivateStage();
6951062SN/A
6962292SN/A        _status = Inactive;
6972292SN/A    } else if (_status == Inactive && (instQueue.hasReadyInsts() ||
6982292SN/A                                       ldstQueue.willWB() ||
6992292SN/A                                       any_unblocking)) {
7002292SN/A        // Otherwise there is internal activity.  Set to active.
7012292SN/A        DPRINTF(IEW, "IEW switching to active\n");
7021062SN/A
7032292SN/A        activateStage();
7041062SN/A
7052292SN/A        _status = Active;
7061062SN/A    }
7071062SN/A}
7081062SN/A
7091681SN/Atemplate <class Impl>
7101062SN/Avoid
7112292SN/ADefaultIEW<Impl>::resetEntries()
7121062SN/A{
7132292SN/A    instQueue.resetEntries();
7142292SN/A    ldstQueue.resetEntries();
7152292SN/A}
7161062SN/A
7172292SN/Atemplate <class Impl>
7182292SN/Avoid
7196221Snate@binkert.orgDefaultIEW<Impl>::readStallSignals(ThreadID tid)
7202292SN/A{
7212292SN/A    if (fromCommit->commitBlock[tid]) {
7222292SN/A        stalls[tid].commit = true;
7232292SN/A    }
7241062SN/A
7252292SN/A    if (fromCommit->commitUnblock[tid]) {
7262292SN/A        assert(stalls[tid].commit);
7272292SN/A        stalls[tid].commit = false;
7282292SN/A    }
7292292SN/A}
7302292SN/A
7312292SN/Atemplate <class Impl>
7322292SN/Abool
7336221Snate@binkert.orgDefaultIEW<Impl>::checkStall(ThreadID tid)
7342292SN/A{
7352292SN/A    bool ret_val(false);
7362292SN/A
7372292SN/A    if (stalls[tid].commit) {
7382292SN/A        DPRINTF(IEW,"[tid:%i]: Stall from Commit stage detected.\n",tid);
7392292SN/A        ret_val = true;
7402292SN/A    } else if (instQueue.isFull(tid)) {
7412292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: IQ  is full.\n",tid);
7422292SN/A        ret_val = true;
7432292SN/A    } else if (ldstQueue.isFull(tid)) {
7442292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: LSQ is full\n",tid);
7452292SN/A
7462292SN/A        if (ldstQueue.numLoads(tid) > 0 ) {
7472292SN/A
7482292SN/A            DPRINTF(IEW,"[tid:%i]: LSQ oldest load: [sn:%i] \n",
7492292SN/A                    tid,ldstQueue.getLoadHeadSeqNum(tid));
7502292SN/A        }
7512292SN/A
7522292SN/A        if (ldstQueue.numStores(tid) > 0) {
7532292SN/A
7542292SN/A            DPRINTF(IEW,"[tid:%i]: LSQ oldest store: [sn:%i] \n",
7552292SN/A                    tid,ldstQueue.getStoreHeadSeqNum(tid));
7562292SN/A        }
7572292SN/A
7582292SN/A        ret_val = true;
7592292SN/A    } else if (ldstQueue.isStalled(tid)) {
7602292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: LSQ stall detected.\n",tid);
7612292SN/A        ret_val = true;
7622292SN/A    }
7632292SN/A
7642292SN/A    return ret_val;
7652292SN/A}
7662292SN/A
7672292SN/Atemplate <class Impl>
7682292SN/Avoid
7696221Snate@binkert.orgDefaultIEW<Impl>::checkSignalsAndUpdate(ThreadID tid)
7702292SN/A{
7712292SN/A    // Check if there's a squash signal, squash if there is
7722292SN/A    // Check stall signals, block if there is.
7732292SN/A    // If status was Blocked
7742292SN/A    //     if so then go to unblocking
7752292SN/A    // If status was Squashing
7762292SN/A    //     check if squashing is not high.  Switch to running this cycle.
7772292SN/A
7782292SN/A    readStallSignals(tid);
7792292SN/A
7802292SN/A    if (fromCommit->commitInfo[tid].squash) {
7812292SN/A        squash(tid);
7822292SN/A
7832292SN/A        if (dispatchStatus[tid] == Blocked ||
7842292SN/A            dispatchStatus[tid] == Unblocking) {
7852292SN/A            toRename->iewUnblock[tid] = true;
7862292SN/A            wroteToTimeBuffer = true;
7872292SN/A        }
7882292SN/A
7892292SN/A        dispatchStatus[tid] = Squashing;
7902292SN/A
7912292SN/A        fetchRedirect[tid] = false;
7922292SN/A        return;
7932292SN/A    }
7942292SN/A
7952292SN/A    if (fromCommit->commitInfo[tid].robSquashing) {
7962702Sktlim@umich.edu        DPRINTF(IEW, "[tid:%i]: ROB is still squashing.\n", tid);
7972292SN/A
7982292SN/A        dispatchStatus[tid] = Squashing;
7992292SN/A
8002702Sktlim@umich.edu        emptyRenameInsts(tid);
8012702Sktlim@umich.edu        wroteToTimeBuffer = true;
8022292SN/A        return;
8032292SN/A    }
8042292SN/A
8052292SN/A    if (checkStall(tid)) {
8062292SN/A        block(tid);
8072292SN/A        dispatchStatus[tid] = Blocked;
8082292SN/A        return;
8092292SN/A    }
8102292SN/A
8112292SN/A    if (dispatchStatus[tid] == Blocked) {
8122292SN/A        // Status from previous cycle was blocked, but there are no more stall
8132292SN/A        // conditions.  Switch over to unblocking.
8142292SN/A        DPRINTF(IEW, "[tid:%i]: Done blocking, switching to unblocking.\n",
8152292SN/A                tid);
8162292SN/A
8172292SN/A        dispatchStatus[tid] = Unblocking;
8182292SN/A
8192292SN/A        unblock(tid);
8202292SN/A
8212292SN/A        return;
8222292SN/A    }
8232292SN/A
8242292SN/A    if (dispatchStatus[tid] == Squashing) {
8252292SN/A        // Switch status to running if rename isn't being told to block or
8262292SN/A        // squash this cycle.
8272292SN/A        DPRINTF(IEW, "[tid:%i]: Done squashing, switching to running.\n",
8282292SN/A                tid);
8292292SN/A
8302292SN/A        dispatchStatus[tid] = Running;
8312292SN/A
8322292SN/A        return;
8332292SN/A    }
8342292SN/A}
8352292SN/A
8362292SN/Atemplate <class Impl>
8372292SN/Avoid
8382292SN/ADefaultIEW<Impl>::sortInsts()
8392292SN/A{
8402292SN/A    int insts_from_rename = fromRename->size;
8412326SN/A#ifdef DEBUG
8426221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++)
8436221Snate@binkert.org        assert(insts[tid].empty());
8442326SN/A#endif
8452292SN/A    for (int i = 0; i < insts_from_rename; ++i) {
8462292SN/A        insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]);
8472292SN/A    }
8482292SN/A}
8492292SN/A
8502292SN/Atemplate <class Impl>
8512292SN/Avoid
8526221Snate@binkert.orgDefaultIEW<Impl>::emptyRenameInsts(ThreadID tid)
8532702Sktlim@umich.edu{
8544632Sgblack@eecs.umich.edu    DPRINTF(IEW, "[tid:%i]: Removing incoming rename instructions\n", tid);
8552935Sksewell@umich.edu
8562702Sktlim@umich.edu    while (!insts[tid].empty()) {
8572935Sksewell@umich.edu
8582702Sktlim@umich.edu        if (insts[tid].front()->isLoad() ||
8592702Sktlim@umich.edu            insts[tid].front()->isStore() ) {
8602702Sktlim@umich.edu            toRename->iewInfo[tid].dispatchedToLSQ++;
8612702Sktlim@umich.edu        }
8622702Sktlim@umich.edu
8632702Sktlim@umich.edu        toRename->iewInfo[tid].dispatched++;
8642702Sktlim@umich.edu
8652702Sktlim@umich.edu        insts[tid].pop();
8662702Sktlim@umich.edu    }
8672702Sktlim@umich.edu}
8682702Sktlim@umich.edu
8692702Sktlim@umich.edutemplate <class Impl>
8702702Sktlim@umich.eduvoid
8712292SN/ADefaultIEW<Impl>::wakeCPU()
8722292SN/A{
8732292SN/A    cpu->wakeCPU();
8742292SN/A}
8752292SN/A
8762292SN/Atemplate <class Impl>
8772292SN/Avoid
8782292SN/ADefaultIEW<Impl>::activityThisCycle()
8792292SN/A{
8802292SN/A    DPRINTF(Activity, "Activity this cycle.\n");
8812292SN/A    cpu->activityThisCycle();
8822292SN/A}
8832292SN/A
8842292SN/Atemplate <class Impl>
8852292SN/Ainline void
8862292SN/ADefaultIEW<Impl>::activateStage()
8872292SN/A{
8882292SN/A    DPRINTF(Activity, "Activating stage.\n");
8892733Sktlim@umich.edu    cpu->activateStage(O3CPU::IEWIdx);
8902292SN/A}
8912292SN/A
8922292SN/Atemplate <class Impl>
8932292SN/Ainline void
8942292SN/ADefaultIEW<Impl>::deactivateStage()
8952292SN/A{
8962292SN/A    DPRINTF(Activity, "Deactivating stage.\n");
8972733Sktlim@umich.edu    cpu->deactivateStage(O3CPU::IEWIdx);
8982292SN/A}
8992292SN/A
9002292SN/Atemplate<class Impl>
9012292SN/Avoid
9026221Snate@binkert.orgDefaultIEW<Impl>::dispatch(ThreadID tid)
9032292SN/A{
9042292SN/A    // If status is Running or idle,
9052292SN/A    //     call dispatchInsts()
9062292SN/A    // If status is Unblocking,
9072292SN/A    //     buffer any instructions coming from rename
9082292SN/A    //     continue trying to empty skid buffer
9092292SN/A    //     check if stall conditions have passed
9102292SN/A
9112292SN/A    if (dispatchStatus[tid] == Blocked) {
9122292SN/A        ++iewBlockCycles;
9132292SN/A
9142292SN/A    } else if (dispatchStatus[tid] == Squashing) {
9152292SN/A        ++iewSquashCycles;
9162292SN/A    }
9172292SN/A
9182292SN/A    // Dispatch should try to dispatch as many instructions as its bandwidth
9192292SN/A    // will allow, as long as it is not currently blocked.
9202292SN/A    if (dispatchStatus[tid] == Running ||
9212292SN/A        dispatchStatus[tid] == Idle) {
9222292SN/A        DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run "
9232292SN/A                "dispatch.\n", tid);
9242292SN/A
9252292SN/A        dispatchInsts(tid);
9262292SN/A    } else if (dispatchStatus[tid] == Unblocking) {
9272292SN/A        // Make sure that the skid buffer has something in it if the
9282292SN/A        // status is unblocking.
9292292SN/A        assert(!skidsEmpty());
9302292SN/A
9312292SN/A        // If the status was unblocking, then instructions from the skid
9322292SN/A        // buffer were used.  Remove those instructions and handle
9332292SN/A        // the rest of unblocking.
9342292SN/A        dispatchInsts(tid);
9352292SN/A
9362292SN/A        ++iewUnblockCycles;
9372292SN/A
9385215Sgblack@eecs.umich.edu        if (validInstsFromRename()) {
9392292SN/A            // Add the current inputs to the skid buffer so they can be
9402292SN/A            // reprocessed when this stage unblocks.
9412292SN/A            skidInsert(tid);
9422292SN/A        }
9432292SN/A
9442292SN/A        unblock(tid);
9452292SN/A    }
9462292SN/A}
9472292SN/A
9482292SN/Atemplate <class Impl>
9492292SN/Avoid
9506221Snate@binkert.orgDefaultIEW<Impl>::dispatchInsts(ThreadID tid)
9512292SN/A{
9522292SN/A    // Obtain instructions from skid buffer if unblocking, or queue from rename
9532292SN/A    // otherwise.
9542292SN/A    std::queue<DynInstPtr> &insts_to_dispatch =
9552292SN/A        dispatchStatus[tid] == Unblocking ?
9562292SN/A        skidBuffer[tid] : insts[tid];
9572292SN/A
9582292SN/A    int insts_to_add = insts_to_dispatch.size();
9592292SN/A
9602292SN/A    DynInstPtr inst;
9612292SN/A    bool add_to_iq = false;
9622292SN/A    int dis_num_inst = 0;
9632292SN/A
9642292SN/A    // Loop through the instructions, putting them in the instruction
9652292SN/A    // queue.
9662292SN/A    for ( ; dis_num_inst < insts_to_add &&
9672820Sktlim@umich.edu              dis_num_inst < dispatchWidth;
9682292SN/A          ++dis_num_inst)
9692292SN/A    {
9702292SN/A        inst = insts_to_dispatch.front();
9712292SN/A
9722292SN/A        if (dispatchStatus[tid] == Unblocking) {
9732292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Examining instruction from skid "
9742292SN/A                    "buffer\n", tid);
9752292SN/A        }
9762292SN/A
9772292SN/A        // Make sure there's a valid instruction there.
9782292SN/A        assert(inst);
9792292SN/A
9807720Sgblack@eecs.umich.edu        DPRINTF(IEW, "[tid:%i]: Issue: Adding PC %s [sn:%lli] [tid:%i] to "
9812292SN/A                "IQ.\n",
9827720Sgblack@eecs.umich.edu                tid, inst->pcState(), inst->seqNum, inst->threadNumber);
9832292SN/A
9842292SN/A        // Be sure to mark these instructions as ready so that the
9852292SN/A        // commit stage can go ahead and execute them, and mark
9862292SN/A        // them as issued so the IQ doesn't reprocess them.
9872292SN/A
9882292SN/A        // Check for squashed instructions.
9892292SN/A        if (inst->isSquashed()) {
9902292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Squashed instruction encountered, "
9912292SN/A                    "not adding to IQ.\n", tid);
9922292SN/A
9932292SN/A            ++iewDispSquashedInsts;
9942292SN/A
9952292SN/A            insts_to_dispatch.pop();
9962292SN/A
9972292SN/A            //Tell Rename That An Instruction has been processed
9982292SN/A            if (inst->isLoad() || inst->isStore()) {
9992292SN/A                toRename->iewInfo[tid].dispatchedToLSQ++;
10002292SN/A            }
10012292SN/A            toRename->iewInfo[tid].dispatched++;
10022292SN/A
10032292SN/A            continue;
10042292SN/A        }
10052292SN/A
10062292SN/A        // Check for full conditions.
10072292SN/A        if (instQueue.isFull(tid)) {
10082292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: IQ has become full.\n", tid);
10092292SN/A
10102292SN/A            // Call function to start blocking.
10112292SN/A            block(tid);
10122292SN/A
10132292SN/A            // Set unblock to false. Special case where we are using
10142292SN/A            // skidbuffer (unblocking) instructions but then we still
10152292SN/A            // get full in the IQ.
10162292SN/A            toRename->iewUnblock[tid] = false;
10172292SN/A
10182292SN/A            ++iewIQFullEvents;
10192292SN/A            break;
10202292SN/A        } else if (ldstQueue.isFull(tid)) {
10212292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: LSQ has become full.\n",tid);
10222292SN/A
10232292SN/A            // Call function to start blocking.
10242292SN/A            block(tid);
10252292SN/A
10262292SN/A            // Set unblock to false. Special case where we are using
10272292SN/A            // skidbuffer (unblocking) instructions but then we still
10282292SN/A            // get full in the IQ.
10292292SN/A            toRename->iewUnblock[tid] = false;
10302292SN/A
10312292SN/A            ++iewLSQFullEvents;
10322292SN/A            break;
10332292SN/A        }
10342292SN/A
10352292SN/A        // Otherwise issue the instruction just fine.
10362292SN/A        if (inst->isLoad()) {
10372292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction "
10382292SN/A                    "encountered, adding to LSQ.\n", tid);
10392292SN/A
10402292SN/A            // Reserve a spot in the load store queue for this
10412292SN/A            // memory access.
10422292SN/A            ldstQueue.insertLoad(inst);
10432292SN/A
10442292SN/A            ++iewDispLoadInsts;
10452292SN/A
10462292SN/A            add_to_iq = true;
10472292SN/A
10482292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
10492292SN/A        } else if (inst->isStore()) {
10502292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction "
10512292SN/A                    "encountered, adding to LSQ.\n", tid);
10522292SN/A
10532292SN/A            ldstQueue.insertStore(inst);
10542292SN/A
10552292SN/A            ++iewDispStoreInsts;
10562292SN/A
10572336SN/A            if (inst->isStoreConditional()) {
10582336SN/A                // Store conditionals need to be set as "canCommit()"
10592336SN/A                // so that commit can process them when they reach the
10602336SN/A                // head of commit.
10612348SN/A                // @todo: This is somewhat specific to Alpha.
10622292SN/A                inst->setCanCommit();
10632292SN/A                instQueue.insertNonSpec(inst);
10642292SN/A                add_to_iq = false;
10652292SN/A
10662292SN/A                ++iewDispNonSpecInsts;
10672292SN/A            } else {
10682292SN/A                add_to_iq = true;
10692292SN/A            }
10702292SN/A
10712292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
10722292SN/A        } else if (inst->isMemBarrier() || inst->isWriteBarrier()) {
10732326SN/A            // Same as non-speculative stores.
10742292SN/A            inst->setCanCommit();
10752292SN/A            instQueue.insertBarrier(inst);
10762292SN/A            add_to_iq = false;
10772292SN/A        } else if (inst->isNop()) {
10782292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Nop instruction encountered, "
10792292SN/A                    "skipping.\n", tid);
10802292SN/A
10812292SN/A            inst->setIssued();
10822292SN/A            inst->setExecuted();
10832292SN/A            inst->setCanCommit();
10842292SN/A
10852326SN/A            instQueue.recordProducer(inst);
10862292SN/A
10872727Sktlim@umich.edu            iewExecutedNop[tid]++;
10882301SN/A
10892292SN/A            add_to_iq = false;
10902292SN/A        } else if (inst->isExecuted()) {
10912292SN/A            assert(0 && "Instruction shouldn't be executed.\n");
10922292SN/A            DPRINTF(IEW, "Issue: Executed branch encountered, "
10932292SN/A                    "skipping.\n");
10942292SN/A
10952292SN/A            inst->setIssued();
10962292SN/A            inst->setCanCommit();
10972292SN/A
10982326SN/A            instQueue.recordProducer(inst);
10992292SN/A
11002292SN/A            add_to_iq = false;
11012292SN/A        } else {
11022292SN/A            add_to_iq = true;
11032292SN/A        }
11044033Sktlim@umich.edu        if (inst->isNonSpeculative()) {
11054033Sktlim@umich.edu            DPRINTF(IEW, "[tid:%i]: Issue: Nonspeculative instruction "
11064033Sktlim@umich.edu                    "encountered, skipping.\n", tid);
11074033Sktlim@umich.edu
11084033Sktlim@umich.edu            // Same as non-speculative stores.
11094033Sktlim@umich.edu            inst->setCanCommit();
11104033Sktlim@umich.edu
11114033Sktlim@umich.edu            // Specifically insert it as nonspeculative.
11124033Sktlim@umich.edu            instQueue.insertNonSpec(inst);
11134033Sktlim@umich.edu
11144033Sktlim@umich.edu            ++iewDispNonSpecInsts;
11154033Sktlim@umich.edu
11164033Sktlim@umich.edu            add_to_iq = false;
11174033Sktlim@umich.edu        }
11182292SN/A
11192292SN/A        // If the instruction queue is not full, then add the
11202292SN/A        // instruction.
11212292SN/A        if (add_to_iq) {
11222292SN/A            instQueue.insert(inst);
11232292SN/A        }
11242292SN/A
11252292SN/A        insts_to_dispatch.pop();
11262292SN/A
11272292SN/A        toRename->iewInfo[tid].dispatched++;
11282292SN/A
11292292SN/A        ++iewDispatchedInsts;
11302292SN/A    }
11312292SN/A
11322292SN/A    if (!insts_to_dispatch.empty()) {
11332935Sksewell@umich.edu        DPRINTF(IEW,"[tid:%i]: Issue: Bandwidth Full. Blocking.\n", tid);
11342292SN/A        block(tid);
11352292SN/A        toRename->iewUnblock[tid] = false;
11362292SN/A    }
11372292SN/A
11382292SN/A    if (dispatchStatus[tid] == Idle && dis_num_inst) {
11392292SN/A        dispatchStatus[tid] = Running;
11402292SN/A
11412292SN/A        updatedQueues = true;
11422292SN/A    }
11432292SN/A
11442292SN/A    dis_num_inst = 0;
11452292SN/A}
11462292SN/A
11472292SN/Atemplate <class Impl>
11482292SN/Avoid
11492292SN/ADefaultIEW<Impl>::printAvailableInsts()
11502292SN/A{
11512292SN/A    int inst = 0;
11522292SN/A
11532980Sgblack@eecs.umich.edu    std::cout << "Available Instructions: ";
11542292SN/A
11552292SN/A    while (fromIssue->insts[inst]) {
11562292SN/A
11572980Sgblack@eecs.umich.edu        if (inst%3==0) std::cout << "\n\t";
11582292SN/A
11597720Sgblack@eecs.umich.edu        std::cout << "PC: " << fromIssue->insts[inst]->pcState()
11602292SN/A             << " TN: " << fromIssue->insts[inst]->threadNumber
11612292SN/A             << " SN: " << fromIssue->insts[inst]->seqNum << " | ";
11622292SN/A
11632292SN/A        inst++;
11642292SN/A
11652292SN/A    }
11662292SN/A
11672980Sgblack@eecs.umich.edu    std::cout << "\n";
11682292SN/A}
11692292SN/A
11702292SN/Atemplate <class Impl>
11712292SN/Avoid
11722292SN/ADefaultIEW<Impl>::executeInsts()
11732292SN/A{
11742292SN/A    wbNumInst = 0;
11752292SN/A    wbCycle = 0;
11762292SN/A
11776221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
11786221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
11792292SN/A
11803867Sbinkertn@umich.edu    while (threads != end) {
11816221Snate@binkert.org        ThreadID tid = *threads++;
11822292SN/A        fetchRedirect[tid] = false;
11832292SN/A    }
11842292SN/A
11852698Sktlim@umich.edu    // Uncomment this if you want to see all available instructions.
11867599Sminkyu.jeong@arm.com    // @todo This doesn't actually work anymore, we should fix it.
11872698Sktlim@umich.edu//    printAvailableInsts();
11881062SN/A
11891062SN/A    // Execute/writeback any instructions that are available.
11902333SN/A    int insts_to_execute = fromIssue->size;
11912292SN/A    int inst_num = 0;
11922333SN/A    for (; inst_num < insts_to_execute;
11932326SN/A          ++inst_num) {
11941062SN/A
11952292SN/A        DPRINTF(IEW, "Execute: Executing instructions from IQ.\n");
11961062SN/A
11972333SN/A        DynInstPtr inst = instQueue.getInstToExecute();
11981062SN/A
11997720Sgblack@eecs.umich.edu        DPRINTF(IEW, "Execute: Processing PC %s, [tid:%i] [sn:%i].\n",
12007720Sgblack@eecs.umich.edu                inst->pcState(), inst->threadNumber,inst->seqNum);
12011062SN/A
12021062SN/A        // Check if the instruction is squashed; if so then skip it
12031062SN/A        if (inst->isSquashed()) {
12042292SN/A            DPRINTF(IEW, "Execute: Instruction was squashed.\n");
12051062SN/A
12061062SN/A            // Consider this instruction executed so that commit can go
12071062SN/A            // ahead and retire the instruction.
12081062SN/A            inst->setExecuted();
12091062SN/A
12102292SN/A            // Not sure if I should set this here or just let commit try to
12112292SN/A            // commit any squashed instructions.  I like the latter a bit more.
12122292SN/A            inst->setCanCommit();
12131062SN/A
12141062SN/A            ++iewExecSquashedInsts;
12151062SN/A
12162820Sktlim@umich.edu            decrWb(inst->seqNum);
12171062SN/A            continue;
12181062SN/A        }
12191062SN/A
12202292SN/A        Fault fault = NoFault;
12211062SN/A
12221062SN/A        // Execute instruction.
12231062SN/A        // Note that if the instruction faults, it will be handled
12241062SN/A        // at the commit stage.
12257850SMatt.Horsnell@arm.com        if (inst->isMemRef()) {
12262292SN/A            DPRINTF(IEW, "Execute: Calculating address for memory "
12271062SN/A                    "reference.\n");
12281062SN/A
12291062SN/A            // Tell the LDSTQ to execute this instruction (if it is a load).
12301062SN/A            if (inst->isLoad()) {
12312292SN/A                // Loads will mark themselves as executed, and their writeback
12322292SN/A                // event adds the instruction to the queue to commit
12332292SN/A                fault = ldstQueue.executeLoad(inst);
12347850SMatt.Horsnell@arm.com                if (inst->isDataPrefetch() || inst->isInstPrefetch()) {
12357850SMatt.Horsnell@arm.com                    fault = NoFault;
12367850SMatt.Horsnell@arm.com                }
12371062SN/A            } else if (inst->isStore()) {
12382367SN/A                fault = ldstQueue.executeStore(inst);
12391062SN/A
12402292SN/A                // If the store had a fault then it may not have a mem req
12417782Sminkyu.jeong@arm.com                if (fault != NoFault || inst->readPredicate() == false ||
12427782Sminkyu.jeong@arm.com                        !inst->isStoreConditional()) {
12437782Sminkyu.jeong@arm.com                    // If the instruction faulted, then we need to send it along
12447782Sminkyu.jeong@arm.com                    // to commit without the instruction completing.
12452367SN/A                    // Send this instruction to commit, also make sure iew stage
12462367SN/A                    // realizes there is activity.
12472367SN/A                    inst->setExecuted();
12482367SN/A                    instToCommit(inst);
12492367SN/A                    activityThisCycle();
12502292SN/A                }
12512326SN/A
12522326SN/A                // Store conditionals will mark themselves as
12532326SN/A                // executed, and their writeback event will add the
12542326SN/A                // instruction to the queue to commit.
12551062SN/A            } else {
12562292SN/A                panic("Unexpected memory type!\n");
12571062SN/A            }
12581062SN/A
12591062SN/A        } else {
12607847Sminkyu.jeong@arm.com            // If the instruction has already faulted, then skip executing it.
12617847Sminkyu.jeong@arm.com            // Such case can happen when it faulted during ITLB translation.
12627847Sminkyu.jeong@arm.com            // If we execute the instruction (even if it's a nop) the fault
12637847Sminkyu.jeong@arm.com            // will be replaced and we will lose it.
12647847Sminkyu.jeong@arm.com            if (inst->getFault() == NoFault) {
12657847Sminkyu.jeong@arm.com                inst->execute();
12667848SAli.Saidi@ARM.com                if (inst->readPredicate() == false)
12677848SAli.Saidi@ARM.com                    inst->forwardOldRegs();
12687847Sminkyu.jeong@arm.com            }
12691062SN/A
12702292SN/A            inst->setExecuted();
12712292SN/A
12722292SN/A            instToCommit(inst);
12731062SN/A        }
12741062SN/A
12752301SN/A        updateExeInstStats(inst);
12761681SN/A
12772326SN/A        // Check if branch prediction was correct, if not then we need
12782326SN/A        // to tell commit to squash in flight instructions.  Only
12792326SN/A        // handle this if there hasn't already been something that
12802107SN/A        // redirects fetch in this group of instructions.
12811681SN/A
12822292SN/A        // This probably needs to prioritize the redirects if a different
12832292SN/A        // scheduler is used.  Currently the scheduler schedules the oldest
12842292SN/A        // instruction first, so the branch resolution order will be correct.
12856221Snate@binkert.org        ThreadID tid = inst->threadNumber;
12861062SN/A
12873732Sktlim@umich.edu        if (!fetchRedirect[tid] ||
12883732Sktlim@umich.edu            toCommit->squashedSeqNum[tid] > inst->seqNum) {
12891062SN/A
12901062SN/A            if (inst->mispredicted()) {
12912292SN/A                fetchRedirect[tid] = true;
12921062SN/A
12932292SN/A                DPRINTF(IEW, "Execute: Branch mispredict detected.\n");
12946036Sksewell@umich.edu                DPRINTF(IEW, "Predicted target was PC:%#x, NPC:%#x.\n",
12957720Sgblack@eecs.umich.edu                        inst->predInstAddr(), inst->predNextInstAddr());
12967720Sgblack@eecs.umich.edu                DPRINTF(IEW, "Execute: Redirecting fetch to PC: %s.\n",
12977720Sgblack@eecs.umich.edu                        inst->pcState(), inst->nextInstAddr());
12981062SN/A                // If incorrect, then signal the ROB that it must be squashed.
12992292SN/A                squashDueToBranch(inst, tid);
13001062SN/A
13013795Sgblack@eecs.umich.edu                if (inst->readPredTaken()) {
13021062SN/A                    predictedTakenIncorrect++;
13032292SN/A                } else {
13042292SN/A                    predictedNotTakenIncorrect++;
13051062SN/A                }
13062292SN/A            } else if (ldstQueue.violation(tid)) {
13074033Sktlim@umich.edu                assert(inst->isMemRef());
13082326SN/A                // If there was an ordering violation, then get the
13092326SN/A                // DynInst that caused the violation.  Note that this
13102292SN/A                // clears the violation signal.
13112292SN/A                DynInstPtr violator;
13122292SN/A                violator = ldstQueue.getMemDepViolator(tid);
13131062SN/A
13147720Sgblack@eecs.umich.edu                DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: %s "
13157720Sgblack@eecs.umich.edu                        "[sn:%lli], inst PC: %s [sn:%lli]. Addr is: %#x.\n",
13167720Sgblack@eecs.umich.edu                        violator->pcState(), violator->seqNum,
13177720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum, inst->physEffAddr);
13187720Sgblack@eecs.umich.edu
13193732Sktlim@umich.edu                fetchRedirect[tid] = true;
13203732Sktlim@umich.edu
13211062SN/A                // Tell the instruction queue that a violation has occured.
13221062SN/A                instQueue.violation(inst, violator);
13231062SN/A
13241062SN/A                // Squash.
13252292SN/A                squashDueToMemOrder(inst,tid);
13261062SN/A
13271062SN/A                ++memOrderViolationEvents;
13282292SN/A            } else if (ldstQueue.loadBlocked(tid) &&
13292292SN/A                       !ldstQueue.isLoadBlockedHandled(tid)) {
13302292SN/A                fetchRedirect[tid] = true;
13312292SN/A
13322292SN/A                DPRINTF(IEW, "Load operation couldn't execute because the "
13337720Sgblack@eecs.umich.edu                        "memory system is blocked.  PC: %s [sn:%lli]\n",
13347720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum);
13352292SN/A
13362292SN/A                squashDueToMemBlocked(inst, tid);
13371062SN/A            }
13384033Sktlim@umich.edu        } else {
13394033Sktlim@umich.edu            // Reset any state associated with redirects that will not
13404033Sktlim@umich.edu            // be used.
13414033Sktlim@umich.edu            if (ldstQueue.violation(tid)) {
13424033Sktlim@umich.edu                assert(inst->isMemRef());
13434033Sktlim@umich.edu
13444033Sktlim@umich.edu                DynInstPtr violator = ldstQueue.getMemDepViolator(tid);
13454033Sktlim@umich.edu
13464033Sktlim@umich.edu                DPRINTF(IEW, "LDSTQ detected a violation.  Violator PC: "
13477720Sgblack@eecs.umich.edu                        "%s, inst PC: %s.  Addr is: %#x.\n",
13487720Sgblack@eecs.umich.edu                        violator->pcState(), inst->pcState(),
13497720Sgblack@eecs.umich.edu                        inst->physEffAddr);
13504033Sktlim@umich.edu                DPRINTF(IEW, "Violation will not be handled because "
13514033Sktlim@umich.edu                        "already squashing\n");
13524033Sktlim@umich.edu
13534033Sktlim@umich.edu                ++memOrderViolationEvents;
13544033Sktlim@umich.edu            }
13554033Sktlim@umich.edu            if (ldstQueue.loadBlocked(tid) &&
13564033Sktlim@umich.edu                !ldstQueue.isLoadBlockedHandled(tid)) {
13574033Sktlim@umich.edu                DPRINTF(IEW, "Load operation couldn't execute because the "
13587720Sgblack@eecs.umich.edu                        "memory system is blocked.  PC: %s [sn:%lli]\n",
13597720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum);
13604033Sktlim@umich.edu                DPRINTF(IEW, "Blocked load will not be handled because "
13614033Sktlim@umich.edu                        "already squashing\n");
13624033Sktlim@umich.edu
13634033Sktlim@umich.edu                ldstQueue.setLoadBlockedHandled(tid);
13644033Sktlim@umich.edu            }
13654033Sktlim@umich.edu
13661062SN/A        }
13671062SN/A    }
13682292SN/A
13692348SN/A    // Update and record activity if we processed any instructions.
13702292SN/A    if (inst_num) {
13712292SN/A        if (exeStatus == Idle) {
13722292SN/A            exeStatus = Running;
13732292SN/A        }
13742292SN/A
13752292SN/A        updatedQueues = true;
13762292SN/A
13772292SN/A        cpu->activityThisCycle();
13782292SN/A    }
13792292SN/A
13802292SN/A    // Need to reset this in case a writeback event needs to write into the
13812292SN/A    // iew queue.  That way the writeback event will write into the correct
13822292SN/A    // spot in the queue.
13832292SN/A    wbNumInst = 0;
13842107SN/A}
13852107SN/A
13862292SN/Atemplate <class Impl>
13872107SN/Avoid
13882292SN/ADefaultIEW<Impl>::writebackInsts()
13892107SN/A{
13902326SN/A    // Loop through the head of the time buffer and wake any
13912326SN/A    // dependents.  These instructions are about to write back.  Also
13922326SN/A    // mark scoreboard that this instruction is finally complete.
13932326SN/A    // Either have IEW have direct access to scoreboard, or have this
13942326SN/A    // as part of backwards communication.
13953958Sgblack@eecs.umich.edu    for (int inst_num = 0; inst_num < wbWidth &&
13962292SN/A             toCommit->insts[inst_num]; inst_num++) {
13972107SN/A        DynInstPtr inst = toCommit->insts[inst_num];
13986221Snate@binkert.org        ThreadID tid = inst->threadNumber;
13992107SN/A
14007720Sgblack@eecs.umich.edu        DPRINTF(IEW, "Sending instructions to commit, [sn:%lli] PC %s.\n",
14017720Sgblack@eecs.umich.edu                inst->seqNum, inst->pcState());
14022107SN/A
14032301SN/A        iewInstsToCommit[tid]++;
14042301SN/A
14052292SN/A        // Some instructions will be sent to commit without having
14062292SN/A        // executed because they need commit to handle them.
14072292SN/A        // E.g. Uncached loads have not actually executed when they
14082292SN/A        // are first sent to commit.  Instead commit must tell the LSQ
14092292SN/A        // when it's ready to execute the uncached load.
14102367SN/A        if (!inst->isSquashed() && inst->isExecuted() && inst->getFault() == NoFault) {
14112301SN/A            int dependents = instQueue.wakeDependents(inst);
14122107SN/A
14132292SN/A            for (int i = 0; i < inst->numDestRegs(); i++) {
14142292SN/A                //mark as Ready
14152292SN/A                DPRINTF(IEW,"Setting Destination Register %i\n",
14162292SN/A                        inst->renamedDestRegIdx(i));
14172292SN/A                scoreboard->setReg(inst->renamedDestRegIdx(i));
14182107SN/A            }
14192301SN/A
14202348SN/A            if (dependents) {
14212348SN/A                producerInst[tid]++;
14222348SN/A                consumerInst[tid]+= dependents;
14232348SN/A            }
14242326SN/A            writebackCount[tid]++;
14252107SN/A        }
14262820Sktlim@umich.edu
14272820Sktlim@umich.edu        decrWb(inst->seqNum);
14282107SN/A    }
14291060SN/A}
14301060SN/A
14311681SN/Atemplate<class Impl>
14321060SN/Avoid
14332292SN/ADefaultIEW<Impl>::tick()
14341060SN/A{
14352292SN/A    wbNumInst = 0;
14362292SN/A    wbCycle = 0;
14371060SN/A
14382292SN/A    wroteToTimeBuffer = false;
14392292SN/A    updatedQueues = false;
14401060SN/A
14412292SN/A    sortInsts();
14421060SN/A
14432326SN/A    // Free function units marked as being freed this cycle.
14442326SN/A    fuPool->processFreeUnits();
14451062SN/A
14466221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
14476221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
14481060SN/A
14492326SN/A    // Check stall and squash signals, dispatch any instructions.
14503867Sbinkertn@umich.edu    while (threads != end) {
14516221Snate@binkert.org        ThreadID tid = *threads++;
14521060SN/A
14532292SN/A        DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid);
14541060SN/A
14552292SN/A        checkSignalsAndUpdate(tid);
14562292SN/A        dispatch(tid);
14571060SN/A    }
14581060SN/A
14592292SN/A    if (exeStatus != Squashing) {
14602292SN/A        executeInsts();
14611060SN/A
14622292SN/A        writebackInsts();
14632292SN/A
14642292SN/A        // Have the instruction queue try to schedule any ready instructions.
14652292SN/A        // (In actuality, this scheduling is for instructions that will
14662292SN/A        // be executed next cycle.)
14672292SN/A        instQueue.scheduleReadyInsts();
14682292SN/A
14692292SN/A        // Also should advance its own time buffers if the stage ran.
14702292SN/A        // Not the best place for it, but this works (hopefully).
14712292SN/A        issueToExecQueue.advance();
14722292SN/A    }
14732292SN/A
14742292SN/A    bool broadcast_free_entries = false;
14752292SN/A
14762292SN/A    if (updatedQueues || exeStatus == Running || updateLSQNextCycle) {
14772292SN/A        exeStatus = Idle;
14782292SN/A        updateLSQNextCycle = false;
14792292SN/A
14802292SN/A        broadcast_free_entries = true;
14812292SN/A    }
14822292SN/A
14832292SN/A    // Writeback any stores using any leftover bandwidth.
14841681SN/A    ldstQueue.writebackStores();
14851681SN/A
14861061SN/A    // Check the committed load/store signals to see if there's a load
14871061SN/A    // or store to commit.  Also check if it's being told to execute a
14881061SN/A    // nonspeculative instruction.
14891681SN/A    // This is pretty inefficient...
14902292SN/A
14913867Sbinkertn@umich.edu    threads = activeThreads->begin();
14923867Sbinkertn@umich.edu    while (threads != end) {
14936221Snate@binkert.org        ThreadID tid = (*threads++);
14942292SN/A
14952292SN/A        DPRINTF(IEW,"Processing [tid:%i]\n",tid);
14962292SN/A
14972348SN/A        // Update structures based on instructions committed.
14982292SN/A        if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
14992292SN/A            !fromCommit->commitInfo[tid].squash &&
15002292SN/A            !fromCommit->commitInfo[tid].robSquashing) {
15012292SN/A
15022292SN/A            ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid);
15032292SN/A
15042292SN/A            ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid);
15052292SN/A
15062292SN/A            updateLSQNextCycle = true;
15072292SN/A            instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid);
15082292SN/A        }
15092292SN/A
15102292SN/A        if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) {
15112292SN/A
15122292SN/A            //DPRINTF(IEW,"NonspecInst from thread %i",tid);
15132292SN/A            if (fromCommit->commitInfo[tid].uncached) {
15142292SN/A                instQueue.replayMemInst(fromCommit->commitInfo[tid].uncachedLoad);
15154033Sktlim@umich.edu                fromCommit->commitInfo[tid].uncachedLoad->setAtCommit();
15162292SN/A            } else {
15172292SN/A                instQueue.scheduleNonSpec(
15182292SN/A                    fromCommit->commitInfo[tid].nonSpecSeqNum);
15192292SN/A            }
15202292SN/A        }
15212292SN/A
15222292SN/A        if (broadcast_free_entries) {
15232292SN/A            toFetch->iewInfo[tid].iqCount =
15242292SN/A                instQueue.getCount(tid);
15252292SN/A            toFetch->iewInfo[tid].ldstqCount =
15262292SN/A                ldstQueue.getCount(tid);
15272292SN/A
15282292SN/A            toRename->iewInfo[tid].usedIQ = true;
15292292SN/A            toRename->iewInfo[tid].freeIQEntries =
15302292SN/A                instQueue.numFreeEntries();
15312292SN/A            toRename->iewInfo[tid].usedLSQ = true;
15322292SN/A            toRename->iewInfo[tid].freeLSQEntries =
15332292SN/A                ldstQueue.numFreeEntries(tid);
15342292SN/A
15352292SN/A            wroteToTimeBuffer = true;
15362292SN/A        }
15372292SN/A
15382292SN/A        DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n",
15392292SN/A                tid, toRename->iewInfo[tid].dispatched);
15401061SN/A    }
15411061SN/A
15422292SN/A    DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i).  "
15432292SN/A            "LSQ has %i free entries.\n",
15442292SN/A            instQueue.numFreeEntries(), instQueue.hasReadyInsts(),
15452292SN/A            ldstQueue.numFreeEntries());
15462292SN/A
15472292SN/A    updateStatus();
15482292SN/A
15492292SN/A    if (wroteToTimeBuffer) {
15502292SN/A        DPRINTF(Activity, "Activity this cycle.\n");
15512292SN/A        cpu->activityThisCycle();
15521061SN/A    }
15531060SN/A}
15541060SN/A
15552301SN/Atemplate <class Impl>
15561060SN/Avoid
15572301SN/ADefaultIEW<Impl>::updateExeInstStats(DynInstPtr &inst)
15581060SN/A{
15596221Snate@binkert.org    ThreadID tid = inst->threadNumber;
15601060SN/A
15612301SN/A    //
15622301SN/A    //  Pick off the software prefetches
15632301SN/A    //
15642301SN/A#ifdef TARGET_ALPHA
15652301SN/A    if (inst->isDataPrefetch())
15666221Snate@binkert.org        iewExecutedSwp[tid]++;
15672301SN/A    else
15682727Sktlim@umich.edu        iewIewExecutedcutedInsts++;
15692301SN/A#else
15702669Sktlim@umich.edu    iewExecutedInsts++;
15712301SN/A#endif
15721060SN/A
15732301SN/A    //
15742301SN/A    //  Control operations
15752301SN/A    //
15762301SN/A    if (inst->isControl())
15776221Snate@binkert.org        iewExecutedBranches[tid]++;
15781060SN/A
15792301SN/A    //
15802301SN/A    //  Memory operations
15812301SN/A    //
15822301SN/A    if (inst->isMemRef()) {
15836221Snate@binkert.org        iewExecutedRefs[tid]++;
15841060SN/A
15852301SN/A        if (inst->isLoad()) {
15866221Snate@binkert.org            iewExecLoadInsts[tid]++;
15871060SN/A        }
15881060SN/A    }
15891060SN/A}
15907598Sminkyu.jeong@arm.com
15917598Sminkyu.jeong@arm.comtemplate <class Impl>
15927598Sminkyu.jeong@arm.comvoid
15937598Sminkyu.jeong@arm.comDefaultIEW<Impl>::checkMisprediction(DynInstPtr &inst)
15947598Sminkyu.jeong@arm.com{
15957598Sminkyu.jeong@arm.com    ThreadID tid = inst->threadNumber;
15967598Sminkyu.jeong@arm.com
15977598Sminkyu.jeong@arm.com    if (!fetchRedirect[tid] ||
15987598Sminkyu.jeong@arm.com        toCommit->squashedSeqNum[tid] > inst->seqNum) {
15997598Sminkyu.jeong@arm.com
16007598Sminkyu.jeong@arm.com        if (inst->mispredicted()) {
16017598Sminkyu.jeong@arm.com            fetchRedirect[tid] = true;
16027598Sminkyu.jeong@arm.com
16037598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Execute: Branch mispredict detected.\n");
16047598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Predicted target was PC:%#x, NPC:%#x.\n",
16057720Sgblack@eecs.umich.edu                    inst->predInstAddr(), inst->predNextInstAddr());
16067598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Execute: Redirecting fetch to PC: %#x,"
16077720Sgblack@eecs.umich.edu                    " NPC: %#x.\n", inst->nextInstAddr(),
16087720Sgblack@eecs.umich.edu                    inst->nextInstAddr());
16097598Sminkyu.jeong@arm.com            // If incorrect, then signal the ROB that it must be squashed.
16107598Sminkyu.jeong@arm.com            squashDueToBranch(inst, tid);
16117598Sminkyu.jeong@arm.com
16127598Sminkyu.jeong@arm.com            if (inst->readPredTaken()) {
16137598Sminkyu.jeong@arm.com                predictedTakenIncorrect++;
16147598Sminkyu.jeong@arm.com            } else {
16157598Sminkyu.jeong@arm.com                predictedNotTakenIncorrect++;
16167598Sminkyu.jeong@arm.com            }
16177598Sminkyu.jeong@arm.com        }
16187598Sminkyu.jeong@arm.com    }
16197598Sminkyu.jeong@arm.com}
1620