summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/aarch64/atomic-inst-cas.c
blob: f6f2892231966037b58289fd06411ec8af7373fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* { dg-do compile } */
/* { dg-options "-O2 -march=armv8-a+lse" } */

/* Test ARMv8.1-A CAS instruction.  */

#include "atomic-inst-ops.inc"

#define TEST TEST_TWO

#define CAS_ATOMIC(FN, TY, MODEL1, MODEL2)				\
  int FNNAME (FN, TY) (TY* val, TY* foo, TY* bar)			\
  {									\
    int model_s = MODEL1;						\
    int model_f = MODEL2;						\
    /* The success memory ordering must be at least as strong as	\
       the failure memory ordering.  */					\
    if (model_s < model_f)						\
      return 0;								\
    /* Ignore invalid memory orderings.  */				\
    if (model_f == __ATOMIC_RELEASE || model_f == __ATOMIC_ACQ_REL)	\
      return 0;								\
    return __atomic_compare_exchange_n (val, foo, bar, 0, model_s, model_f); \
  }

#define CAS_ATOMIC_NORETURN(FN, TY, MODEL1, MODEL2)			\
  void FNNAME (FN, TY) (TY* val, TY* foo, TY* bar)			\
  {									\
    int model_s = MODEL1;						\
    int model_f = MODEL2;						\
    /* The success memory ordering must be at least as strong as	\
       the failure memory ordering.  */					\
    if (model_s < model_f)						\
      return;								\
    /* Ignore invalid memory orderings.  */				\
    if (model_f == __ATOMIC_RELEASE || model_f == __ATOMIC_ACQ_REL)	\
      return;								\
    __atomic_compare_exchange_n (val, foo, bar, 0, model_s, model_f);	\
  }

TEST (cas_atomic, CAS_ATOMIC)
TEST (cas_atomic_noreturn, CAS_ATOMIC_NORETURN)


/* { dg-final { scan-assembler-times "casb\t" 4} } */
/* { dg-final { scan-assembler-times "casab\t" 20} } */
/* { dg-final { scan-assembler-times "caslb\t" 4} } */
/* { dg-final { scan-assembler-times "casalb\t" 36} } */

/* { dg-final { scan-assembler-times "cash\t" 4} } */
/* { dg-final { scan-assembler-times "casah\t" 20} } */
/* { dg-final { scan-assembler-times "caslh\t" 4} } */
/* { dg-final { scan-assembler-times "casalh\t" 36} } */

/* { dg-final { scan-assembler-times "cas\t" 8} } */
/* { dg-final { scan-assembler-times "casa\t" 40} } */
/* { dg-final { scan-assembler-times "casl\t" 8} } */
/* { dg-final { scan-assembler-times "casal\t" 72} } */

/* { dg-final { scan-assembler-not "ldaxr\t" } } */
/* { dg-final { scan-assembler-not "stlxr\t" } } */
/* { dg-final { scan-assembler-not "dmb" } } */