summaryrefslogtreecommitdiffstats
path: root/libatomic/testsuite/libatomic.c/atomic-compare-exchange-3.c
diff options
context:
space:
mode:
authorrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-05-01 15:48:28 +0000
committerrth <rth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-05-01 15:48:28 +0000
commit6db1d2ca83f9327020b75f6c1610649bb18e71db (patch)
tree729dc91fa97f38042aa7777ca6267ebed2edb3e8 /libatomic/testsuite/libatomic.c/atomic-compare-exchange-3.c
parentd8219307493056ea48203be157f0cfb468698f2d (diff)
downloadppe42-gcc-6db1d2ca83f9327020b75f6c1610649bb18e71db.tar.gz
ppe42-gcc-6db1d2ca83f9327020b75f6c1610649bb18e71db.zip
Add libatomic as a target library.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@187018 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libatomic/testsuite/libatomic.c/atomic-compare-exchange-3.c')
-rw-r--r--libatomic/testsuite/libatomic.c/atomic-compare-exchange-3.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/libatomic/testsuite/libatomic.c/atomic-compare-exchange-3.c b/libatomic/testsuite/libatomic.c/atomic-compare-exchange-3.c
new file mode 100644
index 00000000000..26097288c9d
--- /dev/null
+++ b/libatomic/testsuite/libatomic.c/atomic-compare-exchange-3.c
@@ -0,0 +1,85 @@
+/* Test __atomic routines for existence and proper execution on 4 byte
+ values with each valid memory model. */
+/* { dg-do run } */
+/* { dg-require-effective-target sync_int_long } */
+
+/* Test the execution of the __atomic_compare_exchange_n builtin for an int. */
+
+extern void abort(void);
+
+int v = 0;
+int expected = 0;
+int max = ~0;
+int desired = ~0;
+int zero = 0;
+
+#define STRONG 0
+#define WEAK 1
+
+main ()
+{
+
+ if (!__atomic_compare_exchange_n (&v, &expected, max, STRONG , __ATOMIC_RELAXED, __ATOMIC_RELAXED))
+ abort ();
+ if (expected != 0)
+ abort ();
+
+ if (__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
+ abort ();
+ if (expected != max)
+ abort ();
+
+ if (!__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
+ abort ();
+ if (expected != max)
+ abort ();
+ if (v != 0)
+ abort ();
+
+ if (__atomic_compare_exchange_n (&v, &expected, desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
+ abort ();
+ if (expected != 0)
+ abort ();
+
+ if (!__atomic_compare_exchange_n (&v, &expected, desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
+ abort ();
+ if (expected != 0)
+ abort ();
+ if (v != max)
+ abort ();
+
+ /* Now test the generic version. */
+
+ v = 0;
+
+ if (!__atomic_compare_exchange (&v, &expected, &max, STRONG, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
+ abort ();
+ if (expected != 0)
+ abort ();
+
+ if (__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
+ abort ();
+ if (expected != max)
+ abort ();
+
+ if (!__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
+ abort ();
+ if (expected != max)
+ abort ();
+ if (v != 0)
+ abort ();
+
+ if (__atomic_compare_exchange (&v, &expected, &desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
+ abort ();
+ if (expected != 0)
+ abort ();
+
+ if (!__atomic_compare_exchange (&v, &expected, &desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
+ abort ();
+ if (expected != 0)
+ abort ();
+ if (v != max)
+ abort ();
+
+ return 0;
+}
OpenPOWER on IntegriCloud