2 * Copyright (c) 2016-2018,2019 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2004-2005 The Regents of The University of Michigan
15 * Copyright (c) 2013 Advanced Micro Devices, Inc.
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include "cpu/o3/rename_map.hh"
46 #include "cpu/reg_class.hh"
47 #include "debug/Rename.hh"
51 /**** SimpleRenameMap methods ****/
53 SimpleRenameMap::SimpleRenameMap()
54 : freeList(NULL
), zeroReg(IntRegClass
,0)
60 SimpleRenameMap::init(unsigned size
, SimpleFreeList
*_freeList
,
63 assert(freeList
== NULL
);
68 zeroReg
= RegId(IntRegClass
, _zeroReg
);
71 SimpleRenameMap::RenameInfo
72 SimpleRenameMap::rename(const RegId
& arch_reg
)
74 PhysRegIdPtr renamed_reg
;
75 // Record the current physical register that is renamed to the
76 // requested architected register.
77 PhysRegIdPtr prev_reg
= map
[arch_reg
.flatIndex()];
79 if (arch_reg
== zeroReg
) {
80 assert(prev_reg
->isZeroReg());
81 renamed_reg
= prev_reg
;
82 } else if (prev_reg
->getNumPinnedWrites() > 0) {
83 // Do not rename if the register is pinned
84 assert(arch_reg
.getNumPinnedWrites() == 0); // Prevent pinning the
85 // same register twice
86 DPRINTF(Rename
, "Renaming pinned reg, numPinnedWrites %d\n",
87 prev_reg
->getNumPinnedWrites());
88 renamed_reg
= prev_reg
;
89 renamed_reg
->decrNumPinnedWrites();
91 renamed_reg
= freeList
->getReg();
92 map
[arch_reg
.flatIndex()] = renamed_reg
;
93 renamed_reg
->setNumPinnedWrites(arch_reg
.getNumPinnedWrites());
94 renamed_reg
->setNumPinnedWritesToComplete(
95 arch_reg
.getNumPinnedWrites() + 1);
98 DPRINTF(Rename
, "Renamed reg %d to physical reg %d (%d) old mapping was"
100 arch_reg
, renamed_reg
->flatIndex(), renamed_reg
->flatIndex(),
101 prev_reg
->flatIndex(), prev_reg
->flatIndex());
103 return RenameInfo(renamed_reg
, prev_reg
);
107 /**** UnifiedRenameMap methods ****/
110 UnifiedRenameMap::init(PhysRegFile
*_regFile
,
111 RegIndex _intZeroReg
,
112 RegIndex _floatZeroReg
,
113 UnifiedFreeList
*freeList
,
119 intMap
.init(TheISA::NumIntRegs
, &(freeList
->intList
), _intZeroReg
);
121 floatMap
.init(TheISA::NumFloatRegs
, &(freeList
->floatList
), _floatZeroReg
);
123 vecMap
.init(TheISA::NumVecRegs
, &(freeList
->vecList
), (RegIndex
)-1);
125 vecElemMap
.init(TheISA::NumVecRegs
* NVecElems
,
126 &(freeList
->vecElemList
), (RegIndex
)-1);
128 predMap
.init(TheISA::NumVecPredRegs
, &(freeList
->predList
), (RegIndex
)-1);
130 ccMap
.init(TheISA::NumCCRegs
, &(freeList
->ccList
), (RegIndex
)-1);
135 UnifiedRenameMap::switchFreeList(UnifiedFreeList
* freeList
)
137 if (vecMode
== Enums::Elem
) {
139 /* The free list should currently be tracking full registers. */
140 panic_if(freeList
->hasFreeVecElems(),
141 "The free list is already tracking Vec elems");
142 panic_if(freeList
->numFreeVecRegs() !=
143 regFile
->numVecPhysRegs() - TheISA::NumVecRegs
,
144 "The free list has lost vector registers");
146 /* Split the free regs. */
147 while (freeList
->hasFreeVecRegs()) {
148 auto vr
= freeList
->getVecReg();
149 auto range
= this->regFile
->getRegElemIds(vr
);
150 freeList
->addRegs(range
.first
, range
.second
);
153 } else if (vecMode
== Enums::Full
) {
155 /* The free list should currently be tracking register elems. */
156 panic_if(freeList
->hasFreeVecRegs(),
157 "The free list is already tracking full Vec");
158 panic_if(freeList
->numFreeVecElems() !=
159 regFile
->numVecElemPhysRegs() -
160 TheISA::NumVecRegs
* TheISA::NumVecElemPerVecReg
,
161 "The free list has lost vector register elements");
163 auto range
= regFile
->getRegIds(VecRegClass
);
164 freeList
->addRegs(range
.first
+ TheISA::NumVecRegs
, range
.second
);
166 /* We remove the elems from the free list. */
167 while (freeList
->hasFreeVecElems())
168 freeList
->getVecElem();
173 UnifiedRenameMap::switchMode(VecMode newVecMode
)
175 if (newVecMode
== Enums::Elem
&& vecMode
== Enums::Full
) {
177 /* Switch to vector element rename mode. */
178 vecMode
= Enums::Elem
;
180 /* Split the mapping of each arch reg. */
182 for (auto &vec
: vecMap
) {
183 PhysRegFile::IdRange range
= this->regFile
->getRegElemIds(vec
);
185 for (auto phys_elem
= range
.first
;
186 phys_elem
< range
.second
; idx
++, phys_elem
++) {
188 setEntry(RegId(VecElemClass
, vec_idx
, idx
), &(*phys_elem
));
193 } else if (newVecMode
== Enums::Full
&& vecMode
== Enums::Elem
) {
195 /* Switch to full vector register rename mode. */
196 vecMode
= Enums::Full
;
198 /* To rebuild the arch regs we take the easy road:
199 * 1.- Stitch the elems together into vectors.
200 * 2.- Replace the contents of the register file with the vectors
201 * 3.- Set the remaining registers as free
203 TheISA::VecRegContainer new_RF
[TheISA::NumVecRegs
];
204 for (uint32_t i
= 0; i
< TheISA::NumVecRegs
; i
++) {
205 VecReg dst
= new_RF
[i
].as
<TheISA::VecElem
>();
206 for (uint32_t l
= 0; l
< NVecElems
; l
++) {
207 RegId
s_rid(VecElemClass
, i
, l
);
208 PhysRegIdPtr s_prid
= vecElemMap
.lookup(s_rid
);
209 dst
[l
] = regFile
->readVecElem(s_prid
);
213 for (uint32_t i
= 0; i
< TheISA::NumVecRegs
; i
++) {
214 PhysRegId
pregId(VecRegClass
, i
, 0);
215 regFile
->setVecReg(regFile
->getTrueId(&pregId
), new_RF
[i
]);