| 1 |
/* { dg-do compile { target x86_64-*-* } } */ |
| 2 |
/* { dg-require-effective-target lp64 } */ |
| 3 |
|
| 4 |
/* Adapted from Linux x86: page_ref_dec_and_test.c (GPL-2.0). */ |
| 5 |
|
| 6 |
typedef struct { |
| 7 |
int counter; |
| 8 |
} atomic_t; |
| 9 |
|
| 10 |
bool |
| 11 |
arch_atomic_dec_and_test(atomic_t *v) { |
| 12 |
return ({ |
| 13 |
bool c; |
| 14 |
asm volatile(".pushsection .smp_locks,\"a\"\n" |
| 15 |
".balign 4\n" |
| 16 |
".long 671f - .\n" |
| 17 |
".popsection\n" |
| 18 |
"671:" |
| 19 |
"\n\tlock; " |
| 20 |
"decl" |
| 21 |
" " |
| 22 |
"%[var]" |
| 23 |
"\n\t/* output condition code " |
| 24 |
"e" |
| 25 |
"*/\n" |
| 26 |
: [ var ] "+m"(v->counter), "=@cc" |
| 27 |
"e"(c) |
| 28 |
: |
| 29 |
: "memory"); |
| 30 |
c; |
| 31 |
}); |
| 32 |
} |