gem5  v22.1.0.0
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 
42 #include "cpu/o3/regfile.hh"
43 
44 #include "cpu/o3/free_list.hh"
45 
46 namespace gem5
47 {
48 
49 namespace o3
50 {
51 
52 PhysRegFile::PhysRegFile(unsigned _numPhysicalIntRegs,
53  unsigned _numPhysicalFloatRegs,
54  unsigned _numPhysicalVecRegs,
55  unsigned _numPhysicalVecPredRegs,
56  unsigned _numPhysicalCCRegs,
57  const BaseISA::RegClasses &reg_classes)
58  : intRegFile(*reg_classes.at(IntRegClass), _numPhysicalIntRegs),
59  floatRegFile(*reg_classes.at(FloatRegClass), _numPhysicalFloatRegs),
60  vectorRegFile(*reg_classes.at(VecRegClass), _numPhysicalVecRegs),
61  vectorElemRegFile(*reg_classes.at(VecElemClass), _numPhysicalVecRegs * (
62  reg_classes.at(VecElemClass)->numRegs() /
63  reg_classes.at(VecRegClass)->numRegs())),
64  vecPredRegFile(*reg_classes.at(VecPredRegClass),
65  _numPhysicalVecPredRegs),
66  ccRegFile(*reg_classes.at(CCRegClass), _numPhysicalCCRegs),
67  numPhysicalIntRegs(_numPhysicalIntRegs),
68  numPhysicalFloatRegs(_numPhysicalFloatRegs),
69  numPhysicalVecRegs(_numPhysicalVecRegs),
70  numPhysicalVecElemRegs(_numPhysicalVecRegs * (
71  reg_classes.at(VecElemClass)->numRegs() /
72  reg_classes.at(VecRegClass)->numRegs())),
73  numPhysicalVecPredRegs(_numPhysicalVecPredRegs),
74  numPhysicalCCRegs(_numPhysicalCCRegs),
75  totalNumRegs(_numPhysicalIntRegs
76  + _numPhysicalFloatRegs
77  + _numPhysicalVecRegs
78  + numPhysicalVecElemRegs
79  + _numPhysicalVecPredRegs
80  + _numPhysicalCCRegs)
81 {
82  RegIndex phys_reg;
83  RegIndex flat_reg_idx = 0;
84 
85  // The initial batch of registers are the integer ones
86  for (phys_reg = 0; phys_reg < numPhysicalIntRegs; phys_reg++) {
87  intRegIds.emplace_back(*reg_classes.at(IntRegClass),
88  phys_reg, flat_reg_idx++);
89  }
90 
91  // The next batch of the registers are the floating-point physical
92  // registers; put them onto the floating-point free list.
93  for (phys_reg = 0; phys_reg < numPhysicalFloatRegs; phys_reg++) {
94  floatRegIds.emplace_back(*reg_classes.at(FloatRegClass),
95  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  vecRegIds.emplace_back(*reg_classes.at(VecRegClass), phys_reg,
102  flat_reg_idx++);
103  }
104  // The next batch of the registers are the vector element physical
105  // registers; put them onto the vector free list.
106  for (phys_reg = 0; phys_reg < numPhysicalVecElemRegs; phys_reg++) {
107  vecElemIds.emplace_back(*reg_classes.at(VecElemClass), phys_reg,
108  flat_reg_idx++);
109  }
110 
111  // The next batch of the registers are the predicate physical
112  // registers; put them onto the predicate free list.
113  for (phys_reg = 0; phys_reg < numPhysicalVecPredRegs; phys_reg++) {
114  vecPredRegIds.emplace_back(*reg_classes.at(VecPredRegClass), phys_reg,
115  flat_reg_idx++);
116  }
117 
118  // The rest of the registers are the condition-code physical
119  // registers; put them onto the condition-code free list.
120  for (phys_reg = 0; phys_reg < numPhysicalCCRegs; phys_reg++) {
121  ccRegIds.emplace_back(*reg_classes.at(CCRegClass), phys_reg,
122  flat_reg_idx++);
123  }
124 
125  // Misc regs have a fixed mapping but still need PhysRegIds.
126  for (phys_reg = 0; phys_reg < reg_classes.at(MiscRegClass)->numRegs();
127  phys_reg++) {
128  miscRegIds.emplace_back(*reg_classes.at(MiscRegClass), phys_reg, 0);
129  }
130 }
131 
132 
133 void
135 {
136  // Initialize the free lists.
137  int reg_idx = 0;
138 
139  // The initial batch of registers are the integer ones
140  for (reg_idx = 0; reg_idx < numPhysicalIntRegs; reg_idx++) {
141  assert(intRegIds[reg_idx].index() == reg_idx);
142  }
143  freeList->addRegs(intRegIds.begin(), intRegIds.end());
144 
145  // The next batch of the registers are the floating-point physical
146  // registers; put them onto the floating-point free list.
147  for (reg_idx = 0; reg_idx < numPhysicalFloatRegs; reg_idx++) {
148  assert(floatRegIds[reg_idx].index() == reg_idx);
149  }
150  freeList->addRegs(floatRegIds.begin(), floatRegIds.end());
151 
152  /* The next batch of the registers are the vector physical
153  * registers; put them onto the vector free list. */
154  for (reg_idx = 0; reg_idx < numPhysicalVecRegs; reg_idx++) {
155  assert(vecRegIds[reg_idx].index() == reg_idx);
156  }
157  freeList->addRegs(vecRegIds.begin(), vecRegIds.end());
158  for (reg_idx = 0; reg_idx < numPhysicalVecElemRegs; reg_idx++) {
159  assert(vecElemIds[reg_idx].index() == reg_idx);
160  }
161  freeList->addRegs(vecElemIds.begin(), vecElemIds.end());
162 
163  // The next batch of the registers are the predicate physical
164  // registers; put them onto the predicate free list.
165  for (reg_idx = 0; reg_idx < numPhysicalVecPredRegs; reg_idx++) {
166  assert(vecPredRegIds[reg_idx].index() == reg_idx);
167  }
168  freeList->addRegs(vecPredRegIds.begin(), vecPredRegIds.end());
169 
170  // The rest of the registers are the condition-code physical
171  // registers; put them onto the condition-code free list.
172  for (reg_idx = 0; reg_idx < numPhysicalCCRegs; reg_idx++) {
173  assert(ccRegIds[reg_idx].index() == reg_idx);
174  }
175  freeList->addRegs(ccRegIds.begin(), ccRegIds.end());
176 }
177 
180 {
181  switch (cls)
182  {
183  case IntRegClass:
184  return std::make_pair(intRegIds.begin(), intRegIds.end());
185  case FloatRegClass:
186  return std::make_pair(floatRegIds.begin(), floatRegIds.end());
187  case VecRegClass:
188  return std::make_pair(vecRegIds.begin(), vecRegIds.end());
189  case VecElemClass:
190  return std::make_pair(vecElemIds.begin(), vecElemIds.end());
191  case VecPredRegClass:
192  return std::make_pair(vecPredRegIds.begin(), vecPredRegIds.end());
193  case CCRegClass:
194  return std::make_pair(ccRegIds.begin(), ccRegIds.end());
195  case MiscRegClass:
196  return std::make_pair(miscRegIds.begin(), miscRegIds.end());
197  case InvalidRegClass:
198  panic("Tried to get register IDs for the invalid class.");
199  }
200  /* There is no way to make an empty iterator */
201  return std::make_pair(PhysIds::iterator(),
202  PhysIds::iterator());
203 }
204 
207 {
208  switch (reg->classValue()) {
209  case VecRegClass:
210  return &vecRegIds[reg->index()];
211  case VecElemClass:
212  return &vecElemIds[reg->index()];
213  default:
214  panic_if(!reg->is(VecElemClass),
215  "Trying to get the register of a %s register", reg->className());
216  }
217  return nullptr;
218 }
219 
220 } // namespace o3
221 } // namespace gem5
Physical register ID.
Definition: reg_class.hh:392
std::vector< PhysRegId > vecElemIds
Definition: regfile.hh:88
std::vector< PhysRegId > ccRegIds
Definition: regfile.hh:96
std::vector< PhysRegId > miscRegIds
Misc Reg Ids.
Definition: regfile.hh:99
unsigned numPhysicalVecRegs
Number of physical vector registers.
Definition: regfile.hh:114
unsigned numPhysicalCCRegs
Number of physical CC registers.
Definition: regfile.hh:129
unsigned numPhysicalVecPredRegs
Number of physical predicate registers.
Definition: regfile.hh:124
std::vector< PhysRegId > floatRegIds
Definition: regfile.hh:80
std::vector< PhysRegId > vecRegIds
Definition: regfile.hh:84
IdRange getRegIds(RegClassType cls)
Get the PhysRegIds of the elems of all vector registers.
Definition: regfile.cc:179
PhysRegFile(unsigned _numPhysicalIntRegs, unsigned _numPhysicalFloatRegs, unsigned _numPhysicalVecRegs, unsigned _numPhysicalVecPredRegs, unsigned _numPhysicalCCRegs, const BaseISA::RegClasses &classes)
Constructs a physical register file with the specified amount of integer and floating point registers...
Definition: regfile.cc:52
unsigned numPhysicalVecElemRegs
Number of physical vector element registers.
Definition: regfile.hh:119
unsigned numPhysicalFloatRegs
Number of physical floating point registers.
Definition: regfile.hh:109
std::vector< PhysRegId > intRegIds
Definition: regfile.hh:76
std::vector< PhysRegId > vecPredRegIds
Definition: regfile.hh:92
unsigned numPhysicalIntRegs
Number of physical general purpose registers.
Definition: regfile.hh:104
PhysRegIdPtr getTrueId(PhysRegIdPtr reg)
Get the true physical register id.
Definition: regfile.cc:206
void initFreeList(UnifiedFreeList *freeList)
Initialize the free list.
Definition: regfile.cc:134
FreeList class that simply holds the list of free integer and floating point registers.
Definition: free_list.hh:125
void addRegs(InputIt first, InputIt last)
Adds a register back to the free list.
Definition: free_list.hh:167
STL pair class.
Definition: stl.hh:58
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
Bitfield< 35, 32 > at
Definition: misc_types.hh:155
Bitfield< 30, 0 > index
Bitfield< 5, 3 > reg
Definition: types.hh:92
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint16_t RegIndex
Definition: types.hh:176
RegClassType
Enumerate the classes of registers.
Definition: reg_class.hh:59
@ VecPredRegClass
Definition: reg_class.hh:66
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:61
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:67
@ VecRegClass
Vector Register.
Definition: reg_class.hh:63
@ IntRegClass
Integer register.
Definition: reg_class.hh:60
@ InvalidRegClass
Definition: reg_class.hh:69
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:68
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:65

Generated on Wed Dec 21 2022 10:22:31 for gem5 by doxygen 1.9.1