45b8084de13676bd7b6a8f055e499d2b18123add
4 #include "cpu/beta_cpu/rename_map.hh"
8 // Todo: Consider making functions inline. Avoid having things that are
9 // using the zero register or misc registers from adding on the registers
10 // to the free list. Possibly remove the direct communication between
11 // this and the freelist. Considering making inline bool functions that
12 // determine if the register is a logical int, logical fp, physical int,
15 SimpleRenameMap::SimpleRenameMap(unsigned _numLogicalIntRegs
,
16 unsigned _numPhysicalIntRegs
,
17 unsigned _numLogicalFloatRegs
,
18 unsigned _numPhysicalFloatRegs
,
19 unsigned _numMiscRegs
,
21 RegIndex _floatZeroReg
)
22 : numLogicalIntRegs(_numLogicalIntRegs
),
23 numPhysicalIntRegs(_numPhysicalIntRegs
),
24 numLogicalFloatRegs(_numLogicalFloatRegs
),
25 numPhysicalFloatRegs(_numPhysicalFloatRegs
),
26 numMiscRegs(_numMiscRegs
),
27 intZeroReg(_intZeroReg
),
28 floatZeroReg(_floatZeroReg
)
30 DPRINTF(Rename
, "Rename: Creating rename map. Phys: %i / %i, Float: "
31 "%i / %i.\n", numLogicalIntRegs
, numPhysicalIntRegs
,
32 numLogicalFloatRegs
, numPhysicalFloatRegs
);
34 numLogicalRegs
= numLogicalIntRegs
+ numLogicalFloatRegs
;
36 numPhysicalRegs
= numPhysicalIntRegs
+ numPhysicalFloatRegs
;
38 //Create the rename maps, and their scoreboards.
39 intRenameMap
= new RenameEntry
[numLogicalIntRegs
];
40 floatRenameMap
= new RenameEntry
[numLogicalRegs
];
42 // Should combine this into one scoreboard.
43 intScoreboard
.resize(numPhysicalIntRegs
);
44 floatScoreboard
.resize(numPhysicalRegs
);
45 miscScoreboard
.resize(numPhysicalRegs
+ numMiscRegs
);
47 // Initialize the entries in the integer rename map to point to the
48 // physical registers of the same index, and consider each register
49 // ready until the first rename occurs.
50 for (RegIndex index
= 0; index
< numLogicalIntRegs
; ++index
)
52 intRenameMap
[index
].physical_reg
= index
;
53 intScoreboard
[index
] = 1;
56 // Initialize the rest of the physical registers (the ones that don't
57 // directly map to a logical register) as unready.
58 for (PhysRegIndex index
= numLogicalIntRegs
;
59 index
< numPhysicalIntRegs
;
62 intScoreboard
[index
] = 0;
65 int float_reg_idx
= numPhysicalIntRegs
;
67 // Initialize the entries in the floating point rename map to point to
68 // the physical registers of the same index, and consider each register
69 // ready until the first rename occurs.
70 // Although the index refers purely to architected registers, because
71 // the floating reg indices come after the integer reg indices, they
72 // may exceed the size of a normal RegIndex (short).
73 for (PhysRegIndex index
= numLogicalIntRegs
;
74 index
< numLogicalRegs
; ++index
)
76 floatRenameMap
[index
].physical_reg
= float_reg_idx
++;
79 for (PhysRegIndex index
= numPhysicalIntRegs
;
80 index
< numPhysicalIntRegs
+ numLogicalFloatRegs
; ++index
)
82 floatScoreboard
[index
] = 1;
85 // Initialize the rest of the physical registers (the ones that don't
86 // directly map to a logical register) as unready.
87 for (PhysRegIndex index
= numPhysicalIntRegs
+ numLogicalFloatRegs
;
88 index
< numPhysicalRegs
;
91 floatScoreboard
[index
] = 0;
94 // Initialize the entries in the misc register scoreboard to be ready.
95 for (PhysRegIndex index
= numPhysicalRegs
;
96 index
< numPhysicalRegs
+ numMiscRegs
; ++index
)
98 miscScoreboard
[index
] = 1;
102 SimpleRenameMap::~SimpleRenameMap()
104 // Delete the rename maps as they were allocated with new.
105 delete [] intRenameMap
;
106 delete [] floatRenameMap
;
110 SimpleRenameMap::setFreeList(SimpleFreeList
*fl_ptr
)
112 //Setup the interface to the freelist.
117 // Don't allow this stage to fault; force that check to the rename stage.
118 // Simply ask to rename a logical register and get back a new physical
120 SimpleRenameMap::RenameInfo
121 SimpleRenameMap::rename(RegIndex arch_reg
)
123 PhysRegIndex renamed_reg
;
124 PhysRegIndex prev_reg
;
126 if (arch_reg
< numLogicalIntRegs
) {
128 // Record the current physical register that is renamed to the
129 // requested architected register.
130 prev_reg
= intRenameMap
[arch_reg
].physical_reg
;
132 // If it's not referencing the zero register, then mark the register
134 if (arch_reg
!= intZeroReg
) {
135 // Get a free physical register to rename to.
136 renamed_reg
= freeList
->getIntReg();
138 // Update the integer rename map.
139 intRenameMap
[arch_reg
].physical_reg
= renamed_reg
;
141 assert(renamed_reg
>= 0 && renamed_reg
< numPhysicalIntRegs
);
143 // Mark register as not ready.
144 intScoreboard
[renamed_reg
] = false;
146 // Otherwise return the zero register so nothing bad happens.
147 renamed_reg
= intZeroReg
;
149 } else if (arch_reg
< numLogicalRegs
) {
150 // Subtract off the base offset for floating point registers.
151 // arch_reg = arch_reg - numLogicalIntRegs;
153 // Record the current physical register that is renamed to the
154 // requested architected register.
155 prev_reg
= floatRenameMap
[arch_reg
].physical_reg
;
157 // If it's not referencing the zero register, then mark the register
159 if (arch_reg
!= floatZeroReg
) {
160 // Get a free floating point register to rename to.
161 renamed_reg
= freeList
->getFloatReg();
163 // Update the floating point rename map.
164 floatRenameMap
[arch_reg
].physical_reg
= renamed_reg
;
166 assert(renamed_reg
< numPhysicalRegs
&&
167 renamed_reg
>= numPhysicalIntRegs
);
169 // Mark register as not ready.
170 floatScoreboard
[renamed_reg
] = false;
172 // Otherwise return the zero register so nothing bad happens.
173 renamed_reg
= floatZeroReg
;
176 // Subtract off the base offset for miscellaneous registers.
177 arch_reg
= arch_reg
- numLogicalRegs
;
179 // No renaming happens to the misc. registers. They are simply the
180 // registers that come after all the physical registers; thus
181 // take the base architected register and add the physical registers
183 renamed_reg
= arch_reg
+ numPhysicalRegs
;
185 // Set the previous register to the same register; mainly it must be
186 // known that the prev reg was outside the range of normal registers
187 // so the free list can avoid adding it.
188 prev_reg
= renamed_reg
;
190 assert(renamed_reg
< numPhysicalRegs
+ numMiscRegs
);
192 miscScoreboard
[renamed_reg
] = false;
195 return RenameInfo(renamed_reg
, prev_reg
);
198 //Perhaps give this a pair as a return value, of the physical register
199 //and whether or not it's ready.
201 SimpleRenameMap::lookup(RegIndex arch_reg
)
203 if (arch_reg
< numLogicalIntRegs
) {
204 return intRenameMap
[arch_reg
].physical_reg
;
205 } else if (arch_reg
< numLogicalRegs
) {
206 // Subtract off the base FP offset.
207 // arch_reg = arch_reg - numLogicalIntRegs;
209 return floatRenameMap
[arch_reg
].physical_reg
;
211 // Subtract off the misc registers offset.
212 arch_reg
= arch_reg
- numLogicalRegs
;
214 // Misc. regs don't rename, so simply add the base arch reg to
215 // the number of physical registers.
216 return numPhysicalRegs
+ arch_reg
;
221 SimpleRenameMap::isReady(PhysRegIndex phys_reg
)
223 if (phys_reg
< numPhysicalIntRegs
) {
224 return intScoreboard
[phys_reg
];
225 } else if (phys_reg
< numPhysicalRegs
) {
227 // Subtract off the base FP offset.
228 // phys_reg = phys_reg - numPhysicalIntRegs;
230 return floatScoreboard
[phys_reg
];
232 // Subtract off the misc registers offset.
233 // phys_reg = phys_reg - numPhysicalRegs;
235 return miscScoreboard
[phys_reg
];
239 // In this implementation the miscellaneous registers do not actually rename,
240 // so this function does not allow you to try to change their mappings.
242 SimpleRenameMap::setEntry(RegIndex arch_reg
, PhysRegIndex renamed_reg
)
244 if (arch_reg
< numLogicalIntRegs
) {
245 DPRINTF(Rename
, "Rename Map: Integer register %i being set to %i.\n",
246 (int)arch_reg
, renamed_reg
);
248 intRenameMap
[arch_reg
].physical_reg
= renamed_reg
;
250 assert(arch_reg
< (numLogicalIntRegs
+ numLogicalFloatRegs
));
252 DPRINTF(Rename
, "Rename Map: Float register %i being set to %i.\n",
253 (int)arch_reg
- numLogicalIntRegs
, renamed_reg
);
255 floatRenameMap
[arch_reg
].physical_reg
= renamed_reg
;
260 SimpleRenameMap::squash(vector
<RegIndex
> freed_regs
,
261 vector
<UnmapInfo
> unmaps
)
263 panic("Not sure this function should be called.");
265 // Not sure the rename map should be able to access the free list
267 while (!freed_regs
.empty()) {
268 RegIndex free_register
= freed_regs
.back();
270 if (free_register
< numPhysicalIntRegs
) {
271 freeList
->addIntReg(free_register
);
273 // Subtract off the base FP dependence tag.
274 free_register
= free_register
- numPhysicalIntRegs
;
275 freeList
->addFloatReg(free_register
);
278 freed_regs
.pop_back();
281 // Take unmap info and roll back the rename map.
285 SimpleRenameMap::markAsReady(PhysRegIndex ready_reg
)
287 DPRINTF(Rename
, "Rename map: Marking register %i as ready.\n",
290 if (ready_reg
< numPhysicalIntRegs
) {
291 assert(ready_reg
>= 0);
293 intScoreboard
[ready_reg
] = 1;
294 } else if (ready_reg
< numPhysicalRegs
) {
296 // Subtract off the base FP offset.
297 // ready_reg = ready_reg - numPhysicalIntRegs;
299 floatScoreboard
[ready_reg
] = 1;
301 //Subtract off the misc registers offset.
302 // ready_reg = ready_reg - numPhysicalRegs;
304 miscScoreboard
[ready_reg
] = 1;
309 SimpleRenameMap::numFreeEntries()
311 int free_int_regs
= freeList
->numFreeIntRegs();
312 int free_float_regs
= freeList
->numFreeFloatRegs();
314 if (free_int_regs
< free_float_regs
) {
315 return free_int_regs
;
317 return free_float_regs
;