1/* { dg-do run } */
2/* { dg-require-effective-target sync_int_long } */
3/* { dg-options } */
4/* { dg-options "-march=i486" { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
5/* { dg-options "-mcpu=v9" { target sparc*-*-* } } */
6
7/* Test basic functionality of the intrinsics.  */
8
9__extension__ typedef __SIZE_TYPE__ size_t;
10
11extern void abort (void);
12extern void *memcpy (void *, const void *, size_t);
13
14static int AI[4];
15static int init_si[4] = { -30,-30,-50,-50 };
16static int test_si[4] = { -115,-115,25,25 };
17
18static void
19do_si (void)
20{
21  if (__sync_val_compare_and_swap(AI+0, -30, -115) != -30)
22    abort ();
23  if (__sync_val_compare_and_swap(AI+0, -30, -115) != -115)
24    abort ();
25  if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 1)
26    abort ();
27  if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 0)
28    abort ();
29
30  if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != -50)
31    abort ();
32  if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != 25)
33    abort ();
34  if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1)
35    abort ();
36  if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1)
37    abort ();
38}
39
40static long AL[4];
41static long init_di[4] = { -30,-30,-50,-50 };
42static long test_di[4] = { -115,-115,25,25 };
43
44static void
45do_di (void)
46{
47  if (__sync_val_compare_and_swap(AL+0, -30, -115) != -30)
48    abort ();
49  if (__sync_val_compare_and_swap(AL+0, -30, -115) != -115)
50    abort ();
51  if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 1)
52    abort ();
53  if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 0)
54    abort ();
55
56  if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != -50)
57    abort ();
58  if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != 25)
59    abort ();
60  if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1)
61    abort ();
62  if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1)
63    abort ();
64}
65
66int main()
67{
68  memcpy(AI, init_si, sizeof(init_si));
69  memcpy(AL, init_di, sizeof(init_di));
70
71  do_si ();
72  do_di ();
73
74  if (memcmp (AI, test_si, sizeof(test_si)))
75    abort ();
76  if (memcmp (AL, test_di, sizeof(test_di)))
77    abort ();
78
79  return 0;
80}
81