atomic-compare-exchange-5.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* Test __atomic routines for existence and proper execution on 16 byte
  2. values with each valid memory model. */
  3. /* { dg-do run } */
  4. /* { dg-require-effective-target int128 } */
  5. /* Test the execution of __atomic_compare_exchange_n builtin for an int_128. */
  6. extern void abort(void);
  7. __int128_t v = 0;
  8. __int128_t expected = 0;
  9. __int128_t max = ~0;
  10. __int128_t desired = ~0;
  11. __int128_t zero = 0;
  12. #define STRONG 0
  13. #define WEAK 1
  14. int
  15. main ()
  16. {
  17. if (!__atomic_compare_exchange_n (&v, &expected, max, STRONG , __ATOMIC_RELAXED, __ATOMIC_RELAXED))
  18. abort ();
  19. if (expected != 0)
  20. abort ();
  21. if (__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
  22. abort ();
  23. if (expected != max)
  24. abort ();
  25. if (!__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
  26. abort ();
  27. if (expected != max)
  28. abort ();
  29. if (v != 0)
  30. abort ();
  31. if (__atomic_compare_exchange_n (&v, &expected, desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
  32. abort ();
  33. if (expected != 0)
  34. abort ();
  35. if (!__atomic_compare_exchange_n (&v, &expected, desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
  36. abort ();
  37. if (expected != 0)
  38. abort ();
  39. if (v != max)
  40. abort ();
  41. /* Now test the generic version. */
  42. v = 0;
  43. if (!__atomic_compare_exchange (&v, &expected, &max, STRONG, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
  44. abort ();
  45. if (expected != 0)
  46. abort ();
  47. if (__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED))
  48. abort ();
  49. if (expected != max)
  50. abort ();
  51. if (!__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE))
  52. abort ();
  53. if (expected != max)
  54. abort ();
  55. if (v != 0)
  56. abort ();
  57. if (__atomic_compare_exchange (&v, &expected, &desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE))
  58. abort ();
  59. if (expected != 0)
  60. abort ();
  61. if (!__atomic_compare_exchange (&v, &expected, &desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
  62. abort ();
  63. if (expected != 0)
  64. abort ();
  65. if (v != max)
  66. abort ();
  67. return 0;
  68. }