2 * Copyright (c) 2016 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::IntReg IntReg;
69 typedef TheISA::FloatReg FloatReg;
70 typedef TheISA::FloatRegBits FloatRegBits;
71 typedef TheISA::CCReg CCReg;
72 using VecElem = TheISA::VecElem;
73 using VecRegContainer = TheISA::VecRegContainer;
74 using PhysIds = std::vector<PhysRegId>;
75 using VecMode = Enums::VecRegRenameMode;
77 using IdRange = std::pair<PhysIds::const_iterator,
78 PhysIds::const_iterator>;
80 static constexpr auto NumVecElemPerVecReg = TheISA::NumVecElemPerVecReg;
87 /** Integer register file. */
88 std::vector<IntReg> intRegFile;
89 std::vector<PhysRegId> intRegIds;
91 /** Floating point register file. */
92 std::vector<PhysFloatReg> floatRegFile;
93 std::vector<PhysRegId> floatRegIds;
95 /** Vector register file. */
96 std::vector<VecRegContainer> vectorRegFile;
97 std::vector<PhysRegId> vecRegIds;
98 std::vector<PhysRegId> vecElemIds;
100 /** Condition-code register file. */
101 std::vector<CCReg> ccRegFile;
102 std::vector<PhysRegId> ccRegIds;
105 std::vector<PhysRegId> miscRegIds;
108 * Number of physical general purpose registers
110 unsigned numPhysicalIntRegs;
113 * Number of physical floating point registers
115 unsigned numPhysicalFloatRegs;
118 * Number of physical vector registers
120 unsigned numPhysicalVecRegs;
123 * Number of physical vector element registers
125 unsigned numPhysicalVecElemRegs;
128 * Number of physical CC registers
130 unsigned numPhysicalCCRegs;
132 /** Total number of physical registers. */
133 unsigned totalNumRegs;
135 /** Mode in which vector registers are addressed. */
140 * Constructs a physical register file with the specified amount of
141 * integer and floating point registers.
143 PhysRegFile(unsigned _numPhysicalIntRegs,
144 unsigned _numPhysicalFloatRegs,
145 unsigned _numPhysicalVecRegs,
146 unsigned _numPhysicalCCRegs,
151 * Destructor to free resources
155 /** Initialize the free list */
156 void initFreeList(UnifiedFreeList *freeList);
158 /** @return the number of integer physical registers. */
159 unsigned numIntPhysRegs() const { return numPhysicalIntRegs; }
161 /** @return the number of floating-point physical registers. */
162 unsigned numFloatPhysRegs() const { return numPhysicalFloatRegs; }
163 /** @return the number of vector physical registers. */
164 unsigned numVecPhysRegs() const { return numPhysicalVecRegs; }
166 /** @return the number of vector physical registers. */
167 unsigned numVecElemPhysRegs() const { return numPhysicalVecElemRegs; }
169 /** @return the number of condition-code physical registers. */
170 unsigned numCCPhysRegs() const { return numPhysicalCCRegs; }
172 /** @return the total number of physical registers. */
173 unsigned totalNumPhysRegs() const { return totalNumRegs; }
175 /** Gets a misc register PhysRegIdPtr. */
176 PhysRegIdPtr getMiscRegId(RegIndex reg_idx) {
177 return &miscRegIds[reg_idx];
180 /** Reads an integer register. */
181 uint64_t readIntReg(PhysRegIdPtr phys_reg) const
183 assert(phys_reg->isIntPhysReg());
185 DPRINTF(IEW, "RegFile: Access to int register %i, has data "
186 "%#x\n", phys_reg->index(), intRegFile[phys_reg->index()]);
187 return intRegFile[phys_reg->index()];
190 /** Reads a floating point register (double precision). */
191 FloatReg readFloatReg(PhysRegIdPtr phys_reg) const
193 assert(phys_reg->isFloatPhysReg());
195 DPRINTF(IEW, "RegFile: Access to float register %i, has "
196 "data %#x\n", phys_reg->index(),
197 floatRegFile[phys_reg->index()].q);
199 return floatRegFile[phys_reg->index()].d;
202 FloatRegBits readFloatRegBits(PhysRegIdPtr phys_reg) const
204 assert(phys_reg->isFloatPhysReg());
206 FloatRegBits floatRegBits = floatRegFile[phys_reg->index()].q;
208 DPRINTF(IEW, "RegFile: Access to float register %i as int, "
209 "has data %#x\n", phys_reg->index(),
210 (uint64_t)floatRegBits);
215 /** Reads a vector register. */
216 const VecRegContainer& readVecReg(PhysRegIdPtr phys_reg) const
218 assert(phys_reg->isVectorPhysReg());
220 DPRINTF(IEW, "RegFile: Access to vector register %i, has "
221 "data %s\n", int(phys_reg->index()),
222 vectorRegFile[phys_reg->index()].as<VecElem>().print());
224 return vectorRegFile[phys_reg->index()];
227 /** Reads a vector register for modification. */
228 VecRegContainer& getWritableVecReg(PhysRegIdPtr phys_reg)
230 /* const_cast for not duplicating code above. */
231 return const_cast<VecRegContainer&>(readVecReg(phys_reg));
234 /** Reads a vector register lane. */
235 template <typename VecElem, int LaneIdx>
236 VecLaneT<VecElem, true>
237 readVecLane(PhysRegIdPtr phys_reg) const
239 return readVecReg(phys_reg).laneView<VecElem, LaneIdx>();
242 /** Reads a vector register lane. */
243 template <typename VecElem>
244 VecLaneT<VecElem, true>
245 readVecLane(PhysRegIdPtr phys_reg) const
247 return readVecReg(phys_reg).laneView<VecElem>(phys_reg->elemIndex());
250 /** Get a vector register lane for modification. */
251 template <typename LD>
253 setVecLane(PhysRegIdPtr phys_reg, const LD& val)
255 assert(phys_reg->isVectorPhysReg());
257 DPRINTF(IEW, "RegFile: Setting vector register %i[%d] to %lx\n",
258 int(phys_reg->index()), phys_reg->elemIndex(), val);
260 vectorRegFile[phys_reg->index()].laneView<typename LD::UnderlyingType>(
261 phys_reg->elemIndex()) = val;
264 /** Reads a vector element. */
265 const VecElem& readVecElem(PhysRegIdPtr phys_reg) const
267 assert(phys_reg->isVectorPhysElem());
268 auto ret = vectorRegFile[phys_reg->index()].as<VecElem>();
269 const VecElem& val = ret[phys_reg->elemIndex()];
270 DPRINTF(IEW, "RegFile: Access to element %d of vector register %i,"
271 " has data %#x\n", phys_reg->elemIndex(),
272 int(phys_reg->index()), val);
277 /** Reads a condition-code register. */
278 CCReg readCCReg(PhysRegIdPtr phys_reg)
280 assert(phys_reg->isCCPhysReg());
282 DPRINTF(IEW, "RegFile: Access to cc register %i, has "
283 "data %#x\n", phys_reg->index(),
284 ccRegFile[phys_reg->index()]);
286 return ccRegFile[phys_reg->index()];
289 /** Sets an integer register to the given value. */
290 void setIntReg(PhysRegIdPtr phys_reg, uint64_t val)
292 assert(phys_reg->isIntPhysReg());
294 DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n",
295 phys_reg->index(), val);
297 if (!phys_reg->isZeroReg())
298 intRegFile[phys_reg->index()] = val;
301 /** Sets a double precision floating point register to the given value. */
302 void setFloatReg(PhysRegIdPtr phys_reg, FloatReg val)
304 assert(phys_reg->isFloatPhysReg());
306 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
307 phys_reg->index(), (uint64_t)val);
309 if (!phys_reg->isZeroReg())
310 floatRegFile[phys_reg->index()].d = val;
313 void setFloatRegBits(PhysRegIdPtr phys_reg, FloatRegBits val)
315 assert(phys_reg->isFloatPhysReg());
317 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
318 phys_reg->index(), (uint64_t)val);
320 if (!phys_reg->isZeroReg())
321 floatRegFile[phys_reg->index()].q = val;
324 /** Sets a vector register to the given value. */
325 void setVecReg(PhysRegIdPtr phys_reg, const VecRegContainer& val)
327 assert(phys_reg->isVectorPhysReg());
329 DPRINTF(IEW, "RegFile: Setting vector register %i to %s\n",
330 int(phys_reg->index()), val.print());
332 vectorRegFile[phys_reg->index()] = val;
335 /** Sets a vector register to the given value. */
336 void setVecElem(PhysRegIdPtr phys_reg, const VecElem val)
338 assert(phys_reg->isVectorPhysElem());
340 DPRINTF(IEW, "RegFile: Setting element %d of vector register %i to"
341 " %#x\n", phys_reg->elemIndex(), int(phys_reg->index()), val);
343 vectorRegFile[phys_reg->index()].as<VecElem>()[phys_reg->elemIndex()] =
347 /** Sets a condition-code register to the given value. */
348 void setCCReg(PhysRegIdPtr phys_reg, CCReg val)
350 assert(phys_reg->isCCPhysReg());
352 DPRINTF(IEW, "RegFile: Setting cc register %i to %#x\n",
353 phys_reg->index(), (uint64_t)val);
355 ccRegFile[phys_reg->index()] = val;
358 /** Get the PhysRegIds of the elems of a vector register.
359 * Auxiliary function to transition from Full vector mode to Elem mode.
361 IdRange getRegElemIds(PhysRegIdPtr reg);
364 * Get the PhysRegIds of the elems of all vector registers.
365 * Auxiliary function to transition from Full vector mode to Elem mode
366 * and to initialise the rename map.
368 IdRange getRegIds(RegClass cls);
371 * Get the true physical register id.
372 * As many parts work with PhysRegIdPtr, we need to be able to produce
373 * the pointer out of just class and register idx.
375 PhysRegIdPtr getTrueId(PhysRegIdPtr reg);
379 #endif //__CPU_O3_REGFILE_HH__