]>
git.proxmox.com Git - rustc.git/blob - src/test/codegen/atomic-operations.rs
1 // Code generation of atomic operations.
6 use std
::sync
::atomic
::{AtomicI32, Ordering::*}
;
8 // CHECK-LABEL: @compare_exchange
10 pub fn compare_exchange(a
: &AtomicI32
) {
11 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 10 monotonic monotonic
12 let _
= a
.compare_exchange(0, 10, Relaxed
, Relaxed
);
14 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 20 release monotonic
15 let _
= a
.compare_exchange(0, 20, Release
, Relaxed
);
17 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 30 acquire monotonic
18 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 31 acquire acquire
19 let _
= a
.compare_exchange(0, 30, Acquire
, Relaxed
);
20 let _
= a
.compare_exchange(0, 31, Acquire
, Acquire
);
22 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 40 acq_rel monotonic
23 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 41 acq_rel acquire
24 let _
= a
.compare_exchange(0, 40, AcqRel
, Relaxed
);
25 let _
= a
.compare_exchange(0, 41, AcqRel
, Acquire
);
27 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 50 seq_cst monotonic
28 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 51 seq_cst acquire
29 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 52 seq_cst seq_cst
30 let _
= a
.compare_exchange(0, 50, SeqCst
, Relaxed
);
31 let _
= a
.compare_exchange(0, 51, SeqCst
, Acquire
);
32 let _
= a
.compare_exchange(0, 52, SeqCst
, SeqCst
);
35 // CHECK-LABEL: @compare_exchange_weak
37 pub fn compare_exchange_weak(w
: &AtomicI32
) {
38 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 10 monotonic monotonic
39 let _
= w
.compare_exchange_weak(1, 10, Relaxed
, Relaxed
);
41 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 20 release monotonic
42 let _
= w
.compare_exchange_weak(1, 20, Release
, Relaxed
);
44 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 30 acquire monotonic
45 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 31 acquire acquire
46 let _
= w
.compare_exchange_weak(1, 30, Acquire
, Relaxed
);
47 let _
= w
.compare_exchange_weak(1, 31, Acquire
, Acquire
);
49 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 40 acq_rel monotonic
50 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 41 acq_rel acquire
51 let _
= w
.compare_exchange_weak(1, 40, AcqRel
, Relaxed
);
52 let _
= w
.compare_exchange_weak(1, 41, AcqRel
, Acquire
);
54 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 50 seq_cst monotonic
55 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 51 seq_cst acquire
56 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 52 seq_cst seq_cst
57 let _
= w
.compare_exchange_weak(1, 50, SeqCst
, Relaxed
);
58 let _
= w
.compare_exchange_weak(1, 51, SeqCst
, Acquire
);
59 let _
= w
.compare_exchange_weak(1, 52, SeqCst
, SeqCst
);