gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
amo.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * Copyright (c) 2003-2005 The Regents of The University of Michigan
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met: redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer;
12  * redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution;
15  * neither the name of the copyright holders nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef __BASE_AMO_HH__
33 #define __BASE_AMO_HH__
34 
35 #include <array>
36 #include <cstdint>
37 #include <functional>
38 #include <memory>
39 
40 namespace gem5
41 {
42 
44 {
49  virtual void operator()(uint8_t *p) = 0;
50  virtual AtomicOpFunctor* clone() = 0; // end of api_atomic_op
52  virtual ~AtomicOpFunctor() {}
53 };
54 
55 template <class T>
57 {
58  void operator()(uint8_t *p) { execute((T *)p); }
59  virtual AtomicOpFunctor* clone() = 0;
63  virtual void execute(T * p) = 0;
64 };
65 
66 template<typename T>
68 {
69  public:
70  AtomicGeneric2Op(T _a, std::function<void(T*,T)> _op)
71  : a(_a), op(_op)
72  {}
73  AtomicOpFunctor* clone() override
74  {
75  return new AtomicGeneric2Op<T>(*this);
76  }
77  void execute(T *b) override
78  {
79  op(b, a);
80  }
81  private:
82  T a;
83  std::function<void(T*,T)> op;
84  };
85 
86 template<typename T>
88 {
89  public:
90  AtomicGeneric3Op(T _a, T _c, std::function<void(T*, T, T)> _op)
91  : a(_a), c(_c), op(_op)
92  {}
93  AtomicOpFunctor* clone() override
94  {
95  return new AtomicGeneric3Op<T>(*this);
96  }
97  void execute(T *b) override
98  {
99  op(b, a, c);
100  }
101  private:
102  T a;
103  T c;
104  std::function<void(T*, T, T)> op;
105 };
106 
107 template<typename T>
109 {
110  public:
111  AtomicGenericPair3Op(std::array<T, 2>& _a, std::array<T, 2> _c,
112  std::function<void(T*, std::array<T, 2>&, std::array<T, 2>)> _op)
113  : a(_a), c(_c), op(_op)
114  {}
115  AtomicOpFunctor* clone() override
116  {
117  return new AtomicGenericPair3Op<T>(*this);
118  }
119  void execute(T* b) override
120  {
121  op(b, a, c);
122  }
123  private:
124  std::array<T, 2> a;
125  std::array<T, 2> c;
126  std::function<void(T*, std::array<T, 2>&, std::array<T, 2>)> op;
127 };
128 
129 template<typename T>
131 {
132  // Bitwise operations are only legal on integral types
133  template<typename B>
134  typename std::enable_if<std::is_integral<B>::value, void>::type
135  executeImpl(B *b) { *b &= a; }
136 
137  template<typename B>
138  typename std::enable_if<!std::is_integral<B>::value, void>::type
139  executeImpl(B *b) { }
140 
141  public:
142  T a;
143  AtomicOpAnd(T _a) : a(_a) { }
144  void execute(T *b) { executeImpl<T>(b); }
145  AtomicOpFunctor* clone () { return new AtomicOpAnd(a); }
146 };
147 
148 template<typename T>
150 {
151  // Bitwise operations are only legal on integral types
152  template<typename B>
153  typename std::enable_if<std::is_integral<B>::value, void>::type
154  executeImpl(B *b) { *b |= a; }
155 
156  template<typename B>
157  typename std::enable_if<!std::is_integral<B>::value, void>::type
158  executeImpl(B *b) { }
159 
160  public:
161  T a;
162  AtomicOpOr(T _a) : a(_a) { }
163  void execute(T *b) { executeImpl<T>(b); }
164  AtomicOpFunctor* clone () { return new AtomicOpOr(a); }
165 };
166 
167 template<typename T>
169 {
170  // Bitwise operations are only legal on integral types
171  template<typename B>
172  typename std::enable_if<std::is_integral<B>::value, void>::type
173  executeImpl(B *b) { *b ^= a; }
174 
175  template<typename B>
176  typename std::enable_if<!std::is_integral<B>::value, void>::type
177  executeImpl(B *b) { }
178 
179  public:
180  T a;
181  AtomicOpXor(T _a) : a(_a) {}
182  void execute(T *b) { executeImpl<T>(b); }
183  AtomicOpFunctor* clone () { return new AtomicOpXor(a); }
184 };
185 
186 template<typename T>
188 {
189  public:
190  T a;
191  AtomicOpExch(T _a) : a(_a) { }
192  void execute(T *b) { *b = a; }
193  AtomicOpFunctor* clone () { return new AtomicOpExch(a); }
194 };
195 
196 template<typename T>
198 {
199  public:
200  T a;
201  AtomicOpAdd(T _a) : a(_a) { }
202  void execute(T *b) { *b += a; }
203  AtomicOpFunctor* clone () { return new AtomicOpAdd(a); }
204 };
205 
206 template<typename T>
208 {
209  public:
210  T a;
211  AtomicOpSub(T _a) : a(_a) { }
212  void execute(T *b) { *b -= a; }
213  AtomicOpFunctor* clone () { return new AtomicOpSub(a); }
214 };
215 
216 template<typename T>
218 {
219  public:
221  void execute(T *b) { *b += 1; }
222  AtomicOpFunctor* clone () { return new AtomicOpInc(); }
223 };
224 
225 template<typename T>
227 {
228  public:
230  void execute(T *b) { *b -= 1; }
231  AtomicOpFunctor* clone () { return new AtomicOpDec(); }
232 };
233 
234 template<typename T>
236 {
237  public:
238  T a;
239  AtomicOpMax(T _a) : a(_a) { }
240 
241  void
242  execute(T *b)
243  {
244  if (a > *b)
245  *b = a;
246  }
247  AtomicOpFunctor* clone () { return new AtomicOpMax(a); }
248 };
249 
250 template<typename T>
252 {
253  public:
254  T a;
255  AtomicOpMin(T _a) : a(_a) {}
256 
257  void
258  execute(T *b)
259  {
260  if (a < *b)
261  *b = a;
262  }
263  AtomicOpFunctor* clone () { return new AtomicOpMin(a); }
264 };
265 
269 typedef std::unique_ptr<AtomicOpFunctor> AtomicOpFunctorPtr;
270 
271 } // namespace gem5
272 
273 #endif // __BASE_AMO_HH__
gem5::AtomicOpXor::executeImpl
std::enable_if<!std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition: amo.hh:177
gem5::AtomicGenericPair3Op::AtomicGenericPair3Op
AtomicGenericPair3Op(std::array< T, 2 > &_a, std::array< T, 2 > _c, std::function< void(T *, std::array< T, 2 > &, std::array< T, 2 >)> _op)
Definition: amo.hh:111
gem5::AtomicOpInc::AtomicOpInc
AtomicOpInc()
Definition: amo.hh:220
gem5::AtomicGenericPair3Op::c
std::array< T, 2 > c
Definition: amo.hh:125
gem5::AtomicOpExch::clone
AtomicOpFunctor * clone()
Definition: amo.hh:193
gem5::AtomicGeneric3Op::clone
AtomicOpFunctor * clone() override
Definition: amo.hh:93
gem5::AtomicOpSub::a
T a
Definition: amo.hh:210
gem5::AtomicOpInc::execute
void execute(T *b)
Definition: amo.hh:221
gem5::AtomicOpMin::AtomicOpMin
AtomicOpMin(T _a)
Definition: amo.hh:255
gem5::AtomicGeneric3Op::AtomicGeneric3Op
AtomicGeneric3Op(T _a, T _c, std::function< void(T *, T, T)> _op)
Definition: amo.hh:90
gem5::AtomicOpFunctor::clone
virtual AtomicOpFunctor * clone()=0
gem5::AtomicOpFunctor
Definition: amo.hh:43
gem5::AtomicOpMax::AtomicOpMax
AtomicOpMax(T _a)
Definition: amo.hh:239
gem5::AtomicGeneric2Op::AtomicGeneric2Op
AtomicGeneric2Op(T _a, std::function< void(T *, T)> _op)
Definition: amo.hh:70
gem5::AtomicGeneric3Op
Definition: amo.hh:87
gem5::AtomicGeneric2Op
Definition: amo.hh:67
gem5::AtomicOpAnd::clone
AtomicOpFunctor * clone()
Definition: amo.hh:145
gem5::AtomicOpOr
Definition: amo.hh:149
gem5::AtomicGeneric2Op::op
std::function< void(T *, T)> op
Definition: amo.hh:83
gem5::AtomicOpMax::a
T a
Definition: amo.hh:238
gem5::AtomicOpOr::executeImpl
std::enable_if< std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition: amo.hh:154
gem5::AtomicOpDec
Definition: amo.hh:226
gem5::AtomicOpInc
Definition: amo.hh:217
gem5::AtomicOpInc::clone
AtomicOpFunctor * clone()
Definition: amo.hh:222
gem5::AtomicOpOr::clone
AtomicOpFunctor * clone()
Definition: amo.hh:164
gem5::AtomicGeneric3Op::a
T a
Definition: amo.hh:102
gem5::AtomicOpSub::AtomicOpSub
AtomicOpSub(T _a)
Definition: amo.hh:211
gem5::AtomicOpSub::clone
AtomicOpFunctor * clone()
Definition: amo.hh:213
gem5::AtomicOpSub::execute
void execute(T *b)
Definition: amo.hh:212
gem5::AtomicOpMin::execute
void execute(T *b)
Definition: amo.hh:258
gem5::AtomicOpXor::execute
void execute(T *b)
Definition: amo.hh:182
gem5::AtomicOpExch::execute
void execute(T *b)
Definition: amo.hh:192
gem5::AtomicOpExch::AtomicOpExch
AtomicOpExch(T _a)
Definition: amo.hh:191
gem5::AtomicOpAdd::clone
AtomicOpFunctor * clone()
Definition: amo.hh:203
gem5::TypedAtomicOpFunctor
Definition: amo.hh:56
gem5::AtomicOpMin
Definition: amo.hh:251
gem5::AtomicOpXor::a
T a
Definition: amo.hh:180
gem5::AtomicOpDec::execute
void execute(T *b)
Definition: amo.hh:230
gem5::AtomicGeneric3Op::op
std::function< void(T *, T, T)> op
Definition: amo.hh:104
gem5::AtomicOpMax::clone
AtomicOpFunctor * clone()
Definition: amo.hh:247
gem5::AtomicOpOr::executeImpl
std::enable_if<!std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition: amo.hh:158
gem5::ArmISA::b
Bitfield< 7 > b
Definition: misc_types.hh:438
gem5::TypedAtomicOpFunctor::execute
virtual void execute(T *p)=0
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::AtomicGeneric2Op::execute
void execute(T *b) override
Definition: amo.hh:77
gem5::AtomicOpAnd
Definition: amo.hh:130
gem5::AtomicOpExch
Definition: amo.hh:187
gem5::AtomicOpAdd::execute
void execute(T *b)
Definition: amo.hh:202
gem5::AtomicOpSub
Definition: amo.hh:207
gem5::AtomicOpFunctor::operator()
virtual void operator()(uint8_t *p)=0
gem5::X86ISA::type
type
Definition: misc.hh:734
gem5::AtomicOpOr::AtomicOpOr
AtomicOpOr(T _a)
Definition: amo.hh:162
gem5::AtomicOpDec::clone
AtomicOpFunctor * clone()
Definition: amo.hh:231
gem5::AtomicOpXor::executeImpl
std::enable_if< std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition: amo.hh:173
gem5::AtomicOpAdd::a
T a
Definition: amo.hh:200
gem5::AtomicGeneric2Op::a
T a
Definition: amo.hh:82
gem5::AtomicOpXor
Definition: amo.hh:168
gem5::AtomicGenericPair3Op::clone
AtomicOpFunctor * clone() override
Definition: amo.hh:115
gem5::AtomicOpXor::AtomicOpXor
AtomicOpXor(T _a)
Definition: amo.hh:181
gem5::AtomicGenericPair3Op::a
std::array< T, 2 > a
Definition: amo.hh:124
gem5::AtomicOpXor::clone
AtomicOpFunctor * clone()
Definition: amo.hh:183
gem5::AtomicOpFunctor::~AtomicOpFunctor
virtual ~AtomicOpFunctor()
Definition: amo.hh:52
gem5::AtomicOpMin::a
T a
Definition: amo.hh:254
gem5::AtomicGenericPair3Op
Definition: amo.hh:108
gem5::AtomicOpOr::a
T a
Definition: amo.hh:161
gem5::AtomicGeneric3Op::execute
void execute(T *b) override
Definition: amo.hh:97
gem5::TypedAtomicOpFunctor::operator()
void operator()(uint8_t *p)
Definition: amo.hh:58
gem5::AtomicOpAnd::executeImpl
std::enable_if< std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition: amo.hh:135
gem5::AtomicOpAnd::a
T a
Definition: amo.hh:142
gem5::AtomicOpMax
Definition: amo.hh:235
gem5::AtomicOpDec::AtomicOpDec
AtomicOpDec()
Definition: amo.hh:229
gem5::TypedAtomicOpFunctor::clone
virtual AtomicOpFunctor * clone()=0
gem5::AtomicOpExch::a
T a
Definition: amo.hh:190
gem5::AtomicGenericPair3Op::execute
void execute(T *b) override
Definition: amo.hh:119
gem5::AtomicOpAnd::executeImpl
std::enable_if<!std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition: amo.hh:139
gem5::AtomicOpAdd::AtomicOpAdd
AtomicOpAdd(T _a)
Definition: amo.hh:201
gem5::AtomicGeneric2Op::clone
AtomicOpFunctor * clone() override
Definition: amo.hh:73
gem5::AtomicOpMin::clone
AtomicOpFunctor * clone()
Definition: amo.hh:263
gem5::AtomicOpFunctorPtr
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition: amo.hh:269
gem5::AtomicOpMax::execute
void execute(T *b)
Definition: amo.hh:242
gem5::AtomicOpOr::execute
void execute(T *b)
Definition: amo.hh:163
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::AtomicOpAnd::AtomicOpAnd
AtomicOpAnd(T _a)
Definition: amo.hh:143
gem5::AtomicOpAnd::execute
void execute(T *b)
Definition: amo.hh:144
gem5::AtomicGenericPair3Op::op
std::function< void(T *, std::array< T, 2 > &, std::array< T, 2 >)> op
Definition: amo.hh:126
gem5::AtomicOpAdd
Definition: amo.hh:197
gem5::AtomicGeneric3Op::c
T c
Definition: amo.hh:103

Generated on Sun Jul 30 2023 01:56:50 for gem5 by doxygen 1.8.17