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