1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /* Test __atomic routines for existence and proper execution on 2 byte
- values with each valid memory model. */
- /* { dg-do run } */
- /* Test the execution of the __atomic_compare_exchange_n builtin for a short. */
- extern void abort(void);
- short v = 0;
- short expected = 0;
- short max = ~0;
- short desired = ~0;
- short zero = 0;
- #define STRONG 0
- #define WEAK 1
- int
- main ()
- {
- if (!__atomic_compare_exchange_n (&v, &expected, max, STRONG , __ATOMIC_RELAXED, __ATOMIC_RELAXED))
- abort ();
- if (expected != 0)
- abort ();
- if (__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
- abort ();
- if (expected != max)
- abort ();
- if (!__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
- abort ();
- if (expected != max)
- abort ();
- if (v != 0)
- abort ();
- if (__atomic_compare_exchange_n (&v, &expected, desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
- abort ();
- if (expected != 0)
- abort ();
- if (!__atomic_compare_exchange_n (&v, &expected, desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
- abort ();
- if (expected != 0)
- abort ();
- if (v != max)
- abort ();
- /* Now test the generic version. */
- v = 0;
- if (!__atomic_compare_exchange (&v, &expected, &max, STRONG, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
- abort ();
- if (expected != 0)
- abort ();
- if (__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
- abort ();
- if (expected != max)
- abort ();
- if (!__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
- abort ();
- if (expected != max)
- abort ();
- if (v != 0)
- abort ();
- if (__atomic_compare_exchange (&v, &expected, &desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
- abort ();
- if (expected != 0)
- abort ();
- if (!__atomic_compare_exchange (&v, &expected, &desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
- abort ();
- if (expected != 0)
- abort ();
- if (v != max)
- abort ();
- return 0;
- }
|