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 } */
8 /* Test basic functionality of the intrinsics. The operations should
9 not be optimized away if no one checks the return values. */
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. */
16 /* Note: This file is #included by some of the ARM tests. */
18 __extension__ typedef __SIZE_TYPE__ size_t;
20 extern void abort (void);
21 extern void *memcpy (void *, const void *, size_t);
22 extern int memcmp (const void *, const void *, size_t);
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,
29 0x100000002ll, 0x100000002ll,
30 0x100000002ll, 0x100000002ll,
33 42 , 0xc001c0de0000ll,
35 -1ll, 0, 0xff00ff0000ll, -1ll,
38 42 , 0xc001c0de0000ll,
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,
44 0x100000002ll, 0x100000002ll,
45 0x100000002ll, 0x100000002ll,
50 0x300000007ll , 0x500000009ll,
51 0xf100ff0001ll, ~0xa00000007ll,
56 0x300000007ll , 0x500000009ll,
57 0xf100ff0001ll, ~0xa00000007ll };
59 /* First check they work in terms of what they do to memory. */
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);
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);
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);
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);
85 /* These should be the same as the fetch_and_* cases except for
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);
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);
99 /* Now check return values. */
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) !=
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. */
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) !=
118 if (__sync_bool_compare_and_swap (AL+7, 0x100000000ll, 0x1234567890ll) !=
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)
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 ();
132 /* These should be the same as the fetch_and_* cases except for
134 if (__sync_add_and_fetch (AL+16, 1) != 1) abort ();
135 if (__sync_add_and_fetch (AL+17, 0xb000e0000000ll) != 0xc001c0de0000ll)
137 if (__sync_sub_and_fetch (AL+18, 22) != 20) abort ();
138 if (__sync_sub_and_fetch (AL+19, 0xb000e0000000ll) != 0x1000e0de0000ll)
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 ();
149 memcpy (AL, init_di, sizeof (init_di));
153 if (memcmp (AL, test_di, sizeof (test_di)))
156 memcpy (AL, init_di, sizeof (init_di));
160 if (memcmp (AL, test_di, sizeof (test_di)))