OSDN Git Service

e718c1115e2928d341ab66d6a32397df943141cd
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / ia64-sync-3.c
1 /* { dg-do run { target ia64-*-* } } */
2 /* { dg-options } */
3
4 /* Test basic functionality of the intrinsics.  */
5
6 #include <ia64intrin.h>
7
8 static int AI[4];
9 static int init_si[4] = { -30,-30,-50,-50 };
10 static int test_si[4] = { -115,-115,25,25 };
11
12 static void
13 do_si (void)
14 {
15   if (__sync_val_compare_and_swap(AI+0, -30, -115) != -30)
16     abort ();
17   if (__sync_val_compare_and_swap(AI+0, -30, -115) != -115)
18     abort ();
19   if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 1)
20     abort ();
21   if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 0)
22     abort ();
23
24   if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != -50)
25     abort ();
26   if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != 25)
27     abort ();
28   if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1)
29     abort ();
30   if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1)
31     abort ();
32 }
33
34 static long AL[4];
35 static long init_di[4] = { -30,-30,-50,-50 };
36 static long test_di[4] = { -115,-115,25,25 };
37
38 static void
39 do_di (void)
40 {
41   if (__sync_val_compare_and_swap(AL+0, -30, -115) != -30)
42     abort ();
43   if (__sync_val_compare_and_swap(AL+0, -30, -115) != -115)
44     abort ();
45   if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 1)
46     abort ();
47   if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 0)
48     abort ();
49
50   if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != -50)
51     abort ();
52   if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != 25)
53     abort ();
54   if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1)
55     abort ();
56   if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1)
57     abort ();
58 }
59
60 int main()
61 {
62   memcpy(AI, init_si, sizeof(init_si));
63   memcpy(AL, init_di, sizeof(init_di));
64
65   do_si ();
66   do_di ();
67
68   if (memcmp (AI, test_si, sizeof(test_si)))
69     abort ();
70   if (memcmp (AL, test_di, sizeof(test_di)))
71     abort ();
72
73   return 0;
74 }