gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  * Authors: Nathan Binkert
29  */
30 
37 #ifndef __BASE_TYPES_HH__
38 #define __BASE_TYPES_HH__
39 
40 #include <inttypes.h>
41 
42 #include <cassert>
43 #include <memory>
44 #include <ostream>
45 #include <stdexcept>
46 
47 #include "base/refcnt.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 
171 typedef int16_t ThreadID;
173 
175 typedef int ContextID;
177 
181 typedef int16_t PortID;
183 
184 class FaultBase;
185 typedef std::shared_ptr<FaultBase> Fault;
186 
187 // Rather than creating a shared_ptr instance and assigning it nullptr,
188 // we just create an alias.
189 constexpr decltype(nullptr) NoFault = nullptr;
190 
192 {
193  virtual void operator()(uint8_t *p) = 0;
194  virtual ~AtomicOpFunctor() {}
195 };
196 
197 template <class T>
199 {
200  void operator()(uint8_t *p) { execute((T *)p); }
201  virtual void execute(T * p) = 0;
202 };
203 
204 enum ByteOrder {
207 };
208 
209 #endif // __BASE_TYPES_HH__
void operator()(uint8_t *p)
Definition: types.hh:200
constexpr Cycles operator<<(const int32_t shift) const
Definition: types.hh:127
constexpr Cycles operator-(const Cycles &b) const
Definition: types.hh:121
decltype(nullptr) constexpr NoFault
Definition: types.hh:189
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
const Addr MaxAddr
Definition: types.hh:166
constexpr bool operator>(const Cycles &cc) const
Greater than comparison used for > Cycles(0).
Definition: types.hh:115
const PortID InvalidPortID
Definition: types.hh:182
Cycles & operator++()
Prefix increment operator.
Definition: types.hh:103
constexpr Cycles operator+(const Cycles &b) const
Definition: types.hh:118
static const MicroPC MicroPCRomBit
Definition: types.hh:146
constexpr Cycles operator>>(const int32_t shift) const
Definition: types.hh:130
constexpr Cycles(uint64_t _c)
Explicit constructor assigning a value.
Definition: types.hh:94
Bitfield< 7 > b
Definition: miscregs.hh:1564
virtual ~AtomicOpFunctor()
Definition: types.hh:194
const Tick MaxTick
Definition: types.hh:65
Classes for managing reference counted objects.
Cycles & operator+=(const Cycles &cc)
In-place addition of cycles.
Definition: types.hh:111
uint64_t Tick
Tick count type.
Definition: types.hh:63
Bitfield< 6, 5 > shift
Definition: types.hh:122
uint64_t c
Member holding the actual value.
Definition: types.hh:89
ByteOrder
Definition: types.hh:204
uint16_t MicroPC
Definition: types.hh:144
Cycles()
Default constructor for parameter classes.
Definition: types.hh:97
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
#define ULL(N)
uint64_t constant
Definition: types.hh:50
static MicroPC romMicroPC(MicroPC upc)
Definition: types.hh:149
int64_t Counter
Statistics counter type.
Definition: types.hh:58
static bool isRomMicroPC(MicroPC upc)
Definition: types.hh:161
const ThreadID InvalidThreadID
Definition: types.hh:172
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
Cycles & operator--()
Prefix decrement operator.
Definition: types.hh:107
const ContextID InvalidContextID
Definition: types.hh:176
int16_t PortID
Port index/ID type, and a symbolic name for an invalid port id.
Definition: types.hh:181
virtual void execute(T *p)=0
Bitfield< 0 > p
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
static MicroPC normalMicroPC(MicroPC upc)
Definition: types.hh:155
int ContextID
Globally unique thread context ID.
Definition: types.hh:175

Generated on Fri Jun 9 2017 13:03:37 for gem5 by doxygen 1.8.6