fetch2.hh revision 13966:3189413c5894
12SN/A/* 21762SN/A * Copyright (c) 2013-2014 ARM Limited 37534Ssteve.reinhardt@amd.com * All rights reserved 42SN/A * 52SN/A * The license below extends only to copyright in the software and shall 62SN/A * not be construed as granting a license to any other intellectual 72SN/A * property including but not limited to intellectual property relating 82SN/A * to a hardware implementation of the functionality of the software 92SN/A * licensed hereunder. You may use the software subject to the license 102SN/A * terms below provided that you ensure that this notice is replicated 112SN/A * unmodified and in its entirety in all distributions of the software, 122SN/A * modified or unmodified, in source code or in binary form. 132SN/A * 142SN/A * Redistribution and use in source and binary forms, with or without 152SN/A * modification, are permitted provided that the following conditions are 162SN/A * met: redistributions of source code must retain the above copyright 172SN/A * notice, this list of conditions and the following disclaimer; 182SN/A * redistributions in binary form must reproduce the above copyright 192SN/A * notice, this list of conditions and the following disclaimer in the 202SN/A * documentation and/or other materials provided with the distribution; 212SN/A * neither the name of the copyright holders nor the names of its 222SN/A * contributors may be used to endorse or promote products derived from 232SN/A * this software without specific prior written permission. 242SN/A * 252SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 262SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282665Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 292665Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 302665Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 312SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 322SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 342SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 352SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362SN/A * 372SN/A * Authors: Andrew Bardsley 382SN/A */ 392SN/A 405491Sgblack@eecs.umich.edu/** 415491Sgblack@eecs.umich.edu * @file 422SN/A * 435491Sgblack@eecs.umich.edu * Fetch2 receives lines of data from Fetch1, separates them into 442SN/A * instructions and passes them to Decode 452SN/A */ 468737Skoansin.tan@gmail.com 474762Snate@binkert.org#ifndef __CPU_MINOR_FETCH2_HH__ 489342SAndreas.Sandberg@arm.com#define __CPU_MINOR_FETCH2_HH__ 499356Snilay@cs.wisc.edu 5056SN/A#include "cpu/minor/buffers.hh" 512SN/A#include "cpu/minor/cpu.hh" 522797Sktlim@umich.edu#include "cpu/minor/pipe_data.hh" 532797Sktlim@umich.edu#include "cpu/pred/bpred_unit.hh" 5410023Smatt.horsnell@ARM.com#include "params/MinorCPU.hh" 559196SAndreas.Sandberg@arm.com 562SN/Anamespace Minor 572SN/A{ 582SN/A 599196SAndreas.Sandberg@arm.com/** This stage receives lines of data from Fetch1, separates them into 609196SAndreas.Sandberg@arm.com * instructions and passes them to Decode */ 619196SAndreas.Sandberg@arm.comclass Fetch2 : public Named 629196SAndreas.Sandberg@arm.com{ 639196SAndreas.Sandberg@arm.com protected: 649196SAndreas.Sandberg@arm.com /** Pointer back to the containing CPU */ 659196SAndreas.Sandberg@arm.com MinorCPU &cpu; 669196SAndreas.Sandberg@arm.com 679196SAndreas.Sandberg@arm.com /** Input port carrying lines from Fetch1 */ 689196SAndreas.Sandberg@arm.com Latch<ForwardLineData>::Output inp; 699196SAndreas.Sandberg@arm.com 709196SAndreas.Sandberg@arm.com /** Input port carrying branches from Execute. This is a snoop of the 719196SAndreas.Sandberg@arm.com * data provided to F1. */ 729196SAndreas.Sandberg@arm.com Latch<BranchData>::Output branchInp; 739196SAndreas.Sandberg@arm.com 749196SAndreas.Sandberg@arm.com /** Output port carrying predictions back to Fetch1 */ 759196SAndreas.Sandberg@arm.com Latch<BranchData>::Input predictionOut; 769342SAndreas.Sandberg@arm.com 779196SAndreas.Sandberg@arm.com /** Output port carrying instructions into Decode */ 789196SAndreas.Sandberg@arm.com Latch<ForwardInstData>::Input out; 799196SAndreas.Sandberg@arm.com 809196SAndreas.Sandberg@arm.com /** Interface to reserve space in the next stage */ 819196SAndreas.Sandberg@arm.com std::vector<InputBuffer<ForwardInstData>> &nextStageReserve; 829196SAndreas.Sandberg@arm.com 839196SAndreas.Sandberg@arm.com /** Width of output of this stage/input of next in instructions */ 842SN/A unsigned int outputWidth; 859342SAndreas.Sandberg@arm.com 862SN/A /** If true, more than one input word can be processed each cycle if 872SN/A * there is room in the output to contain its processed data */ 882SN/A bool processMoreThanOneInput; 892SN/A 909196SAndreas.Sandberg@arm.com /** Branch predictor passed from Python configuration */ 912SN/A BPredUnit &branchPredictor; 922SN/A 9310023Smatt.horsnell@ARM.com public: 9410023Smatt.horsnell@ARM.com /* Public so that Pipeline can pass it to Fetch1 */ 9510023Smatt.horsnell@ARM.com std::vector<InputBuffer<ForwardLineData>> inputBuffer; 964762Snate@binkert.org 979196SAndreas.Sandberg@arm.com protected: 984762Snate@binkert.org /** Data members after this line are cycle-to-cycle state */ 994762Snate@binkert.org 1002SN/A struct Fetch2ThreadInfo { 1014762Snate@binkert.org 1024762Snate@binkert.org /** Default constructor */ 1034762Snate@binkert.org Fetch2ThreadInfo() : 1042SN/A inputIndex(0), 1052SN/A pc(TheISA::PCState(0)), 1065034Smilesck@eecs.umich.edu havePC(false), 1075034Smilesck@eecs.umich.edu lastStreamSeqNum(InstId::firstStreamSeqNum), 1081553SN/A fetchSeqNum(InstId::firstFetchSeqNum), 109265SN/A expectedStreamSeqNum(InstId::firstStreamSeqNum), 1107532Ssteve.reinhardt@amd.com predictionSeqNum(InstId::firstPredictionSeqNum), 1117532Ssteve.reinhardt@amd.com blocked(false) 1127532Ssteve.reinhardt@amd.com { } 1137532Ssteve.reinhardt@amd.com 1147532Ssteve.reinhardt@amd.com Fetch2ThreadInfo(const Fetch2ThreadInfo& other) : 1157532Ssteve.reinhardt@amd.com inputIndex(other.inputIndex), 116465SN/A pc(other.pc), 117465SN/A havePC(other.havePC), 1187532Ssteve.reinhardt@amd.com lastStreamSeqNum(other.lastStreamSeqNum), 1197532Ssteve.reinhardt@amd.com expectedStreamSeqNum(other.expectedStreamSeqNum), 1207532Ssteve.reinhardt@amd.com predictionSeqNum(other.predictionSeqNum), 1217532Ssteve.reinhardt@amd.com blocked(other.blocked) 1227532Ssteve.reinhardt@amd.com { } 1237532Ssteve.reinhardt@amd.com 1247532Ssteve.reinhardt@amd.com /** Index into an incompletely processed input line that instructions 1257532Ssteve.reinhardt@amd.com * are to be extracted from */ 1269196SAndreas.Sandberg@arm.com unsigned int inputIndex; 1279196SAndreas.Sandberg@arm.com 1287532Ssteve.reinhardt@amd.com 1297532Ssteve.reinhardt@amd.com /** Remembered program counter value. Between contiguous lines, this 1307532Ssteve.reinhardt@amd.com * is just updated with advancePC. For lines following changes of 1317532Ssteve.reinhardt@amd.com * stream, a new PC must be loaded and havePC be set. 1327532Ssteve.reinhardt@amd.com * havePC is needed to accomodate instructions which span across 1337532Ssteve.reinhardt@amd.com * lines meaning that Fetch2 and the decoder need to remember a PC 1347532Ssteve.reinhardt@amd.com * value and a partially-offered instruction from the previous line */ 1357532Ssteve.reinhardt@amd.com TheISA::PCState pc; 1367532Ssteve.reinhardt@amd.com 1377532Ssteve.reinhardt@amd.com /** PC is currently valid. Initially false, gets set to true when a 1389196SAndreas.Sandberg@arm.com * change-of-stream line is received and false again when lines are 1399196SAndreas.Sandberg@arm.com * discarded for any reason */ 1409196SAndreas.Sandberg@arm.com bool havePC; 1412SN/A 1429196SAndreas.Sandberg@arm.com /** Stream sequence number of the last seen line used to identify 1439196SAndreas.Sandberg@arm.com * changes of instruction stream */ 1449196SAndreas.Sandberg@arm.com InstSeqNum lastStreamSeqNum; 1459196SAndreas.Sandberg@arm.com 146330SN/A /** Fetch2 is the source of fetch sequence numbers. These represent the 1472SN/A * sequence that instructions were extracted from fetched lines. */ 1487532Ssteve.reinhardt@amd.com InstSeqNum fetchSeqNum; 14910023Smatt.horsnell@ARM.com 15010023Smatt.horsnell@ARM.com /** Stream sequence number remembered from last time the 15110023Smatt.horsnell@ARM.com * predictionSeqNum changed. Lines should only be discarded when their 15210023Smatt.horsnell@ARM.com * predictionSeqNums disagree with Fetch2::predictionSeqNum *and* they 15310023Smatt.horsnell@ARM.com * are from the same stream that bore that prediction number */ 15410023Smatt.horsnell@ARM.com InstSeqNum expectedStreamSeqNum; 15510023Smatt.horsnell@ARM.com 15610023Smatt.horsnell@ARM.com /** Fetch2 is the source of prediction sequence numbers. These 15710023Smatt.horsnell@ARM.com * represent predicted changes of control flow sources from branch 15810023Smatt.horsnell@ARM.com * prediction in Fetch2. */ 15910023Smatt.horsnell@ARM.com InstSeqNum predictionSeqNum; 16010023Smatt.horsnell@ARM.com 16110023Smatt.horsnell@ARM.com /** Blocked indication for report */ 16210023Smatt.horsnell@ARM.com bool blocked; 16310023Smatt.horsnell@ARM.com }; 1647532Ssteve.reinhardt@amd.com 1657532Ssteve.reinhardt@amd.com std::vector<Fetch2ThreadInfo> fetchInfo; 1667823Ssteve.reinhardt@amd.com ThreadID threadPriority; 1677532Ssteve.reinhardt@amd.com 1687532Ssteve.reinhardt@amd.com /** Stats */ 1697492Ssteve.reinhardt@amd.com Stats::Scalar intInstructions; 170330SN/A Stats::Scalar fpInstructions; 1719196SAndreas.Sandberg@arm.com Stats::Scalar vecInstructions; 1729342SAndreas.Sandberg@arm.com Stats::Scalar loadInstructions; 1739342SAndreas.Sandberg@arm.com Stats::Scalar storeInstructions; 1749342SAndreas.Sandberg@arm.com Stats::Scalar amoInstructions; 1759342SAndreas.Sandberg@arm.com 1769342SAndreas.Sandberg@arm.com protected: 1779342SAndreas.Sandberg@arm.com /** Get a piece of data to work on from the inputBuffer, or 0 if there 1789342SAndreas.Sandberg@arm.com * is no data. */ 1799196SAndreas.Sandberg@arm.com const ForwardLineData *getInput(ThreadID tid); 1809196SAndreas.Sandberg@arm.com 1819196SAndreas.Sandberg@arm.com /** Pop an element off the input buffer, if there are any */ 182938SN/A void popInput(ThreadID tid); 1831031SN/A 1841031SN/A /** Dump the whole contents of the input buffer. Useful after a 1851031SN/A * prediction changes control flow */ 1861031SN/A void dumpAllInput(ThreadID tid); 1871031SN/A 1881031SN/A /** Update local branch prediction structures from feedback from 1895314Sstever@gmail.com * Execute. */ 1905314Sstever@gmail.com void updateBranchPrediction(const BranchData &branch); 1915315Sstever@gmail.com 1925314Sstever@gmail.com /** Predicts branches for the given instruction. Updates the 1935314Sstever@gmail.com * instruction's predicted... fields and also the branch which 1945314Sstever@gmail.com * carries the prediction to Fetch1 */ 1952SN/A void predictBranch(MinorDynInstPtr inst, BranchData &branch); 1962SN/A 1979554Sandreas.hansson@arm.com /** Use the current threading policy to determine the next thread to 1989554Sandreas.hansson@arm.com * fetch from. */ 1999554Sandreas.hansson@arm.com ThreadID getScheduledThread(); 2009554Sandreas.hansson@arm.com 2012SN/A public: 202 Fetch2(const std::string &name, 203 MinorCPU &cpu_, 204 MinorCPUParams ¶ms, 205 Latch<ForwardLineData>::Output inp_, 206 Latch<BranchData>::Output branchInp_, 207 Latch<BranchData>::Input predictionOut_, 208 Latch<ForwardInstData>::Input out_, 209 std::vector<InputBuffer<ForwardInstData>> &next_stage_input_buffer); 210 211 public: 212 /** Pass on input/buffer data to the output if you can */ 213 void evaluate(); 214 215 void minorTrace() const; 216 217 void regStats(); 218 219 /** Is this stage drained? For Fetch2, draining is initiated by 220 * Execute halting Fetch1 causing Fetch2 to naturally drain. 221 * Branch predictions are ignored by Fetch1 during halt */ 222 bool isDrained(); 223}; 224 225} 226 227#endif /* __CPU_MINOR_FETCH2_HH__ */ 228