gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
regfile.cc
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  * Steve Reinhardt
44  */
45 
46 #include "cpu/o3/regfile.hh"
47 
48 #include "cpu/o3/free_list.hh"
49 #include "arch/generic/types.hh"
50 #include "cpu/o3/free_list.hh"
51 
52 PhysRegFile::PhysRegFile(unsigned _numPhysicalIntRegs,
53  unsigned _numPhysicalFloatRegs,
54  unsigned _numPhysicalVecRegs,
55  unsigned _numPhysicalVecPredRegs,
56  unsigned _numPhysicalCCRegs,
57  VecMode vmode)
58  : intRegFile(_numPhysicalIntRegs),
59  floatRegFile(_numPhysicalFloatRegs),
60  vectorRegFile(_numPhysicalVecRegs),
61  vecPredRegFile(_numPhysicalVecPredRegs),
62  ccRegFile(_numPhysicalCCRegs),
63  numPhysicalIntRegs(_numPhysicalIntRegs),
64  numPhysicalFloatRegs(_numPhysicalFloatRegs),
65  numPhysicalVecRegs(_numPhysicalVecRegs),
66  numPhysicalVecElemRegs(_numPhysicalVecRegs *
68  numPhysicalVecPredRegs(_numPhysicalVecPredRegs),
69  numPhysicalCCRegs(_numPhysicalCCRegs),
70  totalNumRegs(_numPhysicalIntRegs
71  + _numPhysicalFloatRegs
72  + _numPhysicalVecRegs
73  + _numPhysicalVecRegs * NumVecElemPerVecReg
74  + _numPhysicalVecPredRegs
75  + _numPhysicalCCRegs),
76  vecMode(vmode)
77 {
78  PhysRegIndex phys_reg;
79  PhysRegIndex flat_reg_idx = 0;
80 
81  if (TheISA::NumCCRegs == 0 && _numPhysicalCCRegs != 0) {
82  // Just make this a warning and go ahead and allocate them
83  // anyway, to keep from having to add checks everywhere
84  warn("Non-zero number of physical CC regs specified, even though\n"
85  " ISA does not use them.\n");
86  }
87  // The initial batch of registers are the integer ones
88  for (phys_reg = 0; phys_reg < numPhysicalIntRegs; phys_reg++) {
89  intRegIds.emplace_back(IntRegClass, phys_reg, flat_reg_idx++);
90  }
91 
92  // The next batch of the registers are the floating-point physical
93  // registers; put them onto the floating-point free list.
94  for (phys_reg = 0; phys_reg < numPhysicalFloatRegs; phys_reg++) {
95  floatRegIds.emplace_back(FloatRegClass, phys_reg, flat_reg_idx++);
96  }
97 
98  // The next batch of the registers are the vector physical
99  // registers; put them onto the vector free list.
100  for (phys_reg = 0; phys_reg < numPhysicalVecRegs; phys_reg++) {
101  vectorRegFile[phys_reg].zero();
102  vecRegIds.emplace_back(VecRegClass, phys_reg, flat_reg_idx++);
103  }
104  // The next batch of the registers are the vector element physical
105  // registers; they refer to the same containers as the vector
106  // registers, just a different (and incompatible) way to access
107  // them; put them onto the vector free list.
108  for (phys_reg = 0; phys_reg < numPhysicalVecRegs; phys_reg++) {
109  for (ElemIndex eIdx = 0; eIdx < NumVecElemPerVecReg; eIdx++) {
110  vecElemIds.emplace_back(VecElemClass, phys_reg,
111  eIdx, flat_reg_idx++);
112  }
113  }
114 
115  // The next batch of the registers are the predicate physical
116  // registers; put them onto the predicate free list.
117  for (phys_reg = 0; phys_reg < numPhysicalVecPredRegs; phys_reg++) {
118  vecPredRegIds.emplace_back(VecPredRegClass, phys_reg, flat_reg_idx++);
119  }
120 
121  // The rest of the registers are the condition-code physical
122  // registers; put them onto the condition-code free list.
123  for (phys_reg = 0; phys_reg < numPhysicalCCRegs; phys_reg++) {
124  ccRegIds.emplace_back(CCRegClass, phys_reg, flat_reg_idx++);
125  }
126 
127  // Misc regs have a fixed mapping but still need PhysRegIds.
128  for (phys_reg = 0; phys_reg < TheISA::NumMiscRegs; phys_reg++) {
129  miscRegIds.emplace_back(MiscRegClass, phys_reg, 0);
130  }
131 }
132 
133 
134 void
136 {
137  // Initialize the free lists.
138  int reg_idx = 0;
139 
140  // The initial batch of registers are the integer ones
141  for (reg_idx = 0; reg_idx < numPhysicalIntRegs; reg_idx++) {
142  assert(intRegIds[reg_idx].index() == reg_idx);
143  }
144  freeList->addRegs(intRegIds.begin(), intRegIds.end());
145 
146  // The next batch of the registers are the floating-point physical
147  // registers; put them onto the floating-point free list.
148  for (reg_idx = 0; reg_idx < numPhysicalFloatRegs; reg_idx++) {
149  assert(floatRegIds[reg_idx].index() == reg_idx);
150  }
151  freeList->addRegs(floatRegIds.begin(), floatRegIds.end());
152 
153  /* The next batch of the registers are the vector physical
154  * registers; put them onto the vector free list. */
155  for (reg_idx = 0; reg_idx < numPhysicalVecRegs; reg_idx++) {
156  assert(vecRegIds[reg_idx].index() == reg_idx);
157  for (ElemIndex elemIdx = 0; elemIdx < NumVecElemPerVecReg; elemIdx++) {
158  assert(vecElemIds[reg_idx * NumVecElemPerVecReg +
159  elemIdx].index() == reg_idx);
160  assert(vecElemIds[reg_idx * NumVecElemPerVecReg +
161  elemIdx].elemIndex() == elemIdx);
162  }
163  }
164 
165  /* depending on the mode we add the vector registers as whole units or
166  * as different elements. */
167  if (vecMode == Enums::Full)
168  freeList->addRegs(vecRegIds.begin(), vecRegIds.end());
169  else
170  freeList->addRegs(vecElemIds.begin(), vecElemIds.end());
171 
172  // The next batch of the registers are the predicate physical
173  // registers; put them onto the predicate free list.
174  for (reg_idx = 0; reg_idx < numPhysicalVecPredRegs; reg_idx++) {
175  assert(vecPredRegIds[reg_idx].index() == reg_idx);
176  }
177  freeList->addRegs(vecPredRegIds.begin(), vecPredRegIds.end());
178 
179  // The rest of the registers are the condition-code physical
180  // registers; put them onto the condition-code free list.
181  for (reg_idx = 0; reg_idx < numPhysicalCCRegs; reg_idx++) {
182  assert(ccRegIds[reg_idx].index() == reg_idx);
183  }
184  freeList->addRegs(ccRegIds.begin(), ccRegIds.end());
185 }
186 
187 auto
189 {
190  panic_if(!reg->isVectorPhysReg(),
191  "Trying to get elems of a %s register", reg->className());
192  auto idx = reg->index();
193  return std::make_pair(
194  vecElemIds.begin() + idx * NumVecElemPerVecReg,
195  vecElemIds.begin() + (idx+1) * NumVecElemPerVecReg);
196 }
197 
198 auto
200 {
201  switch (cls)
202  {
203  case IntRegClass:
204  return std::make_pair(intRegIds.begin(), intRegIds.end());
205  case FloatRegClass:
206  return std::make_pair(floatRegIds.begin(), floatRegIds.end());
207  case VecRegClass:
208  return std::make_pair(vecRegIds.begin(), vecRegIds.end());
209  case VecElemClass:
210  return std::make_pair(vecElemIds.begin(), vecElemIds.end());
211  case VecPredRegClass:
212  return std::make_pair(vecPredRegIds.begin(), vecPredRegIds.end());
213  case CCRegClass:
214  return std::make_pair(ccRegIds.begin(), ccRegIds.end());
215  case MiscRegClass:
216  return std::make_pair(miscRegIds.begin(), miscRegIds.end());
217  }
218  /* There is no way to make an empty iterator */
219  return std::make_pair(PhysIds::iterator(),
220  PhysIds::iterator());
221 }
222 
225 {
226  switch (reg->classValue()) {
227  case VecRegClass:
228  return &vecRegIds[reg->index()];
229  case VecElemClass:
230  return &vecElemIds[reg->index() * NumVecElemPerVecReg +
231  reg->elemIndex()];
232  default:
233  panic_if(!reg->isVectorPhysElem(),
234  "Trying to get the register of a %s register", reg->className());
235  }
236  return nullptr;
237 }
238 
Bitfield< 30, 0 > index
Bitfield< 5, 3 > reg
Definition: types.hh:89
Floating-point register.
Definition: reg_class.hh:58
STL pair class.
Definition: stl.hh:61
Control (misc) register.
Definition: reg_class.hh:65
std::vector< PhysRegId > floatRegIds
Definition: regfile.hh:84
std::vector< PhysRegId > vecPredRegIds
Definition: regfile.hh:93
RegClass
Enumerate the classes of registers.
Definition: reg_class.hh:56
std::vector< VecRegContainer > vectorRegFile
Vector register file.
Definition: regfile.hh:87
std::vector< PhysRegId > ccRegIds
Definition: regfile.hh:97
const RegIndex & elemIndex() const
Elem accessor.
Definition: reg_class.hh:204
std::vector< PhysRegId > intRegIds
Definition: regfile.hh:80
Vector Register Native Elem lane.
Definition: reg_class.hh:62
void initFreeList(UnifiedFreeList *freeList)
Initialize the free list.
Definition: regfile.cc:135
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
const int NumCCRegs
Definition: registers.hh:99
void addRegs(InputIt first, InputIt last)
Adds a register back to the free list.
Definition: free_list.hh:260
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
static constexpr auto NumVecElemPerVecReg
Definition: regfile.hh:76
short int PhysRegIndex
Physical register index type.
Definition: reg_class.hh:223
std::vector< PhysRegId > vecRegIds
Definition: regfile.hh:88
Condition-code register.
Definition: reg_class.hh:64
unsigned numPhysicalVecPredRegs
Number of physical predicate registers.
Definition: regfile.hh:125
PhysRegIdPtr getTrueId(PhysRegIdPtr reg)
Get the true physical register id.
Definition: regfile.cc:224
unsigned numPhysicalVecRegs
Number of physical vector registers.
Definition: regfile.hh:115
const int NumMiscRegs
Definition: registers.hh:100
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
uint16_t ElemIndex
Logical vector register elem index type.
Definition: types.hh:45
unsigned numPhysicalFloatRegs
Number of physical floating point registers.
Definition: regfile.hh:110
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:206
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:179
std::vector< PhysRegId > vecElemIds
Definition: regfile.hh:89
std::vector< PhysRegId > miscRegIds
Misc Reg Ids.
Definition: regfile.hh:100
Integer register.
Definition: reg_class.hh:57
Vector Register.
Definition: reg_class.hh:60
#define warn(...)
Definition: logging.hh:212
unsigned numPhysicalIntRegs
Number of physical general purpose registers.
Definition: regfile.hh:105
IdRange getRegElemIds(PhysRegIdPtr reg)
Get the PhysRegIds of the elems of a vector register.
Definition: regfile.cc:188
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:54
bool isVectorPhysElem() const
true if it is a vector element physical register.
Definition: reg_class.hh:293
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:208

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