gem5  v21.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
misc.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2017 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * For use for simulation and test purposes only
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from this
19  * software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #ifndef __MISC_HH__
35 #define __MISC_HH__
36 
37 #include <bitset>
38 #include <limits>
39 #include <memory>
40 
41 #include "base/logging.hh"
42 #include "sim/clocked_object.hh"
43 
44 namespace gem5
45 {
46 
47 class GPUDynInst;
48 
49 typedef std::bitset<std::numeric_limits<unsigned long long>::digits>
50  VectorMask;
51 typedef std::shared_ptr<GPUDynInst> GPUDynInstPtr;
52 
53 enum InstMemoryHop : int
54 {
55  Initiate = 0,
58  GMEnqueue = 3,
59  Complete = 4,
61 };
62 
63 enum BlockMemoryHop : int
64 {
65  BlockSend = 0,
67 };
68 
69 class WaitClass
70 {
71  public:
73 
74  WaitClass(ClockedObject *_clockedObject, uint64_t _numStages=0)
75  : nxtAvail(0), lookAheadAvail(0), clockedObject(_clockedObject),
76  numStages(_numStages) { }
77 
78  void init(ClockedObject *_clockedObject, uint64_t _numStages=0)
79  {
80  clockedObject = _clockedObject;
81  numStages = _numStages;
82  }
83 
84  void set(uint64_t i)
85  {
87  "Can't allocate resource because it is busy!!!");
89  }
90  void preset(uint64_t delay)
91  {
92  lookAheadAvail = std::max(lookAheadAvail, delay +
94  }
95  bool rdy(Cycles cycles = Cycles(0)) const
96  {
97  return clockedObject->clockEdge(cycles) >= nxtAvail;
98  }
99  bool prerdy() const
100  {
102  }
103 
104  private:
105  // timestamp indicating when resource will be available
106  uint64_t nxtAvail;
107  // timestamp indicating when resource will be available including
108  // pending uses of the resource (when there is a cycle gap between
109  // rdy() and set()
110  uint64_t lookAheadAvail;
111  // clockedObject for current timestamp
113  // number of stages between checking if a resource is ready and
114  // setting the resource's utilization
115  uint64_t numStages;
116 };
117 
118 class Float16
119 {
120  public:
121  uint16_t val;
122 
123  Float16() { val = 0; }
124 
125  Float16(const Float16 &x) : val(x.val) { }
126 
127  Float16(float x)
128  {
129  uint32_t ai = *(reinterpret_cast<uint32_t *>(&x));
130 
131  uint32_t s = (ai >> 31) & 0x1;
132  uint32_t exp = (ai >> 23) & 0xff;
133  uint32_t mant = (ai >> 0) & 0x7fffff;
134 
135  if (exp == 0 || exp <= 0x70) {
136  exp = 0;
137  mant = 0;
138  } else if (exp == 0xff) {
139  exp = 0x1f;
140  } else if (exp >= 0x8f) {
141  exp = 0x1f;
142  mant = 0;
143  } else {
144  exp = exp - 0x7f + 0x0f;
145  }
146 
147  mant = mant >> 13;
148 
149  val = 0;
150  val |= (s << 15);
151  val |= (exp << 10);
152  val |= (mant << 0);
153  }
154 
155  operator float() const
156  {
157  uint32_t s = (val >> 15) & 0x1;
158  uint32_t exp = (val >> 10) & 0x1f;
159  uint32_t mant = (val >> 0) & 0x3ff;
160 
161  if (!exp) {
162  exp = 0;
163  mant = 0;
164  } else if (exp == 0x1f) {
165  exp = 0xff;
166  } else {
167  exp = exp - 0x0f + 0x7f;
168  }
169 
170  uint32_t val1 = 0;
171  val1 |= (s << 31);
172  val1 |= (exp << 23);
173  val1 |= (mant << 13);
174 
175  return *(reinterpret_cast<float *>(&val1));
176  }
177 };
178 
179 } // namespace gem5
180 
181 #endif // __MISC_HH__
gem5::GMEnqueue
@ GMEnqueue
Definition: misc.hh:58
gem5::Float16::Float16
Float16()
Definition: misc.hh:123
gem5::Float16::Float16
Float16(float x)
Definition: misc.hh:127
gem5::Complete
@ Complete
Definition: misc.hh:59
gem5::VectorMask
std::bitset< std::numeric_limits< unsigned long long >::digits > VectorMask
Definition: misc.hh:47
gem5::Float16::val
uint16_t val
Definition: misc.hh:121
gem5::WaitClass::WaitClass
WaitClass()
Definition: misc.hh:72
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::WaitClass::prerdy
bool prerdy() const
Definition: misc.hh:99
gem5::WaitClass::clockedObject
ClockedObject * clockedObject
Definition: misc.hh:112
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::WaitClass::lookAheadAvail
uint64_t lookAheadAvail
Definition: misc.hh:110
gem5::Initiate
@ Initiate
Definition: misc.hh:55
gem5::WaitClass::init
void init(ClockedObject *_clockedObject, uint64_t _numStages=0)
Definition: misc.hh:78
gem5::CoalsrRecv
@ CoalsrRecv
Definition: misc.hh:57
gem5::Float16
Definition: misc.hh:118
gem5::WaitClass::nxtAvail
uint64_t nxtAvail
Definition: misc.hh:106
gem5::WaitClass
Definition: misc.hh:69
gem5::WaitClass::preset
void preset(uint64_t delay)
Definition: misc.hh:90
gem5::GPUDynInst
Definition: gpu_dyn_inst.hh:118
gem5::WaitClass::WaitClass
WaitClass(ClockedObject *_clockedObject, uint64_t _numStages=0)
Definition: misc.hh:74
gem5::BlockRecv
@ BlockRecv
Definition: misc.hh:66
gem5::CoalsrSend
@ CoalsrSend
Definition: misc.hh:56
gem5::InstMemoryHopMax
@ InstMemoryHopMax
Definition: misc.hh:60
gem5::GPUDynInstPtr
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition: misc.hh:51
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::Clocked::clockEdge
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Definition: clocked_object.hh:177
gem5::WaitClass::set
void set(uint64_t i)
Definition: misc.hh:84
gem5::RiscvISA::x
Bitfield< 3 > x
Definition: pagetable.hh:73
gem5::InstMemoryHop
InstMemoryHop
Definition: misc.hh:53
clocked_object.hh
logging.hh
gem5::WaitClass::numStages
uint64_t numStages
Definition: misc.hh:115
gem5::BlockSend
@ BlockSend
Definition: misc.hh:65
gem5::Float16::Float16
Float16(const Float16 &x)
Definition: misc.hh:125
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:225
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::X86ISA::s
Bitfield< 44 > s
Definition: misc.hh:933
gem5::WaitClass::rdy
bool rdy(Cycles cycles=Cycles(0)) const
Definition: misc.hh:95
gem5::BlockMemoryHop
BlockMemoryHop
Definition: misc.hh:63

Generated on Tue Sep 7 2021 14:53:41 for gem5 by doxygen 1.8.17