gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
40namespace gem5
41{
42
44{
49 virtual void operator()(uint8_t *p) = 0;
50 virtual AtomicOpFunctor* clone() = 0;
51 // end of api_atomic_op
52 virtual ~AtomicOpFunctor() {}
53};
54
55template <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
66template<typename T>
68{
69 public:
70 AtomicGeneric2Op(T _a, std::function<void(T*,T)> _op)
71 : a(_a), op(_op)
72 {}
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
86template<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 {}
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
107template<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 {}
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
129template<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
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
148template<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
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
167template<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
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
186template<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
196template<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
206template<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
216template<typename T>
218{
219 public:
221 void execute(T *b) { *b += 1; }
222 AtomicOpFunctor* clone () { return new AtomicOpInc(); }
223};
224
225template<typename T>
227{
228 public:
230 void execute(T *b) { *b -= 1; }
231 AtomicOpFunctor* clone () { return new AtomicOpDec(); }
232};
233
234template<typename T>
236{
237 public:
238 T a;
239 AtomicOpMax(T _a) : a(_a) { }
240
241 void
243 {
244 if (a > *b)
245 *b = a;
246 }
247 AtomicOpFunctor* clone () { return new AtomicOpMax(a); }
248};
249
250template<typename T>
252{
253 public:
254 T a;
255 AtomicOpMin(T _a) : a(_a) {}
256
257 void
259 {
260 if (a < *b)
261 *b = a;
262 }
263 AtomicOpFunctor* clone () { return new AtomicOpMin(a); }
264};
265
269typedef std::unique_ptr<AtomicOpFunctor> AtomicOpFunctorPtr;
270
271} // namespace gem5
272
273#endif // __BASE_AMO_HH__
void execute(T *b) override
Definition amo.hh:77
AtomicOpFunctor * clone() override
Definition amo.hh:73
std::function< void(T *, T)> op
Definition amo.hh:83
AtomicGeneric2Op(T _a, std::function< void(T *, T)> _op)
Definition amo.hh:70
AtomicOpFunctor * clone() override
Definition amo.hh:93
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
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
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() override
Definition amo.hh:115
void execute(T *b)
Definition amo.hh:202
AtomicOpFunctor * clone()
Definition amo.hh:203
AtomicOpAdd(T _a)
Definition amo.hh:201
AtomicOpFunctor * clone()
Definition amo.hh:145
void execute(T *b)
Definition amo.hh:144
AtomicOpAnd(T _a)
Definition amo.hh:143
std::enable_if<!std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition amo.hh:139
std::enable_if< std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition amo.hh:135
AtomicOpFunctor * clone()
Definition amo.hh:231
void execute(T *b)
Definition amo.hh:230
AtomicOpFunctor * clone()
Definition amo.hh:193
void execute(T *b)
Definition amo.hh:192
AtomicOpExch(T _a)
Definition amo.hh:191
void execute(T *b)
Definition amo.hh:221
AtomicOpFunctor * clone()
Definition amo.hh:222
AtomicOpFunctor * clone()
Definition amo.hh:247
void execute(T *b)
Definition amo.hh:242
AtomicOpMax(T _a)
Definition amo.hh:239
AtomicOpMin(T _a)
Definition amo.hh:255
void execute(T *b)
Definition amo.hh:258
AtomicOpFunctor * clone()
Definition amo.hh:263
AtomicOpOr(T _a)
Definition amo.hh:162
void execute(T *b)
Definition amo.hh:163
std::enable_if<!std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition amo.hh:158
AtomicOpFunctor * clone()
Definition amo.hh:164
std::enable_if< std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition amo.hh:154
void execute(T *b)
Definition amo.hh:212
AtomicOpFunctor * clone()
Definition amo.hh:213
AtomicOpSub(T _a)
Definition amo.hh:211
std::enable_if<!std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition amo.hh:177
std::enable_if< std::is_integral< B >::value, void >::type executeImpl(B *b)
Definition amo.hh:173
AtomicOpFunctor * clone()
Definition amo.hh:183
AtomicOpXor(T _a)
Definition amo.hh:181
void execute(T *b)
Definition amo.hh:182
virtual AtomicOpFunctor * clone()=0
std::unique_ptr< AtomicOpFunctor > AtomicOpFunctorPtr
Definition amo.hh:269
virtual void execute(T *p)=0
virtual void operator()(uint8_t *p)=0
Bitfield< 7 > b
Bitfield< 0 > p
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
virtual ~AtomicOpFunctor()
Definition amo.hh:52
void operator()(uint8_t *p)
Definition amo.hh:58
virtual AtomicOpFunctor * clone()=0

Generated on Tue Jun 18 2024 16:24:00 for gem5 by doxygen 1.11.0