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