(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
aarch64/
atomic-inst-cas.c
       1  /* { dg-do compile } */
       2  /* -Winvalid-memory-model warnings are issued before the dead invalid calls
       3     are removed.  */
       4  /* { dg-options "-O2 -march=armv8-a+lse -Wno-invalid-memory-model" } */
       5  
       6  /* Test ARMv8.1-A CAS instruction.  */
       7  
       8  #include "atomic-inst-ops.inc"
       9  
      10  #define TEST TEST_TWO
      11  
      12  #define CAS_ATOMIC(FN, TY, MODEL1, MODEL2)				\
      13    int FNNAME (FN, TY) (TY* val, TY* foo, TY* bar)			\
      14    {									\
      15      int model_s = MODEL1;						\
      16      int model_f = MODEL2;						\
      17      /* The success memory ordering must be at least as strong as	\
      18         the failure memory ordering.  */					\
      19      if (model_s < model_f)						\
      20        return 0;								\
      21      /* Ignore invalid memory orderings.  */				\
      22      if (model_f == __ATOMIC_RELEASE || model_f == __ATOMIC_ACQ_REL)	\
      23        return 0;								\
      24      return __atomic_compare_exchange_n (val, foo, bar, 0, model_s, model_f); \
      25    }
      26  
      27  #define CAS_ATOMIC_NORETURN(FN, TY, MODEL1, MODEL2)			\
      28    void FNNAME (FN, TY) (TY* val, TY* foo, TY* bar)			\
      29    {									\
      30      int model_s = MODEL1;						\
      31      int model_f = MODEL2;						\
      32      /* The success memory ordering must be at least as strong as	\
      33         the failure memory ordering.  */					\
      34      if (model_s < model_f)						\
      35        return;								\
      36      /* Ignore invalid memory orderings.  */				\
      37      if (model_f == __ATOMIC_RELEASE || model_f == __ATOMIC_ACQ_REL)	\
      38        return;								\
      39      __atomic_compare_exchange_n (val, foo, bar, 0, model_s, model_f);	\
      40    }
      41  
      42  TEST (cas_atomic, CAS_ATOMIC)
      43  TEST (cas_atomic_noreturn, CAS_ATOMIC_NORETURN)
      44  
      45  
      46  /* { dg-final { scan-assembler-times "casb\t" 4} } */
      47  /* { dg-final { scan-assembler-times "casab\t" 20} } */
      48  /* { dg-final { scan-assembler-times "caslb\t" 4} } */
      49  /* { dg-final { scan-assembler-times "casalb\t" 36} } */
      50  
      51  /* { dg-final { scan-assembler-times "cash\t" 4} } */
      52  /* { dg-final { scan-assembler-times "casah\t" 20} } */
      53  /* { dg-final { scan-assembler-times "caslh\t" 4} } */
      54  /* { dg-final { scan-assembler-times "casalh\t" 36} } */
      55  
      56  /* { dg-final { scan-assembler-times "cas\t" 8} } */
      57  /* { dg-final { scan-assembler-times "casa\t" 40} } */
      58  /* { dg-final { scan-assembler-times "casl\t" 8} } */
      59  /* { dg-final { scan-assembler-times "casal\t" 72} } */
      60  
      61  /* { dg-final { scan-assembler-not "ldaxr\t" } } */
      62  /* { dg-final { scan-assembler-not "stlxr\t" } } */
      63  /* { dg-final { scan-assembler-not "dmb" } } */