gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
decode.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 ARM Limited
3  * All rights reserved
4  *
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.
13  *
14  * Copyright (c) 2004-2006 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Authors: Kevin Lim
41  */
42 
43 #ifndef __CPU_O3_DECODE_HH__
44 #define __CPU_O3_DECODE_HH__
45 
46 #include <queue>
47 
48 #include "base/statistics.hh"
49 #include "cpu/timebuf.hh"
50 
51 struct DerivO3CPUParams;
52 
60 template<class Impl>
62 {
63  private:
64  // Typedefs from the Impl.
65  typedef typename Impl::O3CPU O3CPU;
66  typedef typename Impl::DynInstPtr DynInstPtr;
67  typedef typename Impl::CPUPol CPUPol;
68 
69  // Typedefs from the CPU policy.
70  typedef typename CPUPol::FetchStruct FetchStruct;
71  typedef typename CPUPol::DecodeStruct DecodeStruct;
72  typedef typename CPUPol::TimeStruct TimeStruct;
73 
74  public:
78  enum DecodeStatus {
81  };
82 
84  enum ThreadStatus {
91  };
92 
93  private:
96 
98  ThreadStatus decodeStatus[Impl::MaxThreads];
99 
100  public:
102  DefaultDecode(O3CPU *_cpu, DerivO3CPUParams *params);
103 
104  void startupStage();
105  void resetStage();
106 
108  std::string name() const;
109 
111  void regStats();
112 
115 
118 
121 
124 
126  void drainSanityCheck() const;
127 
129  bool isDrained() const;
130 
132  void takeOverFrom() { resetStage(); }
133 
137  void tick();
138 
144  void decode(bool &status_change, ThreadID tid);
145 
151  void decodeInsts(ThreadID tid);
152 
153  private:
157  void skidInsert(ThreadID tid);
158 
160  bool skidsEmpty();
161 
163  void updateStatus();
164 
168  void sortInsts();
169 
171  void readStallSignals(ThreadID tid);
172 
175 
177  bool checkStall(ThreadID tid) const;
178 
180  inline bool fetchInstsValid();
181 
186  bool block(ThreadID tid);
187 
192  bool unblock(ThreadID tid);
193 
197  void squash(DynInstPtr &inst, ThreadID tid);
198 
199  public:
203  unsigned squash(ThreadID tid);
204 
205  private:
206  // Interfaces to objects outside of decode.
209 
212 
215 
218 
221 
223  // Might not be the best name as not only fetch will read it.
225 
228 
231 
234 
237 
239  std::queue<DynInstPtr> insts[Impl::MaxThreads];
240 
242  std::queue<DynInstPtr> skidBuffer[Impl::MaxThreads];
243 
248 
250  struct Stalls {
251  bool rename;
252  };
253 
255  Stalls stalls[Impl::MaxThreads];
256 
259 
262 
265 
268 
270  unsigned decodeWidth;
271 
273  unsigned toRenameIndex;
274 
277 
280 
282  unsigned skidBufferMax;
283 
285  Addr bdelayDoneSeqNum[Impl::MaxThreads];
286 
288  DynInstPtr squashInst[Impl::MaxThreads];
289 
294  bool squashAfterDelaySlot[Impl::MaxThreads];
295 
296 
319 };
320 
321 #endif // __CPU_O3_DECODE_HH__
TimeBuffer< TimeStruct > * timeBuffer
Time buffer interface.
Definition: decode.hh:211
void resetStage()
Definition: decode_impl.hh:89
Cycles fetchToDecodeDelay
Fetch to decode delay.
Definition: decode.hh:267
void decode(bool &status_change, ThreadID tid)
Determines what to do based on decode's current status.
Definition: decode_impl.hh:587
ThreadID numThreads
number of Active Threads
Definition: decode.hh:276
unsigned toRenameIndex
Index of instructions being sent to rename.
Definition: decode.hh:273
void setDecodeQueue(TimeBuffer< DecodeStruct > *dq_ptr)
Sets pointer to time buffer used to communicate to the next stage.
Definition: decode_impl.hh:172
bool wroteToTimeBuffer
Variable that tracks if decode has written to the time buffer this cycle.
Definition: decode.hh:247
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
void sortInsts()
Separates instructions from fetch into individual lists of instructions sorted by thread...
Definition: decode_impl.hh:470
DynInstPtr squashInst[Impl::MaxThreads]
Instruction used for squashing branch (used for MIPS)
Definition: decode.hh:288
Stalls stalls[Impl::MaxThreads]
Tracks which stages are telling decode to stall.
Definition: decode.hh:255
bool squashAfterDelaySlot[Impl::MaxThreads]
Tells when their is a pending delay slot inst.
Definition: decode.hh:294
Cycles iewToDecodeDelay
IEW to decode delay.
Definition: decode.hh:261
Stats::Scalar decodeBlockedCycles
Stat for total number of blocked cycles.
Definition: decode.hh:300
bool isDrained() const
Has the stage drained?
Definition: decode_impl.hh:209
void takeOverFrom()
Takes over from another CPU's thread.
Definition: decode.hh:132
DecodeStatus
Overall decode stage status.
Definition: decode.hh:78
TimeBuffer< DecodeStruct >::wire toRename
Wire used to write any information heading to rename.
Definition: decode.hh:230
void tick()
Ticks decode, processing all input signals and decoding as many instructions as possible.
Definition: decode_impl.hh:551
void startupStage()
Definition: decode_impl.hh:82
DefaultDecode(O3CPU *_cpu, DerivO3CPUParams *params)
DefaultDecode constructor.
Definition: decode_impl.hh:62
DefaultDecode class handles both single threaded and SMT decode.
Definition: decode.hh:61
bool skidsEmpty()
Returns if all of the skid buffers are empty.
Definition: decode_impl.hh:415
void skidInsert(ThreadID tid)
Inserts a thread's instructions into the skid buffer, to be decoded once decode unblocks.
Definition: decode_impl.hh:391
unsigned decodeWidth
The width of decode, in instructions.
Definition: decode.hh:270
Declaration of Statistics objects.
TimeBuffer< TimeStruct >::wire fromIEW
Wire to get iew's information from backwards time buffer.
Definition: decode.hh:217
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
Stats::Scalar decodeUnblockCycles
Stat for total number of unblocking cycles.
Definition: decode.hh:304
void regStats()
Registers statistics.
Definition: decode_impl.hh:110
CPUPol::FetchStruct FetchStruct
Definition: decode.hh:70
ThreadStatus decodeStatus[Impl::MaxThreads]
Per-thread status.
Definition: decode.hh:98
unsigned skidBufferMax
Maximum size of the skid buffer.
Definition: decode.hh:282
TimeBuffer< TimeStruct >::wire fromRename
Wire to get rename's output from backwards time buffer.
Definition: decode.hh:214
std::string name() const
Returns the name of decode.
Definition: decode_impl.hh:103
std::list< ThreadID > * activeThreads
List of active thread ids.
Definition: decode.hh:279
Stats::Scalar decodeSquashCycles
Stat for total number of squashing cycles.
Definition: decode.hh:306
Impl::CPUPol CPUPol
Definition: decode.hh:67
Stats::Scalar decodeControlMispred
Stat for number of times decode detected a non-control instruction incorrectly predicted as a branch...
Definition: decode.hh:314
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition: decode_impl.hh:199
CPUPol::DecodeStruct DecodeStruct
Definition: decode.hh:71
TimeBuffer< DecodeStruct > * decodeQueue
Decode instruction queue.
Definition: decode.hh:227
Addr bdelayDoneSeqNum[Impl::MaxThreads]
SeqNum of Squashing Branch Delay Instruction (used for MIPS)
Definition: decode.hh:285
void squash(DynInstPtr &inst, ThreadID tid)
Squashes if there is a PC-relative branch that was predicted incorrectly.
Definition: decode_impl.hh:291
Stats::Scalar decodeBranchResolved
Stat for number of times a branch is resolved at decode.
Definition: decode.hh:308
bool checkStall(ThreadID tid) const
Checks all stall signals, and returns if any are true.
Definition: decode_impl.hh:221
void readStallSignals(ThreadID tid)
Reads all stall signals from the backwards communication timebuffer.
Definition: decode_impl.hh:480
TimeBuffer< TimeStruct >::wire fromCommit
Wire to get commit's information from backwards time buffer.
Definition: decode.hh:220
Impl::DynInstPtr DynInstPtr
Definition: decode.hh:66
Stats::Scalar decodeIdleCycles
Stat for total number of idle cycles.
Definition: decode.hh:298
O3CPU * cpu
CPU interface.
Definition: decode.hh:208
Stats::Scalar decodeSquashedInsts
Stat for total number of squashed instructions.
Definition: decode.hh:318
bool block(ThreadID tid)
Switches decode to blocking, and signals back that decode has become blocked.
Definition: decode_impl.hh:242
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets pointer to list of active threads.
Definition: decode_impl.hh:192
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Source of possible stalls.
Definition: decode.hh:250
void decodeInsts(ThreadID tid)
Processes instructions from fetch and passes them on to rename.
Definition: decode_impl.hh:632
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
TimeBuffer< TimeStruct >::wire toFetch
Wire to write information heading to previous stages.
Definition: decode.hh:224
std::queue< DynInstPtr > insts[Impl::MaxThreads]
Queue of all instructions coming from fetch this cycle.
Definition: decode.hh:239
std::queue< DynInstPtr > skidBuffer[Impl::MaxThreads]
Skid buffer between fetch and decode.
Definition: decode.hh:242
Stats::Scalar decodeBranchMispred
Stat for number of times a branch mispredict is detected.
Definition: decode.hh:310
bool checkSignalsAndUpdate(ThreadID tid)
Checks all input signals and updates decode's status appropriately.
Definition: decode_impl.hh:494
DecodeStatus _status
Decode status.
Definition: decode.hh:95
CPUPol::TimeStruct TimeStruct
Definition: decode.hh:72
Cycles commitToDecodeDelay
Commit to decode delay.
Definition: decode.hh:264
Stats::Scalar decodeRunCycles
Stat for total number of normal running cycles.
Definition: decode.hh:302
void setFetchQueue(TimeBuffer< FetchStruct > *fq_ptr)
Sets pointer to time buffer coming from fetch.
Definition: decode_impl.hh:182
bool unblock(ThreadID tid)
Switches decode to unblocking if the skid buffer is empty, and signals back that decode has unblocked...
Definition: decode_impl.hh:272
Impl::O3CPU O3CPU
Definition: decode.hh:65
ThreadStatus
Individual thread status.
Definition: decode.hh:84
TimeBuffer< FetchStruct >::wire fromFetch
Wire to get fetch's output from fetch queue.
Definition: decode.hh:236
Stats::Scalar decodeDecodedInsts
Stat for total number of decoded instructions.
Definition: decode.hh:316
void updateStatus()
Updates overall decode status based on all of the threads' statuses.
Definition: decode_impl.hh:431
TimeBuffer< FetchStruct > * fetchQueue
Fetch instruction queue interface.
Definition: decode.hh:233
Cycles renameToDecodeDelay
Rename to decode delay.
Definition: decode.hh:258
void setTimeBuffer(TimeBuffer< TimeStruct > *tb_ptr)
Sets the main backwards communication time buffer pointer.
Definition: decode_impl.hh:157
bool fetchInstsValid()
Returns if there any instructions from fetch on this cycle.
Definition: decode_impl.hh:235

Generated on Fri Jun 9 2017 13:03:42 for gem5 by doxygen 1.8.6