(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
riscv/
inline-atomics-8.c
       1  /* Test __atomic routines for existence and proper execution on 2 byte
       2     values with each valid memory model.  */
       3  /* Duplicate logic as libatomic/testsuite/libatomic.c/atomic-exchange-2.c */
       4  /* { dg-do run } */
       5  /* { dg-options "-minline-atomics" } */
       6  
       7  /* Test the execution of the __atomic_X builtin for a short.  */
       8  
       9  extern void abort(void);
      10  
      11  short v, count, ret;
      12  
      13  int
      14  main ()
      15  {
      16    v = 0;
      17    count = 0;
      18  
      19    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELAXED) != count)
      20      abort ();
      21    count++;
      22  
      23    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQUIRE) != count)
      24      abort ();
      25    count++;
      26  
      27    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_RELEASE) != count)
      28      abort ();
      29    count++;
      30  
      31    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_ACQ_REL) != count)
      32      abort ();
      33    count++;
      34  
      35    if (__atomic_exchange_n (&v, count + 1, __ATOMIC_SEQ_CST) != count)
      36      abort ();
      37    count++;
      38  
      39    /* Now test the generic version.  */
      40  
      41    count++;
      42  
      43    __atomic_exchange (&v, &count, &ret, __ATOMIC_RELAXED);
      44    if (ret != count - 1 || v != count)
      45      abort ();
      46    count++;
      47  
      48    __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQUIRE);
      49    if (ret != count - 1 || v != count)
      50      abort ();
      51    count++;
      52  
      53    __atomic_exchange (&v, &count, &ret, __ATOMIC_RELEASE);
      54    if (ret != count - 1 || v != count)
      55      abort ();
      56    count++;
      57  
      58    __atomic_exchange (&v, &count, &ret, __ATOMIC_ACQ_REL);
      59    if (ret != count - 1 || v != count)
      60      abort ();
      61    count++;
      62  
      63    __atomic_exchange (&v, &count, &ret, __ATOMIC_SEQ_CST);
      64    if (ret != count - 1 || v != count)
      65      abort ();
      66    count++;
      67  
      68    return 0;
      69  }