2 * Copyright (c) 2016-2017 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.
45 #ifndef __CPU_O3_REGFILE_HH__
46 #define __CPU_O3_REGFILE_HH__
50 #include "arch/isa_traits.hh"
51 #include "arch/kernel_stats.hh"
52 #include "arch/types.hh"
53 #include "base/trace.hh"
54 #include "config/the_isa.hh"
55 #include "cpu/o3/comm.hh"
56 #include "debug/IEW.hh"
57 #include "enums/VecRegRenameMode.hh"
59 class UnifiedFreeList;
62 * Simple physical register file class.
68 typedef TheISA::CCReg CCReg;
69 using VecElem = TheISA::VecElem;
70 using VecRegContainer = TheISA::VecRegContainer;
71 using PhysIds = std::vector<PhysRegId>;
72 using VecMode = Enums::VecRegRenameMode;
73 using VecPredRegContainer = TheISA::VecPredRegContainer;
75 using IdRange = std::pair<PhysIds::const_iterator,
76 PhysIds::const_iterator>;
78 static constexpr auto NumVecElemPerVecReg = TheISA::NumVecElemPerVecReg;
80 /** Integer register file. */
81 std::vector<RegVal> intRegFile;
82 std::vector<PhysRegId> intRegIds;
84 /** Floating point register file. */
85 std::vector<RegVal> floatRegFile;
86 std::vector<PhysRegId> floatRegIds;
88 /** Vector register file. */
89 std::vector<VecRegContainer> vectorRegFile;
90 std::vector<PhysRegId> vecRegIds;
91 std::vector<PhysRegId> vecElemIds;
93 /** Predicate register file. */
94 std::vector<VecPredRegContainer> vecPredRegFile;
95 std::vector<PhysRegId> vecPredRegIds;
97 /** Condition-code register file. */
98 std::vector<CCReg> ccRegFile;
99 std::vector<PhysRegId> ccRegIds;
102 std::vector<PhysRegId> miscRegIds;
105 * Number of physical general purpose registers
107 unsigned numPhysicalIntRegs;
110 * Number of physical floating point registers
112 unsigned numPhysicalFloatRegs;
115 * Number of physical vector registers
117 unsigned numPhysicalVecRegs;
120 * Number of physical vector element registers
122 unsigned numPhysicalVecElemRegs;
125 * Number of physical predicate registers
127 unsigned numPhysicalVecPredRegs;
130 * Number of physical CC registers
132 unsigned numPhysicalCCRegs;
134 /** Total number of physical registers. */
135 unsigned totalNumRegs;
137 /** Mode in which vector registers are addressed. */
142 * Constructs a physical register file with the specified amount of
143 * integer and floating point registers.
145 PhysRegFile(unsigned _numPhysicalIntRegs,
146 unsigned _numPhysicalFloatRegs,
147 unsigned _numPhysicalVecRegs,
148 unsigned _numPhysicalVecPredRegs,
149 unsigned _numPhysicalCCRegs,
154 * Destructor to free resources
158 /** Initialize the free list */
159 void initFreeList(UnifiedFreeList *freeList);
161 /** @return the number of integer physical registers. */
162 unsigned numIntPhysRegs() const { return numPhysicalIntRegs; }
164 /** @return the number of floating-point physical registers. */
165 unsigned numFloatPhysRegs() const { return numPhysicalFloatRegs; }
166 /** @return the number of vector physical registers. */
167 unsigned numVecPhysRegs() const { return numPhysicalVecRegs; }
168 /** @return the number of predicate physical registers. */
169 unsigned numPredPhysRegs() const { return numPhysicalVecPredRegs; }
171 /** @return the number of vector physical registers. */
172 unsigned numVecElemPhysRegs() const { return numPhysicalVecElemRegs; }
174 /** @return the number of condition-code physical registers. */
175 unsigned numCCPhysRegs() const { return numPhysicalCCRegs; }
177 /** @return the total number of physical registers. */
178 unsigned totalNumPhysRegs() const { return totalNumRegs; }
180 /** Gets a misc register PhysRegIdPtr. */
181 PhysRegIdPtr getMiscRegId(RegIndex reg_idx) {
182 return &miscRegIds[reg_idx];
185 /** Reads an integer register. */
187 readIntReg(PhysRegIdPtr phys_reg) const
189 assert(phys_reg->isIntPhysReg());
191 DPRINTF(IEW, "RegFile: Access to int register %i, has data "
192 "%#x\n", phys_reg->index(), intRegFile[phys_reg->index()]);
193 return intRegFile[phys_reg->index()];
197 readFloatReg(PhysRegIdPtr phys_reg) const
199 assert(phys_reg->isFloatPhysReg());
201 RegVal floatRegBits = floatRegFile[phys_reg->index()];
203 DPRINTF(IEW, "RegFile: Access to float register %i as int, "
204 "has data %#x\n", phys_reg->index(), floatRegBits);
209 /** Reads a vector register. */
210 const VecRegContainer &
211 readVecReg(PhysRegIdPtr phys_reg) const
213 assert(phys_reg->isVectorPhysReg());
215 DPRINTF(IEW, "RegFile: Access to vector register %i, has "
216 "data %s\n", int(phys_reg->index()),
217 vectorRegFile[phys_reg->index()].print());
219 return vectorRegFile[phys_reg->index()];
222 /** Reads a vector register for modification. */
224 getWritableVecReg(PhysRegIdPtr phys_reg)
226 /* const_cast for not duplicating code above. */
227 return const_cast<VecRegContainer&>(readVecReg(phys_reg));
230 /** Reads a vector register lane. */
231 template <typename VecElem, int LaneIdx>
232 VecLaneT<VecElem, true>
233 readVecLane(PhysRegIdPtr phys_reg) const
235 return readVecReg(phys_reg).laneView<VecElem, LaneIdx>();
238 /** Reads a vector register lane. */
239 template <typename VecElem>
240 VecLaneT<VecElem, true>
241 readVecLane(PhysRegIdPtr phys_reg) const
243 return readVecReg(phys_reg).laneView<VecElem>(phys_reg->elemIndex());
246 /** Get a vector register lane for modification. */
247 template <typename LD>
249 setVecLane(PhysRegIdPtr phys_reg, const LD& val)
251 assert(phys_reg->isVectorPhysReg());
253 DPRINTF(IEW, "RegFile: Setting vector register %i[%d] to %lx\n",
254 int(phys_reg->index()), phys_reg->elemIndex(), val);
256 vectorRegFile[phys_reg->index()].laneView<typename LD::UnderlyingType>(
257 phys_reg->elemIndex()) = val;
260 /** Reads a vector element. */
262 readVecElem(PhysRegIdPtr phys_reg) const
264 assert(phys_reg->isVectorPhysElem());
265 auto ret = vectorRegFile[phys_reg->index()].as<VecElem>();
266 const VecElem& val = ret[phys_reg->elemIndex()];
267 DPRINTF(IEW, "RegFile: Access to element %d of vector register %i,"
268 " has data %#x\n", phys_reg->elemIndex(),
269 int(phys_reg->index()), val);
274 /** Reads a predicate register. */
275 const VecPredRegContainer& readVecPredReg(PhysRegIdPtr phys_reg) const
277 assert(phys_reg->isVecPredPhysReg());
279 DPRINTF(IEW, "RegFile: Access to predicate register %i, has "
280 "data %s\n", int(phys_reg->index()),
281 vecPredRegFile[phys_reg->index()].print());
283 return vecPredRegFile[phys_reg->index()];
286 VecPredRegContainer& getWritableVecPredReg(PhysRegIdPtr phys_reg)
288 /* const_cast for not duplicating code above. */
289 return const_cast<VecPredRegContainer&>(readVecPredReg(phys_reg));
292 /** Reads a condition-code register. */
294 readCCReg(PhysRegIdPtr phys_reg)
296 assert(phys_reg->isCCPhysReg());
298 DPRINTF(IEW, "RegFile: Access to cc register %i, has "
299 "data %#x\n", phys_reg->index(),
300 ccRegFile[phys_reg->index()]);
302 return ccRegFile[phys_reg->index()];
305 /** Sets an integer register to the given value. */
307 setIntReg(PhysRegIdPtr phys_reg, RegVal val)
309 assert(phys_reg->isIntPhysReg());
311 DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n",
312 phys_reg->index(), val);
314 if (!phys_reg->isZeroReg())
315 intRegFile[phys_reg->index()] = val;
319 setFloatReg(PhysRegIdPtr phys_reg, RegVal val)
321 assert(phys_reg->isFloatPhysReg());
323 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
324 phys_reg->index(), (uint64_t)val);
326 if (!phys_reg->isZeroReg())
327 floatRegFile[phys_reg->index()] = val;
330 /** Sets a vector register to the given value. */
332 setVecReg(PhysRegIdPtr phys_reg, const VecRegContainer& val)
334 assert(phys_reg->isVectorPhysReg());
336 DPRINTF(IEW, "RegFile: Setting vector register %i to %s\n",
337 int(phys_reg->index()), val.print());
339 vectorRegFile[phys_reg->index()] = val;
342 /** Sets a vector register to the given value. */
344 setVecElem(PhysRegIdPtr phys_reg, const VecElem val)
346 assert(phys_reg->isVectorPhysElem());
348 DPRINTF(IEW, "RegFile: Setting element %d of vector register %i to"
349 " %#x\n", phys_reg->elemIndex(), int(phys_reg->index()), val);
351 vectorRegFile[phys_reg->index()].as<VecElem>()[phys_reg->elemIndex()] =
355 /** Sets a predicate register to the given value. */
356 void setVecPredReg(PhysRegIdPtr phys_reg, const VecPredRegContainer& val)
358 assert(phys_reg->isVecPredPhysReg());
360 DPRINTF(IEW, "RegFile: Setting predicate register %i to %s\n",
361 int(phys_reg->index()), val.print());
363 vecPredRegFile[phys_reg->index()] = val;
366 /** Sets a condition-code register to the given value. */
368 setCCReg(PhysRegIdPtr phys_reg, CCReg val)
370 assert(phys_reg->isCCPhysReg());
372 DPRINTF(IEW, "RegFile: Setting cc register %i to %#x\n",
373 phys_reg->index(), (uint64_t)val);
375 ccRegFile[phys_reg->index()] = val;
378 /** Get the PhysRegIds of the elems of a vector register.
379 * Auxiliary function to transition from Full vector mode to Elem mode.
381 IdRange getRegElemIds(PhysRegIdPtr reg);
384 * Get the PhysRegIds of the elems of all vector registers.
385 * Auxiliary function to transition from Full vector mode to Elem mode
386 * and to initialise the rename map.
388 IdRange getRegIds(RegClass cls);
391 * Get the true physical register id.
392 * As many parts work with PhysRegIdPtr, we need to be able to produce
393 * the pointer out of just class and register idx.
395 PhysRegIdPtr getTrueId(PhysRegIdPtr reg);
399 #endif //__CPU_O3_REGFILE_HH__