(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
atomic-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 the __atomic_X builtin for a long_long.  */
       9  
      10  extern void abort(void);
      11  
      12  long long v, count, ret;
      13  
      14  int
      15  main ()
      16  {
      17    v = 0;
      18    count = 0;
      19  
      20    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELAXED) != count)
      21      abort ();
      22    count++;
      23  
      24    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQUIRE) != count)
      25      abort ();
      26    count++;
      27  
      28    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELEASE) != count)
      29      abort ();
      30    count++;
      31  
      32    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQ_REL) != count)
      33      abort ();
      34    count++;
      35  
      36    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_SEQ_CST) != count)
      37      abort ();
      38    count++;
      39  
      40    /* Now test the generic version.  */
      41  
      42    count++;
      43  
      44    __atomic_exchange (&v, &count, &ret, __ATOMIC_RELAXED);
      45    if (ret != count - 1 || v != count)
      46      abort ();
      47    count++;
      48  
      49    __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQUIRE);
      50    if (ret != count - 1 || v != count)
      51      abort ();
      52    count++;
      53  
      54    __atomic_exchange (&v, &count, &ret, __ATOMIC_RELEASE);
      55    if (ret != count - 1 || v != count)
      56      abort ();
      57    count++;
      58  
      59    __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQ_REL);
      60    if (ret != count - 1 || v != count)
      61      abort ();
      62    count++;
      63  
      64    __atomic_exchange (&v, &count, &ret, __ATOMIC_SEQ_CST);
      65    if (ret != count - 1 || v != count)
      66      abort ();
      67    count++;
      68  
      69    return 0;
      70  }