free_list.hh revision 1060
1#ifndef __FREE_LIST_HH__
2#define __FREE_LIST_HH__
3
4#include <iostream>
5#include <queue>
6
7#include "arch/alpha/isa_traits.hh"
8#include "cpu/beta_cpu/comm.hh"
9#include "base/trace.hh"
10
11using namespace std;
12
13// Question: Do I even need the number of logical registers?
14// How to avoid freeing registers instantly?  Same with ROB entries.
15
16/**
17 * FreeList class that simply holds the list of free integer and floating
18 * point registers.  Can request for a free register of either type, and
19 * also send back free registers of either type.  This is a very simple
20 * class, but it should be sufficient for most implementations.  Like all
21 * other classes, it assumes that the indices for the floating point
22 * registers starts after the integer registers end.  Hence the variable
23 * numPhysicalIntRegs is logically equivalent to the baseFP dependency.
24 * Note that
25 * while this most likely should be called FreeList, the name "FreeList"
26 * is used in a typedef within the CPU Policy, and therefore no class
27 * can be named simply "FreeList".
28 * @todo: Give a better name to the base FP dependency.
29 */
30class SimpleFreeList
31{
32  public:
33
34  private:
35    /** The list of free integer registers. */
36    queue<PhysRegIndex> freeIntRegs;
37
38    /** The list of free floating point registers. */
39    queue<PhysRegIndex> freeFloatRegs;
40
41    /** Number of logical integer registers. */
42    int numLogicalIntRegs;
43
44    /** Number of physical integer registers. */
45    int numPhysicalIntRegs;
46
47    /** Number of logical floating point registers. */
48    int numLogicalFloatRegs;
49
50    /** Number of physical floating point registers. */
51    int numPhysicalFloatRegs;
52
53    /** Total number of physical registers. */
54    int numPhysicalRegs;
55
56  public:
57    SimpleFreeList(unsigned _numLogicalIntRegs,
58                   unsigned _numPhysicalIntRegs,
59                   unsigned _numLogicalFloatRegs,
60                   unsigned _numPhysicalFloatRegs);
61
62    PhysRegIndex getIntReg();
63
64    PhysRegIndex getFloatReg();
65
66    void addReg(PhysRegIndex freed_reg);
67
68    void addIntReg(PhysRegIndex freed_reg);
69
70    void addFloatReg(PhysRegIndex freed_reg);
71
72    bool hasFreeIntRegs()
73    { return !freeIntRegs.empty(); }
74
75    bool hasFreeFloatRegs()
76    { return !freeFloatRegs.empty(); }
77
78    int numFreeIntRegs()
79    { return freeIntRegs.size(); }
80
81    int numFreeFloatRegs()
82    { return freeFloatRegs.size(); }
83};
84
85inline PhysRegIndex
86SimpleFreeList::getIntReg()
87{
88    DPRINTF(Rename, "FreeList: Trying to get free integer register.\n");
89    if (freeIntRegs.empty()) {
90        panic("No free integer registers!");
91    }
92
93    PhysRegIndex free_reg = freeIntRegs.front();
94
95    freeIntRegs.pop();
96
97    return(free_reg);
98}
99
100inline PhysRegIndex
101SimpleFreeList::getFloatReg()
102{
103    DPRINTF(Rename, "FreeList: Trying to get free float register.\n");
104    if (freeFloatRegs.empty()) {
105        panic("No free integer registers!");
106    }
107
108    PhysRegIndex free_reg = freeFloatRegs.front();
109
110    freeFloatRegs.pop();
111
112    return(free_reg);
113}
114
115inline void
116SimpleFreeList::addReg(PhysRegIndex freed_reg)
117{
118    DPRINTF(Rename, "Freelist: Freeing register %i.\n", freed_reg);
119    //Might want to add in a check for whether or not this register is
120    //already in there.  A bit vector or something similar would be useful.
121    if (freed_reg < numPhysicalIntRegs) {
122        freeIntRegs.push(freed_reg);
123    } else if (freed_reg < numPhysicalRegs) {
124        freeFloatRegs.push(freed_reg);
125    }
126}
127
128inline void
129SimpleFreeList::addIntReg(PhysRegIndex freed_reg)
130{
131    DPRINTF(Rename, "Freelist: Freeing int register %i.\n", freed_reg);
132
133    //Might want to add in a check for whether or not this register is
134    //already in there.  A bit vector or something similar would be useful.
135    freeIntRegs.push(freed_reg);
136}
137
138inline void
139SimpleFreeList::addFloatReg(PhysRegIndex freed_reg)
140{
141    DPRINTF(Rename, "Freelist: Freeing float register %i.\n", freed_reg);
142
143    //Might want to add in a check for whether or not this register is
144    //already in there.  A bit vector or something similar would be useful.
145    freeFloatRegs.push(freed_reg);
146}
147
148#endif // __FREE_LIST_HH__
149