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.
42 #ifndef __CPU_O3_REGFILE_HH__
43 #define __CPU_O3_REGFILE_HH__
47 #include "arch/types.hh"
48 #include "base/trace.hh"
49 #include "config/the_isa.hh"
50 #include "cpu/o3/comm.hh"
51 #include "debug/IEW.hh"
52 #include "enums/VecRegRenameMode.hh"
54 class UnifiedFreeList;
57 * Simple physical register file class.
63 using VecElem = TheISA::VecElem;
64 using VecRegContainer = TheISA::VecRegContainer;
65 using PhysIds = std::vector<PhysRegId>;
66 using VecMode = Enums::VecRegRenameMode;
67 using VecPredRegContainer = TheISA::VecPredRegContainer;
69 using IdRange = std::pair<PhysIds::iterator,
72 static constexpr auto NumVecElemPerVecReg = TheISA::NumVecElemPerVecReg;
74 /** Integer register file. */
75 std::vector<RegVal> intRegFile;
76 std::vector<PhysRegId> intRegIds;
78 /** Floating point register file. */
79 std::vector<RegVal> floatRegFile;
80 std::vector<PhysRegId> floatRegIds;
82 /** Vector register file. */
83 std::vector<VecRegContainer> vectorRegFile;
84 std::vector<PhysRegId> vecRegIds;
85 std::vector<PhysRegId> vecElemIds;
87 /** Predicate register file. */
88 std::vector<VecPredRegContainer> vecPredRegFile;
89 std::vector<PhysRegId> vecPredRegIds;
91 /** Condition-code register file. */
92 std::vector<RegVal> ccRegFile;
93 std::vector<PhysRegId> ccRegIds;
96 std::vector<PhysRegId> miscRegIds;
99 * Number of physical general purpose registers
101 unsigned numPhysicalIntRegs;
104 * Number of physical floating point registers
106 unsigned numPhysicalFloatRegs;
109 * Number of physical vector registers
111 unsigned numPhysicalVecRegs;
114 * Number of physical vector element registers
116 unsigned numPhysicalVecElemRegs;
119 * Number of physical predicate registers
121 unsigned numPhysicalVecPredRegs;
124 * Number of physical CC registers
126 unsigned numPhysicalCCRegs;
128 /** Total number of physical registers. */
129 unsigned totalNumRegs;
131 /** Mode in which vector registers are addressed. */
136 * Constructs a physical register file with the specified amount of
137 * integer and floating point registers.
139 PhysRegFile(unsigned _numPhysicalIntRegs,
140 unsigned _numPhysicalFloatRegs,
141 unsigned _numPhysicalVecRegs,
142 unsigned _numPhysicalVecPredRegs,
143 unsigned _numPhysicalCCRegs,
148 * Destructor to free resources
152 /** Initialize the free list */
153 void initFreeList(UnifiedFreeList *freeList);
155 /** @return the number of integer physical registers. */
156 unsigned numIntPhysRegs() const { return numPhysicalIntRegs; }
158 /** @return the number of floating-point physical registers. */
159 unsigned numFloatPhysRegs() const { return numPhysicalFloatRegs; }
160 /** @return the number of vector physical registers. */
161 unsigned numVecPhysRegs() const { return numPhysicalVecRegs; }
162 /** @return the number of predicate physical registers. */
163 unsigned numPredPhysRegs() const { return numPhysicalVecPredRegs; }
165 /** @return the number of vector physical registers. */
166 unsigned numVecElemPhysRegs() const { return numPhysicalVecElemRegs; }
168 /** @return the number of condition-code physical registers. */
169 unsigned numCCPhysRegs() const { return numPhysicalCCRegs; }
171 /** @return the total number of physical registers. */
172 unsigned totalNumPhysRegs() const { return totalNumRegs; }
174 /** Gets a misc register PhysRegIdPtr. */
175 PhysRegIdPtr getMiscRegId(RegIndex reg_idx) {
176 return &miscRegIds[reg_idx];
179 /** Reads an integer register. */
181 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()];
191 readFloatReg(PhysRegIdPtr phys_reg) const
193 assert(phys_reg->isFloatPhysReg());
195 RegVal floatRegBits = floatRegFile[phys_reg->index()];
197 DPRINTF(IEW, "RegFile: Access to float register %i as int, "
198 "has data %#x\n", phys_reg->index(), floatRegBits);
203 /** Reads a vector register. */
204 const VecRegContainer &
205 readVecReg(PhysRegIdPtr phys_reg) const
207 assert(phys_reg->isVectorPhysReg());
209 DPRINTF(IEW, "RegFile: Access to vector register %i, has "
210 "data %s\n", int(phys_reg->index()),
211 vectorRegFile[phys_reg->index()].print());
213 return vectorRegFile[phys_reg->index()];
216 /** Reads a vector register for modification. */
218 getWritableVecReg(PhysRegIdPtr phys_reg)
220 /* const_cast for not duplicating code above. */
221 return const_cast<VecRegContainer&>(readVecReg(phys_reg));
224 /** Reads a vector register lane. */
225 template <typename VecElem, int LaneIdx>
226 VecLaneT<VecElem, true>
227 readVecLane(PhysRegIdPtr phys_reg) const
229 return readVecReg(phys_reg).laneView<VecElem, LaneIdx>();
232 /** Reads a vector register lane. */
233 template <typename VecElem>
234 VecLaneT<VecElem, true>
235 readVecLane(PhysRegIdPtr phys_reg) const
237 return readVecReg(phys_reg).laneView<VecElem>(phys_reg->elemIndex());
240 /** Get a vector register lane for modification. */
241 template <typename LD>
243 setVecLane(PhysRegIdPtr phys_reg, const LD& val)
245 assert(phys_reg->isVectorPhysReg());
247 DPRINTF(IEW, "RegFile: Setting vector register %i[%d] to %lx\n",
248 int(phys_reg->index()), phys_reg->elemIndex(), val);
250 vectorRegFile[phys_reg->index()].laneView<typename LD::UnderlyingType>(
251 phys_reg->elemIndex()) = val;
254 /** Reads a vector element. */
256 readVecElem(PhysRegIdPtr phys_reg) const
258 assert(phys_reg->isVectorPhysElem());
259 auto ret = vectorRegFile[phys_reg->index()].as<VecElem>();
260 const VecElem& val = ret[phys_reg->elemIndex()];
261 DPRINTF(IEW, "RegFile: Access to element %d of vector register %i,"
262 " has data %#x\n", phys_reg->elemIndex(),
263 int(phys_reg->index()), val);
268 /** Reads a predicate register. */
269 const VecPredRegContainer& readVecPredReg(PhysRegIdPtr phys_reg) const
271 assert(phys_reg->isVecPredPhysReg());
273 DPRINTF(IEW, "RegFile: Access to predicate register %i, has "
274 "data %s\n", int(phys_reg->index()),
275 vecPredRegFile[phys_reg->index()].print());
277 return vecPredRegFile[phys_reg->index()];
280 VecPredRegContainer& getWritableVecPredReg(PhysRegIdPtr phys_reg)
282 /* const_cast for not duplicating code above. */
283 return const_cast<VecPredRegContainer&>(readVecPredReg(phys_reg));
286 /** Reads a condition-code register. */
288 readCCReg(PhysRegIdPtr phys_reg)
290 assert(phys_reg->isCCPhysReg());
292 DPRINTF(IEW, "RegFile: Access to cc register %i, has "
293 "data %#x\n", phys_reg->index(),
294 ccRegFile[phys_reg->index()]);
296 return ccRegFile[phys_reg->index()];
299 /** Sets an integer register to the given value. */
301 setIntReg(PhysRegIdPtr phys_reg, RegVal val)
303 assert(phys_reg->isIntPhysReg());
305 DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n",
306 phys_reg->index(), val);
308 if (!phys_reg->isZeroReg())
309 intRegFile[phys_reg->index()] = val;
313 setFloatReg(PhysRegIdPtr phys_reg, RegVal 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()] = val;
324 /** Sets a vector register to the given value. */
326 setVecReg(PhysRegIdPtr phys_reg, const VecRegContainer& val)
328 assert(phys_reg->isVectorPhysReg());
330 DPRINTF(IEW, "RegFile: Setting vector register %i to %s\n",
331 int(phys_reg->index()), val.print());
333 vectorRegFile[phys_reg->index()] = val;
336 /** Sets a vector register to the given value. */
338 setVecElem(PhysRegIdPtr phys_reg, const VecElem val)
340 assert(phys_reg->isVectorPhysElem());
342 DPRINTF(IEW, "RegFile: Setting element %d of vector register %i to"
343 " %#x\n", phys_reg->elemIndex(), int(phys_reg->index()), val);
345 vectorRegFile[phys_reg->index()].as<VecElem>()[phys_reg->elemIndex()] =
349 /** Sets a predicate register to the given value. */
350 void setVecPredReg(PhysRegIdPtr phys_reg, const VecPredRegContainer& val)
352 assert(phys_reg->isVecPredPhysReg());
354 DPRINTF(IEW, "RegFile: Setting predicate register %i to %s\n",
355 int(phys_reg->index()), val.print());
357 vecPredRegFile[phys_reg->index()] = val;
360 /** Sets a condition-code register to the given value. */
362 setCCReg(PhysRegIdPtr phys_reg, RegVal val)
364 assert(phys_reg->isCCPhysReg());
366 DPRINTF(IEW, "RegFile: Setting cc register %i to %#x\n",
367 phys_reg->index(), (uint64_t)val);
369 ccRegFile[phys_reg->index()] = val;
372 /** Get the PhysRegIds of the elems of a vector register.
373 * Auxiliary function to transition from Full vector mode to Elem mode.
375 IdRange getRegElemIds(PhysRegIdPtr reg);
378 * Get the PhysRegIds of the elems of all vector registers.
379 * Auxiliary function to transition from Full vector mode to Elem mode
380 * and to initialise the rename map.
382 IdRange getRegIds(RegClass cls);
385 * Get the true physical register id.
386 * As many parts work with PhysRegIdPtr, we need to be able to produce
387 * the pointer out of just class and register idx.
389 PhysRegIdPtr getTrueId(PhysRegIdPtr reg);
393 #endif //__CPU_O3_REGFILE_HH__