gem5  v20.1.0.0
reg_class.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019 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) 2013 Advanced Micro Devices, Inc.
15  * All rights reserved
16  *.
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 #ifndef __CPU__REG_CLASS_HH__
42 #define __CPU__REG_CLASS_HH__
43 
44 #include <cassert>
45 #include <cstddef>
46 
47 #include "arch/generic/types.hh"
48 #include "arch/registers.hh"
49 #include "config/the_isa.hh"
50 
52 enum RegClass {
55 
62 };
63 
68 const int NumRegClasses = MiscRegClass + 1;
69 
75 class RegId {
76  protected:
77  static const char* regClassStrings[];
81  static constexpr size_t Scale = TheISA::NumVecElemPerVecReg;
83 
84  friend struct std::hash<RegId>;
85 
86  public:
87  RegId() : RegId(IntRegClass, 0) {}
88 
89  RegId(RegClass reg_class, RegIndex reg_idx)
90  : RegId(reg_class, reg_idx, ILLEGAL_ELEM_INDEX) {}
91 
92  explicit RegId(RegClass reg_class, RegIndex reg_idx, ElemIndex elem_idx)
93  : regClass(reg_class), regIdx(reg_idx), elemIdx(elem_idx),
94  numPinnedWrites(0) {
95  if (elemIdx == ILLEGAL_ELEM_INDEX) {
97  "Creating vector physical index w/o element index");
98  } else {
100  "Creating non-vector physical index w/ element index");
101  }
102  }
103 
104  bool operator==(const RegId& that) const {
105  return regClass == that.classValue() && regIdx == that.index()
106  && elemIdx == that.elemIndex();
107  }
108 
109  bool operator!=(const RegId& that) const {
110  return !(*this==that);
111  }
112 
116  bool operator<(const RegId& that) const {
117  return regClass < that.classValue() ||
118  (regClass == that.classValue() && (
119  regIdx < that.index() ||
120  (regIdx == that.index() && elemIdx < that.elemIndex())));
121  }
122 
126  bool isRenameable() const
127  {
128  return regClass != MiscRegClass;
129  }
130 
137  inline bool isZeroReg() const
138  {
139  return regClass == IntRegClass && regIdx == TheISA::ZeroReg;
140  }
141 
143  bool isIntReg() const { return regClass == IntRegClass; }
144 
146  bool isFloatReg() const { return regClass == FloatRegClass; }
147 
149  bool isVecReg() const { return regClass == VecRegClass; }
150 
152  bool isVecElem() const { return regClass == VecElemClass; }
153 
155  bool isVecPredReg() const { return regClass == VecPredRegClass; }
156 
158  bool isCCReg() const { return regClass == CCRegClass; }
159 
161  bool isMiscReg() const { return regClass == MiscRegClass; }
162 
167  {
168  return regClass != MiscRegClass;
169  }
170 
173  const RegIndex& index() const { return regIdx; }
174  RegIndex& index() { return regIdx; }
175 
179  inline RegIndex flatIndex() const
180  {
181  switch (regClass) {
182  case IntRegClass:
183  case FloatRegClass:
184  case VecRegClass:
185  case VecPredRegClass:
186  case CCRegClass:
187  case MiscRegClass:
188  return regIdx;
189  case VecElemClass:
190  return Scale*regIdx + elemIdx;
191  }
192  panic("Trying to flatten a register without class!");
193  return -1;
194  }
198  const RegIndex& elemIndex() const { return elemIdx; }
200  const RegClass& classValue() const { return regClass; }
202  const char* className() const { return regClassStrings[regClass]; }
203 
204  int getNumPinnedWrites() const { return numPinnedWrites; }
205  void setNumPinnedWrites(int num_writes) { numPinnedWrites = num_writes; }
206 
207  friend std::ostream&
208  operator<<(std::ostream& os, const RegId& rid) {
209  return os << rid.className() << "{" << rid.index() << "}";
210  }
211 };
212 
217 using PhysRegIndex = short int;
218 
223 class PhysRegId : private RegId {
224  private:
227  bool pinned;
228 
229  public:
230  explicit PhysRegId() : RegId(IntRegClass, -1), flatIdx(-1),
232  {}
233 
235  explicit PhysRegId(RegClass _regClass, PhysRegIndex _regIdx,
236  PhysRegIndex _flatIdx)
237  : RegId(_regClass, _regIdx), flatIdx(_flatIdx),
239  {}
240 
242  explicit PhysRegId(RegClass _regClass, PhysRegIndex _regIdx,
243  ElemIndex elem_idx, PhysRegIndex flat_idx)
244  : RegId(_regClass, _regIdx, elem_idx), flatIdx(flat_idx),
246  {}
247 
250  using RegId::index;
251  using RegId::classValue;
252  using RegId::isZeroReg;
253  using RegId::className;
254  using RegId::elemIndex;
261  bool operator<(const PhysRegId& that) const {
262  return RegId::operator<(that);
263  }
264 
265  bool operator==(const PhysRegId& that) const {
266  return RegId::operator==(that);
267  }
268 
269  bool operator!=(const PhysRegId& that) const {
270  return RegId::operator!=(that);
271  }
275  bool isIntPhysReg() const { return isIntReg(); }
276 
278  bool isFloatPhysReg() const { return isFloatReg(); }
279 
281  bool isCCPhysReg() const { return isCCReg(); }
282 
284  bool isVectorPhysReg() const { return isVecReg(); }
285 
287  bool isVectorPhysElem() const { return isVecElem(); }
288 
290  bool isVecPredPhysReg() const { return isVecPredReg(); }
291 
293  bool isMiscPhysReg() const { return isMiscReg(); }
294 
299  bool isFixedMapping() const
300  {
301  return !isRenameable();
302  }
303 
305  const PhysRegIndex& flatIndex() const { return flatIdx; }
306 
307  static PhysRegId elemId(PhysRegId* vid, ElemIndex elem)
308  {
309  assert(vid->isVectorPhysReg());
310  return PhysRegId(VecElemClass, vid->index(), elem);
311  }
312 
313  int getNumPinnedWrites() const { return numPinnedWrites; }
314 
315  void setNumPinnedWrites(int numWrites)
316  {
317  // An instruction with a pinned destination reg can get
318  // squashed. The numPinnedWrites counter may be zero when
319  // the squash happens but we need to know if the dest reg
320  // was pinned originally in order to reset counters properly
321  // for a possible re-rename using the same physical reg (which
322  // may be required in case of a mem access order violation).
323  pinned = (numWrites != 0);
324  numPinnedWrites = numWrites;
325  }
326 
329 
330  bool isPinned() const { return pinned; }
331 
333  {
335  }
336 
337  void setNumPinnedWritesToComplete(int numWrites)
338  {
339  numPinnedWritesToComplete = numWrites;
340  }
341 
344 };
345 
347 
348 namespace std
349 {
350 template<>
351 struct hash<RegId>
352 {
353  size_t operator()(const RegId& reg_id) const
354  {
355  // Extract unique integral values for the effective fields of a RegId.
356  const size_t flat_index = static_cast<size_t>(reg_id.flatIndex());
357  const size_t class_num = static_cast<size_t>(reg_id.regClass);
358 
359  const size_t shifted_class_num = class_num << (sizeof(RegIndex) << 3);
360 
361  // Concatenate the class_num to the end of the flat_index, in order to
362  // maximize information retained.
363  const size_t concatenated_hash = flat_index | shifted_class_num;
364 
365  // If RegIndex is larger than size_t, then class_num will not be
366  // considered by this hash function, so we may wish to perform a
367  // different operation to include that information in the hash.
368  static_assert(sizeof(RegIndex) < sizeof(size_t),
369  "sizeof(RegIndex) should be less than sizeof(size_t)");
370 
371  return concatenated_hash;
372  }
373 };
374 }
375 
376 #endif // __CPU__REG_CLASS_HH__
RegId::getNumPinnedWrites
int getNumPinnedWrites() const
Definition: reg_class.hh:204
PhysRegId::isFloatPhysReg
bool isFloatPhysReg() const
Definition: reg_class.hh:278
PhysRegId::elemId
static PhysRegId elemId(PhysRegId *vid, ElemIndex elem)
Definition: reg_class.hh:307
RegId::isMiscReg
bool isMiscReg() const
@Return true if it is a condition-code physical register.
Definition: reg_class.hh:161
RegId::isVecPredReg
bool isVecPredReg() const
@Return true if it is a predicate physical register.
Definition: reg_class.hh:155
PhysRegId::isVectorPhysElem
bool isVectorPhysElem() const
@Return true if it is a vector element physical register.
Definition: reg_class.hh:287
X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:803
RegId::isZeroReg
bool isZeroReg() const
Check if this is the zero register.
Definition: reg_class.hh:137
RegId::RegId
RegId(RegClass reg_class, RegIndex reg_idx, ElemIndex elem_idx)
Definition: reg_class.hh:92
VecElemClass
@ VecElemClass
Vector Register Native Elem lane.
Definition: reg_class.hh:58
RegId::className
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:202
PhysRegId::incrNumPinnedWritesToComplete
void incrNumPinnedWritesToComplete()
Definition: reg_class.hh:343
RegId::RegId
RegId(RegClass reg_class, RegIndex reg_idx)
Definition: reg_class.hh:89
RegId::operator!=
bool operator!=(const RegId &that) const
Definition: reg_class.hh:109
NumRegClasses
const int NumRegClasses
Number of register classes.
Definition: reg_class.hh:68
RegId::regClass
RegClass regClass
Definition: reg_class.hh:78
PhysRegId::operator<
bool operator<(const PhysRegId &that) const
Explicit forward methods, to prevent comparisons of PhysRegId with RegIds.
Definition: reg_class.hh:261
PhysRegId::PhysRegId
PhysRegId(RegClass _regClass, PhysRegIndex _regIdx, ElemIndex elem_idx, PhysRegIndex flat_idx)
Vector PhysRegId constructor (w/ elemIndex).
Definition: reg_class.hh:242
PhysRegId::isVectorPhysReg
bool isVectorPhysReg() const
@Return true if it is a vector physical register.
Definition: reg_class.hh:284
PhysRegId::flatIndex
const PhysRegIndex & flatIndex() const
Flat index accessor.
Definition: reg_class.hh:305
PhysRegId::isFixedMapping
bool isFixedMapping() const
Returns true if this register is always associated to the same architectural register.
Definition: reg_class.hh:299
RegId::isCCReg
bool isCCReg() const
@Return true if it is a condition-code physical register.
Definition: reg_class.hh:158
RegId::elemIndex
const RegIndex & elemIndex() const
Elem accessor.
Definition: reg_class.hh:198
RegId::isRenameable
bool isRenameable()
Return true if this register can be renamed.
Definition: reg_class.hh:166
RegId::regClassStrings
static const char * regClassStrings[]
Definition: reg_class.hh:77
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
PhysRegId::flatIdx
PhysRegIndex flatIdx
Definition: reg_class.hh:225
RegId::setNumPinnedWrites
void setNumPinnedWrites(int num_writes)
Definition: reg_class.hh:205
PhysRegId::index
const RegIndex & index() const
Visible RegId methods.
Definition: reg_class.hh:173
PhysRegId::incrNumPinnedWrites
void incrNumPinnedWrites()
Definition: reg_class.hh:328
RegId::isVecElem
bool isVecElem() const
@Return true if it is a condition-code physical register.
Definition: reg_class.hh:152
FloatRegClass
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:54
RegId::isFloatReg
bool isFloatReg() const
Definition: reg_class.hh:146
RegId::index
RegIndex & index()
Definition: reg_class.hh:174
RegId::Scale
static constexpr size_t Scale
Definition: reg_class.hh:81
RegId::isIntReg
bool isIntReg() const
Definition: reg_class.hh:143
RegClass
RegClass
Enumerate the classes of registers.
Definition: reg_class.hh:52
ArmISA::ZeroReg
const int ZeroReg
Definition: registers.hh:118
ArmISA::NumVecElemPerVecReg
constexpr unsigned NumVecElemPerVecReg
Definition: registers.hh:66
PhysRegId::setNumPinnedWritesToComplete
void setNumPinnedWritesToComplete(int numWrites)
Definition: reg_class.hh:337
PhysRegId::decrNumPinnedWrites
void decrNumPinnedWrites()
Definition: reg_class.hh:327
RegId::operator<<
friend std::ostream & operator<<(std::ostream &os, const RegId &rid)
Definition: reg_class.hh:208
PhysRegId::isCCPhysReg
bool isCCPhysReg() const
@Return true if it is a condition-code physical register.
Definition: reg_class.hh:281
VecPredRegClass
@ VecPredRegClass
Definition: reg_class.hh:59
PhysRegIndex
short int PhysRegIndex
Physical register index type.
Definition: reg_class.hh:217
PhysRegId::decrNumPinnedWritesToComplete
void decrNumPinnedWritesToComplete()
Definition: reg_class.hh:342
PhysRegId::getNumPinnedWrites
int getNumPinnedWrites() const
Definition: reg_class.hh:313
RegId::numPinnedWrites
int numPinnedWrites
Definition: reg_class.hh:82
PhysRegId::isIntPhysReg
bool isIntPhysReg() const
Definition: reg_class.hh:275
PhysRegId::numPinnedWritesToComplete
int numPinnedWritesToComplete
Definition: reg_class.hh:226
IntRegClass
@ IntRegClass
Integer register.
Definition: reg_class.hh:53
PhysRegId::operator==
bool operator==(const PhysRegId &that) const
Definition: reg_class.hh:265
RegId::RegId
RegId()
Definition: reg_class.hh:87
CCRegClass
@ CCRegClass
Condition-code register.
Definition: reg_class.hh:60
RegId::regIdx
RegIndex regIdx
Definition: reg_class.hh:79
types.hh
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
MiscRegClass
@ MiscRegClass
Control (misc) register.
Definition: reg_class.hh:61
VecRegClass
@ VecRegClass
Vector Register.
Definition: reg_class.hh:56
PhysRegId::isMiscPhysReg
bool isMiscPhysReg() const
@Return true if it is a condition-code physical register.
Definition: reg_class.hh:293
PhysRegId::pinned
bool pinned
Definition: reg_class.hh:227
PhysRegId::isPinned
bool isPinned() const
Definition: reg_class.hh:330
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
RegIndex
uint16_t RegIndex
Definition: types.hh:52
PhysRegId::getNumPinnedWritesToComplete
int getNumPinnedWritesToComplete() const
Definition: reg_class.hh:332
PhysRegId::operator!=
bool operator!=(const PhysRegId &that) const
Definition: reg_class.hh:269
PhysRegId::setNumPinnedWrites
void setNumPinnedWrites(int numWrites)
Definition: reg_class.hh:315
ElemIndex
uint16_t ElemIndex
Logical vector register elem index type.
Definition: types.hh:55
PhysRegId::PhysRegId
PhysRegId()
Definition: reg_class.hh:230
PhysRegId::PhysRegId
PhysRegId(RegClass _regClass, PhysRegIndex _regIdx, PhysRegIndex _flatIdx)
Scalar PhysRegId constructor.
Definition: reg_class.hh:235
RegId::elemIdx
ElemIndex elemIdx
Definition: reg_class.hh:80
RegId::operator==
bool operator==(const RegId &that) const
Definition: reg_class.hh:104
RegId::isVecReg
bool isVecReg() const
@Return true if it is a condition-code physical register.
Definition: reg_class.hh:149
PhysRegId
Physical register ID.
Definition: reg_class.hh:223
RegId::isRenameable
bool isRenameable() const
Return true if this register can be renamed.
Definition: reg_class.hh:126
RegId::flatIndex
RegIndex flatIndex() const
Index flattening.
Definition: reg_class.hh:179
RegId::index
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:173
ILLEGAL_ELEM_INDEX
#define ILLEGAL_ELEM_INDEX
ElemIndex value that indicates that the register is not a vector.
Definition: types.hh:58
PhysRegId::isVecPredPhysReg
bool isVecPredPhysReg() const
Definition: reg_class.hh:290
std::hash< RegId >::operator()
size_t operator()(const RegId &reg_id) const
Definition: reg_class.hh:353
RegId::classValue
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:200
RegId::operator<
bool operator<(const RegId &that) const
Order operator.
Definition: reg_class.hh:116
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

Generated on Wed Sep 30 2020 14:02:09 for gem5 by doxygen 1.8.17