gem5  v22.1.0.0
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__
void execute(T *b) override
Definition: amo.hh:77
std::function< void(T *, T)> op
Definition: amo.hh:83
AtomicOpFunctor * clone() override
Definition: amo.hh:73
AtomicGeneric2Op(T _a, std::function< void(T *, T)> _op)
Definition: amo.hh:70
AtomicGeneric3Op(T _a, T _c, std::function< void(T *, T, T)> _op)
Definition: amo.hh:90
std::function< void(T *, T, T)> op
Definition: amo.hh:104
void execute(T *b) override
Definition: amo.hh:97
AtomicOpFunctor * clone() override
Definition: amo.hh:93
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
std::array< T, 2 > a
Definition: amo.hh:124
void execute(T *b) override
Definition: amo.hh:119
AtomicOpFunctor * clone() override
Definition: amo.hh:115
std::array< T, 2 > c
Definition: amo.hh:125
std::function< void(T *, std::array< T, 2 > &, std::array< T, 2 >)> op
Definition: amo.hh:126
AtomicOpFunctor * clone()
Definition: amo.hh:176
void execute(T *b)
Definition: amo.hh:175
AtomicOpAdd(T _a)
Definition: amo.hh:174
void execute(T *b)
Definition: amo.hh:135
AtomicOpAnd(T _a)
Definition: amo.hh:134
AtomicOpFunctor * clone()
Definition: amo.hh:136
void execute(T *b)
Definition: amo.hh:203
AtomicOpFunctor * clone()
Definition: amo.hh:204
AtomicOpFunctor * clone()
Definition: amo.hh:166
void execute(T *b)
Definition: amo.hh:165
AtomicOpExch(T _a)
Definition: amo.hh:164
void execute(T *b)
Definition: amo.hh:194
AtomicOpFunctor * clone()
Definition: amo.hh:195
AtomicOpFunctor * clone()
Definition: amo.hh:220
void execute(T *b)
Definition: amo.hh:215
AtomicOpMax(T _a)
Definition: amo.hh:212
AtomicOpFunctor * clone()
Definition: amo.hh:236
AtomicOpMin(T _a)
Definition: amo.hh:228
void execute(T *b)
Definition: amo.hh:231
AtomicOpOr(T _a)
Definition: amo.hh:144
void execute(T *b)
Definition: amo.hh:145
AtomicOpFunctor * clone()
Definition: amo.hh:146
void execute(T *b)
Definition: amo.hh:185
AtomicOpFunctor * clone()
Definition: amo.hh:186
AtomicOpSub(T _a)
Definition: amo.hh:184
AtomicOpFunctor * clone()
Definition: amo.hh:156
AtomicOpXor(T _a)
Definition: amo.hh:154
void execute(T *b)
Definition: amo.hh:155
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition: amo.hh:242
virtual AtomicOpFunctor * clone()=0
virtual void execute(T *p)=0
virtual void operator()(uint8_t *p)=0
Bitfield< 7 > b
Definition: misc_types.hh:388
Bitfield< 54 > p
Definition: pagetable.hh:70
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
virtual ~AtomicOpFunctor()
Definition: amo.hh:52
virtual AtomicOpFunctor * clone()=0
void operator()(uint8_t *p)
Definition: amo.hh:58

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1