OSDN Git Service

2006-05-20 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / ia64-sync-3.c
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 extern void abort (void);
10 extern void *memcpy (void *, const void *, __SIZE_TYPE__);
11
12 static int AI[4];
13 static int init_si[4] = { -30,-30,-50,-50 };
14 static int test_si[4] = { -115,-115,25,25 };
15
16 static void
17 do_si (void)
18 {
19   if (__sync_val_compare_and_swap(AI+0, -30, -115) != -30)
20     abort ();
21   if (__sync_val_compare_and_swap(AI+0, -30, -115) != -115)
22     abort ();
23   if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 1)
24     abort ();
25   if (__sync_bool_compare_and_swap(AI+1, -30, -115) != 0)
26     abort ();
27
28   if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != -50)
29     abort ();
30   if (__sync_val_compare_and_swap(AI+2, AI[2], 25) != 25)
31     abort ();
32   if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1)
33     abort ();
34   if (__sync_bool_compare_and_swap(AI+3, AI[3], 25) != 1)
35     abort ();
36 }
37
38 static long AL[4];
39 static long init_di[4] = { -30,-30,-50,-50 };
40 static long test_di[4] = { -115,-115,25,25 };
41
42 static void
43 do_di (void)
44 {
45   if (__sync_val_compare_and_swap(AL+0, -30, -115) != -30)
46     abort ();
47   if (__sync_val_compare_and_swap(AL+0, -30, -115) != -115)
48     abort ();
49   if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 1)
50     abort ();
51   if (__sync_bool_compare_and_swap(AL+1, -30, -115) != 0)
52     abort ();
53
54   if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != -50)
55     abort ();
56   if (__sync_val_compare_and_swap(AL+2, AL[2], 25) != 25)
57     abort ();
58   if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1)
59     abort ();
60   if (__sync_bool_compare_and_swap(AL+3, AL[3], 25) != 1)
61     abort ();
62 }
63
64 int main()
65 {
66   memcpy(AI, init_si, sizeof(init_si));
67   memcpy(AL, init_di, sizeof(init_di));
68
69   do_si ();
70   do_di ();
71
72   if (memcmp (AI, test_si, sizeof(test_si)))
73     abort ();
74   if (memcmp (AL, test_di, sizeof(test_di)))
75     abort ();
76
77   return 0;
78 }