1 /* Test __atomic routines for existence and proper execution on 1 byte
2 values with each valid memory model. */
4 /* { dg-require-effective-target sync_char_short } */
6 /* Test the execution of the __atomic_*OP builtin routines for a char. */
8 extern void abort(void);
13 /* The fetch_op routines return the original value before the operation. */
21 if (__atomic_fetch_add (&v, count, __ATOMIC_RELAXED) != 0)
24 if (__atomic_fetch_add (&v, 1, __ATOMIC_CONSUME) != 1)
27 if (__atomic_fetch_add (&v, count, __ATOMIC_ACQUIRE) != 2)
30 if (__atomic_fetch_add (&v, 1, __ATOMIC_RELEASE) != 3)
33 if (__atomic_fetch_add (&v, count, __ATOMIC_ACQ_REL) != 4)
36 if (__atomic_fetch_add (&v, 1, __ATOMIC_SEQ_CST) != 5)
47 if (__atomic_fetch_sub (&v, count + 1, __ATOMIC_RELAXED) != res--)
50 if (__atomic_fetch_sub (&v, 1, __ATOMIC_CONSUME) != res--)
53 if (__atomic_fetch_sub (&v, count + 1, __ATOMIC_ACQUIRE) != res--)
56 if (__atomic_fetch_sub (&v, 1, __ATOMIC_RELEASE) != res--)
59 if (__atomic_fetch_sub (&v, count + 1, __ATOMIC_ACQ_REL) != res--)
62 if (__atomic_fetch_sub (&v, 1, __ATOMIC_SEQ_CST) != res--)
71 if (__atomic_fetch_and (&v, 0, __ATOMIC_RELAXED) != init)
74 if (__atomic_fetch_and (&v, init, __ATOMIC_CONSUME) != 0)
77 if (__atomic_fetch_and (&v, 0, __ATOMIC_ACQUIRE) != 0)
81 if (__atomic_fetch_and (&v, init, __ATOMIC_RELEASE) != init)
84 if (__atomic_fetch_and (&v, 0, __ATOMIC_ACQ_REL) != init)
87 if (__atomic_fetch_and (&v, 0, __ATOMIC_SEQ_CST) != 0)
96 if (__atomic_fetch_nand (&v, 0, __ATOMIC_RELAXED) != init)
99 if (__atomic_fetch_nand (&v, init, __ATOMIC_CONSUME) != init)
102 if (__atomic_fetch_nand (&v, 0, __ATOMIC_ACQUIRE) != 0 )
105 if (__atomic_fetch_nand (&v, init, __ATOMIC_RELEASE) != init)
108 if (__atomic_fetch_nand (&v, init, __ATOMIC_ACQ_REL) != 0)
111 if (__atomic_fetch_nand (&v, 0, __ATOMIC_SEQ_CST) != init)
121 if (__atomic_fetch_xor (&v, count, __ATOMIC_RELAXED) != init)
124 if (__atomic_fetch_xor (&v, ~count, __ATOMIC_CONSUME) != init)
127 if (__atomic_fetch_xor (&v, 0, __ATOMIC_ACQUIRE) != 0)
130 if (__atomic_fetch_xor (&v, ~count, __ATOMIC_RELEASE) != 0)
133 if (__atomic_fetch_xor (&v, 0, __ATOMIC_ACQ_REL) != init)
136 if (__atomic_fetch_xor (&v, ~count, __ATOMIC_SEQ_CST) != init)
146 if (__atomic_fetch_or (&v, count, __ATOMIC_RELAXED) != 0)
150 if (__atomic_fetch_or (&v, 2, __ATOMIC_CONSUME) != 1)
154 if (__atomic_fetch_or (&v, count, __ATOMIC_ACQUIRE) != 3)
158 if (__atomic_fetch_or (&v, 8, __ATOMIC_RELEASE) != 7)
162 if (__atomic_fetch_or (&v, count, __ATOMIC_ACQ_REL) != 15)
166 if (__atomic_fetch_or (&v, count, __ATOMIC_SEQ_CST) != 31)
170 /* The OP_fetch routines return the new value after the operation. */
178 if (__atomic_add_fetch (&v, count, __ATOMIC_RELAXED) != 1)
181 if (__atomic_add_fetch (&v, 1, __ATOMIC_CONSUME) != 2)
184 if (__atomic_add_fetch (&v, count, __ATOMIC_ACQUIRE) != 3)
187 if (__atomic_add_fetch (&v, 1, __ATOMIC_RELEASE) != 4)
190 if (__atomic_add_fetch (&v, count, __ATOMIC_ACQ_REL) != 5)
193 if (__atomic_add_fetch (&v, count, __ATOMIC_SEQ_CST) != 6)
204 if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_RELAXED) != --res)
207 if (__atomic_sub_fetch (&v, 1, __ATOMIC_CONSUME) != --res)
210 if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_ACQUIRE) != --res)
213 if (__atomic_sub_fetch (&v, 1, __ATOMIC_RELEASE) != --res)
216 if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_ACQ_REL) != --res)
219 if (__atomic_sub_fetch (&v, count + 1, __ATOMIC_SEQ_CST) != --res)
228 if (__atomic_and_fetch (&v, 0, __ATOMIC_RELAXED) != 0)
232 if (__atomic_and_fetch (&v, init, __ATOMIC_CONSUME) != init)
235 if (__atomic_and_fetch (&v, 0, __ATOMIC_ACQUIRE) != 0)
239 if (__atomic_and_fetch (&v, init, __ATOMIC_RELEASE) != init)
242 if (__atomic_and_fetch (&v, 0, __ATOMIC_ACQ_REL) != 0)
246 if (__atomic_and_fetch (&v, 0, __ATOMIC_SEQ_CST) != 0)
255 if (__atomic_nand_fetch (&v, 0, __ATOMIC_RELAXED) != init)
258 if (__atomic_nand_fetch (&v, init, __ATOMIC_CONSUME) != 0)
261 if (__atomic_nand_fetch (&v, 0, __ATOMIC_ACQUIRE) != init)
264 if (__atomic_nand_fetch (&v, init, __ATOMIC_RELEASE) != 0)
267 if (__atomic_nand_fetch (&v, init, __ATOMIC_ACQ_REL) != init)
270 if (__atomic_nand_fetch (&v, 0, __ATOMIC_SEQ_CST) != init)
282 if (__atomic_xor_fetch (&v, count, __ATOMIC_RELAXED) != init)
285 if (__atomic_xor_fetch (&v, ~count, __ATOMIC_CONSUME) != 0)
288 if (__atomic_xor_fetch (&v, 0, __ATOMIC_ACQUIRE) != 0)
291 if (__atomic_xor_fetch (&v, ~count, __ATOMIC_RELEASE) != init)
294 if (__atomic_xor_fetch (&v, 0, __ATOMIC_ACQ_REL) != init)
297 if (__atomic_xor_fetch (&v, ~count, __ATOMIC_SEQ_CST) != 0)
307 if (__atomic_or_fetch (&v, count, __ATOMIC_RELAXED) != 1)
311 if (__atomic_or_fetch (&v, 2, __ATOMIC_CONSUME) != 3)
315 if (__atomic_or_fetch (&v, count, __ATOMIC_ACQUIRE) != 7)
319 if (__atomic_or_fetch (&v, 8, __ATOMIC_RELEASE) != 15)
323 if (__atomic_or_fetch (&v, count, __ATOMIC_ACQ_REL) != 31)
327 if (__atomic_or_fetch (&v, count, __ATOMIC_SEQ_CST) != 63)
332 /* Test the OP routines with a result which isn't used. Use both variations
333 within each function. */
341 __atomic_add_fetch (&v, count, __ATOMIC_RELAXED);
345 __atomic_fetch_add (&v, count, __ATOMIC_CONSUME);
349 __atomic_add_fetch (&v, 1 , __ATOMIC_ACQUIRE);
353 __atomic_fetch_add (&v, 1, __ATOMIC_RELEASE);
357 __atomic_add_fetch (&v, count, __ATOMIC_ACQ_REL);
361 __atomic_fetch_add (&v, count, __ATOMIC_SEQ_CST);
373 __atomic_sub_fetch (&v, count + 1, __ATOMIC_RELAXED);
377 __atomic_fetch_sub (&v, count + 1, __ATOMIC_CONSUME);
381 __atomic_sub_fetch (&v, 1, __ATOMIC_ACQUIRE);
385 __atomic_fetch_sub (&v, 1, __ATOMIC_RELEASE);
389 __atomic_sub_fetch (&v, count + 1, __ATOMIC_ACQ_REL);
393 __atomic_fetch_sub (&v, count + 1, __ATOMIC_SEQ_CST);
403 __atomic_and_fetch (&v, 0, __ATOMIC_RELAXED);
408 __atomic_fetch_and (&v, init, __ATOMIC_CONSUME);
412 __atomic_and_fetch (&v, 0, __ATOMIC_ACQUIRE);
417 __atomic_fetch_and (&v, init, __ATOMIC_RELEASE);
421 __atomic_and_fetch (&v, 0, __ATOMIC_ACQ_REL);
426 __atomic_fetch_and (&v, 0, __ATOMIC_SEQ_CST);
436 __atomic_fetch_nand (&v, 0, __ATOMIC_RELAXED);
440 __atomic_fetch_nand (&v, init, __ATOMIC_CONSUME);
444 __atomic_nand_fetch (&v, 0, __ATOMIC_ACQUIRE);
448 __atomic_nand_fetch (&v, init, __ATOMIC_RELEASE);
452 __atomic_fetch_nand (&v, init, __ATOMIC_ACQ_REL);
456 __atomic_nand_fetch (&v, 0, __ATOMIC_SEQ_CST);
469 __atomic_xor_fetch (&v, count, __ATOMIC_RELAXED);
473 __atomic_fetch_xor (&v, ~count, __ATOMIC_CONSUME);
477 __atomic_xor_fetch (&v, 0, __ATOMIC_ACQUIRE);
481 __atomic_fetch_xor (&v, ~count, __ATOMIC_RELEASE);
485 __atomic_fetch_xor (&v, 0, __ATOMIC_ACQ_REL);
489 __atomic_xor_fetch (&v, ~count, __ATOMIC_SEQ_CST);
500 __atomic_or_fetch (&v, count, __ATOMIC_RELAXED);
505 __atomic_fetch_or (&v, count, __ATOMIC_CONSUME);
510 __atomic_or_fetch (&v, 4, __ATOMIC_ACQUIRE);
515 __atomic_fetch_or (&v, 8, __ATOMIC_RELEASE);
520 __atomic_or_fetch (&v, count, __ATOMIC_ACQ_REL);
525 __atomic_fetch_or (&v, count, __ATOMIC_SEQ_CST);