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