(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
atomic-compare-exchange-4.c
       1  /* Test __atomic routines for existence and proper execution on 8 byte 
       2     values with each valid memory model.  */
       3  /* { dg-do run } */
       4  /* { dg-require-effective-target sync_long_long_runtime } */
       5  /* { dg-options "" } */
       6  /* { dg-options "-march=pentium" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
       7  
       8  /* Test the execution of __atomic_compare_exchange_n builtin for a long_long.  */
       9  
      10  extern void abort(void);
      11  
      12  long long v = 0;
      13  long long expected = 0;
      14  long long max = ~0;
      15  long long desired = ~0;
      16  long long zero = 0;
      17  
      18  #define STRONG 0
      19  #define WEAK 1
      20  
      21  int
      22  main ()
      23  {
      24  
      25    if (!__atomic_compare_exchange_n (&v, &expected, max, STRONG , __ATOMIC_RELAXED, __ATOMIC_RELAXED)) 
      26      abort ();
      27    if (expected != 0)
      28      abort ();
      29  
      30    if (__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) 
      31      abort ();
      32    if (expected != max)
      33      abort ();
      34  
      35    if (!__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE)) 
      36      abort ();
      37    if (expected != max)
      38      abort ();
      39    if (v != 0)
      40      abort ();
      41  
      42    if (__atomic_compare_exchange_n (&v, &expected, desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) 
      43      abort ();
      44    if (expected != 0)
      45      abort ();
      46  
      47    if (!__atomic_compare_exchange_n (&v, &expected, desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) 
      48      abort ();
      49    if (expected != 0)
      50      abort ();
      51    if (v != max)
      52      abort ();
      53  
      54    /* Now test the generic version.  */
      55  
      56    v = 0;
      57  
      58    if (!__atomic_compare_exchange (&v, &expected, &max, STRONG, __ATOMIC_RELAXED, __ATOMIC_RELAXED))
      59      abort ();
      60    if (expected != 0)
      61      abort ();
      62  
      63    if (__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) 
      64      abort ();
      65    if (expected != max)
      66      abort ();
      67  
      68    if (!__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE)) 
      69      abort ();
      70    if (expected != max)
      71      abort ();
      72    if (v != 0)
      73      abort ();
      74  
      75    if (__atomic_compare_exchange (&v, &expected, &desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) 
      76      abort ();
      77    if (expected != 0)
      78      abort ();
      79  
      80    if (!__atomic_compare_exchange (&v, &expected, &desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) 
      81      abort ();
      82    if (expected != 0)
      83      abort ();
      84    if (v != max)
      85      abort ();
      86  
      87    return 0;
      88  }