comm.hh revision 13610:5d5404ac6288
12SN/A/*
21762SN/A * Copyright (c) 2011, 2016-2017 ARM Limited
32SN/A * Copyright (c) 2013 Advanced Micro Devices, Inc.
42SN/A * All rights reserved
52SN/A *
62SN/A * The license below extends only to copyright in the software and shall
72SN/A * not be construed as granting a license to any other intellectual
82SN/A * property including but not limited to intellectual property relating
92SN/A * to a hardware implementation of the functionality of the software
102SN/A * licensed hereunder.  You may use the software subject to the license
112SN/A * terms below provided that you ensure that this notice is replicated
122SN/A * unmodified and in its entirety in all distributions of the software,
132SN/A * modified or unmodified, in source code or in binary form.
142SN/A *
152SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
162SN/A * All rights reserved.
172SN/A *
182SN/A * Redistribution and use in source and binary forms, with or without
192SN/A * modification, are permitted provided that the following conditions are
202SN/A * met: redistributions of source code must retain the above copyright
212SN/A * notice, this list of conditions and the following disclaimer;
222SN/A * redistributions in binary form must reproduce the above copyright
232SN/A * notice, this list of conditions and the following disclaimer in the
242SN/A * documentation and/or other materials provided with the distribution;
252SN/A * neither the name of the copyright holders nor the names of its
262SN/A * contributors may be used to endorse or promote products derived from
272665SN/A * this software without specific prior written permission.
282665SN/A *
292665SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
302SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
312SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
322SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
332SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
342SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
352SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3611263Sandreas.sandberg@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3711263Sandreas.sandberg@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
382SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
396216SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40572SN/A *
412SN/A * Authors: Kevin Lim
422SN/A *          Nathanael Premillieu
436214SN/A */
4410905SN/A
45837SN/A#ifndef __CPU_O3_COMM_HH__
462SN/A#define __CPU_O3_COMM_HH__
472SN/A
482SN/A#include <vector>
4910469SN/A
502SN/A#include "arch/types.hh"
512SN/A#include "base/types.hh"
5211701Smichael.lebeane@amd.com#include "cpu/inst_seq.hh"
532007SN/A#include "sim/faults.hh"
542007SN/A
552SN/A/** Physical register index type.
562007SN/A * Although the Impl might be a better for this, but there are a few classes
5711701Smichael.lebeane@amd.com * that need this typedef yet are not templated on the Impl.
5811719Smichael.lebeane@amd.com */
5911719Smichael.lebeane@amd.comusing PhysRegIndex = short int;
6011719Smichael.lebeane@amd.com
6111719Smichael.lebeane@amd.com/** Physical register ID.
6211719Smichael.lebeane@amd.com * Like a register ID but physical. The inheritance is private because the
6311701Smichael.lebeane@amd.com * only relationship between this types is functional, and it is done to
642007SN/A * prevent code replication. */
656227SN/Aclass PhysRegId : private RegId {
662SN/A  private:
6711701Smichael.lebeane@amd.com    PhysRegIndex flatIdx;
6811701Smichael.lebeane@amd.com
6911701Smichael.lebeane@amd.com  public:
7011701Smichael.lebeane@amd.com    explicit PhysRegId() : RegId(IntRegClass, -1), flatIdx(-1) {}
7111701Smichael.lebeane@amd.com
7211701Smichael.lebeane@amd.com    /** Scalar PhysRegId constructor. */
7311701Smichael.lebeane@amd.com    explicit PhysRegId(RegClass _regClass, PhysRegIndex _regIdx,
7411701Smichael.lebeane@amd.com              PhysRegIndex _flatIdx)
7511701Smichael.lebeane@amd.com        : RegId(_regClass, _regIdx), flatIdx(_flatIdx)
765483SN/A    {}
7711719Smichael.lebeane@amd.com
784981SN/A    /** Vector PhysRegId constructor (w/ elemIndex). */
794981SN/A    explicit PhysRegId(RegClass _regClass, PhysRegIndex _regIdx,
806227SN/A              ElemIndex elem_idx, PhysRegIndex flat_idx)
8111719Smichael.lebeane@amd.com        : RegId(_regClass, _regIdx, elem_idx), flatIdx(flat_idx) { }
824981SN/A
834981SN/A    /** Visible RegId methods */
842566SN/A    /** @{ */
85228SN/A    using RegId::index;
8610905SN/A    using RegId::classValue;
8710905SN/A    using RegId::isZeroReg;
882SN/A    using RegId::className;
892SN/A    using RegId::elemIndex;
9010469SN/A     /** @} */
912SN/A    /**
9211263Sandreas.sandberg@arm.com     * Explicit forward methods, to prevent comparisons of PhysRegId with
93     * RegIds.
94     */
95    /** @{ */
96    bool operator<(const PhysRegId& that) const {
97        return RegId::operator<(that);
98    }
99
100    bool operator==(const PhysRegId& that) const {
101        return RegId::operator==(that);
102    }
103
104    bool operator!=(const PhysRegId& that) const {
105        return RegId::operator!=(that);
106    }
107    /** @} */
108
109    /** @return true if it is an integer physical register. */
110    bool isIntPhysReg() const { return isIntReg(); }
111
112    /** @return true if it is a floating-point physical register. */
113    bool isFloatPhysReg() const { return isFloatReg(); }
114
115    /** @Return true if it is a  condition-code physical register. */
116    bool isCCPhysReg() const { return isCCReg(); }
117
118    /** @Return true if it is a vector physical register. */
119    bool isVectorPhysReg() const { return isVecReg(); }
120
121    /** @Return true if it is a vector element physical register. */
122    bool isVectorPhysElem() const { return isVecElem(); }
123
124    /** @return true if it is a vector predicate physical register. */
125    bool isVecPredPhysReg() const { return isVecPredReg(); }
126
127    /** @Return true if it is a  condition-code physical register. */
128    bool isMiscPhysReg() const { return isMiscReg(); }
129
130    /**
131     * Returns true if this register is always associated to the same
132     * architectural register.
133     */
134    bool isFixedMapping() const
135    {
136        return !isRenameable();
137    }
138
139    /** Flat index accessor */
140    const PhysRegIndex& flatIndex() const { return flatIdx; }
141
142    static PhysRegId elemId(const PhysRegId* vid, ElemIndex elem)
143    {
144        assert(vid->isVectorPhysReg());
145        return PhysRegId(VecElemClass, vid->index(), elem);
146    }
147};
148
149/** Constant pointer definition.
150 * PhysRegIds only need to be created once and then we can just share
151 * pointers */
152using PhysRegIdPtr = const PhysRegId*;
153
154/** Struct that defines the information passed from fetch to decode. */
155template<class Impl>
156struct DefaultFetchDefaultDecode {
157    typedef typename Impl::DynInstPtr DynInstPtr;
158
159    int size;
160
161    DynInstPtr insts[Impl::MaxWidth];
162    Fault fetchFault;
163    InstSeqNum fetchFaultSN;
164    bool clearFetchFault;
165};
166
167/** Struct that defines the information passed from decode to rename. */
168template<class Impl>
169struct DefaultDecodeDefaultRename {
170    typedef typename Impl::DynInstPtr DynInstPtr;
171
172    int size;
173
174    DynInstPtr insts[Impl::MaxWidth];
175};
176
177/** Struct that defines the information passed from rename to IEW. */
178template<class Impl>
179struct DefaultRenameDefaultIEW {
180    typedef typename Impl::DynInstPtr DynInstPtr;
181
182    int size;
183
184    DynInstPtr insts[Impl::MaxWidth];
185};
186
187/** Struct that defines the information passed from IEW to commit. */
188template<class Impl>
189struct DefaultIEWDefaultCommit {
190    typedef typename Impl::DynInstPtr DynInstPtr;
191
192    int size;
193
194    DynInstPtr insts[Impl::MaxWidth];
195    DynInstPtr mispredictInst[Impl::MaxThreads];
196    Addr mispredPC[Impl::MaxThreads];
197    InstSeqNum squashedSeqNum[Impl::MaxThreads];
198    TheISA::PCState pc[Impl::MaxThreads];
199
200    bool squash[Impl::MaxThreads];
201    bool branchMispredict[Impl::MaxThreads];
202    bool branchTaken[Impl::MaxThreads];
203    bool includeSquashInst[Impl::MaxThreads];
204};
205
206template<class Impl>
207struct IssueStruct {
208    typedef typename Impl::DynInstPtr DynInstPtr;
209
210    int size;
211
212    DynInstPtr insts[Impl::MaxWidth];
213};
214
215/** Struct that defines all backwards communication. */
216template<class Impl>
217struct TimeBufStruct {
218    typedef typename Impl::DynInstPtr DynInstPtr;
219    struct decodeComm {
220        TheISA::PCState nextPC;
221        DynInstPtr mispredictInst;
222        DynInstPtr squashInst;
223        InstSeqNum doneSeqNum;
224        Addr mispredPC;
225        uint64_t branchAddr;
226        unsigned branchCount;
227        bool squash;
228        bool predIncorrect;
229        bool branchMispredict;
230        bool branchTaken;
231    };
232
233    decodeComm decodeInfo[Impl::MaxThreads];
234
235    struct renameComm {
236    };
237
238    renameComm renameInfo[Impl::MaxThreads];
239
240    struct iewComm {
241        // Also eventually include skid buffer space.
242        unsigned freeIQEntries;
243        unsigned freeLQEntries;
244        unsigned freeSQEntries;
245        unsigned dispatchedToLQ;
246        unsigned dispatchedToSQ;
247
248        unsigned iqCount;
249        unsigned ldstqCount;
250
251        unsigned dispatched;
252        bool usedIQ;
253        bool usedLSQ;
254    };
255
256    iewComm iewInfo[Impl::MaxThreads];
257
258    struct commitComm {
259        /////////////////////////////////////////////////////////////////////
260        // This code has been re-structured for better packing of variables
261        // instead of by stage which is the more logical way to arrange the
262        // data.
263        // F = Fetch
264        // D = Decode
265        // I = IEW
266        // R = Rename
267        // As such each member is annotated with who consumes it
268        // e.g. bool variable name // *F,R for Fetch and Rename
269        /////////////////////////////////////////////////////////////////////
270
271        /// The pc of the next instruction to execute. This is the next
272        /// instruction for a branch mispredict, but the same instruction for
273        /// order violation and the like
274        TheISA::PCState pc; // *F
275
276        /// Provide fetch the instruction that mispredicted, if this
277        /// pointer is not-null a misprediction occured
278        DynInstPtr mispredictInst;  // *F
279
280        /// Instruction that caused the a non-mispredict squash
281        DynInstPtr squashInst; // *F
282
283        /// Hack for now to send back a strictly ordered access to the
284        /// IEW stage.
285        DynInstPtr strictlyOrderedLoad; // *I
286
287        /// Communication specifically to the IQ to tell the IQ that it can
288        /// schedule a non-speculative instruction.
289        InstSeqNum nonSpecSeqNum; // *I
290
291        /// Represents the instruction that has either been retired or
292        /// squashed.  Similar to having a single bus that broadcasts the
293        /// retired or squashed sequence number.
294        InstSeqNum doneSeqNum; // *F, I
295
296        /// Tell Rename how many free entries it has in the ROB
297        unsigned freeROBEntries; // *R
298
299        bool squash; // *F, D, R, I
300        bool robSquashing; // *F, D, R, I
301
302        /// Rename should re-read number of free rob entries
303        bool usedROB; // *R
304
305        /// Notify Rename that the ROB is empty
306        bool emptyROB; // *R
307
308        /// Was the branch taken or not
309        bool branchTaken; // *F
310        /// If an interrupt is pending and fetch should stall
311        bool interruptPending; // *F
312        /// If the interrupt ended up being cleared before being handled
313        bool clearInterrupt; // *F
314
315        /// Hack for now to send back an strictly ordered access to
316        /// the IEW stage.
317        bool strictlyOrdered; // *I
318
319    };
320
321    commitComm commitInfo[Impl::MaxThreads];
322
323    bool decodeBlock[Impl::MaxThreads];
324    bool decodeUnblock[Impl::MaxThreads];
325    bool renameBlock[Impl::MaxThreads];
326    bool renameUnblock[Impl::MaxThreads];
327    bool iewBlock[Impl::MaxThreads];
328    bool iewUnblock[Impl::MaxThreads];
329};
330
331#endif //__CPU_O3_COMM_HH__
332