1 /* { dg-do compile } */
2 /* { dg-options "-O2 -march=armv8-a+lse" } */
3 
4 /* Test ARMv8.1-A Load-ADD instruction.  */
5 
6 #include "atomic-inst-ops.inc"
7 
8 #define TEST TEST_ONE
9 
10 #define LOAD_ADD(FN, TY, MODEL)						\
11   TY FNNAME (FN, TY) (TY* val, TY* foo)					\
12   {									\
13     return __atomic_fetch_add (val, foo, MODEL);			\
14   }
15 
16 #define LOAD_ADD_NORETURN(FN, TY, MODEL)				\
17   void FNNAME (FN, TY) (TY* val, TY* foo)				\
18   {									\
19     __atomic_fetch_add (val, foo, MODEL);				\
20   }
21 
22 #define LOAD_SUB(FN, TY, MODEL)						\
23   TY FNNAME (FN, TY) (TY* val, TY* foo)					\
24   {									\
25     return __atomic_fetch_sub (val, foo, MODEL);			\
26   }
27 
28 #define LOAD_SUB_NORETURN(FN, TY, MODEL)				\
29   void FNNAME (FN, TY) (TY* val, TY* foo)				\
30   {									\
31     __atomic_fetch_sub (val, foo, MODEL);				\
32   }
33 
34 #define ADD_LOAD(FN, TY, MODEL)						\
35   TY FNNAME (FN, TY) (TY* val, TY* foo)					\
36   {									\
37     return __atomic_add_fetch (val, foo, MODEL);			\
38   }
39 
40 #define ADD_LOAD_NORETURN(FN, TY, MODEL)				\
41   void FNNAME (FN, TY) (TY* val, TY* foo)				\
42   {									\
43     __atomic_add_fetch (val, foo, MODEL);				\
44   }
45 
46 #define SUB_LOAD(FN, TY, MODEL)						\
47   TY FNNAME (FN, TY) (TY* val, TY* foo)					\
48   {									\
49     return __atomic_sub_fetch (val, foo, MODEL);			\
50   }
51 
52 #define SUB_LOAD_NORETURN(FN, TY, MODEL)				\
53   void FNNAME (FN, TY) (TY* val, TY* foo)				\
54   {									\
55     __atomic_sub_fetch (val, foo, MODEL);				\
56   }
57 
58 TEST (load_add, LOAD_ADD)
59 TEST (load_add_notreturn, LOAD_ADD_NORETURN)
60 
61 TEST (load_sub, LOAD_SUB)
62 TEST (load_sub_notreturn, LOAD_SUB_NORETURN)
63 
64 TEST (add_load, ADD_LOAD)
65 TEST (add_load_notreturn, ADD_LOAD_NORETURN)
66 
67 TEST (sub_load, SUB_LOAD)
68 TEST (sub_load_notreturn, SUB_LOAD_NORETURN)
69 
70 /* { dg-final { scan-assembler-times "ldaddb\t" 16} } */
71 /* { dg-final { scan-assembler-times "ldaddab\t" 32} } */
72 /* { dg-final { scan-assembler-times "ldaddlb\t" 16} } */
73 /* { dg-final { scan-assembler-times "ldaddalb\t" 32} } */
74 
75 /* { dg-final { scan-assembler-times "ldaddh\t" 16} } */
76 /* { dg-final { scan-assembler-times "ldaddah\t" 32} } */
77 /* { dg-final { scan-assembler-times "ldaddlh\t" 16} } */
78 /* { dg-final { scan-assembler-times "ldaddalh\t" 32} } */
79 
80 /* { dg-final { scan-assembler-times "ldadd\t" 32} } */
81 /* { dg-final { scan-assembler-times "ldadda\t" 64} } */
82 /* { dg-final { scan-assembler-times "ldaddl\t" 32} } */
83 /* { dg-final { scan-assembler-times "ldaddal\t" 64} } */
84 
85 /* { dg-final { scan-assembler-not "ldaxr\t" } } */
86 /* { dg-final { scan-assembler-not "stlxr\t" } } */
87 /* { dg-final { scan-assembler-not "dmb" } } */
88