gem5  v20.0.0.3
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 
43 class GPUDynInst;
44 
45 typedef std::bitset<std::numeric_limits<unsigned long long>::digits> VectorMask;
46 typedef std::shared_ptr<GPUDynInst> GPUDynInstPtr;
47 
48 class WaitClass
49 {
50  public:
52  void init(uint64_t *_tcnt, uint32_t _numStages=0)
53  {
54  tcnt = _tcnt;
55  numStages = _numStages;
56  }
57 
58  void set(uint32_t i)
59  {
61  "Can't allocate resource because it is busy!!!");
62  nxtAvail = *tcnt + i;
63  }
64  void preset(uint32_t delay)
65  {
66  lookAheadAvail = std::max(lookAheadAvail, delay + (*tcnt) - numStages);
67  }
68  bool rdy() const { return *tcnt >= nxtAvail; }
69  bool prerdy() const { return *tcnt >= lookAheadAvail; }
70 
71  private:
72  // timestamp indicating when resource will be available
73  uint64_t nxtAvail;
74  // timestamp indicating when resource will be available including
75  // pending uses of the resource (when there is a cycle gap between
76  // rdy() and set()
77  uint64_t lookAheadAvail;
78  // current timestamp
79  uint64_t *tcnt;
80  // number of stages between checking if a resource is ready and
81  // setting the resource's utilization
82  uint32_t numStages;
83 };
84 
85 class Float16
86 {
87  public:
88  uint16_t val;
89 
90  Float16() { val = 0; }
91 
92  Float16(const Float16 &x) : val(x.val) { }
93 
94  Float16(float x)
95  {
96  uint32_t ai = *(uint32_t *)&x;
97 
98  uint32_t s = (ai >> 31) & 0x1;
99  uint32_t exp = (ai >> 23) & 0xff;
100  uint32_t mant = (ai >> 0) & 0x7fffff;
101 
102  if (exp == 0 || exp <= 0x70) {
103  exp = 0;
104  mant = 0;
105  } else if (exp == 0xff) {
106  exp = 0x1f;
107  } else if (exp >= 0x8f) {
108  exp = 0x1f;
109  mant = 0;
110  } else {
111  exp = exp - 0x7f + 0x0f;
112  }
113 
114  mant = mant >> 13;
115 
116  val = 0;
117  val |= (s << 15);
118  val |= (exp << 10);
119  val |= (mant << 0);
120  }
121 
122  operator float() const
123  {
124  uint32_t s = (val >> 15) & 0x1;
125  uint32_t exp = (val >> 10) & 0x1f;
126  uint32_t mant = (val >> 0) & 0x3ff;
127 
128  if (!exp) {
129  exp = 0;
130  mant = 0;
131  } else if (exp == 0x1f) {
132  exp = 0xff;
133  } else {
134  exp = exp - 0x0f + 0x7f;
135  }
136 
137  uint32_t val1 = 0;
138  val1 |= (s << 31);
139  val1 |= (exp << 23);
140  val1 |= (mant << 13);
141 
142  return *(float*)&val1;
143  }
144 };
145 
146 #endif // __MISC_HH__
Bitfield< 7 > i
uint64_t nxtAvail
Definition: misc.hh:73
std::bitset< std::numeric_limits< unsigned long long >::digits > VectorMask
Definition: misc.hh:43
bool rdy() const
Definition: misc.hh:68
Bitfield< 3 > x
Definition: pagetable.hh:69
std::shared_ptr< GPUDynInst > GPUDynInstPtr
Definition: misc.hh:46
Float16(float x)
Definition: misc.hh:94
uint64_t lookAheadAvail
Definition: misc.hh:77
uint16_t val
Definition: misc.hh:88
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:199
void preset(uint32_t delay)
Definition: misc.hh:64
Definition: misc.hh:85
uint64_t * tcnt
Definition: misc.hh:79
bool prerdy() const
Definition: misc.hh:69
void init(uint64_t *_tcnt, uint32_t _numStages=0)
Definition: misc.hh:52
Bitfield< 44 > s
Definition: misc.hh:927
Float16(const Float16 &x)
Definition: misc.hh:92
WaitClass()
Definition: misc.hh:51
Float16()
Definition: misc.hh:90
uint32_t numStages
Definition: misc.hh:82

Generated on Fri Jul 3 2020 15:42:39 for gem5 by doxygen 1.8.13