1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 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; --- 20 unchanged lines hidden (view full) --- 29 */ 30 31#include <vector> 32 33#include "cpu/o3/rename_map.hh" 34 35using namespace std; 36 |
37// @todo: Consider making inline bool functions that determine if the 38// register is a logical int, logical fp, physical int, physical fp, 39// etc. |
40 |
41SimpleRenameMap::~SimpleRenameMap() |
42{ |
43} 44 45void 46SimpleRenameMap::init(unsigned _numLogicalIntRegs, 47 unsigned _numPhysicalIntRegs, 48 PhysRegIndex &ireg_idx, 49 50 unsigned _numLogicalFloatRegs, 51 unsigned _numPhysicalFloatRegs, 52 PhysRegIndex &freg_idx, 53 54 unsigned _numMiscRegs, 55 56 RegIndex _intZeroReg, 57 RegIndex _floatZeroReg, 58 59 int map_id, 60 bool bindRegs) 61{ 62 id = map_id; 63 64 numLogicalIntRegs = _numLogicalIntRegs; 65 66 numLogicalFloatRegs = _numLogicalFloatRegs; 67 68 numPhysicalIntRegs = _numPhysicalIntRegs; 69 70 numPhysicalFloatRegs = _numPhysicalFloatRegs; 71 72 numMiscRegs = _numMiscRegs; 73 74 intZeroReg = _intZeroReg; 75 floatZeroReg = _floatZeroReg; 76 77 DPRINTF(Rename, "Creating rename map %i. Phys: %i / %i, Float: " 78 "%i / %i.\n", id, numLogicalIntRegs, numPhysicalIntRegs, |
79 numLogicalFloatRegs, numPhysicalFloatRegs); 80 81 numLogicalRegs = numLogicalIntRegs + numLogicalFloatRegs; 82 83 numPhysicalRegs = numPhysicalIntRegs + numPhysicalFloatRegs; 84 |
85 //Create the rename maps 86 intRenameMap.resize(numLogicalIntRegs); 87 floatRenameMap.resize(numLogicalRegs); |
88 |
89 if (bindRegs) { 90 DPRINTF(Rename, "Binding registers into rename map %i",id); |
91 |
92 // Initialize the entries in the integer rename map to point to the 93 // physical registers of the same index 94 for (RegIndex index = 0; index < numLogicalIntRegs; ++index) 95 { 96 intRenameMap[index].physical_reg = ireg_idx++; 97 } |
98 |
99 // Initialize the entries in the floating point rename map to point to 100 // the physical registers of the same index 101 // Although the index refers purely to architected registers, because 102 // the floating reg indices come after the integer reg indices, they 103 // may exceed the size of a normal RegIndex (short). 104 for (PhysRegIndex index = numLogicalIntRegs; 105 index < numLogicalRegs; ++index) 106 { 107 floatRenameMap[index].physical_reg = freg_idx++; 108 } 109 } else { 110 DPRINTF(Rename, "Binding registers into rename map %i",id); |
111 |
112 PhysRegIndex temp_ireg = ireg_idx; |
113 |
114 for (RegIndex index = 0; index < numLogicalIntRegs; ++index) 115 { 116 intRenameMap[index].physical_reg = temp_ireg++; 117 } |
118 |
119 PhysRegIndex temp_freg = freg_idx; |
120 |
121 for (PhysRegIndex index = numLogicalIntRegs; 122 index < numLogicalRegs; ++index) 123 { 124 floatRenameMap[index].physical_reg = temp_freg++; 125 } |
126 } |
127} 128 |
129void 130SimpleRenameMap::setFreeList(SimpleFreeList *fl_ptr) 131{ |
132 freeList = fl_ptr; 133} 134 135 |
136SimpleRenameMap::RenameInfo 137SimpleRenameMap::rename(RegIndex arch_reg) 138{ 139 PhysRegIndex renamed_reg; 140 PhysRegIndex prev_reg; 141 142 if (arch_reg < numLogicalIntRegs) { 143 144 // Record the current physical register that is renamed to the 145 // requested architected register. 146 prev_reg = intRenameMap[arch_reg].physical_reg; 147 |
148 // If it's not referencing the zero register, then rename the 149 // register. |
150 if (arch_reg != intZeroReg) { |
151 renamed_reg = freeList->getIntReg(); 152 |
153 intRenameMap[arch_reg].physical_reg = renamed_reg; 154 155 assert(renamed_reg >= 0 && renamed_reg < numPhysicalIntRegs); 156 |
157 } else { 158 // Otherwise return the zero register so nothing bad happens. 159 renamed_reg = intZeroReg; 160 } 161 } else if (arch_reg < numLogicalRegs) { |
162 // Record the current physical register that is renamed to the 163 // requested architected register. 164 prev_reg = floatRenameMap[arch_reg].physical_reg; 165 |
166 // If it's not referencing the zero register, then rename the 167 // register. |
168 if (arch_reg != floatZeroReg) { |
169 renamed_reg = freeList->getFloatReg(); 170 |
171 floatRenameMap[arch_reg].physical_reg = renamed_reg; 172 173 assert(renamed_reg < numPhysicalRegs && 174 renamed_reg >= numPhysicalIntRegs); |
175 } else { 176 // Otherwise return the zero register so nothing bad happens. 177 renamed_reg = floatZeroReg; 178 } 179 } else { 180 // Subtract off the base offset for miscellaneous registers. 181 arch_reg = arch_reg - numLogicalRegs; 182 |
183 // No renaming happens to the misc. registers. They are 184 // simply the registers that come after all the physical 185 // registers; thus take the base architected register and add 186 // the physical registers to it. |
187 renamed_reg = arch_reg + numPhysicalRegs; 188 189 // Set the previous register to the same register; mainly it must be 190 // known that the prev reg was outside the range of normal registers 191 // so the free list can avoid adding it. 192 prev_reg = renamed_reg; 193 194 assert(renamed_reg < numPhysicalRegs + numMiscRegs); |
195 } 196 197 return RenameInfo(renamed_reg, prev_reg); 198} 199 |
200PhysRegIndex 201SimpleRenameMap::lookup(RegIndex arch_reg) 202{ 203 if (arch_reg < numLogicalIntRegs) { 204 return intRenameMap[arch_reg].physical_reg; 205 } else if (arch_reg < numLogicalRegs) { |
206 return floatRenameMap[arch_reg].physical_reg; 207 } else { 208 // Subtract off the misc registers offset. 209 arch_reg = arch_reg - numLogicalRegs; 210 211 // Misc. regs don't rename, so simply add the base arch reg to 212 // the number of physical registers. 213 return numPhysicalRegs + arch_reg; 214 } 215} 216 |
217void 218SimpleRenameMap::setEntry(RegIndex arch_reg, PhysRegIndex renamed_reg) 219{ |
220 // In this implementation the miscellaneous registers do not 221 // actually rename, so this function does not allow you to try to 222 // change their mappings. |
223 if (arch_reg < numLogicalIntRegs) { 224 DPRINTF(Rename, "Rename Map: Integer register %i being set to %i.\n", 225 (int)arch_reg, renamed_reg); 226 227 intRenameMap[arch_reg].physical_reg = renamed_reg; |
228 } else if (arch_reg < numLogicalIntRegs + numLogicalFloatRegs) { |
229 DPRINTF(Rename, "Rename Map: Float register %i being set to %i.\n", 230 (int)arch_reg - numLogicalIntRegs, renamed_reg); 231 232 floatRenameMap[arch_reg].physical_reg = renamed_reg; 233 } 234} 235 |
236int 237SimpleRenameMap::numFreeEntries() 238{ 239 int free_int_regs = freeList->numFreeIntRegs(); 240 int free_float_regs = freeList->numFreeFloatRegs(); 241 242 if (free_int_regs < free_float_regs) { 243 return free_int_regs; 244 } else { 245 return free_float_regs; 246 } 247} |