From ef9d76cf88282030c0ed269f73ab8f332f784437 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 24 Jul 2020 10:18:22 -0700 Subject: `InterlockedAdd` CPU intrinsic implementation. (#1455) Co-authored-by: Yong He Co-authored-by: Tim Foley --- prelude/slang-cpp-scalar-intrinsics.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h index 54900c3a3..ec3882cfb 100644 --- a/prelude/slang-cpp-scalar-intrinsics.h +++ b/prelude/slang-cpp-scalar-intrinsics.h @@ -264,6 +264,20 @@ SLANG_FORCE_INLINE int64_t I64_abs(int64_t f) { return (f < 0) ? -f : f; } SLANG_FORCE_INLINE int64_t I64_min(int64_t a, int64_t b) { return a < b ? a : b; } SLANG_FORCE_INLINE int64_t I64_max(int64_t a, int64_t b) { return a > b ? a : b; } + +// ----------------------------- Interlocked --------------------------------- +#ifdef _WIN32 +#include +#endif + +void InterlockedAdd(uint32_t* dest, uint32_t value, uint32_t* oldValue) +{ +#ifdef _WIN32 + *oldValue = _InterlockedExchangeAdd((long*)dest, (long)value); +#else + *oldValue = __sync_fetch_and_add(dest, value); +#endif +} #ifdef SLANG_PRELUDE_NAMESPACE } #endif -- cgit v1.2.3