From 6339f93279b24b5a61eeed2a5040b8b2a0d3ab42 Mon Sep 17 00:00:00 2001 From: Kwok Cheung Yeung Date: Thu, 6 Aug 2020 13:52:52 +0200 Subject: [PATCH] [testsuite] Add gcc.dg/ia64-sync-5.c 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. 2020-08-06 Kwok Cheung Yeung Tom de Vries 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(+) create mode 100644 gcc/testsuite/gcc.dg/ia64-sync-5.c 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 0000000..8b16b29b --- /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; +} -- 2.7.4