gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Steve Reinhardt
41  * Nathanael Premillieu
42  * Rekai Gonzalez
43  */
44 
45 #ifndef __CPU__REG_CLASS_HH__
46 #define __CPU__REG_CLASS_HH__
47 
48 #include <cassert>
49 #include <cstddef>
50 
51 #include "arch/generic/types.hh"
52 #include "arch/registers.hh"
53 #include "config/the_isa.hh"
54 
56 enum RegClass {
59 
66 };
67 
72 const int NumRegClasses = MiscRegClass + 1;
73 
79 class RegId {
80  protected:
81  static const char* regClassStrings[];
85  static constexpr size_t Scale = TheISA::NumVecElemPerVecReg;
87 
88  friend struct std::hash<RegId>;
89 
90  public:
91  RegId() : RegId(IntRegClass, 0) {}
92 
93  RegId(RegClass reg_class, RegIndex reg_idx)
94  : RegId(reg_class, reg_idx, ILLEGAL_ELEM_INDEX) {}
95 
96  explicit RegId(RegClass reg_class, RegIndex reg_idx, ElemIndex elem_idx)
97  : regClass(reg_class), regIdx(reg_idx), elemIdx(elem_idx),
98  numPinnedWrites(0) {
99  if (elemIdx == ILLEGAL_ELEM_INDEX) {
100  panic_if(regClass == VecElemClass,
101  "Creating vector physical index w/o element index");
102  } else {
103  panic_if(regClass != VecElemClass,
104  "Creating non-vector physical index w/ element index");
105  }
106  }
107 
108  bool operator==(const RegId& that) const {
109  return regClass == that.classValue() && regIdx == that.index()
110  && elemIdx == that.elemIndex();
111  }
112 
113  bool operator!=(const RegId& that) const {
114  return !(*this==that);
115  }
116 
120  bool operator<(const RegId& that) const {
121  return regClass < that.classValue() ||
122  (regClass == that.classValue() && (
123  regIdx < that.index() ||
124  (regIdx == that.index() && elemIdx < that.elemIndex())));
125  }
126 
130  bool isRenameable() const
131  {
132  return regClass != MiscRegClass;
133  }
134 
141  inline bool isZeroReg() const
142  {
143  return ((regClass == IntRegClass && regIdx == TheISA::ZeroReg) ||
144  (THE_ISA == ALPHA_ISA && regClass == FloatRegClass &&
145  regIdx == TheISA::ZeroReg));
146  }
147 
149  bool isIntReg() const { return regClass == IntRegClass; }
150 
152  bool isFloatReg() const { return regClass == FloatRegClass; }
153 
155  bool isVecReg() const { return regClass == VecRegClass; }
156 
158  bool isVecElem() const { return regClass == VecElemClass; }
159 
161  bool isVecPredReg() const { return regClass == VecPredRegClass; }
162 
164  bool isCCReg() const { return regClass == CCRegClass; }
165 
167  bool isMiscReg() const { return regClass == MiscRegClass; }
168 
173  {
174  return regClass != MiscRegClass;
175  }
176 
179  const RegIndex& index() const { return regIdx; }
180  RegIndex& index() { return regIdx; }
181 
185  inline RegIndex flatIndex() const
186  {
187  switch (regClass) {
188  case IntRegClass:
189  case FloatRegClass:
190  case VecRegClass:
191  case VecPredRegClass:
192  case CCRegClass:
193  case MiscRegClass:
194  return regIdx;
195  case VecElemClass:
196  return Scale*regIdx + elemIdx;
197  }
198  panic("Trying to flatten a register without class!");
199  return -1;
200  }
204  const RegIndex& elemIndex() const { return elemIdx; }
206  const RegClass& classValue() const { return regClass; }
208  const char* className() const { return regClassStrings[regClass]; }
209 
210  int getNumPinnedWrites() const { return numPinnedWrites; }
211  void setNumPinnedWrites(int num_writes) { numPinnedWrites = num_writes; }
212 
213  friend std::ostream&
214  operator<<(std::ostream& os, const RegId& rid) {
215  return os << rid.className() << "{" << rid.index() << "}";
216  }
217 };
218 
223 using PhysRegIndex = short int;
224 
229 class PhysRegId : private RegId {
230  private:
233  bool pinned;
234 
235  public:
236  explicit PhysRegId() : RegId(IntRegClass, -1), flatIdx(-1),
237  numPinnedWritesToComplete(0)
238  {}
239 
241  explicit PhysRegId(RegClass _regClass, PhysRegIndex _regIdx,
242  PhysRegIndex _flatIdx)
243  : RegId(_regClass, _regIdx), flatIdx(_flatIdx),
244  numPinnedWritesToComplete(0), pinned(false)
245  {}
246 
248  explicit PhysRegId(RegClass _regClass, PhysRegIndex _regIdx,
249  ElemIndex elem_idx, PhysRegIndex flat_idx)
250  : RegId(_regClass, _regIdx, elem_idx), flatIdx(flat_idx),
251  numPinnedWritesToComplete(0), pinned(false)
252  {}
253 
256  using RegId::index;
257  using RegId::classValue;
258  using RegId::isZeroReg;
259  using RegId::className;
260  using RegId::elemIndex;
267  bool operator<(const PhysRegId& that) const {
268  return RegId::operator<(that);
269  }
270 
271  bool operator==(const PhysRegId& that) const {
272  return RegId::operator==(that);
273  }
274 
275  bool operator!=(const PhysRegId& that) const {
276  return RegId::operator!=(that);
277  }
281  bool isIntPhysReg() const { return isIntReg(); }
282 
284  bool isFloatPhysReg() const { return isFloatReg(); }
285 
287  bool isCCPhysReg() const { return isCCReg(); }
288 
290  bool isVectorPhysReg() const { return isVecReg(); }
291 
293  bool isVectorPhysElem() const { return isVecElem(); }
294 
296  bool isVecPredPhysReg() const { return isVecPredReg(); }
297 
299  bool isMiscPhysReg() const { return isMiscReg(); }
300 
305  bool isFixedMapping() const
306  {
307  return !isRenameable();
308  }
309 
311  const PhysRegIndex& flatIndex() const { return flatIdx; }
312 
313  static PhysRegId elemId(PhysRegId* vid, ElemIndex elem)
314  {
315  assert(vid->isVectorPhysReg());
316  return PhysRegId(VecElemClass, vid->index(), elem);
317  }
318 
319  int getNumPinnedWrites() const { return numPinnedWrites; }
320 
321  void setNumPinnedWrites(int numWrites)
322  {
323  // An instruction with a pinned destination reg can get
324  // squashed. The numPinnedWrites counter may be zero when
325  // the squash happens but we need to know if the dest reg
326  // was pinned originally in order to reset counters properly
327  // for a possible re-rename using the same physical reg (which
328  // may be required in case of a mem access order violation).
329  pinned = (numWrites != 0);
330  numPinnedWrites = numWrites;
331  }
332 
335 
336  bool isPinned() const { return pinned; }
337 
339  {
340  return numPinnedWritesToComplete;
341  }
342 
343  void setNumPinnedWritesToComplete(int numWrites)
344  {
345  numPinnedWritesToComplete = numWrites;
346  }
347 
348  void decrNumPinnedWritesToComplete() { --numPinnedWritesToComplete; }
349  void incrNumPinnedWritesToComplete() { ++numPinnedWritesToComplete; }
350 };
351 
353 
354 namespace std
355 {
356 template<>
357 struct hash<RegId>
358 {
359  size_t operator()(const RegId& reg_id) const
360  {
361  // Extract unique integral values for the effective fields of a RegId.
362  const size_t flat_index = static_cast<size_t>(reg_id.flatIndex());
363  const size_t class_num = static_cast<size_t>(reg_id.regClass);
364 
365  const size_t shifted_class_num = class_num << (sizeof(RegIndex) << 3);
366 
367  // Concatenate the class_num to the end of the flat_index, in order to
368  // maximize information retained.
369  const size_t concatenated_hash = flat_index | shifted_class_num;
370 
371  // If RegIndex is larger than size_t, then class_num will not be
372  // considered by this hash function, so we may wish to perform a
373  // different operation to include that information in the hash.
374  static_assert(sizeof(RegIndex) < sizeof(size_t),
375  "sizeof(RegIndex) should be less than sizeof(size_t)");
376 
377  return concatenated_hash;
378  }
379 };
380 }
381 
382 #endif // __CPU__REG_CLASS_HH__
bool operator!=(const RegId &that) const
Definition: reg_class.hh:113
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
int getNumPinnedWrites() const
Definition: reg_class.hh:210
int getNumPinnedWritesToComplete() const
Definition: reg_class.hh:338
bool isMiscReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:167
void setNumPinnedWrites(int numWrites)
Definition: reg_class.hh:321
Floating-point register.
Definition: reg_class.hh:58
bool isCCPhysReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:287
RegId(RegClass reg_class, RegIndex reg_idx)
Definition: reg_class.hh:93
Control (misc) register.
Definition: reg_class.hh:65
bool isVectorPhysReg() const
true if it is a vector physical register.
Definition: reg_class.hh:290
void setNumPinnedWritesToComplete(int numWrites)
Definition: reg_class.hh:343
RegClass
Enumerate the classes of registers.
Definition: reg_class.hh:56
PhysRegIndex flatIdx
Definition: reg_class.hh:231
RegClass regClass
Definition: reg_class.hh:82
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:586
bool operator<(const PhysRegId &that) const
Explicit forward methods, to prevent comparisons of PhysRegId with RegIds.
Definition: reg_class.hh:267
RegId(RegClass reg_class, RegIndex reg_idx, ElemIndex elem_idx)
Definition: reg_class.hh:96
PhysRegId(RegClass _regClass, PhysRegIndex _regIdx, ElemIndex elem_idx, PhysRegIndex flat_idx)
Vector PhysRegId constructor (w/ elemIndex).
Definition: reg_class.hh:248
static const char * regClassStrings[]
Definition: reg_class.hh:81
const int NumRegClasses
Number of register classes.
Definition: reg_class.hh:72
void decrNumPinnedWritesToComplete()
Definition: reg_class.hh:348
static constexpr size_t Scale
Definition: reg_class.hh:85
Bitfield< 17 > os
Definition: misc.hh:805
int numPinnedWritesToComplete
Definition: reg_class.hh:232
void setNumPinnedWrites(int num_writes)
Definition: reg_class.hh:211
void incrNumPinnedWrites()
Definition: reg_class.hh:334
bool isCCReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:164
bool isVecElem() const
true if it is a condition-code physical register.
Definition: reg_class.hh:158
void incrNumPinnedWritesToComplete()
Definition: reg_class.hh:349
const RegIndex & elemIndex() const
Elem accessor.
Definition: reg_class.hh:204
bool isPinned() const
Definition: reg_class.hh:336
bool isVecPredPhysReg() const
Definition: reg_class.hh:296
Vector Register Native Elem lane.
Definition: reg_class.hh:62
bool isMiscPhysReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:299
uint16_t RegIndex
Definition: types.hh:42
bool isRenameable()
Return true if this register can be renamed.
Definition: reg_class.hh:172
size_t operator()(const RegId &reg_id) const
Definition: reg_class.hh:359
RegId()
Definition: reg_class.hh:91
const RegIndex ZeroReg
Definition: registers.hh:75
short int PhysRegIndex
Physical register index type.
Definition: reg_class.hh:223
RegIndex & index()
Definition: reg_class.hh:180
Condition-code register.
Definition: reg_class.hh:64
bool operator==(const PhysRegId &that) const
Definition: reg_class.hh:271
bool isIntReg() const
Definition: reg_class.hh:149
int getNumPinnedWrites() const
Definition: reg_class.hh:319
bool isFloatReg() const
Definition: reg_class.hh:152
RegIndex regIdx
Definition: reg_class.hh:83
bool isFloatPhysReg() const
Definition: reg_class.hh:284
bool isVecReg() const
true if it is a condition-code physical register.
Definition: reg_class.hh:155
Physical register ID.
Definition: reg_class.hh:229
int numPinnedWrites
Definition: reg_class.hh:86
void decrNumPinnedWrites()
Definition: reg_class.hh:333
bool isIntPhysReg() const
Definition: reg_class.hh:281
bool operator!=(const PhysRegId &that) const
Definition: reg_class.hh:275
const PhysRegIndex & flatIndex() const
Flat index accessor.
Definition: reg_class.hh:311
friend std::ostream & operator<<(std::ostream &os, const RegId &rid)
Definition: reg_class.hh:214
static PhysRegId elemId(PhysRegId *vid, ElemIndex elem)
Definition: reg_class.hh:313
uint16_t ElemIndex
Logical vector register elem index type.
Definition: types.hh:45
const RegClass & classValue() const
Class accessor.
Definition: reg_class.hh:206
RegIndex flatIndex() const
Index flattening.
Definition: reg_class.hh:185
const RegIndex & index() const
Index accessors.
Definition: reg_class.hh:179
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:79
Integer register.
Definition: reg_class.hh:57
ElemIndex elemIdx
Definition: reg_class.hh:84
bool pinned
Definition: reg_class.hh:233
Vector Register.
Definition: reg_class.hh:60
bool operator<(const RegId &that) const
Order operator.
Definition: reg_class.hh:120
bool isVecPredReg() const
true if it is a predicate physical register.
Definition: reg_class.hh:161
bool isRenameable() const
Return true if this register can be renamed.
Definition: reg_class.hh:130
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
bool isFixedMapping() const
Returns true if this register is always associated to the same architectural register.
Definition: reg_class.hh:305
PhysRegId(RegClass _regClass, PhysRegIndex _regIdx, PhysRegIndex _flatIdx)
Scalar PhysRegId constructor.
Definition: reg_class.hh:241
bool isZeroReg() const
Check if this is the zero register.
Definition: reg_class.hh:141
const char * className() const
Return a const char* with the register class name.
Definition: reg_class.hh:208
bool operator==(const RegId &that) const
Definition: reg_class.hh:108
#define ILLEGAL_ELEM_INDEX
ElemIndex value that indicates that the register is not a vector.
Definition: types.hh:48

Generated on Fri Feb 28 2020 16:27:00 for gem5 by doxygen 1.8.13