aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-04-10 10:56:48 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-04-10 10:56:59 -0700
commitca8d5a649c4e8c1f29178d093cc7bbcf192e3197 (patch)
tree18bce64550dee37d86c6fe32420b59022c3427dd
parent6e06d8e9c442966f07479c3a4d8d7e48630620b9 (diff)
finish 64-bit atomics; fixes #2273
-rw-r--r--tests/core/test_atomic_cxx.cpp34
-rw-r--r--tests/core/test_atomic_cxx.txt101
2 files changed, 97 insertions, 38 deletions
diff --git a/tests/core/test_atomic_cxx.cpp b/tests/core/test_atomic_cxx.cpp
index 1b48b153..e347c34a 100644
--- a/tests/core/test_atomic_cxx.cpp
+++ b/tests/core/test_atomic_cxx.cpp
@@ -23,7 +23,7 @@ template<typename TYPE> void test(TYPE mask0, TYPE mask1, TYPE mask2) {
// test atomic<int>
std::atomic<dog> atomicDog(5);
- printf("atomic<int>.is_lock_free(): %s", atomicDog.is_lock_free() ? "true" : "false");
+ printf("atomic<int>.is_lock_free(): %s\n", atomicDog.is_lock_free() ? "true" : "false");
printf("atomic<int> value: %lld\n", (long long)TYPE(atomicDog));
// test store/load
@@ -41,67 +41,67 @@ template<typename TYPE> void test(TYPE mask0, TYPE mask1, TYPE mask2) {
// compare_exchange_weak
for (TYPE i = 0; i < numMemoryOrders; i++) {
bool success = atomicDog.compare_exchange_weak(i, i + 1, memoryOrder[i], memoryOrder[i]);
- printf("compare_exchange_weak %ld: success = %s\n", i, success ? "true" : "false");
+ printf("compare_exchange_weak %lld: success = %s\n", (long long)i, success ? "true" : "false");
}
// compare_exchange_strong
for (TYPE i = 0; i < numMemoryOrders; i++) {
bool success = atomicDog.compare_exchange_strong(i, i + 1, memoryOrder[i], memoryOrder[i]);
- printf("compare_exchange_strong %ld: success = %s\n", i, success ? "true" : "false");
+ printf("compare_exchange_strong %lld: success = %s\n", (long long)i, success ? "true" : "false");
}
// fetch_add
atomicDog = 0;
for (TYPE i = 0; i < numMemoryOrders; i++) {
TYPE old = atomicDog.fetch_add(1, memoryOrder[i]);
- printf("fetch_add %ld: old=%d new=%ld\n", i, old, TYPE(atomicDog));
+ printf("fetch_add %lld: old=%lld new=%lld\n", (long long)i, (long long)old, TYPE(atomicDog));
}
// fetch_sub
for (TYPE i = 0; i < numMemoryOrders; i++) {
TYPE old = atomicDog.fetch_sub(1, memoryOrder[i]);
- printf("fetch_sub %ld: old=%d new=%ld\n", i, old, TYPE(atomicDog));
+ printf("fetch_sub %lld: old=%lld new=%lld\n", (long long)i, (long long)old, TYPE(atomicDog));
}
// fetch_and
for (TYPE i = 0; i < numMemoryOrders; i++) {
atomicDog.store(mask0, memoryOrder[i]);
TYPE old = atomicDog.fetch_and((1<<i), memoryOrder[i]);
- printf("fetch_and %ld: old=%lx, new=%lx\n", i, old, TYPE(atomicDog));
+ printf("fetch_and %lld: old=%llx, new=%llx\n", (long long)i, (long long)old, TYPE(atomicDog));
}
// fetch_or
atomicDog = 0;
for (TYPE i = 0; i < numMemoryOrders; i++) {
TYPE old = atomicDog.fetch_or((1<<i), memoryOrder[i]);
- printf("fetch_or %ld: old=%lx, new=%lx\n", i, old, TYPE(atomicDog));
+ printf("fetch_or %lld: old=%llx, new=%llx\n", (long long)i, (long long)old, TYPE(atomicDog));
}
// fetch_xor
atomicDog = 0;
for (int i = 0; i < numMemoryOrders; i++) {
int old = atomicDog.fetch_xor((1<<i), memoryOrder[i]);
- printf("fetch_xor %ld: old=%llx, new=%lx\n", i, (long long)old, TYPE(atomicDog));
+ printf("fetch_xor %lld: old=%llx, new=%llx\n", (long long)i, (long long)old, TYPE(atomicDog));
}
// operator++, --
atomicDog = 0;
atomicDog++;
- printf("operator++: %ld\n", TYPE(atomicDog));
+ printf("operator++: %lld\n", TYPE(atomicDog));
atomicDog--;
- printf("operator--: %ld\n", TYPE(atomicDog));
+ printf("operator--: %lld\n", TYPE(atomicDog));
// operator +=, -=, &=, |=, ^=
atomicDog += 10;
- printf("operator+=: %ld\n", TYPE(atomicDog));
+ printf("operator+=: %lld\n", TYPE(atomicDog));
atomicDog -= 5;
- printf("operator-=: %ld\n", TYPE(atomicDog));
+ printf("operator-=: %lld\n", TYPE(atomicDog));
atomicDog |= mask0;
- printf("operator|=: %lx\n", TYPE(atomicDog));
+ printf("operator|=: %llx\n", TYPE(atomicDog));
atomicDog &= mask1;
- printf("operator|=: %lx\n", TYPE(atomicDog));
+ printf("operator|=: %llx\n", TYPE(atomicDog));
atomicDog ^= mask2;
- printf("operator^=: %lx\n", TYPE(atomicDog));
+ printf("operator^=: %llx\n", TYPE(atomicDog));
}
@@ -114,8 +114,8 @@ int main() {
test<short>(0xFFFF, 0xF0F0, 0x0F0F);
printf("\n32 bits\n\n");
test<int>(0xFFFFFFFF, 0xF0F0F0F0, 0x0F0F0F0F);
- //printf("\n64 bits\n\n");
- //test<long long>(0xFFFFFFFFFFFFFFFF, 0xF0F0F0F0F0F0F0F0, 0x0F0F0F0F0F0F0F0F);
+ printf("\n64 bits\n\n");
+ test<long long>(0xFFFFFFFFFFFFFFFF, 0xF0F0F0F0F0F0F0F0, 0x0F0F0F0F0F0F0F0F);
// test atomic_flag (should also have memory_orders, but probably doesn't matter
// to find the missing atomic functions)
diff --git a/tests/core/test_atomic_cxx.txt b/tests/core/test_atomic_cxx.txt
index 3076f24b..e0beb498 100644
--- a/tests/core/test_atomic_cxx.txt
+++ b/tests/core/test_atomic_cxx.txt
@@ -1,7 +1,8 @@
8 bits
-atomic<int>.is_lock_free(): trueatomic<int> value: 5
+atomic<int>.is_lock_free(): true
+atomic<int> value: 5
store/load 0: 0
store/load 1: 1
store/load 2: 2
@@ -28,12 +29,12 @@ fetch_sub 2: old=4 new=3
fetch_sub 3: old=3 new=2
fetch_sub 4: old=2 new=1
fetch_sub 5: old=1 new=0
-fetch_and 0: old=ffffffff, new=1
-fetch_and 1: old=ffffffff, new=2
-fetch_and 2: old=ffffffff, new=4
-fetch_and 3: old=ffffffff, new=8
-fetch_and 4: old=ffffffff, new=10
-fetch_and 5: old=ffffffff, new=20
+fetch_and 0: old=ffffffffffffffff, new=1
+fetch_and 1: old=ffffffffffffffff, new=2
+fetch_and 2: old=ffffffffffffffff, new=4
+fetch_and 3: old=ffffffffffffffff, new=8
+fetch_and 4: old=ffffffffffffffff, new=10
+fetch_and 5: old=ffffffffffffffff, new=20
fetch_or 0: old=0, new=1
fetch_or 1: old=1, new=3
fetch_or 2: old=3, new=7
@@ -56,7 +57,8 @@ operator^=: ffffffff
16 bits
-atomic<int>.is_lock_free(): trueatomic<int> value: 5
+atomic<int>.is_lock_free(): true
+atomic<int> value: 5
store/load 0: 0
store/load 1: 1
store/load 2: 2
@@ -83,12 +85,12 @@ fetch_sub 2: old=4 new=3
fetch_sub 3: old=3 new=2
fetch_sub 4: old=2 new=1
fetch_sub 5: old=1 new=0
-fetch_and 0: old=ffffffff, new=1
-fetch_and 1: old=ffffffff, new=2
-fetch_and 2: old=ffffffff, new=4
-fetch_and 3: old=ffffffff, new=8
-fetch_and 4: old=ffffffff, new=10
-fetch_and 5: old=ffffffff, new=20
+fetch_and 0: old=ffffffffffffffff, new=1
+fetch_and 1: old=ffffffffffffffff, new=2
+fetch_and 2: old=ffffffffffffffff, new=4
+fetch_and 3: old=ffffffffffffffff, new=8
+fetch_and 4: old=ffffffffffffffff, new=10
+fetch_and 5: old=ffffffffffffffff, new=20
fetch_or 0: old=0, new=1
fetch_or 1: old=1, new=3
fetch_or 2: old=3, new=7
@@ -111,7 +113,8 @@ operator^=: ffffffff
32 bits
-atomic<int>.is_lock_free(): trueatomic<int> value: 5
+atomic<int>.is_lock_free(): true
+atomic<int> value: 5
store/load 0: 0
store/load 1: 1
store/load 2: 2
@@ -138,12 +141,12 @@ fetch_sub 2: old=4 new=3
fetch_sub 3: old=3 new=2
fetch_sub 4: old=2 new=1
fetch_sub 5: old=1 new=0
-fetch_and 0: old=ffffffff, new=1
-fetch_and 1: old=ffffffff, new=2
-fetch_and 2: old=ffffffff, new=4
-fetch_and 3: old=ffffffff, new=8
-fetch_and 4: old=ffffffff, new=10
-fetch_and 5: old=ffffffff, new=20
+fetch_and 0: old=ffffffffffffffff, new=1
+fetch_and 1: old=ffffffffffffffff, new=2
+fetch_and 2: old=ffffffffffffffff, new=4
+fetch_and 3: old=ffffffffffffffff, new=8
+fetch_and 4: old=ffffffffffffffff, new=10
+fetch_and 5: old=ffffffffffffffff, new=20
fetch_or 0: old=0, new=1
fetch_or 1: old=1, new=3
fetch_or 2: old=3, new=7
@@ -163,5 +166,61 @@ operator-=: 5
operator|=: ffffffff
operator|=: f0f0f0f0
operator^=: ffffffff
+
+64 bits
+
+atomic<int>.is_lock_free(): false
+atomic<int> value: 5
+store/load 0: 0
+store/load 1: 1
+store/load 2: 2
+store/load 3: 3
+store/load 4: 4
+store/load 5: 5
+exchange 0: old=5 new=0
+exchange 1: old=0 new=1
+exchange 2: old=1 new=2
+exchange 3: old=2 new=3
+exchange 4: old=3 new=4
+exchange 5: old=4 new=5
+compare_exchange_weak 5: success = false
+compare_exchange_strong 5: success = false
+fetch_add 0: old=0 new=1
+fetch_add 1: old=1 new=2
+fetch_add 2: old=2 new=3
+fetch_add 3: old=3 new=4
+fetch_add 4: old=4 new=5
+fetch_add 5: old=5 new=6
+fetch_sub 0: old=6 new=5
+fetch_sub 1: old=5 new=4
+fetch_sub 2: old=4 new=3
+fetch_sub 3: old=3 new=2
+fetch_sub 4: old=2 new=1
+fetch_sub 5: old=1 new=0
+fetch_and 0: old=ffffffffffffffff, new=1
+fetch_and 1: old=ffffffffffffffff, new=2
+fetch_and 2: old=ffffffffffffffff, new=4
+fetch_and 3: old=ffffffffffffffff, new=8
+fetch_and 4: old=ffffffffffffffff, new=10
+fetch_and 5: old=ffffffffffffffff, new=20
+fetch_or 0: old=0, new=1
+fetch_or 1: old=1, new=3
+fetch_or 2: old=3, new=7
+fetch_or 3: old=7, new=f
+fetch_or 4: old=f, new=1f
+fetch_or 5: old=1f, new=3f
+fetch_xor 0: old=0, new=1
+fetch_xor 1: old=1, new=3
+fetch_xor 2: old=3, new=7
+fetch_xor 3: old=7, new=f
+fetch_xor 4: old=f, new=1f
+fetch_xor 5: old=1f, new=3f
+operator++: 1
+operator--: 0
+operator+=: 10
+operator-=: 5
+operator|=: ffffffffffffffff
+operator|=: f0f0f0f0f0f0f0f0
+operator^=: ffffffffffffffff
atomic_flag: false
done.