OSDN Git Service

gcc/testsuite/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / di-longlong64-sync-1.c
1 /* { dg-do run } */
2 /* { dg-require-effective-target sync_longlong } */
3 /* { dg-options "-std=gnu99" } */
4 /* { dg-message "note: '__sync_fetch_and_nand' changed semantics in GCC 4.4" "" { target *-*-* } 0 } */
5 /* { dg-message "note: '__sync_nand_and_fetch' changed semantics in GCC 4.4" "" { target *-*-* } 0 } */
6
7
8 /* Test basic functionality of the intrinsics.  The operations should
9    not be optimized away if no one checks the return values.  */
10
11 /* Based on ia64-sync-[12].c, but 1) long on ARM is 32 bit so use long long
12    (an explicit 64bit type maybe a better bet) and 2) Use values that cross
13    the 32bit boundary and cause carries since the actual maths are done as
14    pairs of 32 bit instructions.  */
15
16 /* Note: This file is #included by some of the ARM tests.  */
17
18 __extension__ typedef __SIZE_TYPE__ size_t;
19
20 extern void abort (void);
21 extern void *memcpy (void *, const void *, size_t);
22 extern int memcmp (const void *, const void *, size_t);
23
24 /* Temporary space where the work actually gets done.  */
25 static long long AL[24];
26 /* Values copied into AL before we start.  */
27 static long long init_di[24] = { 0x100000002ll, 0x200000003ll, 0, 1,
28
29                                  0x100000002ll, 0x100000002ll,
30                                  0x100000002ll, 0x100000002ll,
31
32                                  0, 0x1000e0de0000ll,
33                                  42 , 0xc001c0de0000ll,
34
35                                  -1ll, 0, 0xff00ff0000ll, -1ll,
36
37                                  0, 0x1000e0de0000ll,
38                                  42 , 0xc001c0de0000ll,
39
40                                  -1ll, 0, 0xff00ff0000ll, -1ll};
41 /* This is what should be in AL at the end.  */
42 static long long test_di[24] = { 0x1234567890ll, 0x1234567890ll, 1, 0,
43
44                                  0x100000002ll, 0x100000002ll,
45                                  0x100000002ll, 0x100000002ll,
46
47                                  1, 0xc001c0de0000ll,
48                                  20, 0x1000e0de0000ll,
49
50                                  0x300000007ll , 0x500000009ll,
51                                  0xf100ff0001ll, ~0xa00000007ll,
52
53                                  1, 0xc001c0de0000ll,
54                                  20, 0x1000e0de0000ll,
55
56                                  0x300000007ll , 0x500000009ll,
57                                  0xf100ff0001ll, ~0xa00000007ll };
58
59 /* First check they work in terms of what they do to memory.  */
60 static void
61 do_noret_di (void)
62 {
63   __sync_val_compare_and_swap (AL+0, 0x100000002ll, 0x1234567890ll);
64   __sync_bool_compare_and_swap (AL+1, 0x200000003ll, 0x1234567890ll);
65   __sync_lock_test_and_set (AL+2, 1);
66   __sync_lock_release (AL+3);
67
68   /* The following tests should not change the value since the
69      original does NOT match.  */
70   __sync_val_compare_and_swap (AL+4, 0x000000002ll, 0x1234567890ll);
71   __sync_val_compare_and_swap (AL+5, 0x100000000ll, 0x1234567890ll);
72   __sync_bool_compare_and_swap (AL+6, 0x000000002ll, 0x1234567890ll);
73   __sync_bool_compare_and_swap (AL+7, 0x100000000ll, 0x1234567890ll);
74
75   __sync_fetch_and_add (AL+8, 1);
76   __sync_fetch_and_add (AL+9, 0xb000e0000000ll); /* + to both halves & carry.  */
77   __sync_fetch_and_sub (AL+10, 22);
78   __sync_fetch_and_sub (AL+11, 0xb000e0000000ll);
79
80   __sync_fetch_and_and (AL+12, 0x300000007ll);
81   __sync_fetch_and_or (AL+13, 0x500000009ll);
82   __sync_fetch_and_xor (AL+14, 0xe00000001ll);
83   __sync_fetch_and_nand (AL+15, 0xa00000007ll);
84
85   /* These should be the same as the fetch_and_* cases except for
86      return value.  */
87   __sync_add_and_fetch (AL+16, 1);
88   /* add to both halves & carry.  */
89   __sync_add_and_fetch (AL+17, 0xb000e0000000ll);
90   __sync_sub_and_fetch (AL+18, 22);
91   __sync_sub_and_fetch (AL+19, 0xb000e0000000ll);
92
93   __sync_and_and_fetch (AL+20, 0x300000007ll);
94   __sync_or_and_fetch (AL+21, 0x500000009ll);
95   __sync_xor_and_fetch (AL+22, 0xe00000001ll);
96   __sync_nand_and_fetch (AL+23, 0xa00000007ll);
97 }
98
99 /* Now check return values.  */
100 static void
101 do_ret_di (void)
102 {
103   if (__sync_val_compare_and_swap (AL+0, 0x100000002ll, 0x1234567890ll) !=
104         0x100000002ll) abort ();
105   if (__sync_bool_compare_and_swap (AL+1, 0x200000003ll, 0x1234567890ll) !=
106         1) abort ();
107   if (__sync_lock_test_and_set (AL+2, 1) != 0) abort ();
108   __sync_lock_release (AL+3); /* no return value, but keep to match results.  */
109
110   /* The following tests should not change the value since the
111      original does NOT match.  */
112   if (__sync_val_compare_and_swap (AL+4, 0x000000002ll, 0x1234567890ll) !=
113         0x100000002ll) abort ();
114   if (__sync_val_compare_and_swap (AL+5, 0x100000000ll, 0x1234567890ll) !=
115         0x100000002ll) abort ();
116   if (__sync_bool_compare_and_swap (AL+6, 0x000000002ll, 0x1234567890ll) !=
117         0) abort ();
118   if (__sync_bool_compare_and_swap (AL+7, 0x100000000ll, 0x1234567890ll) !=
119         0) abort ();
120
121   if (__sync_fetch_and_add (AL+8, 1) != 0) abort ();
122   if (__sync_fetch_and_add (AL+9, 0xb000e0000000ll) != 0x1000e0de0000ll) abort ();
123   if (__sync_fetch_and_sub (AL+10, 22) != 42) abort ();
124   if (__sync_fetch_and_sub (AL+11, 0xb000e0000000ll) != 0xc001c0de0000ll)
125         abort ();
126
127   if (__sync_fetch_and_and (AL+12, 0x300000007ll) != -1ll) abort ();
128   if (__sync_fetch_and_or (AL+13, 0x500000009ll) != 0) abort ();
129   if (__sync_fetch_and_xor (AL+14, 0xe00000001ll) != 0xff00ff0000ll) abort ();
130   if (__sync_fetch_and_nand (AL+15, 0xa00000007ll) != -1ll) abort ();
131
132   /* These should be the same as the fetch_and_* cases except for
133      return value.  */
134   if (__sync_add_and_fetch (AL+16, 1) != 1) abort ();
135   if (__sync_add_and_fetch (AL+17, 0xb000e0000000ll) != 0xc001c0de0000ll)
136         abort ();
137   if (__sync_sub_and_fetch (AL+18, 22) != 20) abort ();
138   if (__sync_sub_and_fetch (AL+19, 0xb000e0000000ll) != 0x1000e0de0000ll)
139         abort ();
140
141   if (__sync_and_and_fetch (AL+20, 0x300000007ll) != 0x300000007ll) abort ();
142   if (__sync_or_and_fetch (AL+21, 0x500000009ll) != 0x500000009ll) abort ();
143   if (__sync_xor_and_fetch (AL+22, 0xe00000001ll) != 0xf100ff0001ll) abort ();
144   if (__sync_nand_and_fetch (AL+23, 0xa00000007ll) != ~0xa00000007ll) abort ();
145 }
146
147 int main ()
148 {
149   memcpy (AL, init_di, sizeof (init_di));
150
151   do_noret_di ();
152
153   if (memcmp (AL, test_di, sizeof (test_di)))
154     abort ();
155
156   memcpy (AL, init_di, sizeof (init_di));
157
158   do_ret_di ();
159
160   if (memcmp (AL, test_di, sizeof (test_di)))
161     abort ();
162
163   return 0;
164 }