gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
regfile.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2018 ARM Limited
3  * All rights reserved
4  *
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.
13  *
14  * Copyright (c) 2004-2005 The Regents of The University of Michigan
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
16  * All rights reserved.
17  *
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.
28  *
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.
40  *
41  * Authors: Kevin Lim
42  * Gabe Black
43  */
44 
45 #ifndef __CPU_O3_REGFILE_HH__
46 #define __CPU_O3_REGFILE_HH__
47 
48 #include <vector>
49 
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"
57 
58 class UnifiedFreeList;
59 
64 {
65  private:
66 
70  using VecMode = Enums::VecRegRenameMode;
72  public:
73  using IdRange = std::pair<PhysIds::iterator,
74  PhysIds::iterator>;
75  private:
77 
81 
85 
90 
94 
98 
101 
106 
111 
116 
121 
126 
131 
133  unsigned totalNumRegs;
134 
137 
138  public:
143  PhysRegFile(unsigned _numPhysicalIntRegs,
144  unsigned _numPhysicalFloatRegs,
145  unsigned _numPhysicalVecRegs,
146  unsigned _numPhysicalVecPredRegs,
147  unsigned _numPhysicalCCRegs,
148  VecMode vmode
149  );
150 
155 
157  void initFreeList(UnifiedFreeList *freeList);
158 
160  unsigned numIntPhysRegs() const { return numPhysicalIntRegs; }
161 
163  unsigned numFloatPhysRegs() const { return numPhysicalFloatRegs; }
165  unsigned numVecPhysRegs() const { return numPhysicalVecRegs; }
167  unsigned numPredPhysRegs() const { return numPhysicalVecPredRegs; }
168 
170  unsigned numVecElemPhysRegs() const { return numPhysicalVecElemRegs; }
171 
173  unsigned numCCPhysRegs() const { return numPhysicalCCRegs; }
174 
176  unsigned totalNumPhysRegs() const { return totalNumRegs; }
177 
180  return &miscRegIds[reg_idx];
181  }
182 
184  RegVal
185  readIntReg(PhysRegIdPtr phys_reg) const
186  {
187  assert(phys_reg->isIntPhysReg());
188 
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()];
192  }
193 
194  RegVal
195  readFloatReg(PhysRegIdPtr phys_reg) const
196  {
197  assert(phys_reg->isFloatPhysReg());
198 
199  RegVal floatRegBits = floatRegFile[phys_reg->index()];
200 
201  DPRINTF(IEW, "RegFile: Access to float register %i as int, "
202  "has data %#x\n", phys_reg->index(), floatRegBits);
203 
204  return floatRegBits;
205  }
206 
208  const VecRegContainer &
209  readVecReg(PhysRegIdPtr phys_reg) const
210  {
211  assert(phys_reg->isVectorPhysReg());
212 
213  DPRINTF(IEW, "RegFile: Access to vector register %i, has "
214  "data %s\n", int(phys_reg->index()),
215  vectorRegFile[phys_reg->index()].print());
216 
217  return vectorRegFile[phys_reg->index()];
218  }
219 
223  {
224  /* const_cast for not duplicating code above. */
225  return const_cast<VecRegContainer&>(readVecReg(phys_reg));
226  }
227 
229  template <typename VecElem, int LaneIdx>
231  readVecLane(PhysRegIdPtr phys_reg) const
232  {
233  return readVecReg(phys_reg).laneView<VecElem, LaneIdx>();
234  }
235 
237  template <typename VecElem>
239  readVecLane(PhysRegIdPtr phys_reg) const
240  {
241  return readVecReg(phys_reg).laneView<VecElem>(phys_reg->elemIndex());
242  }
243 
245  template <typename LD>
246  void
247  setVecLane(PhysRegIdPtr phys_reg, const LD& val)
248  {
249  assert(phys_reg->isVectorPhysReg());
250 
251  DPRINTF(IEW, "RegFile: Setting vector register %i[%d] to %lx\n",
252  int(phys_reg->index()), phys_reg->elemIndex(), val);
253 
254  vectorRegFile[phys_reg->index()].laneView<typename LD::UnderlyingType>(
255  phys_reg->elemIndex()) = val;
256  }
257 
259  const VecElem &
260  readVecElem(PhysRegIdPtr phys_reg) const
261  {
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);
268 
269  return val;
270  }
271 
274  {
275  assert(phys_reg->isVecPredPhysReg());
276 
277  DPRINTF(IEW, "RegFile: Access to predicate register %i, has "
278  "data %s\n", int(phys_reg->index()),
279  vecPredRegFile[phys_reg->index()].print());
280 
281  return vecPredRegFile[phys_reg->index()];
282  }
283 
285  {
286  /* const_cast for not duplicating code above. */
287  return const_cast<VecPredRegContainer&>(readVecPredReg(phys_reg));
288  }
289 
291  RegVal
293  {
294  assert(phys_reg->isCCPhysReg());
295 
296  DPRINTF(IEW, "RegFile: Access to cc register %i, has "
297  "data %#x\n", phys_reg->index(),
298  ccRegFile[phys_reg->index()]);
299 
300  return ccRegFile[phys_reg->index()];
301  }
302 
304  void
306  {
307  assert(phys_reg->isIntPhysReg());
308 
309  DPRINTF(IEW, "RegFile: Setting int register %i to %#x\n",
310  phys_reg->index(), val);
311 
312  if (!phys_reg->isZeroReg())
313  intRegFile[phys_reg->index()] = val;
314  }
315 
316  void
318  {
319  assert(phys_reg->isFloatPhysReg());
320 
321  DPRINTF(IEW, "RegFile: Setting float register %i to %#x\n",
322  phys_reg->index(), (uint64_t)val);
323 
324  if (!phys_reg->isZeroReg())
325  floatRegFile[phys_reg->index()] = val;
326  }
327 
329  void
331  {
332  assert(phys_reg->isVectorPhysReg());
333 
334  DPRINTF(IEW, "RegFile: Setting vector register %i to %s\n",
335  int(phys_reg->index()), val.print());
336 
337  vectorRegFile[phys_reg->index()] = val;
338  }
339 
341  void
343  {
344  assert(phys_reg->isVectorPhysElem());
345 
346  DPRINTF(IEW, "RegFile: Setting element %d of vector register %i to"
347  " %#x\n", phys_reg->elemIndex(), int(phys_reg->index()), val);
348 
349  vectorRegFile[phys_reg->index()].as<VecElem>()[phys_reg->elemIndex()] =
350  val;
351  }
352 
355  {
356  assert(phys_reg->isVecPredPhysReg());
357 
358  DPRINTF(IEW, "RegFile: Setting predicate register %i to %s\n",
359  int(phys_reg->index()), val.print());
360 
361  vecPredRegFile[phys_reg->index()] = val;
362  }
363 
365  void
367  {
368  assert(phys_reg->isCCPhysReg());
369 
370  DPRINTF(IEW, "RegFile: Setting cc register %i to %#x\n",
371  phys_reg->index(), (uint64_t)val);
372 
373  ccRegFile[phys_reg->index()] = val;
374  }
375 
380 
387 
394 };
395 
396 
397 #endif //__CPU_O3_REGFILE_HH__
#define DPRINTF(x,...)
Definition: trace.hh:229
std::vector< VecPredRegContainer > vecPredRegFile
Predicate register file.
Definition: regfile.hh:92
void setVecLane(PhysRegIdPtr phys_reg, const LD &val)
Get a vector register lane for modification.
Definition: regfile.hh:247
Bitfield< 5, 3 > reg
Definition: types.hh:89
bool isCCPhysReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:287
STL pair class.
Definition: stl.hh:61
VecPredRegContainer & getWritableVecPredReg(PhysRegIdPtr phys_reg)
Definition: regfile.hh:284
Vector Register Abstraction This generic class is the model in a particularization of MVC...
Definition: vec_reg.hh:160
Simple physical register file class.
Definition: regfile.hh:63
bool isVectorPhysReg() const
true if it is a vector physical register.
Definition: reg_class.hh:290
std::vector< PhysRegId > floatRegIds
Definition: regfile.hh:84
const VecElem & readVecElem(PhysRegIdPtr phys_reg) const
Reads a vector element.
Definition: regfile.hh:260
std::vector< PhysRegId > vecPredRegIds
Definition: regfile.hh:93
RegClass
Enumerate the classes of registers.
Definition: reg_class.hh:56
VecLaneT< VecElem, true > readVecLane(PhysRegIdPtr phys_reg) const
Reads a vector register lane.
Definition: regfile.hh:231
void setCCReg(PhysRegIdPtr phys_reg, RegVal val)
Sets a condition-code register to the given value.
Definition: regfile.hh:366
unsigned totalNumRegs
Total number of physical registers.
Definition: regfile.hh:133
unsigned numIntPhysRegs() const
Definition: regfile.hh:160
uint64_t RegVal
Definition: types.hh:168
VecLaneT< VecElem, true > readVecLane(PhysRegIdPtr phys_reg) const
Reads a vector register lane.
Definition: regfile.hh:239
std::vector< RegVal > ccRegFile
Condition-code register file.
Definition: regfile.hh:96
std::vector< VecRegContainer > vectorRegFile
Vector register file.
Definition: regfile.hh:87
RegVal readIntReg(PhysRegIdPtr phys_reg) const
Reads an integer register.
Definition: regfile.hh:185
std::vector< PhysRegId > ccRegIds
Definition: regfile.hh:97
Bitfield< 63 > val
Definition: misc.hh:771
unsigned numCCPhysRegs() const
Definition: regfile.hh:173
const RegIndex & elemIndex() const
Elem accessor.
Definition: reg_class.hh:204
bool isVecPredPhysReg() const
Definition: reg_class.hh:296
std::vector< PhysRegId > intRegIds
Definition: regfile.hh:80
PhysRegIdPtr getMiscRegId(RegIndex reg_idx)
Gets a misc register PhysRegIdPtr.
Definition: regfile.hh:179
void initFreeList(UnifiedFreeList *freeList)
Initialize the free list.
Definition: regfile.cc:135
VecRegContainer & getWritableVecReg(PhysRegIdPtr phys_reg)
Reads a vector register for modification.
Definition: regfile.hh:222
PhysRegFile(unsigned _numPhysicalIntRegs, unsigned _numPhysicalFloatRegs, unsigned _numPhysicalVecRegs, unsigned _numPhysicalVecPredRegs, unsigned _numPhysicalCCRegs, VecMode vmode)
Constructs a physical register file with the specified amount of integer and floating point registers...
Definition: regfile.cc:52
Enums::VecRegRenameMode VecMode
Definition: regfile.hh:70
uint16_t RegIndex
Definition: types.hh:42
void setVecPredReg(PhysRegIdPtr phys_reg, const VecPredRegContainer &val)
Sets a predicate register to the given value.
Definition: regfile.hh:354
::DummyVecPredRegContainer VecPredRegContainer
Definition: registers.hh:60
unsigned numPhysicalCCRegs
Number of physical CC registers.
Definition: regfile.hh:130
VecMode vecMode
Mode in which vector registers are addressed.
Definition: regfile.hh:136
IdRange getRegIds(RegClass cls)
Get the PhysRegIds of the elems of all vector registers.
Definition: regfile.cc:199
unsigned numPhysicalVecElemRegs
Number of physical vector element registers.
Definition: regfile.hh:120
::DummyVecRegContainer VecRegContainer
Definition: registers.hh:53
static constexpr auto NumVecElemPerVecReg
Definition: regfile.hh:76
RegVal readCCReg(PhysRegIdPtr phys_reg)
Reads a condition-code register.
Definition: regfile.hh:292
std::vector< PhysRegId > vecRegIds
Definition: regfile.hh:88
~PhysRegFile()
Destructor to free resources.
Definition: regfile.hh:154
void setVecElem(PhysRegIdPtr phys_reg, const VecElem val)
Sets a vector register to the given value.
Definition: regfile.hh:342
void setFloatReg(PhysRegIdPtr phys_reg, RegVal val)
Definition: regfile.hh:317
void setVecReg(PhysRegIdPtr phys_reg, const VecRegContainer &val)
Sets a vector register to the given value.
Definition: regfile.hh:330
unsigned numVecPhysRegs() const
Definition: regfile.hh:165
unsigned numPhysicalVecPredRegs
Number of physical predicate registers.
Definition: regfile.hh:125
unsigned numPredPhysRegs() const
Definition: regfile.hh:167
PhysRegIdPtr getTrueId(PhysRegIdPtr reg)
Get the true physical register id.
Definition: regfile.cc:224
bool isFloatPhysReg() const
Definition: reg_class.hh:284
unsigned numPhysicalVecRegs
Number of physical vector registers.
Definition: regfile.hh:115
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:117
Physical register ID.
Definition: reg_class.hh:229
const VecPredRegContainer & readVecPredReg(PhysRegIdPtr phys_reg) const
Reads a predicate register.
Definition: regfile.hh:273
unsigned numFloatPhysRegs() const
Definition: regfile.hh:163
bool isIntPhysReg() const
Definition: reg_class.hh:281
const std::string print() const
Returns a string representation of the register content.
TheISA::VecElem VecElem
Definition: regfile.hh:67
void setIntReg(PhysRegIdPtr phys_reg, RegVal val)
Sets an integer register to the given value.
Definition: regfile.hh:305
std::vector< RegVal > intRegFile
Integer register file.
Definition: regfile.hh:79
unsigned numPhysicalFloatRegs
Number of physical floating point registers.
Definition: regfile.hh:110
Generic predicate register container.
Definition: vec_pred_reg.hh:51
const VecRegContainer & readVecReg(PhysRegIdPtr phys_reg) const
Reads a vector register.
Definition: regfile.hh:209
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:179
unsigned totalNumPhysRegs() const
Definition: regfile.hh:176
std::vector< PhysRegId > vecElemIds
Definition: regfile.hh:89
std::vector< PhysRegId > miscRegIds
Misc Reg Ids.
Definition: regfile.hh:100
VecLaneT< VecElem, false > laneView()
View as the Nth lane of type VecElem.
Definition: vec_reg.hh:595
RegVal readFloatReg(PhysRegIdPtr phys_reg) const
Definition: regfile.hh:195
::DummyVecElem VecElem
Definition: registers.hh:50
unsigned numPhysicalIntRegs
Number of physical general purpose registers.
Definition: regfile.hh:105
std::vector< RegVal > floatRegFile
Floating point register file.
Definition: regfile.hh:83
unsigned numVecElemPhysRegs() const
Definition: regfile.hh:170
IdRange getRegElemIds(PhysRegIdPtr reg)
Get the PhysRegIds of the elems of a vector register.
Definition: regfile.cc:188
Vector Lane abstraction Another view of a container.
Definition: vec_reg.hh:262
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:54
bool isVectorPhysElem() const
true if it is a vector element physical register.
Definition: reg_class.hh:293
bool isZeroReg() const
Check if this is the zero register.
Definition: reg_class.hh:141
const std::string print() const
Definition: vec_reg.hh:365

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13