diff mbox series

[testsuite] Add gcc.dg/ia64-sync-5.c

Message ID 20200806122351.GA20360@delia
State New
Headers show
Series [testsuite] Add gcc.dg/ia64-sync-5.c | expand

Commit Message

Tom de Vries Aug. 6, 2020, 12:23 p.m. UTC
Hi,

There currently is no sync_char_short-enabled run test that tests
__sync_val_compare_and_swap.

Fix this by copying ia64-sync-3.c and modifying it for char/short.

Tested on x86_64.

OK for trunk?

Thanks,
- Tom

[testsuite] Add gcc.dg/ia64-sync-5.c

2020-08-06  Kwok Cheung Yeung  <kcy@codesourcery.com>
	    Tom de Vries  <tdevries@suse.de>

gcc/testsuite/ChangeLog:

	* gcc.dg/ia64-sync-5.c: New test.

---
 gcc/testsuite/gcc.dg/ia64-sync-5.c | 83 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

Comments

Mike Stump Aug. 6, 2020, 11:55 p.m. UTC | #1
On Aug 6, 2020, at 5:23 AM, Tom de Vries <tdevries@suse.de> wrote:
> 
> There currently is no sync_char_short-enabled run test that tests
> __sync_val_compare_and_swap.
> 
> OK for trunk?

Ok.
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/ia64-sync-5.c b/gcc/testsuite/gcc.dg/ia64-sync-5.c
new file mode 100644
index 00000000000..8b16b29b20e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ia64-sync-5.c
@@ -0,0 +1,83 @@ 
+/* { dg-do run } */
+/* { dg-require-effective-target sync_char_short } */
+/* { dg-options } */
+/* { dg-options "-march=i486" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
+/* { dg-options "-mcpu=v9" { target sparc*-*-* } } */
+
+/* Test basic functionality of the intrinsics.  */
+
+/* This is a copy of gcc.dg/ia64-sync-3.c, for 8-bit and 16-bit.  */
+
+__extension__ typedef __SIZE_TYPE__ size_t;
+
+extern void abort (void);
+extern void *memcpy (void *, const void *, size_t);
+extern int memcmp (const void *, const void *, size_t);
+
+static char AC[4];
+static char init_qi[4] = { -30,-30,-50,-50 };
+static char test_qi[4] = { -115,-115,25,25 };
+
+static void
+do_qi (void)
+{
+  if (__sync_val_compare_and_swap(AC+0, -30, -115) != -30)
+    abort ();
+  if (__sync_val_compare_and_swap(AC+0, -30, -115) != -115)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+1, -30, -115) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+1, -30, -115) != 0)
+    abort ();
+
+  if (__sync_val_compare_and_swap(AC+2, AC[2], 25) != -50)
+    abort ();
+  if (__sync_val_compare_and_swap(AC+2, AC[2], 25) != 25)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+3, AC[3], 25) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AC+3, AC[3], 25) != 1)
+    abort ();
+}
+
+static short AS[4];
+static short init_hi[4] = { -30,-30,-50,-50 };
+static short test_hi[4] = { -115,-115,25,25 };
+
+static void
+do_hi (void)
+{
+  if (__sync_val_compare_and_swap(AS+0, -30, -115) != -30)
+    abort ();
+  if (__sync_val_compare_and_swap(AS+0, -30, -115) != -115)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+1, -30, -115) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+1, -30, -115) != 0)
+    abort ();
+
+  if (__sync_val_compare_and_swap(AS+2, AS[2], 25) != -50)
+    abort ();
+  if (__sync_val_compare_and_swap(AS+2, AS[2], 25) != 25)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+3, AS[3], 25) != 1)
+    abort ();
+  if (__sync_bool_compare_and_swap(AS+3, AS[3], 25) != 1)
+    abort ();
+}
+
+int main()
+{
+  memcpy(AC, init_qi, sizeof(init_qi));
+  memcpy(AS, init_hi, sizeof(init_hi));
+
+  do_qi ();
+  do_hi ();
+
+  if (memcmp (AC, test_qi, sizeof(test_qi)))
+    abort ();
+  if (memcmp (AS, test_hi, sizeof(test_hi)))
+    abort ();
+
+  return 0;
+}