gem5  v20.1.0.0
types.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
35 #ifndef __BASE_TYPES_HH__
36 #define __BASE_TYPES_HH__
37 
38 #include <inttypes.h>
39 
40 #include <cassert>
41 #include <memory>
42 #include <ostream>
43 #include <stdexcept>
44 
45 #include "base/refcnt.hh"
46 /* Hide the fact that this enum is generated by Python */
47 #include "enums/ByteOrder.hh"
48 
50 #define ULL(N) ((uint64_t)N##ULL)
51 
52 #define LL(N) ((int64_t)N##LL)
53 
58 typedef int64_t Counter;
59 
63 typedef uint64_t Tick;
64 
65 const Tick MaxTick = ULL(0xffffffffffffffff);
66 
83 class Cycles
84 {
85 
86  private:
87 
89  uint64_t c;
90 
91  public:
92 
94  explicit constexpr Cycles(uint64_t _c) : c(_c) { }
95 
97  Cycles() : c(0) { }
98 
100  constexpr operator uint64_t() const { return c; }
101 
104  { ++c; return *this; }
105 
108  { assert(c != 0); --c; return *this; }
109 
112  { c += cc.c; return *this; }
113 
115  constexpr bool operator>(const Cycles& cc) const
116  { return c > cc.c; }
117 
118  constexpr Cycles operator +(const Cycles& b) const
119  { return Cycles(c + b.c); }
120 
121  constexpr Cycles operator -(const Cycles& b) const
122  {
123  return c >= b.c ? Cycles(c - b.c) :
124  throw std::invalid_argument("RHS cycle value larger than LHS");
125  }
126 
127  constexpr Cycles operator <<(const int32_t shift) const
128  { return Cycles(c << shift); }
129 
130  constexpr Cycles operator >>(const int32_t shift) const
131  { return Cycles(c >> shift); }
132 
133  friend std::ostream& operator<<(std::ostream &out, const Cycles & cycles);
134 };
135 
142 typedef uint64_t Addr;
143 
144 typedef uint16_t MicroPC;
145 
146 static const MicroPC MicroPCRomBit = 1 << (sizeof(MicroPC) * 8 - 1);
147 
148 static inline MicroPC
150 {
151  return upc | MicroPCRomBit;
152 }
153 
154 static inline MicroPC
156 {
157  return upc & ~MicroPCRomBit;
158 }
159 
160 static inline bool
162 {
163  return MicroPCRomBit & upc;
164 }
165 
166 const Addr MaxAddr = (Addr)-1;
167 
168 typedef uint64_t RegVal;
169 
170 static inline uint32_t
172 {
173  union
174  {
175  float f;
176  uint32_t i;
177  } u;
178  u.f = val;
179  return u.i;
180 }
181 
182 static inline uint64_t
184 {
185  union
186  {
187  double f;
188  uint64_t i;
189  } u;
190  u.f = val;
191  return u.i;
192 }
193 
194 static inline uint64_t floatToBits(double val) { return floatToBits64(val); }
195 static inline uint32_t floatToBits(float val) { return floatToBits32(val); }
196 
197 static inline float
199 {
200  union
201  {
202  float f;
203  uint32_t i;
204  } u;
205  u.i = val;
206  return u.f;
207 }
208 
209 static inline double
211 {
212  union
213  {
214  double f;
215  uint64_t i;
216  } u;
217  u.i = val;
218  return u.f;
219 }
220 
221 static inline double bitsToFloat(uint64_t val) { return bitsToFloat64(val); }
222 static inline float bitsToFloat(uint32_t val) { return bitsToFloat32(val); }
223 
227 typedef int16_t ThreadID;
229 
231 typedef int ContextID;
233 
237 typedef int16_t PortID;
239 
240 class FaultBase;
241 typedef std::shared_ptr<FaultBase> Fault;
242 
243 // Rather than creating a shared_ptr instance and assigning it nullptr,
244 // we just create an alias.
245 constexpr decltype(nullptr) NoFault = nullptr;
246 
247 #endif // __BASE_TYPES_HH__
InvalidThreadID
const ThreadID InvalidThreadID
Definition: types.hh:228
refcnt.hh
Cycles::operator<<
constexpr Cycles operator<<(const int32_t shift) const
Definition: types.hh:127
InvalidPortID
const PortID InvalidPortID
Definition: types.hh:238
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
bitsToFloat32
static float bitsToFloat32(uint32_t val)
Definition: types.hh:198
ThreadID
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:227
romMicroPC
static MicroPC romMicroPC(MicroPC upc)
Definition: types.hh:149
ContextID
int ContextID
Globally unique thread context ID.
Definition: types.hh:231
Cycles::operator+=
Cycles & operator+=(const Cycles &cc)
In-place addition of cycles.
Definition: types.hh:111
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
PortID
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:237
InvalidContextID
const ContextID InvalidContextID
Definition: types.hh:232
MaxAddr
const Addr MaxAddr
Definition: types.hh:166
Cycles::operator+
constexpr Cycles operator+(const Cycles &b) const
Definition: types.hh:118
Cycles::operator++
Cycles & operator++()
Prefix increment operator.
Definition: types.hh:103
Cycles::operator-
constexpr Cycles operator-(const Cycles &b) const
Definition: types.hh:121
Counter
int64_t Counter
Statistics counter type.
Definition: types.hh:58
ArmISA::shift
Bitfield< 6, 5 > shift
Definition: types.hh:126
Cycles::operator--
Cycles & operator--()
Prefix decrement operator.
Definition: types.hh:107
Fault
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
MicroPCRomBit
static const MicroPC MicroPCRomBit
Definition: types.hh:146
Cycles::operator>>
constexpr Cycles operator>>(const int32_t shift) const
Definition: types.hh:130
Cycles::operator>
constexpr bool operator>(const Cycles &cc) const
Greater than comparison used for > Cycles(0).
Definition: types.hh:115
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
NoFault
constexpr decltype(nullptr) NoFault
Definition: types.hh:245
bitsToFloat64
static double bitsToFloat64(uint64_t val)
Definition: types.hh:210
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
isRomMicroPC
static bool isRomMicroPC(MicroPC upc)
Definition: types.hh:161
ArmISA::u
Bitfield< 22 > u
Definition: miscregs_types.hh:348
Cycles::Cycles
constexpr Cycles(uint64_t _c)
Explicit constructor assigning a value.
Definition: types.hh:94
ArmISA::b
Bitfield< 7 > b
Definition: miscregs_types.hh:376
bitsToFloat
static double bitsToFloat(uint64_t val)
Definition: types.hh:221
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
normalMicroPC
static MicroPC normalMicroPC(MicroPC upc)
Definition: types.hh:155
Cycles::c
uint64_t c
Member holding the actual value.
Definition: types.hh:89
MicroPC
uint16_t MicroPC
Definition: types.hh:144
floatToBits
static uint64_t floatToBits(double val)
Definition: types.hh:194
floatToBits32
static uint32_t floatToBits32(float val)
Definition: types.hh:171
FaultBase
Definition: faults.hh:54
MaxTick
const Tick MaxTick
Definition: types.hh:65
Cycles::Cycles
Cycles()
Default constructor for parameter classes.
Definition: types.hh:97
ULL
#define ULL(N)
uint64_t constant
Definition: types.hh:50
RegVal
uint64_t RegVal
Definition: types.hh:168
floatToBits64
static uint64_t floatToBits64(double val)
Definition: types.hh:183
ArmISA::f
Bitfield< 6 > f
Definition: miscregs_types.hh:64

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