gem5  v21.1.0.2
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  public:
133  T a;
134  AtomicOpAnd(T _a) : a(_a) { }
135  void execute(T *b) { *b &= a; }
136  AtomicOpFunctor* clone () { return new AtomicOpAnd(a); }
137 };
138 
139 template<typename T>
141 {
142  public:
143  T a;
144  AtomicOpOr(T _a) : a(_a) { }
145  void execute(T *b) { *b |= a; }
146  AtomicOpFunctor* clone () { return new AtomicOpOr(a); }
147 };
148 
149 template<typename T>
151 {
152  public:
153  T a;
154  AtomicOpXor(T _a) : a(_a) {}
155  void execute(T *b) { *b ^= a; }
156  AtomicOpFunctor* clone () { return new AtomicOpXor(a); }
157 };
158 
159 template<typename T>
161 {
162  public:
163  T a;
164  AtomicOpExch(T _a) : a(_a) { }
165  void execute(T *b) { *b = a; }
166  AtomicOpFunctor* clone () { return new AtomicOpExch(a); }
167 };
168 
169 template<typename T>
171 {
172  public:
173  T a;
174  AtomicOpAdd(T _a) : a(_a) { }
175  void execute(T *b) { *b += a; }
176  AtomicOpFunctor* clone () { return new AtomicOpAdd(a); }
177 };
178 
179 template<typename T>
181 {
182  public:
183  T a;
184  AtomicOpSub(T _a) : a(_a) { }
185  void execute(T *b) { *b -= a; }
186  AtomicOpFunctor* clone () { return new AtomicOpSub(a); }
187 };
188 
189 template<typename T>
191 {
192  public:
194  void execute(T *b) { *b += 1; }
195  AtomicOpFunctor* clone () { return new AtomicOpInc(); }
196 };
197 
198 template<typename T>
200 {
201  public:
203  void execute(T *b) { *b -= 1; }
204  AtomicOpFunctor* clone () { return new AtomicOpDec(); }
205 };
206 
207 template<typename T>
209 {
210  public:
211  T a;
212  AtomicOpMax(T _a) : a(_a) { }
213 
214  void
215  execute(T *b)
216  {
217  if (a > *b)
218  *b = a;
219  }
220  AtomicOpFunctor* clone () { return new AtomicOpMax(a); }
221 };
222 
223 template<typename T>
225 {
226  public:
227  T a;
228  AtomicOpMin(T _a) : a(_a) {}
229 
230  void
231  execute(T *b)
232  {
233  if (a < *b)
234  *b = a;
235  }
236  AtomicOpFunctor* clone () { return new AtomicOpMin(a); }
237 };
238 
242 typedef std::unique_ptr<AtomicOpFunctor> AtomicOpFunctorPtr;
243 
244 } // namespace gem5
245 
246 #endif // __BASE_AMO_HH__
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:193
gem5::AtomicGenericPair3Op::c
std::array< T, 2 > c
Definition: amo.hh:125
gem5::AtomicOpExch::clone
AtomicOpFunctor * clone()
Definition: amo.hh:166
gem5::AtomicGeneric3Op::clone
AtomicOpFunctor * clone() override
Definition: amo.hh:93
gem5::AtomicOpSub::a
T a
Definition: amo.hh:183
gem5::AtomicOpInc::execute
void execute(T *b)
Definition: amo.hh:194
gem5::AtomicOpMin::AtomicOpMin
AtomicOpMin(T _a)
Definition: amo.hh:228
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:212
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:136
gem5::AtomicOpOr
Definition: amo.hh:140
gem5::AtomicGeneric2Op::op
std::function< void(T *, T)> op
Definition: amo.hh:83
gem5::AtomicOpMax::a
T a
Definition: amo.hh:211
gem5::AtomicOpDec
Definition: amo.hh:199
gem5::AtomicOpInc
Definition: amo.hh:190
gem5::AtomicOpInc::clone
AtomicOpFunctor * clone()
Definition: amo.hh:195
gem5::AtomicOpOr::clone
AtomicOpFunctor * clone()
Definition: amo.hh:146
gem5::AtomicGeneric3Op::a
T a
Definition: amo.hh:102
gem5::AtomicOpSub::AtomicOpSub
AtomicOpSub(T _a)
Definition: amo.hh:184
gem5::AtomicOpSub::clone
AtomicOpFunctor * clone()
Definition: amo.hh:186
gem5::AtomicOpSub::execute
void execute(T *b)
Definition: amo.hh:185
gem5::AtomicOpMin::execute
void execute(T *b)
Definition: amo.hh:231
gem5::AtomicOpXor::execute
void execute(T *b)
Definition: amo.hh:155
gem5::AtomicOpExch::execute
void execute(T *b)
Definition: amo.hh:165
gem5::AtomicOpExch::AtomicOpExch
AtomicOpExch(T _a)
Definition: amo.hh:164
gem5::AtomicOpAdd::clone
AtomicOpFunctor * clone()
Definition: amo.hh:176
gem5::TypedAtomicOpFunctor
Definition: amo.hh:56
gem5::AtomicOpMin
Definition: amo.hh:224
gem5::AtomicOpXor::a
T a
Definition: amo.hh:153
gem5::AtomicOpDec::execute
void execute(T *b)
Definition: amo.hh:203
gem5::AtomicGeneric3Op::op
std::function< void(T *, T, T)> op
Definition: amo.hh:104
gem5::AtomicOpMax::clone
AtomicOpFunctor * clone()
Definition: amo.hh:220
gem5::ArmISA::b
Bitfield< 7 > b
Definition: misc_types.hh:381
gem5::TypedAtomicOpFunctor::execute
virtual void execute(T *p)=0
gem5::AtomicGeneric2Op::execute
void execute(T *b) override
Definition: amo.hh:77
gem5::AtomicOpAnd
Definition: amo.hh:130
gem5::AtomicOpExch
Definition: amo.hh:160
gem5::AtomicOpAdd::execute
void execute(T *b)
Definition: amo.hh:175
gem5::AtomicOpSub
Definition: amo.hh:180
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::AtomicOpFunctor::operator()
virtual void operator()(uint8_t *p)=0
gem5::AtomicOpOr::AtomicOpOr
AtomicOpOr(T _a)
Definition: amo.hh:144
gem5::AtomicOpDec::clone
AtomicOpFunctor * clone()
Definition: amo.hh:204
gem5::AtomicOpAdd::a
T a
Definition: amo.hh:173
gem5::AtomicGeneric2Op::a
T a
Definition: amo.hh:82
gem5::AtomicOpXor
Definition: amo.hh:150
gem5::AtomicGenericPair3Op::clone
AtomicOpFunctor * clone() override
Definition: amo.hh:115
gem5::AtomicOpXor::AtomicOpXor
AtomicOpXor(T _a)
Definition: amo.hh:154
gem5::AtomicGenericPair3Op::a
std::array< T, 2 > a
Definition: amo.hh:124
gem5::AtomicOpXor::clone
AtomicOpFunctor * clone()
Definition: amo.hh:156
gem5::AtomicOpFunctor::~AtomicOpFunctor
virtual ~AtomicOpFunctor()
Definition: amo.hh:52
gem5::AtomicOpMin::a
T a
Definition: amo.hh:227
gem5::AtomicGenericPair3Op
Definition: amo.hh:108
gem5::AtomicOpOr::a
T a
Definition: amo.hh:143
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::a
T a
Definition: amo.hh:133
gem5::AtomicOpMax
Definition: amo.hh:208
gem5::AtomicOpDec::AtomicOpDec
AtomicOpDec()
Definition: amo.hh:202
gem5::TypedAtomicOpFunctor::clone
virtual AtomicOpFunctor * clone()=0
gem5::AtomicOpExch::a
T a
Definition: amo.hh:163
gem5::AtomicGenericPair3Op::execute
void execute(T *b) override
Definition: amo.hh:119
gem5::AtomicOpAdd::AtomicOpAdd
AtomicOpAdd(T _a)
Definition: amo.hh:174
gem5::AtomicGeneric2Op::clone
AtomicOpFunctor * clone() override
Definition: amo.hh:73
gem5::AtomicOpMin::clone
AtomicOpFunctor * clone()
Definition: amo.hh:236
gem5::AtomicOpFunctorPtr
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition: amo.hh:242
gem5::AtomicOpMax::execute
void execute(T *b)
Definition: amo.hh:215
gem5::AtomicOpOr::execute
void execute(T *b)
Definition: amo.hh:145
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::AtomicOpAnd::AtomicOpAnd
AtomicOpAnd(T _a)
Definition: amo.hh:134
gem5::AtomicOpAnd::execute
void execute(T *b)
Definition: amo.hh:135
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:170
gem5::AtomicGeneric3Op::c
T c
Definition: amo.hh:103

Generated on Tue Sep 21 2021 12:24:51 for gem5 by doxygen 1.8.17