Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Unified Diff: crosstest/test_sync_atomic.cpp

Issue 362463002: Subzero: lower the rest of the atomic operations. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: comment cleanup Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: crosstest/test_sync_atomic.cpp
diff --git a/crosstest/test_sync_atomic.cpp b/crosstest/test_sync_atomic.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..dd11f018c1810c2bffb867ed8bbf0a4978189ded
--- /dev/null
+++ b/crosstest/test_sync_atomic.cpp
@@ -0,0 +1,43 @@
+// This aims to test that all the atomic RMW instructions and compare and swap
+// work across the allowed atomic types. This uses the __sync_* builtins
+// to test the atomic operations.
+
+#include <stdint.h>
+
+#include <cstdlib>
+
+#include "test_sync_atomic.h"
+
+#define X(inst, type) \
+ type test_##inst(bool fetch_first, volatile type *ptr, type a) { \
+ if (fetch_first) return __sync_fetch_and_##inst(ptr, a); \
Jim Stichnoth 2014/07/08 04:50:19 Violation (here and below) of Google style guide.
jvoung (off chromium) 2014/07/08 18:14:06 Done.
+ else return __sync_##inst##_and_fetch(ptr, a); \
+ } \
+ type test_alloca_##inst(bool fetch, volatile type *ptr, type a) { \
+ const size_t buf_size = 8; \
+ type buf[buf_size]; \
+ for (size_t i = 0; i < buf_size; ++i) { \
+ if (fetch) buf[i] = __sync_fetch_and_##inst(ptr, a); \
+ else buf[i] = __sync_##inst##_and_fetch(ptr, a); \
+ } \
+ type sum = 0; \
+ for (size_t i = 0; i < buf_size; ++i) { \
+ sum += buf[i]; \
+ } \
+ return sum; \
+ } \
+ type test_const_##inst(bool fetch, volatile type *ptr, type ign) { \
+ if (fetch) return __sync_fetch_and_##inst(ptr, 42); \
+ else return __sync_##inst##_and_fetch(ptr, 99); \
+ }
+
+FOR_ALL_RMWOP_TYPES(X)
+#undef X
+
+#define X(type) \
+ type test_val_cmp_swap(volatile type *ptr, type oldval, type newval) { \
+ return __sync_val_compare_and_swap(ptr, oldval, newval); \
+ }
+
+ATOMIC_TYPE_TABLE
+#undef X

Powered by Google App Engine
This is Rietveld 408576698