2 * Copyright (c) 2016-2018 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/types.hh"
52 #include "base/trace.hh"
53 #include "config/the_isa.hh"
54 #include "cpu/o3/comm.hh"
55 #include "debug/IEW.hh"
56 #include "enums/VecRegRenameMode.hh"
58 class UnifiedFreeList;
61 * Simple physical register file class.
67 using VecElem = TheISA::VecElem;
68 using VecRegContainer = TheISA::VecRegContainer;
69 using PhysIds = std::vector<PhysRegId>;
70 using VecMode = Enums::VecRegRenameMode;
71 using VecPredRegContainer = TheISA::VecPredRegContainer;
73 using IdRange = std::pair<PhysIds::iterator,
76 static constexpr auto NumVecElemPerVecReg = TheISA::NumVecElemPerVecReg;
78 /** Integer register file. */
79 std::vector<RegVal> intRegFile;
80 std::vector<PhysRegId> intRegIds;
82 /** Floating point register file. */
83 std::vector<RegVal> floatRegFile;
84 std::vector<PhysRegId> floatRegIds;
86 /** Vector register file. */
87 std::vector<VecRegContainer> vectorRegFile;
88 std::vector<PhysRegId> vecRegIds;
89 std::vector<PhysRegId> vecElemIds;
91 /** Predicate register file. */
92 std::vector<VecPredRegContainer> vecPredRegFile;
93 std::vector<PhysRegId> vecPredRegIds;
95 /** Condition-code register file. */
96 std::vector<RegVal> ccRegFile;
97 std::vector<PhysRegId> ccRegIds;
100 std::vector<PhysRegId> miscRegIds;
103 * Number of physical general purpose registers
105 unsigned numPhysicalIntRegs;
108 * Number of physical floating point registers
110 unsigned numPhysicalFloatRegs;
113 * Number of physical vector registers
115 unsigned numPhysicalVecRegs;
118 * Number of physical vector element registers
120 unsigned numPhysicalVecElemRegs;
123 * Number of physical predicate registers
125 unsigned numPhysicalVecPredRegs;
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 _numPhysicalVecPredRegs,
147 unsigned _numPhysicalCCRegs,
152 * Destructor to free resources
156 /** Initialize the free list */
157 void initFreeList(UnifiedFreeList *freeList);
159 /** @return the number of integer physical registers. */
160 unsigned numIntPhysRegs() const { return numPhysicalIntRegs; }
162 /** @return the number of floating-point physical registers. */
163 unsigned numFloatPhysRegs() const { return numPhysicalFloatRegs; }
164 /** @return the number of vector physical registers. */
165 unsigned numVecPhysRegs() const { return numPhysicalVecRegs; }
166 /** @return the number of predicate physical registers. */
167 unsigned numPredPhysRegs() const { return numPhysicalVecPredRegs; }
169 /** @return the number of vector physical registers. */
170 unsigned numVecElemPhysRegs() const { return numPhysicalVecElemRegs; }
172 /** @return the number of condition-code physical registers. */
173 unsigned numCCPhysRegs() const { return numPhysicalCCRegs; }
175 /** @return the total number of physical registers. */
176 unsigned totalNumPhysRegs() const { return totalNumRegs; }
178 /** Gets a misc register PhysRegIdPtr. */
179 PhysRegIdPtr getMiscRegId(RegIndex reg_idx) {
180 return &miscRegIds[reg_idx];
183 /** Reads an integer register. */
185 readIntReg(PhysRegIdPtr phys_reg) const
187 assert(phys_reg->isIntPhysReg());
189 DPRINTF(IEW, "RegFile: Access to int register %i, has data "
190 "%#x\n", phys_reg->index(), intRegFile[phys_reg->index()]);
191 return intRegFile[phys_reg->index()];
195 readFloatReg(PhysRegIdPtr phys_reg) const
197 assert(phys_reg->isFloatPhysReg());
199 RegVal floatRegBits = floatRegFile[phys_reg->index()];
201 DPRINTF(IEW, "RegFile: Access to float register %i as int, "
202 "has data %#x\n", phys_reg->index(), floatRegBits);
207 /** Reads a vector register. */
208 const VecRegContainer &
209 readVecReg(PhysRegIdPtr phys_reg) const
211 assert(phys_reg->isVectorPhysReg());
213 DPRINTF(IEW, "RegFile: Access to vector register %i, has "
214 "data %s\n", int(phys_reg->index()),
215 vectorRegFile[phys_reg->index()].print());
217 return vectorRegFile[phys_reg->index()];
220 /** Reads a vector register for modification. */
222 getWritableVecReg(PhysRegIdPtr phys_reg)
224 /* const_cast for not duplicating code above. */
225 return const_cast<VecRegContainer&>(readVecReg(phys_reg));
228 /** Reads a vector register lane. */
229 template <typename VecElem, int LaneIdx>
230 VecLaneT<VecElem, true>
231 readVecLane(PhysRegIdPtr phys_reg) const
233 return readVecReg(phys_reg).laneView<VecElem, LaneIdx>();
236 /** Reads a vector register lane. */
237 template <typename VecElem>
238 VecLaneT<VecElem, true>
239 readVecLane(PhysRegIdPtr phys_reg) const
241 return readVecReg(phys_reg).laneView<VecElem>(phys_reg->elemIndex());
244 /** Get a vector register lane for modification. */
245 template <typename LD>
247 setVecLane(PhysRegIdPtr phys_reg, const LD& val)
249 assert(phys_reg->isVectorPhysReg());
251 DPRINTF(IEW, "RegFile: Setting vector register %i[%d] to %lx\n",
252 int(phys_reg->index()), phys_reg->elemIndex(), val);
254 vectorRegFile[phys_reg->index()].laneView<typename LD::UnderlyingType>(
255 phys_reg->elemIndex()) = val;
258 /** Reads a vector element. */
260 readVecElem(PhysRegIdPtr phys_reg) const
262 assert(phys_reg->isVectorPhysElem());
263 auto ret = vectorRegFile[phys_reg->index()].as<VecElem>();
264 const VecElem& val = ret[phys_reg->elemIndex()];
265 DPRINTF(IEW, "RegFile: Access to element %d of vector register %i,"
266 " has data %#x\n", phys_reg->elemIndex(),
267 int(phys_reg->index()), val);
272 /** Reads a predicate register. */
273 const VecPredRegContainer& readVecPredReg(PhysRegIdPtr phys_reg) const
275 assert(phys_reg->isVecPredPhysReg());
277 DPRINTF(IEW, "RegFile: Access to predicate register %i, has "
278 "data %s\n", int(phys_reg->index()),
279 vecPredRegFile[phys_reg->index()].print());
281 return vecPredRegFile[phys_reg->index()];
284 VecPredRegContainer& getWritableVecPredReg(PhysRegIdPtr phys_reg)
286 /* const_cast for not duplicating code above. */
287 return const_cast<VecPredRegContainer&>(readVecPredReg(phys_reg));
290 /** Reads a condition-code register. */
292 readCCReg(PhysRegIdPtr phys_reg)
294 assert(phys_reg->isCCPhysReg());
296 DPRINTF(IEW, "RegFile: Access to cc register %i, has "
297 "data %#x\n", phys_reg->index(),
298 ccRegFile[phys_reg->index()]);
300 return ccRegFile[phys_reg->index()];
303 /** Sets an integer register to the given value. */
305 setIntReg(PhysRegIdPtr phys_reg, RegVal val)
307 assert(phys_reg->isIntPhysReg());
309 DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n",
310 phys_reg->index(), val);
312 if (!phys_reg->isZeroReg())
313 intRegFile[phys_reg->index()] = val;
317 setFloatReg(PhysRegIdPtr phys_reg, RegVal val)
319 assert(phys_reg->isFloatPhysReg());
321 DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
322 phys_reg->index(), (uint64_t)val);
324 if (!phys_reg->isZeroReg())
325 floatRegFile[phys_reg->index()] = val;
328 /** Sets a vector register to the given value. */
330 setVecReg(PhysRegIdPtr phys_reg, const VecRegContainer& val)
332 assert(phys_reg->isVectorPhysReg());
334 DPRINTF(IEW, "RegFile: Setting vector register %i to %s\n",
335 int(phys_reg->index()), val.print());
337 vectorRegFile[phys_reg->index()] = val;
340 /** Sets a vector register to the given value. */
342 setVecElem(PhysRegIdPtr phys_reg, const VecElem val)
344 assert(phys_reg->isVectorPhysElem());
346 DPRINTF(IEW, "RegFile: Setting element %d of vector register %i to"
347 " %#x\n", phys_reg->elemIndex(), int(phys_reg->index()), val);
349 vectorRegFile[phys_reg->index()].as<VecElem>()[phys_reg->elemIndex()] =
353 /** Sets a predicate register to the given value. */
354 void setVecPredReg(PhysRegIdPtr phys_reg, const VecPredRegContainer& val)
356 assert(phys_reg->isVecPredPhysReg());
358 DPRINTF(IEW, "RegFile: Setting predicate register %i to %s\n",
359 int(phys_reg->index()), val.print());
361 vecPredRegFile[phys_reg->index()] = val;
364 /** Sets a condition-code register to the given value. */
366 setCCReg(PhysRegIdPtr phys_reg, RegVal val)
368 assert(phys_reg->isCCPhysReg());
370 DPRINTF(IEW, "RegFile: Setting cc register %i to %#x\n",
371 phys_reg->index(), (uint64_t)val);
373 ccRegFile[phys_reg->index()] = val;
376 /** Get the PhysRegIds of the elems of a vector register.
377 * Auxiliary function to transition from Full vector mode to Elem mode.
379 IdRange getRegElemIds(PhysRegIdPtr reg);
382 * Get the PhysRegIds of the elems of all vector registers.
383 * Auxiliary function to transition from Full vector mode to Elem mode
384 * and to initialise the rename map.
386 IdRange getRegIds(RegClass cls);
389 * Get the true physical register id.
390 * As many parts work with PhysRegIdPtr, we need to be able to produce
391 * the pointer out of just class and register idx.
393 PhysRegIdPtr getTrueId(PhysRegIdPtr reg);
397 #endif //__CPU_O3_REGFILE_HH__