rob.hh revision 1461
1802SN/A// Todo: Probably add in support for scheduling events (more than one as
21762SN/A// well) on the case of the ROB being empty or full.  Considering tracking
3802SN/A// free entries instead of insts in ROB.  Differentiate between squashing
4802SN/A// all instructions after the instruction, and all instructions after *and*
5802SN/A// including that instruction.
6802SN/A
7802SN/A#ifndef __CPU_BETA_CPU_ROB_HH__
8802SN/A#define __CPU_BETA_CPU_ROB_HH__
9802SN/A
10802SN/A#include <utility>
11802SN/A#include <vector>
12802SN/A
13802SN/A//#include "arch/alpha/isa_traits.hh"
14802SN/A
15802SN/A/**
16802SN/A * ROB class.  Uses the instruction list that exists within the CPU to
17802SN/A * represent the ROB.  This class doesn't contain that list, but instead
18802SN/A * a pointer to the CPU to get access to the list.  The ROB, in this first
19802SN/A * implementation, is largely what drives squashing.
20802SN/A */
21802SN/Atemplate <class Impl>
22802SN/Aclass ROB
23802SN/A{
24802SN/A  public:
25802SN/A    //Typedefs from the Impl.
26802SN/A    typedef typename Impl::FullCPU FullCPU;
272665Ssaidi@eecs.umich.edu    typedef typename Impl::DynInstPtr DynInstPtr;
282665Ssaidi@eecs.umich.edu
29802SN/A    typedef std::pair<RegIndex, PhysRegIndex> UnmapInfo_t;
30802SN/A    typedef typename list<DynInstPtr>::iterator InstIt_t;
311722SN/A
32802SN/A  public:
33802SN/A    /** ROB constructor.
34802SN/A     *  @params _numEntries Number of entries in ROB.
35802SN/A     *  @params _squashWidth Number of instructions that can be squashed in a
361310SN/A     *                       single cycle.
371310SN/A     */
38802SN/A    ROB(unsigned _numEntries, unsigned _squashWidth);
39909SN/A
404762Snate@binkert.org    /** Function to set the CPU pointer, necessary due to which object the ROB
412257SN/A     *  is created within.
42802SN/A     *  @params cpu_ptr Pointer to the implementation specific full CPU object.
43802SN/A     */
44802SN/A    void setCPU(FullCPU *cpu_ptr);
45802SN/A
46802SN/A    /** Function to insert an instruction into the ROB.  The parameter inst is
47802SN/A     *  not truly required, but is useful for checking correctness.  Note
482539SN/A     *  that whatever calls this function must ensure that there is enough
49802SN/A     *  space within the ROB for the new instruction.
50802SN/A     *  @params inst The instruction being inserted into the ROB.
512539SN/A     *  @todo Remove the parameter once correctness is ensured.
52802SN/A     */
532539SN/A    void insertInst(DynInstPtr &inst);
544762Snate@binkert.org
554762Snate@binkert.org    /** Returns pointer to the head instruction within the ROB.  There is
564762Snate@binkert.org     *  no guarantee as to the return value if the ROB is empty.
574762Snate@binkert.org     *  @retval Pointer to the DynInst that is at the head of the ROB.
584762Snate@binkert.org     */
592539SN/A    DynInstPtr readHeadInst() { return cpu->instList.front(); }
604762Snate@binkert.org
614762Snate@binkert.org    DynInstPtr readTailInst() { return (*tail); }
62802SN/A
63802SN/A    void retireHead();
64885SN/A
65885SN/A    bool isHeadReady();
662539SN/A
67885SN/A    unsigned numFreeEntries();
68885SN/A
692539SN/A    bool isFull()
70802SN/A    { return numInstsInROB == numEntries; }
713349Sbinkertn@umich.edu
723349Sbinkertn@umich.edu    bool isEmpty()
73802SN/A    { return numInstsInROB == 0; }
74802SN/A
751310SN/A    void doSquash();
76
77    void squash(InstSeqNum squash_num);
78
79    uint64_t readHeadPC();
80
81    uint64_t readHeadNextPC();
82
83    InstSeqNum readHeadSeqNum();
84
85    uint64_t readTailPC();
86
87    InstSeqNum readTailSeqNum();
88
89    /** Checks if the ROB is still in the process of squashing instructions.
90     *  @retval Whether or not the ROB is done squashing.
91     */
92    bool isDoneSquashing() const { return doneSquashing; }
93
94    /** This is more of a debugging function than anything.  Use
95     *  numInstsInROB to get the instructions in the ROB unless you are
96     *  double checking that variable.
97     */
98    int countInsts();
99
100  private:
101
102    /** Pointer to the CPU. */
103    FullCPU *cpu;
104
105    /** Number of instructions in the ROB. */
106    unsigned numEntries;
107
108    /** Number of instructions that can be squashed in a single cycle. */
109    unsigned squashWidth;
110
111    /** Iterator pointing to the instruction which is the last instruction
112     *  in the ROB.  This may at times be invalid (ie when the ROB is empty),
113     *  however it should never be incorrect.
114     */
115    InstIt_t tail;
116
117    /** Iterator used for walking through the list of instructions when
118     *  squashing.  Used so that there is persistent state between cycles;
119     *  when squashing, the instructions are marked as squashed but not
120     *  immediately removed, meaning the tail iterator remains the same before
121     *  and after a squash.
122     *  This will always be set to cpu->instList.end() if it is invalid.
123     */
124    InstIt_t squashIt;
125
126    /** Number of instructions in the ROB. */
127    int numInstsInROB;
128
129    /** The sequence number of the squashed instruction. */
130    InstSeqNum squashedSeqNum;
131
132    /** Is the ROB done squashing. */
133    bool doneSquashing;
134};
135
136#endif //__CPU_BETA_CPU_ROB_HH__
137