iew_impl.hh revision 9783
11689SN/A/*
29783Sandreas.hansson@arm.com * Copyright (c) 2010-2013 ARM Limited
37598Sminkyu.jeong@arm.com * All rights reserved.
47598Sminkyu.jeong@arm.com *
57598Sminkyu.jeong@arm.com * The license below extends only to copyright in the software and shall
67598Sminkyu.jeong@arm.com * not be construed as granting a license to any other intellectual
77598Sminkyu.jeong@arm.com * property including but not limited to intellectual property relating
87598Sminkyu.jeong@arm.com * to a hardware implementation of the functionality of the software
97598Sminkyu.jeong@arm.com * licensed hereunder.  You may use the software subject to the license
107598Sminkyu.jeong@arm.com * terms below provided that you ensure that this notice is replicated
117598Sminkyu.jeong@arm.com * unmodified and in its entirety in all distributions of the software,
127598Sminkyu.jeong@arm.com * modified or unmodified, in source code or in binary form.
137598Sminkyu.jeong@arm.com *
142326SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
151689SN/A * All rights reserved.
161689SN/A *
171689SN/A * Redistribution and use in source and binary forms, with or without
181689SN/A * modification, are permitted provided that the following conditions are
191689SN/A * met: redistributions of source code must retain the above copyright
201689SN/A * notice, this list of conditions and the following disclaimer;
211689SN/A * redistributions in binary form must reproduce the above copyright
221689SN/A * notice, this list of conditions and the following disclaimer in the
231689SN/A * documentation and/or other materials provided with the distribution;
241689SN/A * neither the name of the copyright holders nor the names of its
251689SN/A * contributors may be used to endorse or promote products derived from
261689SN/A * this software without specific prior written permission.
271689SN/A *
281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
411689SN/A */
421689SN/A
431060SN/A// @todo: Fix the instantaneous communication among all the stages within
441060SN/A// iew.  There's a clear delay between issue and execute, yet backwards
451689SN/A// communication happens simultaneously.
461060SN/A
471060SN/A#include <queue>
481060SN/A
498230Snate@binkert.org#include "arch/utility.hh"
506658Snate@binkert.org#include "config/the_isa.hh"
518887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh"
522292SN/A#include "cpu/o3/fu_pool.hh"
531717SN/A#include "cpu/o3/iew.hh"
548229Snate@binkert.org#include "cpu/timebuf.hh"
558232Snate@binkert.org#include "debug/Activity.hh"
568232Snate@binkert.org#include "debug/Decode.hh"
579444SAndreas.Sandberg@ARM.com#include "debug/Drain.hh"
588232Snate@binkert.org#include "debug/IEW.hh"
599527SMatt.Horsnell@arm.com#include "debug/O3PipeView.hh"
605529Snate@binkert.org#include "params/DerivO3CPU.hh"
611060SN/A
626221Snate@binkert.orgusing namespace std;
636221Snate@binkert.org
641681SN/Atemplate<class Impl>
655529Snate@binkert.orgDefaultIEW<Impl>::DefaultIEW(O3CPU *_cpu, DerivO3CPUParams *params)
662873Sktlim@umich.edu    : issueToExecQueue(params->backComSize, params->forwardComSize),
674329Sktlim@umich.edu      cpu(_cpu),
684329Sktlim@umich.edu      instQueue(_cpu, this, params),
694329Sktlim@umich.edu      ldstQueue(_cpu, this, params),
702292SN/A      fuPool(params->fuPool),
712292SN/A      commitToIEWDelay(params->commitToIEWDelay),
722292SN/A      renameToIEWDelay(params->renameToIEWDelay),
732292SN/A      issueToExecuteDelay(params->issueToExecuteDelay),
742820Sktlim@umich.edu      dispatchWidth(params->dispatchWidth),
752292SN/A      issueWidth(params->issueWidth),
762820Sktlim@umich.edu      wbOutstanding(0),
772820Sktlim@umich.edu      wbWidth(params->wbWidth),
789444SAndreas.Sandberg@ARM.com      numThreads(params->numThreads)
791060SN/A{
802292SN/A    _status = Active;
812292SN/A    exeStatus = Running;
822292SN/A    wbStatus = Idle;
831060SN/A
841060SN/A    // Setup wire to read instructions coming from issue.
851060SN/A    fromIssue = issueToExecQueue.getWire(-issueToExecuteDelay);
861060SN/A
871060SN/A    // Instruction queue needs the queue between issue and execute.
881060SN/A    instQueue.setIssueToExecuteQueue(&issueToExecQueue);
891681SN/A
906221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
916221Snate@binkert.org        dispatchStatus[tid] = Running;
926221Snate@binkert.org        stalls[tid].commit = false;
936221Snate@binkert.org        fetchRedirect[tid] = false;
942292SN/A    }
952292SN/A
962820Sktlim@umich.edu    wbMax = wbWidth * params->wbDepth;
972820Sktlim@umich.edu
982292SN/A    updateLSQNextCycle = false;
992292SN/A
1002820Sktlim@umich.edu    ableToIssue = true;
1012820Sktlim@umich.edu
1022292SN/A    skidBufferMax = (3 * (renameToIEWDelay * params->renameWidth)) + issueWidth;
1032292SN/A}
1042292SN/A
1052292SN/Atemplate <class Impl>
1062292SN/Astd::string
1072292SN/ADefaultIEW<Impl>::name() const
1082292SN/A{
1092292SN/A    return cpu->name() + ".iew";
1101060SN/A}
1111060SN/A
1121681SN/Atemplate <class Impl>
1131062SN/Avoid
1142292SN/ADefaultIEW<Impl>::regStats()
1151062SN/A{
1162301SN/A    using namespace Stats;
1172301SN/A
1181062SN/A    instQueue.regStats();
1192727Sktlim@umich.edu    ldstQueue.regStats();
1201062SN/A
1211062SN/A    iewIdleCycles
1221062SN/A        .name(name() + ".iewIdleCycles")
1231062SN/A        .desc("Number of cycles IEW is idle");
1241062SN/A
1251062SN/A    iewSquashCycles
1261062SN/A        .name(name() + ".iewSquashCycles")
1271062SN/A        .desc("Number of cycles IEW is squashing");
1281062SN/A
1291062SN/A    iewBlockCycles
1301062SN/A        .name(name() + ".iewBlockCycles")
1311062SN/A        .desc("Number of cycles IEW is blocking");
1321062SN/A
1331062SN/A    iewUnblockCycles
1341062SN/A        .name(name() + ".iewUnblockCycles")
1351062SN/A        .desc("Number of cycles IEW is unblocking");
1361062SN/A
1371062SN/A    iewDispatchedInsts
1381062SN/A        .name(name() + ".iewDispatchedInsts")
1391062SN/A        .desc("Number of instructions dispatched to IQ");
1401062SN/A
1411062SN/A    iewDispSquashedInsts
1421062SN/A        .name(name() + ".iewDispSquashedInsts")
1431062SN/A        .desc("Number of squashed instructions skipped by dispatch");
1441062SN/A
1451062SN/A    iewDispLoadInsts
1461062SN/A        .name(name() + ".iewDispLoadInsts")
1471062SN/A        .desc("Number of dispatched load instructions");
1481062SN/A
1491062SN/A    iewDispStoreInsts
1501062SN/A        .name(name() + ".iewDispStoreInsts")
1511062SN/A        .desc("Number of dispatched store instructions");
1521062SN/A
1531062SN/A    iewDispNonSpecInsts
1541062SN/A        .name(name() + ".iewDispNonSpecInsts")
1551062SN/A        .desc("Number of dispatched non-speculative instructions");
1561062SN/A
1571062SN/A    iewIQFullEvents
1581062SN/A        .name(name() + ".iewIQFullEvents")
1591062SN/A        .desc("Number of times the IQ has become full, causing a stall");
1601062SN/A
1612292SN/A    iewLSQFullEvents
1622292SN/A        .name(name() + ".iewLSQFullEvents")
1632292SN/A        .desc("Number of times the LSQ has become full, causing a stall");
1642292SN/A
1651062SN/A    memOrderViolationEvents
1661062SN/A        .name(name() + ".memOrderViolationEvents")
1671062SN/A        .desc("Number of memory order violations");
1681062SN/A
1691062SN/A    predictedTakenIncorrect
1701062SN/A        .name(name() + ".predictedTakenIncorrect")
1711062SN/A        .desc("Number of branches that were predicted taken incorrectly");
1722292SN/A
1732292SN/A    predictedNotTakenIncorrect
1742292SN/A        .name(name() + ".predictedNotTakenIncorrect")
1752292SN/A        .desc("Number of branches that were predicted not taken incorrectly");
1762292SN/A
1772292SN/A    branchMispredicts
1782292SN/A        .name(name() + ".branchMispredicts")
1792292SN/A        .desc("Number of branch mispredicts detected at execute");
1802292SN/A
1812292SN/A    branchMispredicts = predictedTakenIncorrect + predictedNotTakenIncorrect;
1822301SN/A
1832727Sktlim@umich.edu    iewExecutedInsts
1842353SN/A        .name(name() + ".iewExecutedInsts")
1852727Sktlim@umich.edu        .desc("Number of executed instructions");
1862727Sktlim@umich.edu
1872727Sktlim@umich.edu    iewExecLoadInsts
1886221Snate@binkert.org        .init(cpu->numThreads)
1892353SN/A        .name(name() + ".iewExecLoadInsts")
1902727Sktlim@umich.edu        .desc("Number of load instructions executed")
1912727Sktlim@umich.edu        .flags(total);
1922727Sktlim@umich.edu
1932727Sktlim@umich.edu    iewExecSquashedInsts
1942353SN/A        .name(name() + ".iewExecSquashedInsts")
1952727Sktlim@umich.edu        .desc("Number of squashed instructions skipped in execute");
1962727Sktlim@umich.edu
1972727Sktlim@umich.edu    iewExecutedSwp
1986221Snate@binkert.org        .init(cpu->numThreads)
1998240Snate@binkert.org        .name(name() + ".exec_swp")
2002301SN/A        .desc("number of swp insts executed")
2012727Sktlim@umich.edu        .flags(total);
2022301SN/A
2032727Sktlim@umich.edu    iewExecutedNop
2046221Snate@binkert.org        .init(cpu->numThreads)
2058240Snate@binkert.org        .name(name() + ".exec_nop")
2062301SN/A        .desc("number of nop insts executed")
2072727Sktlim@umich.edu        .flags(total);
2082301SN/A
2092727Sktlim@umich.edu    iewExecutedRefs
2106221Snate@binkert.org        .init(cpu->numThreads)
2118240Snate@binkert.org        .name(name() + ".exec_refs")
2122301SN/A        .desc("number of memory reference insts executed")
2132727Sktlim@umich.edu        .flags(total);
2142301SN/A
2152727Sktlim@umich.edu    iewExecutedBranches
2166221Snate@binkert.org        .init(cpu->numThreads)
2178240Snate@binkert.org        .name(name() + ".exec_branches")
2182301SN/A        .desc("Number of branches executed")
2192727Sktlim@umich.edu        .flags(total);
2202301SN/A
2212301SN/A    iewExecStoreInsts
2228240Snate@binkert.org        .name(name() + ".exec_stores")
2232301SN/A        .desc("Number of stores executed")
2242727Sktlim@umich.edu        .flags(total);
2252727Sktlim@umich.edu    iewExecStoreInsts = iewExecutedRefs - iewExecLoadInsts;
2262727Sktlim@umich.edu
2272727Sktlim@umich.edu    iewExecRate
2288240Snate@binkert.org        .name(name() + ".exec_rate")
2292727Sktlim@umich.edu        .desc("Inst execution rate")
2302727Sktlim@umich.edu        .flags(total);
2312727Sktlim@umich.edu
2322727Sktlim@umich.edu    iewExecRate = iewExecutedInsts / cpu->numCycles;
2332301SN/A
2342301SN/A    iewInstsToCommit
2356221Snate@binkert.org        .init(cpu->numThreads)
2368240Snate@binkert.org        .name(name() + ".wb_sent")
2372301SN/A        .desc("cumulative count of insts sent to commit")
2382727Sktlim@umich.edu        .flags(total);
2392301SN/A
2402326SN/A    writebackCount
2416221Snate@binkert.org        .init(cpu->numThreads)
2428240Snate@binkert.org        .name(name() + ".wb_count")
2432301SN/A        .desc("cumulative count of insts written-back")
2442727Sktlim@umich.edu        .flags(total);
2452301SN/A
2462326SN/A    producerInst
2476221Snate@binkert.org        .init(cpu->numThreads)
2488240Snate@binkert.org        .name(name() + ".wb_producers")
2492301SN/A        .desc("num instructions producing a value")
2502727Sktlim@umich.edu        .flags(total);
2512301SN/A
2522326SN/A    consumerInst
2536221Snate@binkert.org        .init(cpu->numThreads)
2548240Snate@binkert.org        .name(name() + ".wb_consumers")
2552301SN/A        .desc("num instructions consuming a value")
2562727Sktlim@umich.edu        .flags(total);
2572301SN/A
2582326SN/A    wbPenalized
2596221Snate@binkert.org        .init(cpu->numThreads)
2608240Snate@binkert.org        .name(name() + ".wb_penalized")
2612301SN/A        .desc("number of instrctions required to write to 'other' IQ")
2622727Sktlim@umich.edu        .flags(total);
2632301SN/A
2642326SN/A    wbPenalizedRate
2658240Snate@binkert.org        .name(name() + ".wb_penalized_rate")
2662301SN/A        .desc ("fraction of instructions written-back that wrote to 'other' IQ")
2672727Sktlim@umich.edu        .flags(total);
2682301SN/A
2692326SN/A    wbPenalizedRate = wbPenalized / writebackCount;
2702301SN/A
2712326SN/A    wbFanout
2728240Snate@binkert.org        .name(name() + ".wb_fanout")
2732301SN/A        .desc("average fanout of values written-back")
2742727Sktlim@umich.edu        .flags(total);
2752301SN/A
2762326SN/A    wbFanout = producerInst / consumerInst;
2772301SN/A
2782326SN/A    wbRate
2798240Snate@binkert.org        .name(name() + ".wb_rate")
2802301SN/A        .desc("insts written-back per cycle")
2812727Sktlim@umich.edu        .flags(total);
2822326SN/A    wbRate = writebackCount / cpu->numCycles;
2831062SN/A}
2841062SN/A
2851681SN/Atemplate<class Impl>
2861060SN/Avoid
2879427SAndreas.Sandberg@ARM.comDefaultIEW<Impl>::startupStage()
2881060SN/A{
2896221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
2902292SN/A        toRename->iewInfo[tid].usedIQ = true;
2912292SN/A        toRename->iewInfo[tid].freeIQEntries =
2922292SN/A            instQueue.numFreeEntries(tid);
2932292SN/A
2942292SN/A        toRename->iewInfo[tid].usedLSQ = true;
2952292SN/A        toRename->iewInfo[tid].freeLSQEntries =
2962292SN/A            ldstQueue.numFreeEntries(tid);
2972292SN/A    }
2982292SN/A
2998887Sgeoffrey.blake@arm.com    // Initialize the checker's dcache port here
3008733Sgeoffrey.blake@arm.com    if (cpu->checker) {
3018850Sandreas.hansson@arm.com        cpu->checker->setDcachePort(&cpu->getDataPort());
3028887Sgeoffrey.blake@arm.com    }
3038733Sgeoffrey.blake@arm.com
3042733Sktlim@umich.edu    cpu->activateStage(O3CPU::IEWIdx);
3051060SN/A}
3061060SN/A
3071681SN/Atemplate<class Impl>
3081060SN/Avoid
3092292SN/ADefaultIEW<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *tb_ptr)
3101060SN/A{
3111060SN/A    timeBuffer = tb_ptr;
3121060SN/A
3131060SN/A    // Setup wire to read information from time buffer, from commit.
3141060SN/A    fromCommit = timeBuffer->getWire(-commitToIEWDelay);
3151060SN/A
3161060SN/A    // Setup wire to write information back to previous stages.
3171060SN/A    toRename = timeBuffer->getWire(0);
3181060SN/A
3192292SN/A    toFetch = timeBuffer->getWire(0);
3202292SN/A
3211060SN/A    // Instruction queue also needs main time buffer.
3221060SN/A    instQueue.setTimeBuffer(tb_ptr);
3231060SN/A}
3241060SN/A
3251681SN/Atemplate<class Impl>
3261060SN/Avoid
3272292SN/ADefaultIEW<Impl>::setRenameQueue(TimeBuffer<RenameStruct> *rq_ptr)
3281060SN/A{
3291060SN/A    renameQueue = rq_ptr;
3301060SN/A
3311060SN/A    // Setup wire to read information from rename queue.
3321060SN/A    fromRename = renameQueue->getWire(-renameToIEWDelay);
3331060SN/A}
3341060SN/A
3351681SN/Atemplate<class Impl>
3361060SN/Avoid
3372292SN/ADefaultIEW<Impl>::setIEWQueue(TimeBuffer<IEWStruct> *iq_ptr)
3381060SN/A{
3391060SN/A    iewQueue = iq_ptr;
3401060SN/A
3411060SN/A    // Setup wire to write instructions to commit.
3421060SN/A    toCommit = iewQueue->getWire(0);
3431060SN/A}
3441060SN/A
3451681SN/Atemplate<class Impl>
3461060SN/Avoid
3476221Snate@binkert.orgDefaultIEW<Impl>::setActiveThreads(list<ThreadID> *at_ptr)
3481060SN/A{
3492292SN/A    activeThreads = at_ptr;
3502292SN/A
3512292SN/A    ldstQueue.setActiveThreads(at_ptr);
3522292SN/A    instQueue.setActiveThreads(at_ptr);
3531060SN/A}
3541060SN/A
3551681SN/Atemplate<class Impl>
3561060SN/Avoid
3572292SN/ADefaultIEW<Impl>::setScoreboard(Scoreboard *sb_ptr)
3581060SN/A{
3592292SN/A    scoreboard = sb_ptr;
3601060SN/A}
3611060SN/A
3622307SN/Atemplate <class Impl>
3632863Sktlim@umich.edubool
3649444SAndreas.Sandberg@ARM.comDefaultIEW<Impl>::isDrained() const
3652307SN/A{
3669444SAndreas.Sandberg@ARM.com    bool drained(ldstQueue.isDrained());
3679444SAndreas.Sandberg@ARM.com
3689444SAndreas.Sandberg@ARM.com    for (ThreadID tid = 0; tid < numThreads; tid++) {
3699444SAndreas.Sandberg@ARM.com        if (!insts[tid].empty()) {
3709444SAndreas.Sandberg@ARM.com            DPRINTF(Drain, "%i: Insts not empty.\n", tid);
3719444SAndreas.Sandberg@ARM.com            drained = false;
3729444SAndreas.Sandberg@ARM.com        }
3739444SAndreas.Sandberg@ARM.com        if (!skidBuffer[tid].empty()) {
3749444SAndreas.Sandberg@ARM.com            DPRINTF(Drain, "%i: Skid buffer not empty.\n", tid);
3759444SAndreas.Sandberg@ARM.com            drained = false;
3769444SAndreas.Sandberg@ARM.com        }
3779444SAndreas.Sandberg@ARM.com    }
3789444SAndreas.Sandberg@ARM.com
3799783Sandreas.hansson@arm.com    // Also check the FU pool as instructions are "stored" in FU
3809783Sandreas.hansson@arm.com    // completion events until they are done and not accounted for
3819783Sandreas.hansson@arm.com    // above
3829783Sandreas.hansson@arm.com    if (drained && !fuPool->isDrained()) {
3839783Sandreas.hansson@arm.com        DPRINTF(Drain, "FU pool still busy.\n");
3849783Sandreas.hansson@arm.com        drained = false;
3859783Sandreas.hansson@arm.com    }
3869783Sandreas.hansson@arm.com
3879444SAndreas.Sandberg@ARM.com    return drained;
3881681SN/A}
3891681SN/A
3902316SN/Atemplate <class Impl>
3911681SN/Avoid
3929444SAndreas.Sandberg@ARM.comDefaultIEW<Impl>::drainSanityCheck() const
3932843Sktlim@umich.edu{
3949444SAndreas.Sandberg@ARM.com    assert(isDrained());
3952843Sktlim@umich.edu
3969444SAndreas.Sandberg@ARM.com    instQueue.drainSanityCheck();
3979444SAndreas.Sandberg@ARM.com    ldstQueue.drainSanityCheck();
3981681SN/A}
3991681SN/A
4002307SN/Atemplate <class Impl>
4011681SN/Avoid
4022307SN/ADefaultIEW<Impl>::takeOverFrom()
4031060SN/A{
4042348SN/A    // Reset all state.
4052307SN/A    _status = Active;
4062307SN/A    exeStatus = Running;
4072307SN/A    wbStatus = Idle;
4081060SN/A
4092307SN/A    instQueue.takeOverFrom();
4102307SN/A    ldstQueue.takeOverFrom();
4119444SAndreas.Sandberg@ARM.com    fuPool->takeOverFrom();
4121060SN/A
4139427SAndreas.Sandberg@ARM.com    startupStage();
4142307SN/A    cpu->activityThisCycle();
4151060SN/A
4166221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
4176221Snate@binkert.org        dispatchStatus[tid] = Running;
4186221Snate@binkert.org        stalls[tid].commit = false;
4196221Snate@binkert.org        fetchRedirect[tid] = false;
4202307SN/A    }
4211060SN/A
4222307SN/A    updateLSQNextCycle = false;
4232307SN/A
4242873Sktlim@umich.edu    for (int i = 0; i < issueToExecQueue.getSize(); ++i) {
4252307SN/A        issueToExecQueue.advance();
4261060SN/A    }
4271060SN/A}
4281060SN/A
4291681SN/Atemplate<class Impl>
4301060SN/Avoid
4316221Snate@binkert.orgDefaultIEW<Impl>::squash(ThreadID tid)
4322107SN/A{
4336221Snate@binkert.org    DPRINTF(IEW, "[tid:%i]: Squashing all instructions.\n", tid);
4342107SN/A
4352292SN/A    // Tell the IQ to start squashing.
4362292SN/A    instQueue.squash(tid);
4372107SN/A
4382292SN/A    // Tell the LDSTQ to start squashing.
4392326SN/A    ldstQueue.squash(fromCommit->commitInfo[tid].doneSeqNum, tid);
4402292SN/A    updatedQueues = true;
4412107SN/A
4422292SN/A    // Clear the skid buffer in case it has any data in it.
4432935Sksewell@umich.edu    DPRINTF(IEW, "[tid:%i]: Removing skidbuffer instructions until [sn:%i].\n",
4444632Sgblack@eecs.umich.edu            tid, fromCommit->commitInfo[tid].doneSeqNum);
4452935Sksewell@umich.edu
4462292SN/A    while (!skidBuffer[tid].empty()) {
4472292SN/A        if (skidBuffer[tid].front()->isLoad() ||
4482292SN/A            skidBuffer[tid].front()->isStore() ) {
4492292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
4502292SN/A        }
4512107SN/A
4522292SN/A        toRename->iewInfo[tid].dispatched++;
4532107SN/A
4542292SN/A        skidBuffer[tid].pop();
4552292SN/A    }
4562107SN/A
4572702Sktlim@umich.edu    emptyRenameInsts(tid);
4582107SN/A}
4592107SN/A
4602107SN/Atemplate<class Impl>
4612107SN/Avoid
4626221Snate@binkert.orgDefaultIEW<Impl>::squashDueToBranch(DynInstPtr &inst, ThreadID tid)
4632292SN/A{
4647720Sgblack@eecs.umich.edu    DPRINTF(IEW, "[tid:%i]: Squashing from a specific instruction, PC: %s "
4657720Sgblack@eecs.umich.edu            "[sn:%i].\n", tid, inst->pcState(), inst->seqNum);
4662292SN/A
4677852SMatt.Horsnell@arm.com    if (toCommit->squash[tid] == false ||
4687852SMatt.Horsnell@arm.com            inst->seqNum < toCommit->squashedSeqNum[tid]) {
4697852SMatt.Horsnell@arm.com        toCommit->squash[tid] = true;
4707852SMatt.Horsnell@arm.com        toCommit->squashedSeqNum[tid] = inst->seqNum;
4717852SMatt.Horsnell@arm.com        toCommit->branchTaken[tid] = inst->pcState().branching();
4722935Sksewell@umich.edu
4737852SMatt.Horsnell@arm.com        TheISA::PCState pc = inst->pcState();
4747852SMatt.Horsnell@arm.com        TheISA::advancePC(pc, inst->staticInst);
4752292SN/A
4767852SMatt.Horsnell@arm.com        toCommit->pc[tid] = pc;
4777852SMatt.Horsnell@arm.com        toCommit->mispredictInst[tid] = inst;
4787852SMatt.Horsnell@arm.com        toCommit->includeSquashInst[tid] = false;
4792292SN/A
4807852SMatt.Horsnell@arm.com        wroteToTimeBuffer = true;
4817852SMatt.Horsnell@arm.com    }
4827852SMatt.Horsnell@arm.com
4832292SN/A}
4842292SN/A
4852292SN/Atemplate<class Impl>
4862292SN/Avoid
4876221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemOrder(DynInstPtr &inst, ThreadID tid)
4882292SN/A{
4898513SGiacomo.Gabrielli@arm.com    DPRINTF(IEW, "[tid:%i]: Memory violation, squashing violator and younger "
4908513SGiacomo.Gabrielli@arm.com            "insts, PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum);
4918513SGiacomo.Gabrielli@arm.com    // Need to include inst->seqNum in the following comparison to cover the
4928513SGiacomo.Gabrielli@arm.com    // corner case when a branch misprediction and a memory violation for the
4938513SGiacomo.Gabrielli@arm.com    // same instruction (e.g. load PC) are detected in the same cycle.  In this
4948513SGiacomo.Gabrielli@arm.com    // case the memory violator should take precedence over the branch
4958513SGiacomo.Gabrielli@arm.com    // misprediction because it requires the violator itself to be included in
4968513SGiacomo.Gabrielli@arm.com    // the squash.
4978513SGiacomo.Gabrielli@arm.com    if (toCommit->squash[tid] == false ||
4988513SGiacomo.Gabrielli@arm.com            inst->seqNum <= toCommit->squashedSeqNum[tid]) {
4998513SGiacomo.Gabrielli@arm.com        toCommit->squash[tid] = true;
5002292SN/A
5017852SMatt.Horsnell@arm.com        toCommit->squashedSeqNum[tid] = inst->seqNum;
5028513SGiacomo.Gabrielli@arm.com        toCommit->pc[tid] = inst->pcState();
5038137SAli.Saidi@ARM.com        toCommit->mispredictInst[tid] = NULL;
5042292SN/A
5058513SGiacomo.Gabrielli@arm.com        // Must include the memory violator in the squash.
5068513SGiacomo.Gabrielli@arm.com        toCommit->includeSquashInst[tid] = true;
5072292SN/A
5087852SMatt.Horsnell@arm.com        wroteToTimeBuffer = true;
5097852SMatt.Horsnell@arm.com    }
5102292SN/A}
5112292SN/A
5122292SN/Atemplate<class Impl>
5132292SN/Avoid
5146221Snate@binkert.orgDefaultIEW<Impl>::squashDueToMemBlocked(DynInstPtr &inst, ThreadID tid)
5152292SN/A{
5162292SN/A    DPRINTF(IEW, "[tid:%i]: Memory blocked, squashing load and younger insts, "
5177720Sgblack@eecs.umich.edu            "PC: %s [sn:%i].\n", tid, inst->pcState(), inst->seqNum);
5187852SMatt.Horsnell@arm.com    if (toCommit->squash[tid] == false ||
5197852SMatt.Horsnell@arm.com            inst->seqNum < toCommit->squashedSeqNum[tid]) {
5207852SMatt.Horsnell@arm.com        toCommit->squash[tid] = true;
5212292SN/A
5227852SMatt.Horsnell@arm.com        toCommit->squashedSeqNum[tid] = inst->seqNum;
5237852SMatt.Horsnell@arm.com        toCommit->pc[tid] = inst->pcState();
5248137SAli.Saidi@ARM.com        toCommit->mispredictInst[tid] = NULL;
5252292SN/A
5267852SMatt.Horsnell@arm.com        // Must include the broadcasted SN in the squash.
5277852SMatt.Horsnell@arm.com        toCommit->includeSquashInst[tid] = true;
5282292SN/A
5297852SMatt.Horsnell@arm.com        ldstQueue.setLoadBlockedHandled(tid);
5302292SN/A
5317852SMatt.Horsnell@arm.com        wroteToTimeBuffer = true;
5327852SMatt.Horsnell@arm.com    }
5332292SN/A}
5342292SN/A
5352292SN/Atemplate<class Impl>
5362292SN/Avoid
5376221Snate@binkert.orgDefaultIEW<Impl>::block(ThreadID tid)
5382292SN/A{
5392292SN/A    DPRINTF(IEW, "[tid:%u]: Blocking.\n", tid);
5402292SN/A
5412292SN/A    if (dispatchStatus[tid] != Blocked &&
5422292SN/A        dispatchStatus[tid] != Unblocking) {
5432292SN/A        toRename->iewBlock[tid] = true;
5442292SN/A        wroteToTimeBuffer = true;
5452292SN/A    }
5462292SN/A
5472292SN/A    // Add the current inputs to the skid buffer so they can be
5482292SN/A    // reprocessed when this stage unblocks.
5492292SN/A    skidInsert(tid);
5502292SN/A
5512292SN/A    dispatchStatus[tid] = Blocked;
5522292SN/A}
5532292SN/A
5542292SN/Atemplate<class Impl>
5552292SN/Avoid
5566221Snate@binkert.orgDefaultIEW<Impl>::unblock(ThreadID tid)
5572292SN/A{
5582292SN/A    DPRINTF(IEW, "[tid:%i]: Reading instructions out of the skid "
5592292SN/A            "buffer %u.\n",tid, tid);
5602292SN/A
5612292SN/A    // If the skid bufffer is empty, signal back to previous stages to unblock.
5622292SN/A    // Also switch status to running.
5632292SN/A    if (skidBuffer[tid].empty()) {
5642292SN/A        toRename->iewUnblock[tid] = true;
5652292SN/A        wroteToTimeBuffer = true;
5662292SN/A        DPRINTF(IEW, "[tid:%i]: Done unblocking.\n",tid);
5672292SN/A        dispatchStatus[tid] = Running;
5682292SN/A    }
5692292SN/A}
5702292SN/A
5712292SN/Atemplate<class Impl>
5722292SN/Avoid
5732292SN/ADefaultIEW<Impl>::wakeDependents(DynInstPtr &inst)
5741060SN/A{
5751681SN/A    instQueue.wakeDependents(inst);
5761060SN/A}
5771060SN/A
5782292SN/Atemplate<class Impl>
5792292SN/Avoid
5802292SN/ADefaultIEW<Impl>::rescheduleMemInst(DynInstPtr &inst)
5812292SN/A{
5822292SN/A    instQueue.rescheduleMemInst(inst);
5832292SN/A}
5841681SN/A
5851681SN/Atemplate<class Impl>
5861060SN/Avoid
5872292SN/ADefaultIEW<Impl>::replayMemInst(DynInstPtr &inst)
5881060SN/A{
5892292SN/A    instQueue.replayMemInst(inst);
5902292SN/A}
5911060SN/A
5922292SN/Atemplate<class Impl>
5932292SN/Avoid
5942292SN/ADefaultIEW<Impl>::instToCommit(DynInstPtr &inst)
5952292SN/A{
5963221Sktlim@umich.edu    // This function should not be called after writebackInsts in a
5973221Sktlim@umich.edu    // single cycle.  That will cause problems with an instruction
5983221Sktlim@umich.edu    // being added to the queue to commit without being processed by
5993221Sktlim@umich.edu    // writebackInsts prior to being sent to commit.
6003221Sktlim@umich.edu
6012292SN/A    // First check the time slot that this instruction will write
6022292SN/A    // to.  If there are free write ports at the time, then go ahead
6032292SN/A    // and write the instruction to that time.  If there are not,
6042292SN/A    // keep looking back to see where's the first time there's a
6052326SN/A    // free slot.
6062292SN/A    while ((*iewQueue)[wbCycle].insts[wbNumInst]) {
6072292SN/A        ++wbNumInst;
6082820Sktlim@umich.edu        if (wbNumInst == wbWidth) {
6092292SN/A            ++wbCycle;
6102292SN/A            wbNumInst = 0;
6112292SN/A        }
6122292SN/A
6132353SN/A        assert((wbCycle * wbWidth + wbNumInst) <= wbMax);
6142292SN/A    }
6152292SN/A
6162353SN/A    DPRINTF(IEW, "Current wb cycle: %i, width: %i, numInst: %i\nwbActual:%i\n",
6172353SN/A            wbCycle, wbWidth, wbNumInst, wbCycle * wbWidth + wbNumInst);
6182292SN/A    // Add finished instruction to queue to commit.
6192292SN/A    (*iewQueue)[wbCycle].insts[wbNumInst] = inst;
6202292SN/A    (*iewQueue)[wbCycle].size++;
6212292SN/A}
6222292SN/A
6232292SN/Atemplate <class Impl>
6242292SN/Aunsigned
6252292SN/ADefaultIEW<Impl>::validInstsFromRename()
6262292SN/A{
6272292SN/A    unsigned inst_count = 0;
6282292SN/A
6292292SN/A    for (int i=0; i<fromRename->size; i++) {
6302731Sktlim@umich.edu        if (!fromRename->insts[i]->isSquashed())
6312292SN/A            inst_count++;
6322292SN/A    }
6332292SN/A
6342292SN/A    return inst_count;
6352292SN/A}
6362292SN/A
6372292SN/Atemplate<class Impl>
6382292SN/Avoid
6396221Snate@binkert.orgDefaultIEW<Impl>::skidInsert(ThreadID tid)
6402292SN/A{
6412292SN/A    DynInstPtr inst = NULL;
6422292SN/A
6432292SN/A    while (!insts[tid].empty()) {
6442292SN/A        inst = insts[tid].front();
6452292SN/A
6462292SN/A        insts[tid].pop();
6472292SN/A
6487720Sgblack@eecs.umich.edu        DPRINTF(Decode,"[tid:%i]: Inserting [sn:%lli] PC:%s into "
6492292SN/A                "dispatch skidBuffer %i\n",tid, inst->seqNum,
6507720Sgblack@eecs.umich.edu                inst->pcState(),tid);
6512292SN/A
6522292SN/A        skidBuffer[tid].push(inst);
6532292SN/A    }
6542292SN/A
6552292SN/A    assert(skidBuffer[tid].size() <= skidBufferMax &&
6562292SN/A           "Skidbuffer Exceeded Max Size");
6572292SN/A}
6582292SN/A
6592292SN/Atemplate<class Impl>
6602292SN/Aint
6612292SN/ADefaultIEW<Impl>::skidCount()
6622292SN/A{
6632292SN/A    int max=0;
6642292SN/A
6656221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6666221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6672292SN/A
6683867Sbinkertn@umich.edu    while (threads != end) {
6696221Snate@binkert.org        ThreadID tid = *threads++;
6703867Sbinkertn@umich.edu        unsigned thread_count = skidBuffer[tid].size();
6712292SN/A        if (max < thread_count)
6722292SN/A            max = thread_count;
6732292SN/A    }
6742292SN/A
6752292SN/A    return max;
6762292SN/A}
6772292SN/A
6782292SN/Atemplate<class Impl>
6792292SN/Abool
6802292SN/ADefaultIEW<Impl>::skidsEmpty()
6812292SN/A{
6826221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
6836221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
6842292SN/A
6853867Sbinkertn@umich.edu    while (threads != end) {
6866221Snate@binkert.org        ThreadID tid = *threads++;
6873867Sbinkertn@umich.edu
6883867Sbinkertn@umich.edu        if (!skidBuffer[tid].empty())
6892292SN/A            return false;
6902292SN/A    }
6912292SN/A
6922292SN/A    return true;
6931062SN/A}
6941062SN/A
6951681SN/Atemplate <class Impl>
6961062SN/Avoid
6972292SN/ADefaultIEW<Impl>::updateStatus()
6981062SN/A{
6992292SN/A    bool any_unblocking = false;
7001062SN/A
7016221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
7026221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
7031062SN/A
7043867Sbinkertn@umich.edu    while (threads != end) {
7056221Snate@binkert.org        ThreadID tid = *threads++;
7061062SN/A
7072292SN/A        if (dispatchStatus[tid] == Unblocking) {
7082292SN/A            any_unblocking = true;
7092292SN/A            break;
7102292SN/A        }
7112292SN/A    }
7121062SN/A
7132292SN/A    // If there are no ready instructions waiting to be scheduled by the IQ,
7142292SN/A    // and there's no stores waiting to write back, and dispatch is not
7152292SN/A    // unblocking, then there is no internal activity for the IEW stage.
7167897Shestness@cs.utexas.edu    instQueue.intInstQueueReads++;
7172292SN/A    if (_status == Active && !instQueue.hasReadyInsts() &&
7182292SN/A        !ldstQueue.willWB() && !any_unblocking) {
7192292SN/A        DPRINTF(IEW, "IEW switching to idle\n");
7201062SN/A
7212292SN/A        deactivateStage();
7221062SN/A
7232292SN/A        _status = Inactive;
7242292SN/A    } else if (_status == Inactive && (instQueue.hasReadyInsts() ||
7252292SN/A                                       ldstQueue.willWB() ||
7262292SN/A                                       any_unblocking)) {
7272292SN/A        // Otherwise there is internal activity.  Set to active.
7282292SN/A        DPRINTF(IEW, "IEW switching to active\n");
7291062SN/A
7302292SN/A        activateStage();
7311062SN/A
7322292SN/A        _status = Active;
7331062SN/A    }
7341062SN/A}
7351062SN/A
7361681SN/Atemplate <class Impl>
7371062SN/Avoid
7382292SN/ADefaultIEW<Impl>::resetEntries()
7391062SN/A{
7402292SN/A    instQueue.resetEntries();
7412292SN/A    ldstQueue.resetEntries();
7422292SN/A}
7431062SN/A
7442292SN/Atemplate <class Impl>
7452292SN/Avoid
7466221Snate@binkert.orgDefaultIEW<Impl>::readStallSignals(ThreadID tid)
7472292SN/A{
7482292SN/A    if (fromCommit->commitBlock[tid]) {
7492292SN/A        stalls[tid].commit = true;
7502292SN/A    }
7511062SN/A
7522292SN/A    if (fromCommit->commitUnblock[tid]) {
7532292SN/A        assert(stalls[tid].commit);
7542292SN/A        stalls[tid].commit = false;
7552292SN/A    }
7562292SN/A}
7572292SN/A
7582292SN/Atemplate <class Impl>
7592292SN/Abool
7606221Snate@binkert.orgDefaultIEW<Impl>::checkStall(ThreadID tid)
7612292SN/A{
7622292SN/A    bool ret_val(false);
7632292SN/A
7642292SN/A    if (stalls[tid].commit) {
7652292SN/A        DPRINTF(IEW,"[tid:%i]: Stall from Commit stage detected.\n",tid);
7662292SN/A        ret_val = true;
7672292SN/A    } else if (instQueue.isFull(tid)) {
7682292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: IQ  is full.\n",tid);
7692292SN/A        ret_val = true;
7702292SN/A    } else if (ldstQueue.isFull(tid)) {
7712292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: LSQ is full\n",tid);
7722292SN/A
7732292SN/A        if (ldstQueue.numLoads(tid) > 0 ) {
7742292SN/A
7752292SN/A            DPRINTF(IEW,"[tid:%i]: LSQ oldest load: [sn:%i] \n",
7762292SN/A                    tid,ldstQueue.getLoadHeadSeqNum(tid));
7772292SN/A        }
7782292SN/A
7792292SN/A        if (ldstQueue.numStores(tid) > 0) {
7802292SN/A
7812292SN/A            DPRINTF(IEW,"[tid:%i]: LSQ oldest store: [sn:%i] \n",
7822292SN/A                    tid,ldstQueue.getStoreHeadSeqNum(tid));
7832292SN/A        }
7842292SN/A
7852292SN/A        ret_val = true;
7862292SN/A    } else if (ldstQueue.isStalled(tid)) {
7872292SN/A        DPRINTF(IEW,"[tid:%i]: Stall: LSQ stall detected.\n",tid);
7882292SN/A        ret_val = true;
7892292SN/A    }
7902292SN/A
7912292SN/A    return ret_val;
7922292SN/A}
7932292SN/A
7942292SN/Atemplate <class Impl>
7952292SN/Avoid
7966221Snate@binkert.orgDefaultIEW<Impl>::checkSignalsAndUpdate(ThreadID tid)
7972292SN/A{
7982292SN/A    // Check if there's a squash signal, squash if there is
7992292SN/A    // Check stall signals, block if there is.
8002292SN/A    // If status was Blocked
8012292SN/A    //     if so then go to unblocking
8022292SN/A    // If status was Squashing
8032292SN/A    //     check if squashing is not high.  Switch to running this cycle.
8042292SN/A
8052292SN/A    readStallSignals(tid);
8062292SN/A
8072292SN/A    if (fromCommit->commitInfo[tid].squash) {
8082292SN/A        squash(tid);
8092292SN/A
8102292SN/A        if (dispatchStatus[tid] == Blocked ||
8112292SN/A            dispatchStatus[tid] == Unblocking) {
8122292SN/A            toRename->iewUnblock[tid] = true;
8132292SN/A            wroteToTimeBuffer = true;
8142292SN/A        }
8152292SN/A
8162292SN/A        dispatchStatus[tid] = Squashing;
8172292SN/A        fetchRedirect[tid] = false;
8182292SN/A        return;
8192292SN/A    }
8202292SN/A
8212292SN/A    if (fromCommit->commitInfo[tid].robSquashing) {
8222702Sktlim@umich.edu        DPRINTF(IEW, "[tid:%i]: ROB is still squashing.\n", tid);
8232292SN/A
8242292SN/A        dispatchStatus[tid] = Squashing;
8252702Sktlim@umich.edu        emptyRenameInsts(tid);
8262702Sktlim@umich.edu        wroteToTimeBuffer = true;
8272292SN/A        return;
8282292SN/A    }
8292292SN/A
8302292SN/A    if (checkStall(tid)) {
8312292SN/A        block(tid);
8322292SN/A        dispatchStatus[tid] = Blocked;
8332292SN/A        return;
8342292SN/A    }
8352292SN/A
8362292SN/A    if (dispatchStatus[tid] == Blocked) {
8372292SN/A        // Status from previous cycle was blocked, but there are no more stall
8382292SN/A        // conditions.  Switch over to unblocking.
8392292SN/A        DPRINTF(IEW, "[tid:%i]: Done blocking, switching to unblocking.\n",
8402292SN/A                tid);
8412292SN/A
8422292SN/A        dispatchStatus[tid] = Unblocking;
8432292SN/A
8442292SN/A        unblock(tid);
8452292SN/A
8462292SN/A        return;
8472292SN/A    }
8482292SN/A
8492292SN/A    if (dispatchStatus[tid] == Squashing) {
8502292SN/A        // Switch status to running if rename isn't being told to block or
8512292SN/A        // squash this cycle.
8522292SN/A        DPRINTF(IEW, "[tid:%i]: Done squashing, switching to running.\n",
8532292SN/A                tid);
8542292SN/A
8552292SN/A        dispatchStatus[tid] = Running;
8562292SN/A
8572292SN/A        return;
8582292SN/A    }
8592292SN/A}
8602292SN/A
8612292SN/Atemplate <class Impl>
8622292SN/Avoid
8632292SN/ADefaultIEW<Impl>::sortInsts()
8642292SN/A{
8652292SN/A    int insts_from_rename = fromRename->size;
8662326SN/A#ifdef DEBUG
8676221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++)
8686221Snate@binkert.org        assert(insts[tid].empty());
8692326SN/A#endif
8702292SN/A    for (int i = 0; i < insts_from_rename; ++i) {
8712292SN/A        insts[fromRename->insts[i]->threadNumber].push(fromRename->insts[i]);
8722292SN/A    }
8732292SN/A}
8742292SN/A
8752292SN/Atemplate <class Impl>
8762292SN/Avoid
8776221Snate@binkert.orgDefaultIEW<Impl>::emptyRenameInsts(ThreadID tid)
8782702Sktlim@umich.edu{
8794632Sgblack@eecs.umich.edu    DPRINTF(IEW, "[tid:%i]: Removing incoming rename instructions\n", tid);
8802935Sksewell@umich.edu
8812702Sktlim@umich.edu    while (!insts[tid].empty()) {
8822935Sksewell@umich.edu
8832702Sktlim@umich.edu        if (insts[tid].front()->isLoad() ||
8842702Sktlim@umich.edu            insts[tid].front()->isStore() ) {
8852702Sktlim@umich.edu            toRename->iewInfo[tid].dispatchedToLSQ++;
8862702Sktlim@umich.edu        }
8872702Sktlim@umich.edu
8882702Sktlim@umich.edu        toRename->iewInfo[tid].dispatched++;
8892702Sktlim@umich.edu
8902702Sktlim@umich.edu        insts[tid].pop();
8912702Sktlim@umich.edu    }
8922702Sktlim@umich.edu}
8932702Sktlim@umich.edu
8942702Sktlim@umich.edutemplate <class Impl>
8952702Sktlim@umich.eduvoid
8962292SN/ADefaultIEW<Impl>::wakeCPU()
8972292SN/A{
8982292SN/A    cpu->wakeCPU();
8992292SN/A}
9002292SN/A
9012292SN/Atemplate <class Impl>
9022292SN/Avoid
9032292SN/ADefaultIEW<Impl>::activityThisCycle()
9042292SN/A{
9052292SN/A    DPRINTF(Activity, "Activity this cycle.\n");
9062292SN/A    cpu->activityThisCycle();
9072292SN/A}
9082292SN/A
9092292SN/Atemplate <class Impl>
9102292SN/Ainline void
9112292SN/ADefaultIEW<Impl>::activateStage()
9122292SN/A{
9132292SN/A    DPRINTF(Activity, "Activating stage.\n");
9142733Sktlim@umich.edu    cpu->activateStage(O3CPU::IEWIdx);
9152292SN/A}
9162292SN/A
9172292SN/Atemplate <class Impl>
9182292SN/Ainline void
9192292SN/ADefaultIEW<Impl>::deactivateStage()
9202292SN/A{
9212292SN/A    DPRINTF(Activity, "Deactivating stage.\n");
9222733Sktlim@umich.edu    cpu->deactivateStage(O3CPU::IEWIdx);
9232292SN/A}
9242292SN/A
9252292SN/Atemplate<class Impl>
9262292SN/Avoid
9276221Snate@binkert.orgDefaultIEW<Impl>::dispatch(ThreadID tid)
9282292SN/A{
9292292SN/A    // If status is Running or idle,
9302292SN/A    //     call dispatchInsts()
9312292SN/A    // If status is Unblocking,
9322292SN/A    //     buffer any instructions coming from rename
9332292SN/A    //     continue trying to empty skid buffer
9342292SN/A    //     check if stall conditions have passed
9352292SN/A
9362292SN/A    if (dispatchStatus[tid] == Blocked) {
9372292SN/A        ++iewBlockCycles;
9382292SN/A
9392292SN/A    } else if (dispatchStatus[tid] == Squashing) {
9402292SN/A        ++iewSquashCycles;
9412292SN/A    }
9422292SN/A
9432292SN/A    // Dispatch should try to dispatch as many instructions as its bandwidth
9442292SN/A    // will allow, as long as it is not currently blocked.
9452292SN/A    if (dispatchStatus[tid] == Running ||
9462292SN/A        dispatchStatus[tid] == Idle) {
9472292SN/A        DPRINTF(IEW, "[tid:%i] Not blocked, so attempting to run "
9482292SN/A                "dispatch.\n", tid);
9492292SN/A
9502292SN/A        dispatchInsts(tid);
9512292SN/A    } else if (dispatchStatus[tid] == Unblocking) {
9522292SN/A        // Make sure that the skid buffer has something in it if the
9532292SN/A        // status is unblocking.
9542292SN/A        assert(!skidsEmpty());
9552292SN/A
9562292SN/A        // If the status was unblocking, then instructions from the skid
9572292SN/A        // buffer were used.  Remove those instructions and handle
9582292SN/A        // the rest of unblocking.
9592292SN/A        dispatchInsts(tid);
9602292SN/A
9612292SN/A        ++iewUnblockCycles;
9622292SN/A
9635215Sgblack@eecs.umich.edu        if (validInstsFromRename()) {
9642292SN/A            // Add the current inputs to the skid buffer so they can be
9652292SN/A            // reprocessed when this stage unblocks.
9662292SN/A            skidInsert(tid);
9672292SN/A        }
9682292SN/A
9692292SN/A        unblock(tid);
9702292SN/A    }
9712292SN/A}
9722292SN/A
9732292SN/Atemplate <class Impl>
9742292SN/Avoid
9756221Snate@binkert.orgDefaultIEW<Impl>::dispatchInsts(ThreadID tid)
9762292SN/A{
9772292SN/A    // Obtain instructions from skid buffer if unblocking, or queue from rename
9782292SN/A    // otherwise.
9792292SN/A    std::queue<DynInstPtr> &insts_to_dispatch =
9802292SN/A        dispatchStatus[tid] == Unblocking ?
9812292SN/A        skidBuffer[tid] : insts[tid];
9822292SN/A
9832292SN/A    int insts_to_add = insts_to_dispatch.size();
9842292SN/A
9852292SN/A    DynInstPtr inst;
9862292SN/A    bool add_to_iq = false;
9872292SN/A    int dis_num_inst = 0;
9882292SN/A
9892292SN/A    // Loop through the instructions, putting them in the instruction
9902292SN/A    // queue.
9912292SN/A    for ( ; dis_num_inst < insts_to_add &&
9922820Sktlim@umich.edu              dis_num_inst < dispatchWidth;
9932292SN/A          ++dis_num_inst)
9942292SN/A    {
9952292SN/A        inst = insts_to_dispatch.front();
9962292SN/A
9972292SN/A        if (dispatchStatus[tid] == Unblocking) {
9982292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Examining instruction from skid "
9992292SN/A                    "buffer\n", tid);
10002292SN/A        }
10012292SN/A
10022292SN/A        // Make sure there's a valid instruction there.
10032292SN/A        assert(inst);
10042292SN/A
10057720Sgblack@eecs.umich.edu        DPRINTF(IEW, "[tid:%i]: Issue: Adding PC %s [sn:%lli] [tid:%i] to "
10062292SN/A                "IQ.\n",
10077720Sgblack@eecs.umich.edu                tid, inst->pcState(), inst->seqNum, inst->threadNumber);
10082292SN/A
10092292SN/A        // Be sure to mark these instructions as ready so that the
10102292SN/A        // commit stage can go ahead and execute them, and mark
10112292SN/A        // them as issued so the IQ doesn't reprocess them.
10122292SN/A
10132292SN/A        // Check for squashed instructions.
10142292SN/A        if (inst->isSquashed()) {
10152292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Squashed instruction encountered, "
10162292SN/A                    "not adding to IQ.\n", tid);
10172292SN/A
10182292SN/A            ++iewDispSquashedInsts;
10192292SN/A
10202292SN/A            insts_to_dispatch.pop();
10212292SN/A
10222292SN/A            //Tell Rename That An Instruction has been processed
10232292SN/A            if (inst->isLoad() || inst->isStore()) {
10242292SN/A                toRename->iewInfo[tid].dispatchedToLSQ++;
10252292SN/A            }
10262292SN/A            toRename->iewInfo[tid].dispatched++;
10272292SN/A
10282292SN/A            continue;
10292292SN/A        }
10302292SN/A
10312292SN/A        // Check for full conditions.
10322292SN/A        if (instQueue.isFull(tid)) {
10332292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: IQ 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            ++iewIQFullEvents;
10442292SN/A            break;
10452292SN/A        } else if (ldstQueue.isFull(tid)) {
10462292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: LSQ has become full.\n",tid);
10472292SN/A
10482292SN/A            // Call function to start blocking.
10492292SN/A            block(tid);
10502292SN/A
10512292SN/A            // Set unblock to false. Special case where we are using
10522292SN/A            // skidbuffer (unblocking) instructions but then we still
10532292SN/A            // get full in the IQ.
10542292SN/A            toRename->iewUnblock[tid] = false;
10552292SN/A
10562292SN/A            ++iewLSQFullEvents;
10572292SN/A            break;
10582292SN/A        }
10592292SN/A
10602292SN/A        // Otherwise issue the instruction just fine.
10612292SN/A        if (inst->isLoad()) {
10622292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction "
10632292SN/A                    "encountered, adding to LSQ.\n", tid);
10642292SN/A
10652292SN/A            // Reserve a spot in the load store queue for this
10662292SN/A            // memory access.
10672292SN/A            ldstQueue.insertLoad(inst);
10682292SN/A
10692292SN/A            ++iewDispLoadInsts;
10702292SN/A
10712292SN/A            add_to_iq = true;
10722292SN/A
10732292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
10742292SN/A        } else if (inst->isStore()) {
10752292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Memory instruction "
10762292SN/A                    "encountered, adding to LSQ.\n", tid);
10772292SN/A
10782292SN/A            ldstQueue.insertStore(inst);
10792292SN/A
10802292SN/A            ++iewDispStoreInsts;
10812292SN/A
10822336SN/A            if (inst->isStoreConditional()) {
10832336SN/A                // Store conditionals need to be set as "canCommit()"
10842336SN/A                // so that commit can process them when they reach the
10852336SN/A                // head of commit.
10862348SN/A                // @todo: This is somewhat specific to Alpha.
10872292SN/A                inst->setCanCommit();
10882292SN/A                instQueue.insertNonSpec(inst);
10892292SN/A                add_to_iq = false;
10902292SN/A
10912292SN/A                ++iewDispNonSpecInsts;
10922292SN/A            } else {
10932292SN/A                add_to_iq = true;
10942292SN/A            }
10952292SN/A
10962292SN/A            toRename->iewInfo[tid].dispatchedToLSQ++;
10972292SN/A        } else if (inst->isMemBarrier() || inst->isWriteBarrier()) {
10982326SN/A            // Same as non-speculative stores.
10992292SN/A            inst->setCanCommit();
11002292SN/A            instQueue.insertBarrier(inst);
11012292SN/A            add_to_iq = false;
11022292SN/A        } else if (inst->isNop()) {
11032292SN/A            DPRINTF(IEW, "[tid:%i]: Issue: Nop instruction encountered, "
11042292SN/A                    "skipping.\n", tid);
11052292SN/A
11062292SN/A            inst->setIssued();
11072292SN/A            inst->setExecuted();
11082292SN/A            inst->setCanCommit();
11092292SN/A
11102326SN/A            instQueue.recordProducer(inst);
11112292SN/A
11122727Sktlim@umich.edu            iewExecutedNop[tid]++;
11132301SN/A
11142292SN/A            add_to_iq = false;
11152292SN/A        } else if (inst->isExecuted()) {
11162292SN/A            assert(0 && "Instruction shouldn't be executed.\n");
11172292SN/A            DPRINTF(IEW, "Issue: Executed branch encountered, "
11182292SN/A                    "skipping.\n");
11192292SN/A
11202292SN/A            inst->setIssued();
11212292SN/A            inst->setCanCommit();
11222292SN/A
11232326SN/A            instQueue.recordProducer(inst);
11242292SN/A
11252292SN/A            add_to_iq = false;
11262292SN/A        } else {
11272292SN/A            add_to_iq = true;
11282292SN/A        }
11294033Sktlim@umich.edu        if (inst->isNonSpeculative()) {
11304033Sktlim@umich.edu            DPRINTF(IEW, "[tid:%i]: Issue: Nonspeculative instruction "
11314033Sktlim@umich.edu                    "encountered, skipping.\n", tid);
11324033Sktlim@umich.edu
11334033Sktlim@umich.edu            // Same as non-speculative stores.
11344033Sktlim@umich.edu            inst->setCanCommit();
11354033Sktlim@umich.edu
11364033Sktlim@umich.edu            // Specifically insert it as nonspeculative.
11374033Sktlim@umich.edu            instQueue.insertNonSpec(inst);
11384033Sktlim@umich.edu
11394033Sktlim@umich.edu            ++iewDispNonSpecInsts;
11404033Sktlim@umich.edu
11414033Sktlim@umich.edu            add_to_iq = false;
11424033Sktlim@umich.edu        }
11432292SN/A
11442292SN/A        // If the instruction queue is not full, then add the
11452292SN/A        // instruction.
11462292SN/A        if (add_to_iq) {
11472292SN/A            instQueue.insert(inst);
11482292SN/A        }
11492292SN/A
11502292SN/A        insts_to_dispatch.pop();
11512292SN/A
11522292SN/A        toRename->iewInfo[tid].dispatched++;
11532292SN/A
11542292SN/A        ++iewDispatchedInsts;
11558471SGiacomo.Gabrielli@arm.com
11568471SGiacomo.Gabrielli@arm.com#if TRACING_ON
11579046SAli.Saidi@ARM.com        inst->dispatchTick = curTick() - inst->fetchTick;
11588471SGiacomo.Gabrielli@arm.com#endif
11592292SN/A    }
11602292SN/A
11612292SN/A    if (!insts_to_dispatch.empty()) {
11622935Sksewell@umich.edu        DPRINTF(IEW,"[tid:%i]: Issue: Bandwidth Full. Blocking.\n", tid);
11632292SN/A        block(tid);
11642292SN/A        toRename->iewUnblock[tid] = false;
11652292SN/A    }
11662292SN/A
11672292SN/A    if (dispatchStatus[tid] == Idle && dis_num_inst) {
11682292SN/A        dispatchStatus[tid] = Running;
11692292SN/A
11702292SN/A        updatedQueues = true;
11712292SN/A    }
11722292SN/A
11732292SN/A    dis_num_inst = 0;
11742292SN/A}
11752292SN/A
11762292SN/Atemplate <class Impl>
11772292SN/Avoid
11782292SN/ADefaultIEW<Impl>::printAvailableInsts()
11792292SN/A{
11802292SN/A    int inst = 0;
11812292SN/A
11822980Sgblack@eecs.umich.edu    std::cout << "Available Instructions: ";
11832292SN/A
11842292SN/A    while (fromIssue->insts[inst]) {
11852292SN/A
11862980Sgblack@eecs.umich.edu        if (inst%3==0) std::cout << "\n\t";
11872292SN/A
11887720Sgblack@eecs.umich.edu        std::cout << "PC: " << fromIssue->insts[inst]->pcState()
11892292SN/A             << " TN: " << fromIssue->insts[inst]->threadNumber
11902292SN/A             << " SN: " << fromIssue->insts[inst]->seqNum << " | ";
11912292SN/A
11922292SN/A        inst++;
11932292SN/A
11942292SN/A    }
11952292SN/A
11962980Sgblack@eecs.umich.edu    std::cout << "\n";
11972292SN/A}
11982292SN/A
11992292SN/Atemplate <class Impl>
12002292SN/Avoid
12012292SN/ADefaultIEW<Impl>::executeInsts()
12022292SN/A{
12032292SN/A    wbNumInst = 0;
12042292SN/A    wbCycle = 0;
12052292SN/A
12066221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
12076221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
12082292SN/A
12093867Sbinkertn@umich.edu    while (threads != end) {
12106221Snate@binkert.org        ThreadID tid = *threads++;
12112292SN/A        fetchRedirect[tid] = false;
12122292SN/A    }
12132292SN/A
12142698Sktlim@umich.edu    // Uncomment this if you want to see all available instructions.
12157599Sminkyu.jeong@arm.com    // @todo This doesn't actually work anymore, we should fix it.
12162698Sktlim@umich.edu//    printAvailableInsts();
12171062SN/A
12181062SN/A    // Execute/writeback any instructions that are available.
12192333SN/A    int insts_to_execute = fromIssue->size;
12202292SN/A    int inst_num = 0;
12212333SN/A    for (; inst_num < insts_to_execute;
12222326SN/A          ++inst_num) {
12231062SN/A
12242292SN/A        DPRINTF(IEW, "Execute: Executing instructions from IQ.\n");
12251062SN/A
12262333SN/A        DynInstPtr inst = instQueue.getInstToExecute();
12271062SN/A
12287720Sgblack@eecs.umich.edu        DPRINTF(IEW, "Execute: Processing PC %s, [tid:%i] [sn:%i].\n",
12297720Sgblack@eecs.umich.edu                inst->pcState(), inst->threadNumber,inst->seqNum);
12301062SN/A
12311062SN/A        // Check if the instruction is squashed; if so then skip it
12321062SN/A        if (inst->isSquashed()) {
12338315Sgeoffrey.blake@arm.com            DPRINTF(IEW, "Execute: Instruction was squashed. PC: %s, [tid:%i]"
12348315Sgeoffrey.blake@arm.com                         " [sn:%i]\n", inst->pcState(), inst->threadNumber,
12358315Sgeoffrey.blake@arm.com                         inst->seqNum);
12361062SN/A
12371062SN/A            // Consider this instruction executed so that commit can go
12381062SN/A            // ahead and retire the instruction.
12391062SN/A            inst->setExecuted();
12401062SN/A
12412292SN/A            // Not sure if I should set this here or just let commit try to
12422292SN/A            // commit any squashed instructions.  I like the latter a bit more.
12432292SN/A            inst->setCanCommit();
12441062SN/A
12451062SN/A            ++iewExecSquashedInsts;
12461062SN/A
12472820Sktlim@umich.edu            decrWb(inst->seqNum);
12481062SN/A            continue;
12491062SN/A        }
12501062SN/A
12512292SN/A        Fault fault = NoFault;
12521062SN/A
12531062SN/A        // Execute instruction.
12541062SN/A        // Note that if the instruction faults, it will be handled
12551062SN/A        // at the commit stage.
12567850SMatt.Horsnell@arm.com        if (inst->isMemRef()) {
12572292SN/A            DPRINTF(IEW, "Execute: Calculating address for memory "
12581062SN/A                    "reference.\n");
12591062SN/A
12601062SN/A            // Tell the LDSTQ to execute this instruction (if it is a load).
12611062SN/A            if (inst->isLoad()) {
12622292SN/A                // Loads will mark themselves as executed, and their writeback
12632292SN/A                // event adds the instruction to the queue to commit
12642292SN/A                fault = ldstQueue.executeLoad(inst);
12657944SGiacomo.Gabrielli@arm.com
12667944SGiacomo.Gabrielli@arm.com                if (inst->isTranslationDelayed() &&
12677944SGiacomo.Gabrielli@arm.com                    fault == NoFault) {
12687944SGiacomo.Gabrielli@arm.com                    // A hw page table walk is currently going on; the
12697944SGiacomo.Gabrielli@arm.com                    // instruction must be deferred.
12707944SGiacomo.Gabrielli@arm.com                    DPRINTF(IEW, "Execute: Delayed translation, deferring "
12717944SGiacomo.Gabrielli@arm.com                            "load.\n");
12727944SGiacomo.Gabrielli@arm.com                    instQueue.deferMemInst(inst);
12737944SGiacomo.Gabrielli@arm.com                    continue;
12747944SGiacomo.Gabrielli@arm.com                }
12757944SGiacomo.Gabrielli@arm.com
12767850SMatt.Horsnell@arm.com                if (inst->isDataPrefetch() || inst->isInstPrefetch()) {
12778073SAli.Saidi@ARM.com                    inst->fault = NoFault;
12787850SMatt.Horsnell@arm.com                }
12791062SN/A            } else if (inst->isStore()) {
12802367SN/A                fault = ldstQueue.executeStore(inst);
12811062SN/A
12827944SGiacomo.Gabrielli@arm.com                if (inst->isTranslationDelayed() &&
12837944SGiacomo.Gabrielli@arm.com                    fault == NoFault) {
12847944SGiacomo.Gabrielli@arm.com                    // A hw page table walk is currently going on; the
12857944SGiacomo.Gabrielli@arm.com                    // instruction must be deferred.
12867944SGiacomo.Gabrielli@arm.com                    DPRINTF(IEW, "Execute: Delayed translation, deferring "
12877944SGiacomo.Gabrielli@arm.com                            "store.\n");
12887944SGiacomo.Gabrielli@arm.com                    instQueue.deferMemInst(inst);
12897944SGiacomo.Gabrielli@arm.com                    continue;
12907944SGiacomo.Gabrielli@arm.com                }
12917944SGiacomo.Gabrielli@arm.com
12922292SN/A                // If the store had a fault then it may not have a mem req
12937782Sminkyu.jeong@arm.com                if (fault != NoFault || inst->readPredicate() == false ||
12947782Sminkyu.jeong@arm.com                        !inst->isStoreConditional()) {
12957782Sminkyu.jeong@arm.com                    // If the instruction faulted, then we need to send it along
12967782Sminkyu.jeong@arm.com                    // to commit without the instruction completing.
12972367SN/A                    // Send this instruction to commit, also make sure iew stage
12982367SN/A                    // realizes there is activity.
12992367SN/A                    inst->setExecuted();
13002367SN/A                    instToCommit(inst);
13012367SN/A                    activityThisCycle();
13022292SN/A                }
13032326SN/A
13042326SN/A                // Store conditionals will mark themselves as
13052326SN/A                // executed, and their writeback event will add the
13062326SN/A                // instruction to the queue to commit.
13071062SN/A            } else {
13082292SN/A                panic("Unexpected memory type!\n");
13091062SN/A            }
13101062SN/A
13111062SN/A        } else {
13127847Sminkyu.jeong@arm.com            // If the instruction has already faulted, then skip executing it.
13137847Sminkyu.jeong@arm.com            // Such case can happen when it faulted during ITLB translation.
13147847Sminkyu.jeong@arm.com            // If we execute the instruction (even if it's a nop) the fault
13157847Sminkyu.jeong@arm.com            // will be replaced and we will lose it.
13167847Sminkyu.jeong@arm.com            if (inst->getFault() == NoFault) {
13177847Sminkyu.jeong@arm.com                inst->execute();
13187848SAli.Saidi@ARM.com                if (inst->readPredicate() == false)
13197848SAli.Saidi@ARM.com                    inst->forwardOldRegs();
13207847Sminkyu.jeong@arm.com            }
13211062SN/A
13222292SN/A            inst->setExecuted();
13232292SN/A
13242292SN/A            instToCommit(inst);
13251062SN/A        }
13261062SN/A
13272301SN/A        updateExeInstStats(inst);
13281681SN/A
13292326SN/A        // Check if branch prediction was correct, if not then we need
13302326SN/A        // to tell commit to squash in flight instructions.  Only
13312326SN/A        // handle this if there hasn't already been something that
13322107SN/A        // redirects fetch in this group of instructions.
13331681SN/A
13342292SN/A        // This probably needs to prioritize the redirects if a different
13352292SN/A        // scheduler is used.  Currently the scheduler schedules the oldest
13362292SN/A        // instruction first, so the branch resolution order will be correct.
13376221Snate@binkert.org        ThreadID tid = inst->threadNumber;
13381062SN/A
13393732Sktlim@umich.edu        if (!fetchRedirect[tid] ||
13407852SMatt.Horsnell@arm.com            !toCommit->squash[tid] ||
13413732Sktlim@umich.edu            toCommit->squashedSeqNum[tid] > inst->seqNum) {
13421062SN/A
13437856SMatt.Horsnell@arm.com            // Prevent testing for misprediction on load instructions,
13447856SMatt.Horsnell@arm.com            // that have not been executed.
13457856SMatt.Horsnell@arm.com            bool loadNotExecuted = !inst->isExecuted() && inst->isLoad();
13467856SMatt.Horsnell@arm.com
13477856SMatt.Horsnell@arm.com            if (inst->mispredicted() && !loadNotExecuted) {
13482292SN/A                fetchRedirect[tid] = true;
13491062SN/A
13502292SN/A                DPRINTF(IEW, "Execute: Branch mispredict detected.\n");
13518674Snilay@cs.wisc.edu                DPRINTF(IEW, "Predicted target was PC: %s.\n",
13528674Snilay@cs.wisc.edu                        inst->readPredTarg());
13537720Sgblack@eecs.umich.edu                DPRINTF(IEW, "Execute: Redirecting fetch to PC: %s.\n",
13548674Snilay@cs.wisc.edu                        inst->pcState());
13551062SN/A                // If incorrect, then signal the ROB that it must be squashed.
13562292SN/A                squashDueToBranch(inst, tid);
13571062SN/A
13583795Sgblack@eecs.umich.edu                if (inst->readPredTaken()) {
13591062SN/A                    predictedTakenIncorrect++;
13602292SN/A                } else {
13612292SN/A                    predictedNotTakenIncorrect++;
13621062SN/A                }
13632292SN/A            } else if (ldstQueue.violation(tid)) {
13644033Sktlim@umich.edu                assert(inst->isMemRef());
13652326SN/A                // If there was an ordering violation, then get the
13662326SN/A                // DynInst that caused the violation.  Note that this
13672292SN/A                // clears the violation signal.
13682292SN/A                DynInstPtr violator;
13692292SN/A                violator = ldstQueue.getMemDepViolator(tid);
13701062SN/A
13717720Sgblack@eecs.umich.edu                DPRINTF(IEW, "LDSTQ detected a violation. Violator PC: %s "
13727720Sgblack@eecs.umich.edu                        "[sn:%lli], inst PC: %s [sn:%lli]. Addr is: %#x.\n",
13737720Sgblack@eecs.umich.edu                        violator->pcState(), violator->seqNum,
13747720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum, inst->physEffAddr);
13757720Sgblack@eecs.umich.edu
13763732Sktlim@umich.edu                fetchRedirect[tid] = true;
13773732Sktlim@umich.edu
13781062SN/A                // Tell the instruction queue that a violation has occured.
13791062SN/A                instQueue.violation(inst, violator);
13801062SN/A
13811062SN/A                // Squash.
13828513SGiacomo.Gabrielli@arm.com                squashDueToMemOrder(violator, tid);
13831062SN/A
13841062SN/A                ++memOrderViolationEvents;
13852292SN/A            } else if (ldstQueue.loadBlocked(tid) &&
13862292SN/A                       !ldstQueue.isLoadBlockedHandled(tid)) {
13872292SN/A                fetchRedirect[tid] = true;
13882292SN/A
13892292SN/A                DPRINTF(IEW, "Load operation couldn't execute because the "
13907720Sgblack@eecs.umich.edu                        "memory system is blocked.  PC: %s [sn:%lli]\n",
13917720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum);
13922292SN/A
13932292SN/A                squashDueToMemBlocked(inst, tid);
13941062SN/A            }
13954033Sktlim@umich.edu        } else {
13964033Sktlim@umich.edu            // Reset any state associated with redirects that will not
13974033Sktlim@umich.edu            // be used.
13984033Sktlim@umich.edu            if (ldstQueue.violation(tid)) {
13994033Sktlim@umich.edu                assert(inst->isMemRef());
14004033Sktlim@umich.edu
14014033Sktlim@umich.edu                DynInstPtr violator = ldstQueue.getMemDepViolator(tid);
14024033Sktlim@umich.edu
14034033Sktlim@umich.edu                DPRINTF(IEW, "LDSTQ detected a violation.  Violator PC: "
14047720Sgblack@eecs.umich.edu                        "%s, inst PC: %s.  Addr is: %#x.\n",
14057720Sgblack@eecs.umich.edu                        violator->pcState(), inst->pcState(),
14067720Sgblack@eecs.umich.edu                        inst->physEffAddr);
14074033Sktlim@umich.edu                DPRINTF(IEW, "Violation will not be handled because "
14084033Sktlim@umich.edu                        "already squashing\n");
14094033Sktlim@umich.edu
14104033Sktlim@umich.edu                ++memOrderViolationEvents;
14114033Sktlim@umich.edu            }
14124033Sktlim@umich.edu            if (ldstQueue.loadBlocked(tid) &&
14134033Sktlim@umich.edu                !ldstQueue.isLoadBlockedHandled(tid)) {
14144033Sktlim@umich.edu                DPRINTF(IEW, "Load operation couldn't execute because the "
14157720Sgblack@eecs.umich.edu                        "memory system is blocked.  PC: %s [sn:%lli]\n",
14167720Sgblack@eecs.umich.edu                        inst->pcState(), inst->seqNum);
14174033Sktlim@umich.edu                DPRINTF(IEW, "Blocked load will not be handled because "
14184033Sktlim@umich.edu                        "already squashing\n");
14194033Sktlim@umich.edu
14204033Sktlim@umich.edu                ldstQueue.setLoadBlockedHandled(tid);
14214033Sktlim@umich.edu            }
14224033Sktlim@umich.edu
14231062SN/A        }
14241062SN/A    }
14252292SN/A
14262348SN/A    // Update and record activity if we processed any instructions.
14272292SN/A    if (inst_num) {
14282292SN/A        if (exeStatus == Idle) {
14292292SN/A            exeStatus = Running;
14302292SN/A        }
14312292SN/A
14322292SN/A        updatedQueues = true;
14332292SN/A
14342292SN/A        cpu->activityThisCycle();
14352292SN/A    }
14362292SN/A
14372292SN/A    // Need to reset this in case a writeback event needs to write into the
14382292SN/A    // iew queue.  That way the writeback event will write into the correct
14392292SN/A    // spot in the queue.
14402292SN/A    wbNumInst = 0;
14417852SMatt.Horsnell@arm.com
14422107SN/A}
14432107SN/A
14442292SN/Atemplate <class Impl>
14452107SN/Avoid
14462292SN/ADefaultIEW<Impl>::writebackInsts()
14472107SN/A{
14482326SN/A    // Loop through the head of the time buffer and wake any
14492326SN/A    // dependents.  These instructions are about to write back.  Also
14502326SN/A    // mark scoreboard that this instruction is finally complete.
14512326SN/A    // Either have IEW have direct access to scoreboard, or have this
14522326SN/A    // as part of backwards communication.
14533958Sgblack@eecs.umich.edu    for (int inst_num = 0; inst_num < wbWidth &&
14542292SN/A             toCommit->insts[inst_num]; inst_num++) {
14552107SN/A        DynInstPtr inst = toCommit->insts[inst_num];
14566221Snate@binkert.org        ThreadID tid = inst->threadNumber;
14572107SN/A
14587720Sgblack@eecs.umich.edu        DPRINTF(IEW, "Sending instructions to commit, [sn:%lli] PC %s.\n",
14597720Sgblack@eecs.umich.edu                inst->seqNum, inst->pcState());
14602107SN/A
14612301SN/A        iewInstsToCommit[tid]++;
14622301SN/A
14632292SN/A        // Some instructions will be sent to commit without having
14642292SN/A        // executed because they need commit to handle them.
14652292SN/A        // E.g. Uncached loads have not actually executed when they
14662292SN/A        // are first sent to commit.  Instead commit must tell the LSQ
14672292SN/A        // when it's ready to execute the uncached load.
14682367SN/A        if (!inst->isSquashed() && inst->isExecuted() && inst->getFault() == NoFault) {
14692301SN/A            int dependents = instQueue.wakeDependents(inst);
14702107SN/A
14712292SN/A            for (int i = 0; i < inst->numDestRegs(); i++) {
14722292SN/A                //mark as Ready
14732292SN/A                DPRINTF(IEW,"Setting Destination Register %i\n",
14742292SN/A                        inst->renamedDestRegIdx(i));
14752292SN/A                scoreboard->setReg(inst->renamedDestRegIdx(i));
14762107SN/A            }
14772301SN/A
14782348SN/A            if (dependents) {
14792348SN/A                producerInst[tid]++;
14802348SN/A                consumerInst[tid]+= dependents;
14812348SN/A            }
14822326SN/A            writebackCount[tid]++;
14832107SN/A        }
14842820Sktlim@umich.edu
14852820Sktlim@umich.edu        decrWb(inst->seqNum);
14862107SN/A    }
14871060SN/A}
14881060SN/A
14891681SN/Atemplate<class Impl>
14901060SN/Avoid
14912292SN/ADefaultIEW<Impl>::tick()
14921060SN/A{
14932292SN/A    wbNumInst = 0;
14942292SN/A    wbCycle = 0;
14951060SN/A
14962292SN/A    wroteToTimeBuffer = false;
14972292SN/A    updatedQueues = false;
14981060SN/A
14992292SN/A    sortInsts();
15001060SN/A
15012326SN/A    // Free function units marked as being freed this cycle.
15022326SN/A    fuPool->processFreeUnits();
15031062SN/A
15046221Snate@binkert.org    list<ThreadID>::iterator threads = activeThreads->begin();
15056221Snate@binkert.org    list<ThreadID>::iterator end = activeThreads->end();
15061060SN/A
15072326SN/A    // Check stall and squash signals, dispatch any instructions.
15083867Sbinkertn@umich.edu    while (threads != end) {
15096221Snate@binkert.org        ThreadID tid = *threads++;
15101060SN/A
15112292SN/A        DPRINTF(IEW,"Issue: Processing [tid:%i]\n",tid);
15121060SN/A
15132292SN/A        checkSignalsAndUpdate(tid);
15142292SN/A        dispatch(tid);
15151060SN/A    }
15161060SN/A
15172292SN/A    if (exeStatus != Squashing) {
15182292SN/A        executeInsts();
15191060SN/A
15202292SN/A        writebackInsts();
15212292SN/A
15222292SN/A        // Have the instruction queue try to schedule any ready instructions.
15232292SN/A        // (In actuality, this scheduling is for instructions that will
15242292SN/A        // be executed next cycle.)
15252292SN/A        instQueue.scheduleReadyInsts();
15262292SN/A
15272292SN/A        // Also should advance its own time buffers if the stage ran.
15282292SN/A        // Not the best place for it, but this works (hopefully).
15292292SN/A        issueToExecQueue.advance();
15302292SN/A    }
15312292SN/A
15322292SN/A    bool broadcast_free_entries = false;
15332292SN/A
15342292SN/A    if (updatedQueues || exeStatus == Running || updateLSQNextCycle) {
15352292SN/A        exeStatus = Idle;
15362292SN/A        updateLSQNextCycle = false;
15372292SN/A
15382292SN/A        broadcast_free_entries = true;
15392292SN/A    }
15402292SN/A
15412292SN/A    // Writeback any stores using any leftover bandwidth.
15421681SN/A    ldstQueue.writebackStores();
15431681SN/A
15441061SN/A    // Check the committed load/store signals to see if there's a load
15451061SN/A    // or store to commit.  Also check if it's being told to execute a
15461061SN/A    // nonspeculative instruction.
15471681SN/A    // This is pretty inefficient...
15482292SN/A
15493867Sbinkertn@umich.edu    threads = activeThreads->begin();
15503867Sbinkertn@umich.edu    while (threads != end) {
15516221Snate@binkert.org        ThreadID tid = (*threads++);
15522292SN/A
15532292SN/A        DPRINTF(IEW,"Processing [tid:%i]\n",tid);
15542292SN/A
15552348SN/A        // Update structures based on instructions committed.
15562292SN/A        if (fromCommit->commitInfo[tid].doneSeqNum != 0 &&
15572292SN/A            !fromCommit->commitInfo[tid].squash &&
15582292SN/A            !fromCommit->commitInfo[tid].robSquashing) {
15592292SN/A
15602292SN/A            ldstQueue.commitStores(fromCommit->commitInfo[tid].doneSeqNum,tid);
15612292SN/A
15622292SN/A            ldstQueue.commitLoads(fromCommit->commitInfo[tid].doneSeqNum,tid);
15632292SN/A
15642292SN/A            updateLSQNextCycle = true;
15652292SN/A            instQueue.commit(fromCommit->commitInfo[tid].doneSeqNum,tid);
15662292SN/A        }
15672292SN/A
15682292SN/A        if (fromCommit->commitInfo[tid].nonSpecSeqNum != 0) {
15692292SN/A
15702292SN/A            //DPRINTF(IEW,"NonspecInst from thread %i",tid);
15712292SN/A            if (fromCommit->commitInfo[tid].uncached) {
15722292SN/A                instQueue.replayMemInst(fromCommit->commitInfo[tid].uncachedLoad);
15734033Sktlim@umich.edu                fromCommit->commitInfo[tid].uncachedLoad->setAtCommit();
15742292SN/A            } else {
15752292SN/A                instQueue.scheduleNonSpec(
15762292SN/A                    fromCommit->commitInfo[tid].nonSpecSeqNum);
15772292SN/A            }
15782292SN/A        }
15792292SN/A
15802292SN/A        if (broadcast_free_entries) {
15812292SN/A            toFetch->iewInfo[tid].iqCount =
15822292SN/A                instQueue.getCount(tid);
15832292SN/A            toFetch->iewInfo[tid].ldstqCount =
15842292SN/A                ldstQueue.getCount(tid);
15852292SN/A
15862292SN/A            toRename->iewInfo[tid].usedIQ = true;
15872292SN/A            toRename->iewInfo[tid].freeIQEntries =
15882292SN/A                instQueue.numFreeEntries();
15892292SN/A            toRename->iewInfo[tid].usedLSQ = true;
15902292SN/A            toRename->iewInfo[tid].freeLSQEntries =
15912292SN/A                ldstQueue.numFreeEntries(tid);
15922292SN/A
15932292SN/A            wroteToTimeBuffer = true;
15942292SN/A        }
15952292SN/A
15962292SN/A        DPRINTF(IEW, "[tid:%i], Dispatch dispatched %i instructions.\n",
15972292SN/A                tid, toRename->iewInfo[tid].dispatched);
15981061SN/A    }
15991061SN/A
16002292SN/A    DPRINTF(IEW, "IQ has %i free entries (Can schedule: %i).  "
16012292SN/A            "LSQ has %i free entries.\n",
16022292SN/A            instQueue.numFreeEntries(), instQueue.hasReadyInsts(),
16032292SN/A            ldstQueue.numFreeEntries());
16042292SN/A
16052292SN/A    updateStatus();
16062292SN/A
16072292SN/A    if (wroteToTimeBuffer) {
16082292SN/A        DPRINTF(Activity, "Activity this cycle.\n");
16092292SN/A        cpu->activityThisCycle();
16101061SN/A    }
16111060SN/A}
16121060SN/A
16132301SN/Atemplate <class Impl>
16141060SN/Avoid
16152301SN/ADefaultIEW<Impl>::updateExeInstStats(DynInstPtr &inst)
16161060SN/A{
16176221Snate@binkert.org    ThreadID tid = inst->threadNumber;
16181060SN/A
16192669Sktlim@umich.edu    iewExecutedInsts++;
16201060SN/A
16218471SGiacomo.Gabrielli@arm.com#if TRACING_ON
16229527SMatt.Horsnell@arm.com    if (DTRACE(O3PipeView)) {
16239527SMatt.Horsnell@arm.com        inst->completeTick = curTick() - inst->fetchTick;
16249527SMatt.Horsnell@arm.com    }
16258471SGiacomo.Gabrielli@arm.com#endif
16268471SGiacomo.Gabrielli@arm.com
16272301SN/A    //
16282301SN/A    //  Control operations
16292301SN/A    //
16302301SN/A    if (inst->isControl())
16316221Snate@binkert.org        iewExecutedBranches[tid]++;
16321060SN/A
16332301SN/A    //
16342301SN/A    //  Memory operations
16352301SN/A    //
16362301SN/A    if (inst->isMemRef()) {
16376221Snate@binkert.org        iewExecutedRefs[tid]++;
16381060SN/A
16392301SN/A        if (inst->isLoad()) {
16406221Snate@binkert.org            iewExecLoadInsts[tid]++;
16411060SN/A        }
16421060SN/A    }
16431060SN/A}
16447598Sminkyu.jeong@arm.com
16457598Sminkyu.jeong@arm.comtemplate <class Impl>
16467598Sminkyu.jeong@arm.comvoid
16477598Sminkyu.jeong@arm.comDefaultIEW<Impl>::checkMisprediction(DynInstPtr &inst)
16487598Sminkyu.jeong@arm.com{
16497598Sminkyu.jeong@arm.com    ThreadID tid = inst->threadNumber;
16507598Sminkyu.jeong@arm.com
16517598Sminkyu.jeong@arm.com    if (!fetchRedirect[tid] ||
16527852SMatt.Horsnell@arm.com        !toCommit->squash[tid] ||
16537598Sminkyu.jeong@arm.com        toCommit->squashedSeqNum[tid] > inst->seqNum) {
16547598Sminkyu.jeong@arm.com
16557598Sminkyu.jeong@arm.com        if (inst->mispredicted()) {
16567598Sminkyu.jeong@arm.com            fetchRedirect[tid] = true;
16577598Sminkyu.jeong@arm.com
16587598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Execute: Branch mispredict detected.\n");
16597598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Predicted target was PC:%#x, NPC:%#x.\n",
16607720Sgblack@eecs.umich.edu                    inst->predInstAddr(), inst->predNextInstAddr());
16617598Sminkyu.jeong@arm.com            DPRINTF(IEW, "Execute: Redirecting fetch to PC: %#x,"
16627720Sgblack@eecs.umich.edu                    " NPC: %#x.\n", inst->nextInstAddr(),
16637720Sgblack@eecs.umich.edu                    inst->nextInstAddr());
16647598Sminkyu.jeong@arm.com            // If incorrect, then signal the ROB that it must be squashed.
16657598Sminkyu.jeong@arm.com            squashDueToBranch(inst, tid);
16667598Sminkyu.jeong@arm.com
16677598Sminkyu.jeong@arm.com            if (inst->readPredTaken()) {
16687598Sminkyu.jeong@arm.com                predictedTakenIncorrect++;
16697598Sminkyu.jeong@arm.com            } else {
16707598Sminkyu.jeong@arm.com                predictedNotTakenIncorrect++;
16717598Sminkyu.jeong@arm.com            }
16727598Sminkyu.jeong@arm.com        }
16737598Sminkyu.jeong@arm.com    }
16747598Sminkyu.jeong@arm.com}
1675