summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-07-24 10:18:22 -0700
committerGitHub <noreply@github.com>2020-07-24 10:18:22 -0700
commitef9d76cf88282030c0ed269f73ab8f332f784437 (patch)
tree0417a89f4d303ee3bc4e52e26f017229d5565265
parentcb0a08b55f3d1be44b36fc4fc5f34405c2b1516e (diff)
`InterlockedAdd` CPU intrinsic implementation. (#1455)
Co-authored-by: Yong He <yhe@nvidia.com> Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
-rw-r--r--prelude/slang-cpp-scalar-intrinsics.h14
1 files changed, 14 insertions, 0 deletions
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 <intrin.h>
+#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