1 // { dg-do compile { target i?86-*-* x86_64-*-* } }
2 // { dg-options "-std=gnu++0x -g0 -fno-exceptions -fno-asynchronous-unwind-tables" }
3 // { dg-options "-std=gnu++0x -g0 -fno-exceptions -fno-asynchronous-unwind-tables -march=i486" { target ia32 } }
4 // { dg-final { scan-assembler-times "xacquire\|\.byte\[^\n\r]*0xf2" 14 } }
5 // { dg-final { scan-assembler-times "xrelease\|\.byte\[^\n\r]*0xf3" 14 } }
7 // Copyright (C) 2008-2013 Free Software Foundation, Inc.
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3, or (at your option)
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
26 #define ACQ memory_order_acquire | __memory_order_hle_acquire
27 #define REL memory_order_release | __memory_order_hle_release
33 atomic_flag af = ATOMIC_FLAG_INIT;
35 if (!af.test_and_set(ACQ))
38 atomic_uint au = ATOMIC_VAR_INIT(0);
40 if (au.exchange(1, ACQ))
43 if (au.exchange(1, ACQ))
48 if (au.compare_exchange_weak(zero, 1, ACQ, memory_order_consume))
49 au.compare_exchange_weak(one, 0, REL, memory_order_consume);
53 if (au.compare_exchange_strong(zero, 1, ACQ, memory_order_consume))
54 au.compare_exchange_strong(one, 0, REL, memory_order_consume);
56 if (!au.fetch_add(1, ACQ))
57 au.fetch_add(-1, REL);
59 if (!au.fetch_sub(1, ACQ))
60 au.fetch_sub(-1, REL);
62 #if 0 /* broken in underlying target */
63 if (!au.fetch_and(1, ACQ))
64 au.fetch_and(-1, REL);
66 if (!au.fetch_or(1, ACQ))
69 if (!au.fetch_xor(1, ACQ))
70 au.fetch_xor(-1, REL);
72 if (!au.fetch_nand(1, ACQ))
73 au.fetch_nand(-1, REL);
76 volatile atomic_flag vaf = ATOMIC_FLAG_INIT;
78 if (!vaf.test_and_set(ACQ))
81 volatile atomic_uint vau = ATOMIC_VAR_INIT(0);
83 if (!vau.exchange(1, ACQ))
86 if (!vau.exchange(1, ACQ))
91 if (vau.compare_exchange_weak(zero, 1, ACQ, memory_order_consume))
92 vau.compare_exchange_weak(one, 0, REL, memory_order_consume);
96 if (vau.compare_exchange_strong(zero, 1, ACQ, memory_order_consume))
97 vau.compare_exchange_strong(one, 0, REL, memory_order_consume);
99 if (!vau.fetch_add(1, ACQ))
100 vau.fetch_add(-1, REL);
102 if (!vau.fetch_sub(1, ACQ))
103 vau.fetch_sub(-1, REL);
105 #if 0 /* broken in underlying target */
107 if (!vau.fetch_and(1, ACQ))
108 vau.fetch_and(-1, REL);
110 if (!vau.fetch_or(1, ACQ))
111 vau.fetch_or(-1, REL);
113 if (!vau.fetch_xor(1, ACQ))
114 vau.fetch_xor(-1, REL);
116 if (!vau.fetch_nand(1, ACQ))
117 vau.fetch_nand(-1, REL);