2 * Copyright (c) 2013-2014 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Authors: Andrew Bardsley
43 * Contains class definitions for data flowing between pipeline stages in
44 * the top-level structure portion of this model. Latch types are also
45 * defined which pair forward/backward flowing data specific to each stage
48 * No post-configuration inter-stage communication should *ever* take place
49 * outside these classes (except for reservation!)
52 #ifndef __CPU_MINOR_PIPE_DATA_HH__
53 #define __CPU_MINOR_PIPE_DATA_HH__
55 #include "cpu/minor/buffers.hh"
56 #include "cpu/minor/dyn_inst.hh"
57 #include "cpu/base.hh"
62 /** Forward data betwen Execute and Fetch1 carrying change-of-address/stream
64 class BranchData /* : public ReportIF, public BubbleIF */
69 /* *** No change of stream (information to branch prediction) */
71 /* Don't branch at all (bubble) */
73 /* Don't branch, but here's the details of a correct prediction
74 * that was executed */
75 CorrectlyPredictedBranch,
77 /* *** Change of stream */
79 /* Take an unpredicted branch */
81 /* Take a branch on branch prediction data (from Fetch2) */
83 /* Prediction of wrong target PC */
84 BadlyPredictedBranchTarget,
85 /* Bad branch prediction (didn't actually branch). Need to branch
86 * back to correct stream. If the target is wrong, use
87 * BadlyPredictedBranchTarget */
89 /* Suspend fetching for this thread (inst->id.threadId).
90 * This will be woken up by another stream changing branch so
91 * count it as stream changing itself and expect pc to be the PC
92 * of the next instruction */
94 /* Branch from an interrupt (no instruction) */
96 /* Stop fetching in anticipation of of draining */
100 /** Is a request with this reason actually a request to change the
101 * PC rather than a bubble or branch prediction information */
102 static bool isStreamChange(const BranchData::Reason reason);
104 /** Is a request with this reason actually a 'real' branch, that is,
105 * a stream change that's not just an instruction to Fetch1 to halt
107 static bool isBranch(const BranchData::Reason reason);
110 /** Explanation for this branch */
113 /** ThreadID associated with branch */
116 /** Sequence number of new stream/prediction to be adopted */
117 InstSeqNum newStreamSeqNum;
118 InstSeqNum newPredictionSeqNum;
120 /** Starting PC of that stream */
121 TheISA::PCState target;
123 /** Instruction which caused this branch */
124 MinorDynInstPtr inst;
128 reason(NoBranch), threadId(InvalidThreadID), newStreamSeqNum(0),
129 newPredictionSeqNum(0), target(TheISA::PCState(0)),
130 inst(MinorDynInst::bubble())
136 InstSeqNum new_stream_seq_num,
137 InstSeqNum new_prediction_seq_num,
138 TheISA::PCState target,
139 MinorDynInstPtr inst_) :
142 newStreamSeqNum(new_stream_seq_num),
143 newPredictionSeqNum(new_prediction_seq_num),
148 /** BubbleIF interface */
149 static BranchData bubble() { return BranchData(); }
150 bool isBubble() const { return reason == NoBranch; }
152 /** As static isStreamChange but on this branch data */
153 bool isStreamChange() const { return isStreamChange(reason); }
155 /** As static isBranch but on this branch data */
156 bool isBranch() const { return isBranch(reason); }
158 /** ReportIF interface */
159 void reportData(std::ostream &os) const;
162 /** Print a branch reason enum */
163 std::ostream &operator <<(std::ostream &os, BranchData::Reason reason);
165 /** Print BranchData contents in a format suitable for DPRINTF comments, not
167 std::ostream &operator <<(std::ostream &os, const BranchData &branch);
169 /** Line fetch data in the forward direction. Contains a single cache line
170 * (or fragment of a line), its address, a sequence number assigned when
171 * that line was fetched and a bubbleFlag that can allow ForwardLineData to
172 * be used to represent the absence of line data in a pipeline. */
173 class ForwardLineData /* : public ReportIF, public BubbleIF */
176 /** This line is a bubble. No other data member is required to be valid
181 /** First byte address in the line. This is allowed to be
182 * <= pc.instAddr() */
185 /** PC of the first requested inst within this line */
188 /** Explicit line width, don't rely on data.size */
189 unsigned int lineWidth;
192 /** This line has a fault. The bubble flag will be false and seqNums
193 * will be valid but no data will */
196 /** Thread, stream, prediction ... id of this line */
199 /** Line data. line[0] is the byte at address pc.instAddr(). Data is
200 * only valid upto lineWidth - 1. */
203 /** Packet from which the line is taken */
215 /* Make lines bubbles by default */
218 ~ForwardLineData() { line = NULL; }
221 /** This is a fault, not a line */
222 bool isFault() const { return fault != NoFault; }
224 /** Set fault and possible clear the bubble flag */
225 void setFault(Fault fault_);
227 /** In-place initialise a ForwardLineData, freeing and overridding the
229 void allocateLine(unsigned int width_);
231 /** Use the data from a packet as line instead of allocating new
232 * space. On destruction of this object, the packet will be destroyed */
233 void adoptPacketData(Packet *packet);
235 /** Free this ForwardLineData line. Note that these are shared between
236 * line objects and so you must be careful when deallocating them.
237 * Copying of ForwardLineData can, therefore, be done by default copy
238 * constructors/assignment */
241 /** BubbleIF interface */
242 static ForwardLineData bubble() { return ForwardLineData(); }
243 bool isBubble() const { return bubbleFlag; }
245 /** ReportIF interface */
246 void reportData(std::ostream &os) const;
249 /** Maximum number of instructions that can be carried by the pipeline. */
250 const unsigned int MAX_FORWARD_INSTS = 16;
252 /** Forward flowing data between Fetch2,Decode,Execute carrying a packet of
253 * instructions of a width appropriate to the configured stage widths.
254 * Also carries exception information where instructions are not valid */
255 class ForwardInstData /* : public ReportIF, public BubbleIF */
258 /** Array of carried insts, ref counted */
259 MinorDynInstPtr insts[MAX_FORWARD_INSTS];
261 /** The number of insts slots that can be expected to be valid insts */
262 unsigned int numInsts;
264 /** Thread associated with these instructions */
268 explicit ForwardInstData(unsigned int width = 0,
269 ThreadID tid = InvalidThreadID);
271 ForwardInstData(const ForwardInstData &src);
274 /** Number of instructions carried by this object */
275 unsigned int width() const { return numInsts; }
277 /** Copy the inst array only as far as numInsts */
278 ForwardInstData &operator =(const ForwardInstData &src);
280 /** Resize a bubble/empty ForwardInstData and fill with bubbles */
281 void resize(unsigned int width);
283 /** Fill with bubbles from 0 to width() - 1 */
286 /** BubbleIF interface */
287 bool isBubble() const;
289 /** ReportIF interface */
290 void reportData(std::ostream &os) const;
295 #endif /* __CPU_MINOR_PIPE_DATA_HH__ */