]> git.proxmox.com Git - rustc.git/blob - src/test/codegen/atomic-operations.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / test / codegen / atomic-operations.rs
1 // Code generation of atomic operations.
2 //
3 // compile-flags: -O
4 #![crate_type = "lib"]
5
6 use std::sync::atomic::{AtomicI32, Ordering::*};
7
8 // CHECK-LABEL: @compare_exchange
9 #[no_mangle]
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);
13
14 // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 20 release monotonic
15 let _ = a.compare_exchange(0, 20, Release, Relaxed);
16
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);
21
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);
26
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);
33 }
34
35 // CHECK-LABEL: @compare_exchange_weak
36 #[no_mangle]
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);
40
41 // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 20 release monotonic
42 let _ = w.compare_exchange_weak(1, 20, Release, Relaxed);
43
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);
48
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);
53
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);
60 }