dyn_inst.hh revision 13954:2f400a5f2627
13898Ssaidi@eecs.umich.edu/*
23898Ssaidi@eecs.umich.edu * Copyright (c) 2013-2014 ARM Limited
33898Ssaidi@eecs.umich.edu * All rights reserved
43898Ssaidi@eecs.umich.edu *
53898Ssaidi@eecs.umich.edu * The license below extends only to copyright in the software and shall
63898Ssaidi@eecs.umich.edu * not be construed as granting a license to any other intellectual
73898Ssaidi@eecs.umich.edu * property including but not limited to intellectual property relating
83898Ssaidi@eecs.umich.edu * to a hardware implementation of the functionality of the software
93898Ssaidi@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
103898Ssaidi@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
113898Ssaidi@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
123898Ssaidi@eecs.umich.edu * modified or unmodified, in source code or in binary form.
133898Ssaidi@eecs.umich.edu *
143898Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
153898Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are
163898Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright
173898Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
183898Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
193898Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
203898Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution;
213898Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its
223898Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from
233898Ssaidi@eecs.umich.edu * this software without specific prior written permission.
243898Ssaidi@eecs.umich.edu *
253898Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
263898Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
273898Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
283898Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
293898Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
303898Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
313898Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
323898Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
333898Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
343898Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
353898Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
363898Ssaidi@eecs.umich.edu *
373898Ssaidi@eecs.umich.edu * Authors: Andrew Bardsley
383898Ssaidi@eecs.umich.edu */
393898Ssaidi@eecs.umich.edu
4011264Sandreas.sandberg@arm.com/**
414762Snate@binkert.org * @file
423898Ssaidi@eecs.umich.edu *
433898Ssaidi@eecs.umich.edu *  The dynamic instruction and instruction/line id (sequence numbers)
443898Ssaidi@eecs.umich.edu *  definition for Minor.  A spirited attempt is made here to not carry too
453898Ssaidi@eecs.umich.edu *  much on this structure.
463898Ssaidi@eecs.umich.edu */
473898Ssaidi@eecs.umich.edu
483898Ssaidi@eecs.umich.edu#ifndef __CPU_MINOR_DYN_INST_HH__
494011Ssaidi@eecs.umich.edu#define __CPU_MINOR_DYN_INST_HH__
503898Ssaidi@eecs.umich.edu
513898Ssaidi@eecs.umich.edu#include <iostream>
524762Snate@binkert.org
534762Snate@binkert.org#include "base/refcnt.hh"
544762Snate@binkert.org#include "cpu/minor/buffers.hh"
554762Snate@binkert.org#include "cpu/inst_seq.hh"
564762Snate@binkert.org#include "cpu/static_inst.hh"
573898Ssaidi@eecs.umich.edu#include "cpu/timing_expr.hh"
584762Snate@binkert.org#include "sim/faults.hh"
594762Snate@binkert.org
603898Ssaidi@eecs.umich.edunamespace Minor
613898Ssaidi@eecs.umich.edu{
623898Ssaidi@eecs.umich.edu
634011Ssaidi@eecs.umich.educlass MinorDynInst;
6411168Sandreas.hansson@arm.com
653898Ssaidi@eecs.umich.edu/** MinorDynInsts are currently reference counted. */
663898Ssaidi@eecs.umich.edutypedef RefCountingPtr<MinorDynInst> MinorDynInstPtr;
673898Ssaidi@eecs.umich.edu
683898Ssaidi@eecs.umich.edu/** Id for lines and instructions.  This includes all the relevant sequence
69 *  numbers and thread ids for all stages of execution. */
70class InstId
71{
72  public:
73    /** First sequence numbers to use in initialisation of the pipeline and
74     *  to be expected on the first line/instruction issued */
75    static const InstSeqNum firstStreamSeqNum = 1;
76    static const InstSeqNum firstPredictionSeqNum = 1;
77    static const InstSeqNum firstLineSeqNum = 1;
78    static const InstSeqNum firstFetchSeqNum = 1;
79    static const InstSeqNum firstExecSeqNum = 1;
80
81  public:
82    /** The thread to which this line/instruction belongs */
83    ThreadID threadId;
84
85    /** The 'stream' this instruction belongs to.  Streams are interrupted
86     *  (and sequence numbers increased) when Execute finds it wants to
87     *  change the stream of instructions due to a branch. */
88    InstSeqNum streamSeqNum;
89
90    /** The predicted qualifier to stream, attached by Fetch2 as a
91     *  consequence of branch prediction */
92    InstSeqNum predictionSeqNum;
93
94    /** Line sequence number.  This is the sequence number of the fetched
95     *  line from which this instruction was fetched */
96    InstSeqNum lineSeqNum;
97
98    /** Fetch sequence number.  This is 0 for bubbles and an ascending
99     *  sequence for the stream of all fetched instructions */
100    InstSeqNum fetchSeqNum;
101
102    /** 'Execute' sequence number.  These are assigned after micro-op
103     *  decomposition and form an ascending sequence (starting with 1) for
104     *  post-micro-op decomposed instructions. */
105    InstSeqNum execSeqNum;
106
107  public:
108    /** Very boring default constructor */
109    InstId(
110        ThreadID thread_id = 0, InstSeqNum stream_seq_num = 0,
111        InstSeqNum prediction_seq_num = 0, InstSeqNum line_seq_num = 0,
112        InstSeqNum fetch_seq_num = 0, InstSeqNum exec_seq_num = 0) :
113        threadId(thread_id), streamSeqNum(stream_seq_num),
114        predictionSeqNum(prediction_seq_num), lineSeqNum(line_seq_num),
115        fetchSeqNum(fetch_seq_num), execSeqNum(exec_seq_num)
116    { }
117
118  public:
119    /* Equal if the thread and last set sequence number matches */
120    bool
121    operator== (const InstId &rhs)
122    {
123        /* If any of fetch and exec sequence number are not set
124         *  they need to be 0, so a straight comparison is still
125         *  fine */
126        bool ret = (threadId == rhs.threadId &&
127            lineSeqNum == rhs.lineSeqNum &&
128            fetchSeqNum == rhs.fetchSeqNum &&
129            execSeqNum == rhs.execSeqNum);
130
131        /* Stream and prediction *must* match if these are the same id */
132        if (ret) {
133            assert(streamSeqNum == rhs.streamSeqNum &&
134                predictionSeqNum == rhs.predictionSeqNum);
135        }
136
137        return ret;
138    }
139};
140
141/** Print this id in the usual slash-separated format expected by
142 *  MinorTrace */
143std::ostream &operator <<(std::ostream &os, const InstId &id);
144
145class MinorDynInst;
146
147/** Print a short reference to this instruction.  '-' for a bubble and a
148 *  series of '/' separated sequence numbers for other instructions.  The
149 *  sequence numbers will be in the order: stream, prediction, line, fetch,
150 *  exec with exec absent if it is 0.  This is used by MinorTrace. */
151std::ostream &operator <<(std::ostream &os, const MinorDynInst &inst);
152
153/** Dynamic instruction for Minor.
154 *  MinorDynInst implements the BubbleIF interface
155 *  Has two separate notions of sequence number for pre/post-micro-op
156 *  decomposition: fetchSeqNum and execSeqNum */
157class MinorDynInst : public RefCounted
158{
159  private:
160    /** A prototypical bubble instruction.  You must call MinorDynInst::init
161     *  to initialise this */
162    static MinorDynInstPtr bubbleInst;
163
164  public:
165    StaticInstPtr staticInst;
166
167    InstId id;
168
169    /** Trace information for this instruction's execution */
170    Trace::InstRecord *traceData;
171
172    /** The fetch address of this instruction */
173    TheISA::PCState pc;
174
175    /** This is actually a fault masquerading as an instruction */
176    Fault fault;
177
178    /** Tried to predict the destination of this inst (if a control
179     *  instruction or a sys call) */
180    bool triedToPredict;
181
182    /** This instruction was predicted to change control flow and
183     *  the following instructions will have a newer predictionSeqNum */
184    bool predictedTaken;
185
186    /** Predicted branch target */
187    TheISA::PCState predictedTarget;
188
189    /** Fields only set during execution */
190
191    /** FU this instruction is issued to */
192    unsigned int fuIndex;
193
194    /** This instruction is in the LSQ, not a functional unit */
195    bool inLSQ;
196
197    /** The instruction has been sent to the store buffer */
198    bool inStoreBuffer;
199
200    /** Can this instruction be executed out of order.  In this model,
201     *  this only happens with mem refs that need to be issued early
202     *  to allow other instructions to fill the fetch delay */
203    bool canEarlyIssue;
204
205    /** Flag controlling conditional execution of the instruction */
206    bool predicate;
207
208    /** Flag controlling conditional execution of the memory access associated
209     *  with the instruction (only meaningful for loads/stores) */
210    bool memAccPredicate;
211
212    /** execSeqNum of the latest inst on which this inst depends.
213     *  This can be used as a sanity check for dependency ordering
214     *  where slightly out of order execution is required (notably
215     *  initiateAcc for memory ops) */
216    InstSeqNum instToWaitFor;
217
218    /** Extra delay at the end of the pipeline */
219    Cycles extraCommitDelay;
220    TimingExpr *extraCommitDelayExpr;
221
222    /** Once issued, extraCommitDelay becomes minimumCommitCycle
223     *  to account for delay in absolute time */
224    Cycles minimumCommitCycle;
225
226    /** Flat register indices so that, when clearing the scoreboard, we
227     *  have the same register indices as when the instruction was marked
228     *  up */
229    RegId flatDestRegIdx[TheISA::MaxInstDestRegs];
230
231  public:
232    MinorDynInst(InstId id_ = InstId(), Fault fault_ = NoFault) :
233        staticInst(NULL), id(id_), traceData(NULL),
234        pc(TheISA::PCState(0)), fault(fault_),
235        triedToPredict(false), predictedTaken(false),
236        fuIndex(0), inLSQ(false), inStoreBuffer(false),
237        canEarlyIssue(false), predicate(true), memAccPredicate(true),
238        instToWaitFor(0), extraCommitDelay(Cycles(0)),
239        extraCommitDelayExpr(NULL), minimumCommitCycle(Cycles(0))
240    { }
241
242  public:
243    /** The BubbleIF interface. */
244    bool isBubble() const { return id.fetchSeqNum == 0; }
245
246    /** There is a single bubble inst */
247    static MinorDynInstPtr bubble() { return bubbleInst; }
248
249    /** Is this a fault rather than instruction */
250    bool isFault() const { return fault != NoFault; }
251
252    /** Is this a real instruction */
253    bool isInst() const { return !isBubble() && !isFault(); }
254
255    /** Is this a real mem ref instruction */
256    bool isMemRef() const { return isInst() && staticInst->isMemRef(); }
257
258    /** Is this an instruction that can be executed `for free' and
259     *  needn't spend time in an FU */
260    bool isNoCostInst() const;
261
262    /** Assuming this is not a fault, is this instruction either
263     *  a whole instruction or the last microop from a macroop */
264    bool isLastOpInInst() const;
265
266    /** Initialise the class */
267    static void init();
268
269    /** Print (possibly verbose) instruction information for
270     *  MinorTrace using the given Named object's name */
271    void minorTraceInst(const Named &named_object) const;
272
273    /** ReportIF interface */
274    void reportData(std::ostream &os) const;
275
276    bool readPredicate() const { return predicate; }
277
278    void setPredicate(bool val) { predicate = val; }
279
280    bool readMemAccPredicate() const { return memAccPredicate; }
281
282    void setMemAccPredicate(bool val) { memAccPredicate = val; }
283
284    ~MinorDynInst();
285};
286
287/** Print a summary of the instruction */
288std::ostream &operator <<(std::ostream &os, const MinorDynInst &inst);
289
290}
291
292#endif /* __CPU_MINOR_DYN_INST_HH__ */
293