| 1 |
/* { dg-do compile { target c++11 } } */ |
| 2 |
/* { dg-options "-O2" } */ |
| 3 |
|
| 4 |
#include <atomic> |
| 5 |
|
| 6 |
template<uint32_t b> |
| 7 |
void lock_bts(std::atomic<uint32_t> &a) { while (!(a.fetch_or(b) & b)); } |
| 8 |
template<uint32_t b> |
| 9 |
void lock_btr(std::atomic<uint32_t> &a) { while (a.fetch_and(~b) & b); } |
| 10 |
template<uint32_t b> |
| 11 |
void lock_btc(std::atomic<uint32_t> &a) { while (a.fetch_xor(b) & b); } |
| 12 |
template void lock_bts<1U<<30>(std::atomic<uint32_t> &a); |
| 13 |
template void lock_btr<1U<<30>(std::atomic<uint32_t> &a); |
| 14 |
template void lock_btc<1U<<30>(std::atomic<uint32_t> &a); |
| 15 |
template void lock_bts<1U<<31>(std::atomic<uint32_t> &a); |
| 16 |
template void lock_btr<1U<<31>(std::atomic<uint32_t> &a); |
| 17 |
template void lock_btc<1U<<31>(std::atomic<uint32_t> &a); |
| 18 |
|
| 19 |
/* { dg-final { scan-assembler-times "lock;?\[ \t\]*btsl" 2 } } */ |
| 20 |
/* { dg-final { scan-assembler-times "lock;?\[ \t\]*btrl" 2 } } */ |
| 21 |
/* { dg-final { scan-assembler-times "lock;?\[ \t\]*btcl" 2 } } */ |
| 22 |
/* { dg-final { scan-assembler-not "cmpxchg" } } */ |