gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
48 #define ULL(N) ((uint64_t)N##ULL)
49 
50 #define LL(N) ((int64_t)N##LL)
51 
56 typedef int64_t Counter;
57 
61 typedef uint64_t Tick;
62 
63 const Tick MaxTick = ULL(0xffffffffffffffff);
64 
81 class Cycles
82 {
83 
84  private:
85 
87  uint64_t c;
88 
89  public:
90 
92  explicit constexpr Cycles(uint64_t _c) : c(_c) { }
93 
95  Cycles() : c(0) { }
96 
98  constexpr operator uint64_t() const { return c; }
99 
102  { ++c; return *this; }
103 
106  { assert(c != 0); --c; return *this; }
107 
110  { c += cc.c; return *this; }
111 
113  constexpr bool operator>(const Cycles& cc) const
114  { return c > cc.c; }
115 
116  constexpr Cycles operator +(const Cycles& b) const
117  { return Cycles(c + b.c); }
118 
119  constexpr Cycles operator -(const Cycles& b) const
120  {
121  return c >= b.c ? Cycles(c - b.c) :
122  throw std::invalid_argument("RHS cycle value larger than LHS");
123  }
124 
125  constexpr Cycles operator <<(const int32_t shift) const
126  { return Cycles(c << shift); }
127 
128  constexpr Cycles operator >>(const int32_t shift) const
129  { return Cycles(c >> shift); }
130 
131  friend std::ostream& operator<<(std::ostream &out, const Cycles & cycles);
132 };
133 
140 typedef uint64_t Addr;
141 
142 typedef uint16_t MicroPC;
143 
144 static const MicroPC MicroPCRomBit = 1 << (sizeof(MicroPC) * 8 - 1);
145 
146 static inline MicroPC
148 {
149  return upc | MicroPCRomBit;
150 }
151 
152 static inline MicroPC
154 {
155  return upc & ~MicroPCRomBit;
156 }
157 
158 static inline bool
160 {
161  return MicroPCRomBit & upc;
162 }
163 
164 const Addr MaxAddr = (Addr)-1;
165 
166 typedef uint64_t RegVal;
167 
168 static inline uint32_t
170 {
171  union
172  {
173  float f;
174  uint32_t i;
175  } u;
176  u.f = val;
177  return u.i;
178 }
179 
180 static inline uint64_t
182 {
183  union
184  {
185  double f;
186  uint64_t i;
187  } u;
188  u.f = val;
189  return u.i;
190 }
191 
192 static inline uint64_t floatToBits(double val) { return floatToBits64(val); }
193 static inline uint32_t floatToBits(float val) { return floatToBits32(val); }
194 
195 static inline float
197 {
198  union
199  {
200  float f;
201  uint32_t i;
202  } u;
203  u.i = val;
204  return u.f;
205 }
206 
207 static inline double
209 {
210  union
211  {
212  double f;
213  uint64_t i;
214  } u;
215  u.i = val;
216  return u.f;
217 }
218 
219 static inline double bitsToFloat(uint64_t val) { return bitsToFloat64(val); }
220 static inline float bitsToFloat(uint32_t val) { return bitsToFloat32(val); }
221 
225 typedef int16_t ThreadID;
227 
229 typedef int ContextID;
231 
235 typedef int16_t PortID;
237 
238 class FaultBase;
239 typedef std::shared_ptr<FaultBase> Fault;
240 
241 // Rather than creating a shared_ptr instance and assigning it nullptr,
242 // we just create an alias.
243 constexpr decltype(nullptr) NoFault = nullptr;
244 
245 enum ByteOrder {
248 };
249 
250 #endif // __BASE_TYPES_HH__
constexpr Cycles operator-(const Cycles &b) const
Definition: types.hh:119
decltype(nullptr) constexpr NoFault
Definition: types.hh:243
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:81
const Addr MaxAddr
Definition: types.hh:164
Bitfield< 7 > i
const PortID InvalidPortID
Definition: types.hh:236
uint64_t RegVal
Definition: types.hh:166
Cycles & operator++()
Prefix increment operator.
Definition: types.hh:101
static float bitsToFloat32(uint32_t val)
Definition: types.hh:196
constexpr Cycles operator>>(const int32_t shift) const
Definition: types.hh:128
Bitfield< 63 > val
Definition: misc.hh:769
Bitfield< 6 > f
static const MicroPC MicroPCRomBit
Definition: types.hh:144
constexpr Cycles(uint64_t _c)
Explicit constructor assigning a value.
Definition: types.hh:92
Bitfield< 7 > b
static double bitsToFloat64(uint64_t val)
Definition: types.hh:208
const Tick MaxTick
Definition: types.hh:63
Classes for managing reference counted objects.
Bitfield< 22 > u
Cycles & operator+=(const Cycles &cc)
In-place addition of cycles.
Definition: types.hh:109
uint64_t Tick
Tick count type.
Definition: types.hh:61
Bitfield< 6, 5 > shift
Definition: types.hh:125
uint64_t c
Member holding the actual value.
Definition: types.hh:87
ByteOrder
Definition: types.hh:245
uint16_t MicroPC
Definition: types.hh:142
Cycles()
Default constructor for parameter classes.
Definition: types.hh:95
constexpr Cycles operator+(const Cycles &b) const
Definition: types.hh:116
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
#define ULL(N)
uint64_t constant
Definition: types.hh:48
static uint64_t floatToBits64(double val)
Definition: types.hh:181
static MicroPC romMicroPC(MicroPC upc)
Definition: types.hh:147
int64_t Counter
Statistics counter type.
Definition: types.hh:56
static bool isRomMicroPC(MicroPC upc)
Definition: types.hh:159
static double bitsToFloat(uint64_t val)
Definition: types.hh:219
const ThreadID InvalidThreadID
Definition: types.hh:226
constexpr bool operator>(const Cycles &cc) const
Greater than comparison used for > Cycles(0).
Definition: types.hh:113
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:225
Cycles & operator--()
Prefix decrement operator.
Definition: types.hh:105
const ContextID InvalidContextID
Definition: types.hh:230
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:235
static uint64_t floatToBits(double val)
Definition: types.hh:192
constexpr Cycles operator<<(const int32_t shift) const
Definition: types.hh:125
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
static MicroPC normalMicroPC(MicroPC upc)
Definition: types.hh:153
int ContextID
Globally unique thread context ID.
Definition: types.hh:229
static uint32_t floatToBits32(float val)
Definition: types.hh:169

Generated on Thu May 28 2020 16:11:03 for gem5 by doxygen 1.8.13