diff options
Diffstat (limited to 'src/base/amo.hh')
-rw-r--r-- | src/base/amo.hh | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/base/amo.hh b/src/base/amo.hh index 624c755ed..ec0598199 100644 --- a/src/base/amo.hh +++ b/src/base/amo.hh @@ -1,4 +1,7 @@ /* + * Copyright (c) 2015-2017 Advanced Micro Devices, Inc. + * All rights reserved. + * * Copyright (c) 2003-2005 The Regents of The University of Michigan * All rights reserved. * @@ -26,6 +29,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Authors: Nathan Binkert + * Anthony Gutierrez */ #ifndef __BASE_AMO_HH__ @@ -109,6 +113,116 @@ class AtomicGenericPair3Op : public TypedAtomicOpFunctor<T> std::function<void(T*, std::array<T, 2>&, std::array<T, 2>)> op; }; +template<typename T> +class AtomicOpAnd : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpAnd(T _a) : a(_a) { } + void execute(T *b) { *b &= a; } + AtomicOpFunctor* clone () { return new AtomicOpAnd(a); } +}; + +template<typename T> +class AtomicOpOr : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpOr(T _a) : a(_a) { } + void execute(T *b) { *b |= a; } + AtomicOpFunctor* clone () { return new AtomicOpOr(a); } +}; + +template<typename T> +class AtomicOpXor : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpXor(T _a) : a(_a) {} + void execute(T *b) { *b ^= a; } + AtomicOpFunctor* clone () { return new AtomicOpXor(a); } +}; + +template<typename T> +class AtomicOpExch : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpExch(T _a) : a(_a) { } + void execute(T *b) { *b = a; } + AtomicOpFunctor* clone () { return new AtomicOpExch(a); } +}; + +template<typename T> +class AtomicOpAdd : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpAdd(T _a) : a(_a) { } + void execute(T *b) { *b += a; } + AtomicOpFunctor* clone () { return new AtomicOpAdd(a); } +}; + +template<typename T> +class AtomicOpSub : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpSub(T _a) : a(_a) { } + void execute(T *b) { *b -= a; } + AtomicOpFunctor* clone () { return new AtomicOpSub(a); } +}; + +template<typename T> +class AtomicOpInc : public TypedAtomicOpFunctor<T> +{ + public: + AtomicOpInc() { } + void execute(T *b) { *b += 1; } + AtomicOpFunctor* clone () { return new AtomicOpInc(); } +}; + +template<typename T> +class AtomicOpDec : public TypedAtomicOpFunctor<T> +{ + public: + AtomicOpDec() {} + void execute(T *b) { *b -= 1; } + AtomicOpFunctor* clone () { return new AtomicOpDec(); } +}; + +template<typename T> +class AtomicOpMax : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpMax(T _a) : a(_a) { } + + void + execute(T *b) + { + if (a > *b) + *b = a; + } + AtomicOpFunctor* clone () { return new AtomicOpMax(a); } +}; + +template<typename T> +class AtomicOpMin : public TypedAtomicOpFunctor<T> +{ + public: + T a; + AtomicOpMin(T _a) : a(_a) {} + + void + execute(T *b) + { + if (a < *b) + *b = a; + } + AtomicOpFunctor* clone () { return new AtomicOpMin(a); } +}; + typedef std::unique_ptr<AtomicOpFunctor> AtomicOpFunctorPtr; #endif // __BASE_AMO_HH__ |