2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef __CPU_O3_CPU_FREE_LIST_HH__
30 #define __CPU_O3_CPU_FREE_LIST_HH__
35 #include "arch/isa_traits.hh"
36 #include "base/trace.hh"
37 #include "base/traceflags.hh"
38 #include "cpu/o3/comm.hh"
41 * FreeList class that simply holds the list of free integer and floating
42 * point registers. Can request for a free register of either type, and
43 * also send back free registers of either type. This is a very simple
44 * class, but it should be sufficient for most implementations. Like all
45 * other classes, it assumes that the indices for the floating point
46 * registers starts after the integer registers end. Hence the variable
47 * numPhysicalIntRegs is logically equivalent to the baseFP dependency.
49 * while this most likely should be called FreeList, the name "FreeList"
50 * is used in a typedef within the CPU Policy, and therefore no class
51 * can be named simply "FreeList".
52 * @todo: Give a better name to the base FP dependency.
57 /** The list of free integer registers. */
58 std::queue<PhysRegIndex> freeIntRegs;
60 /** The list of free floating point registers. */
61 std::queue<PhysRegIndex> freeFloatRegs;
63 /** Number of logical integer registers. */
64 int numLogicalIntRegs;
66 /** Number of physical integer registers. */
67 int numPhysicalIntRegs;
69 /** Number of logical floating point registers. */
70 int numLogicalFloatRegs;
72 /** Number of physical floating point registers. */
73 int numPhysicalFloatRegs;
75 /** Total number of physical registers. */
78 /** DEBUG stuff below. */
79 std::vector<int> freeIntRegsScoreboard;
81 std::vector<bool> freeFloatRegsScoreboard;
84 SimpleFreeList(unsigned _numLogicalIntRegs,
85 unsigned _numPhysicalIntRegs,
86 unsigned _numLogicalFloatRegs,
87 unsigned _numPhysicalFloatRegs);
89 inline PhysRegIndex getIntReg();
91 inline PhysRegIndex getFloatReg();
93 inline void addReg(PhysRegIndex freed_reg);
95 inline void addIntReg(PhysRegIndex freed_reg);
97 inline void addFloatReg(PhysRegIndex freed_reg);
100 { return !freeIntRegs.empty(); }
102 bool hasFreeFloatRegs()
103 { return !freeFloatRegs.empty(); }
106 { return freeIntRegs.size(); }
108 int numFreeFloatRegs()
109 { return freeFloatRegs.size(); }
113 SimpleFreeList::getIntReg()
115 DPRINTF(Rename, "FreeList: Trying to get free integer register.\n");
116 if (freeIntRegs.empty()) {
117 panic("No free integer registers!");
120 PhysRegIndex free_reg = freeIntRegs.front();
125 assert(freeIntRegsScoreboard[free_reg]);
126 freeIntRegsScoreboard[free_reg] = 0;
132 SimpleFreeList::getFloatReg()
134 DPRINTF(Rename, "FreeList: Trying to get free float register.\n");
135 if (freeFloatRegs.empty()) {
136 panic("No free integer registers!");
139 PhysRegIndex free_reg = freeFloatRegs.front();
144 assert(freeFloatRegsScoreboard[free_reg]);
145 freeFloatRegsScoreboard[free_reg] = 0;
151 SimpleFreeList::addReg(PhysRegIndex freed_reg)
153 DPRINTF(Rename, "Freelist: Freeing register %i.\n", freed_reg);
154 //Might want to add in a check for whether or not this register is
155 //already in there. A bit vector or something similar would be useful.
156 if (freed_reg < numPhysicalIntRegs) {
157 freeIntRegs.push(freed_reg);
160 assert(freeIntRegsScoreboard[freed_reg] == false);
161 freeIntRegsScoreboard[freed_reg] = 1;
162 } else if (freed_reg < numPhysicalRegs) {
163 freeFloatRegs.push(freed_reg);
166 assert(freeFloatRegsScoreboard[freed_reg] == false);
167 freeFloatRegsScoreboard[freed_reg] = 1;
172 SimpleFreeList::addIntReg(PhysRegIndex freed_reg)
174 DPRINTF(Rename, "Freelist: Freeing int register %i.\n", freed_reg);
177 assert(!freeIntRegsScoreboard[freed_reg]);
178 freeIntRegsScoreboard[freed_reg] = 1;
180 freeIntRegs.push(freed_reg);
184 SimpleFreeList::addFloatReg(PhysRegIndex freed_reg)
186 DPRINTF(Rename, "Freelist: Freeing float register %i.\n", freed_reg);
189 assert(!freeFloatRegsScoreboard[freed_reg]);
190 freeFloatRegsScoreboard[freed_reg] = 1;
192 freeFloatRegs.push(freed_reg);
195 #endif // __CPU_O3_CPU_FREE_LIST_HH__