(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
atomic-generic-aux.c
       1  /* Supply a set of generic atomic functions to test the compiler make the
       2     calls properly.  */
       3  /* { dg-do compile } */
       4  /* { dg-options "-w" } */
       5  
       6  /* Test that the generic builtins make calls as expected.  */
       7  
       8  #include <stdlib.h>
       9  #include <stdbool.h>
      10  #include <string.h>
      11  
      12  void
      13  __atomic_exchange (size_t size, void *obj, void *val, void *ret, int model)
      14  {
      15    /* Copy old value into *ret.  */
      16    memcpy (ret, obj, size);
      17    /* Copy val into object.  */
      18    memcpy (obj, val, size);
      19  }
      20  
      21  
      22  /* Note that the external version of this routine has the boolean weak/strong
      23     parameter removed.  This is required by the external library.  */
      24  bool
      25  __atomic_compare_exchange (size_t size, void *obj, void *expected,
      26  			   void *desired, int model1, int model2)
      27  {
      28    bool ret;
      29    if (!memcmp (obj, expected, size))
      30      {
      31        memcpy (obj, desired, size);
      32        ret = true;
      33      }
      34    else
      35      {
      36        memcpy (expected, obj, size);
      37        ret = false;
      38      }
      39  
      40    /* Make sure the parameters have been properly adjusted for the external
      41       function call (no weak/strong parameter.  */
      42    if (model1 != __ATOMIC_SEQ_CST || model2 != __ATOMIC_ACQUIRE)
      43      ret = !ret;
      44  
      45    return ret;
      46  }
      47  
      48  
      49  void __atomic_load (size_t size, void *obj, void *ret, int model)
      50  {
      51    memcpy (ret, obj, size);
      52  }
      53  
      54  
      55  void __atomic_store (size_t size, void *obj, void *val, int model)
      56  {
      57    memcpy (obj, val, size);
      58  }