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

Side by Side 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: revert register alloc workarounds 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 unified diff | Download patch
OLDNEW
(Empty)
1 // This aims to test that all the atomic RMW instructions and compare and swap
2 // work across the allowed atomic types. This uses the __sync_* builtins
3 // to test the atomic operations.
4
5 #include <stdint.h>
6
7 #include <cstdlib>
8
9 #include "test_sync_atomic.h"
10
11 #define X(inst, type) \
12 type test_##inst(bool fetch_first, volatile type *ptr, type a) { \
13 if (fetch_first) { \
14 return __sync_fetch_and_##inst(ptr, a); \
15 } else { \
16 return __sync_##inst##_and_fetch(ptr, a); \
17 } \
18 } \
19 type test_alloca_##inst(bool fetch, volatile type *ptr, type a) { \
20 const size_t buf_size = 8; \
21 type buf[buf_size]; \
22 for (size_t i = 0; i < buf_size; ++i) { \
23 if (fetch) { \
24 buf[i] = __sync_fetch_and_##inst(ptr, a); \
25 } else { \
26 buf[i] = __sync_##inst##_and_fetch(ptr, a); \
27 } \
28 } \
29 type sum = 0; \
30 for (size_t i = 0; i < buf_size; ++i) { \
31 sum += buf[i]; \
32 } \
33 return sum; \
34 } \
35 type test_const_##inst(bool fetch, volatile type *ptr, type ign) { \
36 if (fetch) { \
37 return __sync_fetch_and_##inst(ptr, 42); \
38 } else { \
39 return __sync_##inst##_and_fetch(ptr, 99); \
40 } \
41 }
42
43 FOR_ALL_RMWOP_TYPES(X)
44 #undef X
45
46 #define X(type) \
47 type test_val_cmp_swap(volatile type *ptr, type oldval, type newval) { \
48 return __sync_val_compare_and_swap(ptr, oldval, newval); \
49 }
50
51 ATOMIC_TYPE_TABLE
52 #undef X
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698