]> git.lizzy.rs Git - rust.git/blob - tests/codegen/atomic-operations.rs
Rollup merge of #106638 - RalfJung:realstd, r=thomcc
[rust.git] / tests / codegen / atomic-operations.rs
1 // Code generation of atomic operations.
2 // compile-flags: -O
3 #![crate_type = "lib"]
4
5 use std::sync::atomic::{AtomicI32, Ordering::*};
6
7 // CHECK-LABEL: @compare_exchange
8 #[no_mangle]
9 pub fn compare_exchange(a: &AtomicI32) {
10     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 10 monotonic monotonic
11     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 11 monotonic acquire
12     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 12 monotonic seq_cst
13     let _ = a.compare_exchange(0, 10, Relaxed, Relaxed);
14     let _ = a.compare_exchange(0, 11, Relaxed, Acquire);
15     let _ = a.compare_exchange(0, 12, Relaxed, SeqCst);
16
17     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 20 release monotonic
18     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 21 release acquire
19     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 22 release seq_cst
20     let _ = a.compare_exchange(0, 20, Release, Relaxed);
21     let _ = a.compare_exchange(0, 21, Release, Acquire);
22     let _ = a.compare_exchange(0, 22, Release, SeqCst);
23
24     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 30 acquire monotonic
25     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 31 acquire acquire
26     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 32 acquire seq_cst
27     let _ = a.compare_exchange(0, 30, Acquire, Relaxed);
28     let _ = a.compare_exchange(0, 31, Acquire, Acquire);
29     let _ = a.compare_exchange(0, 32, Acquire, SeqCst);
30
31     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 40 acq_rel monotonic
32     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 41 acq_rel acquire
33     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 42 acq_rel seq_cst
34     let _ = a.compare_exchange(0, 40, AcqRel, Relaxed);
35     let _ = a.compare_exchange(0, 41, AcqRel, Acquire);
36     let _ = a.compare_exchange(0, 42, AcqRel, SeqCst);
37
38     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 50 seq_cst monotonic
39     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 51 seq_cst acquire
40     // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 52 seq_cst seq_cst
41     let _ = a.compare_exchange(0, 50, SeqCst, Relaxed);
42     let _ = a.compare_exchange(0, 51, SeqCst, Acquire);
43     let _ = a.compare_exchange(0, 52, SeqCst, SeqCst);
44 }
45
46 // CHECK-LABEL: @compare_exchange_weak
47 #[no_mangle]
48 pub fn compare_exchange_weak(w: &AtomicI32) {
49     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 10 monotonic monotonic
50     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 11 monotonic acquire
51     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 12 monotonic seq_cst
52     let _ = w.compare_exchange_weak(1, 10, Relaxed, Relaxed);
53     let _ = w.compare_exchange_weak(1, 11, Relaxed, Acquire);
54     let _ = w.compare_exchange_weak(1, 12, Relaxed, SeqCst);
55
56     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 20 release monotonic
57     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 21 release acquire
58     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 22 release seq_cst
59     let _ = w.compare_exchange_weak(1, 20, Release, Relaxed);
60     let _ = w.compare_exchange_weak(1, 21, Release, Acquire);
61     let _ = w.compare_exchange_weak(1, 22, Release, SeqCst);
62
63     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 30 acquire monotonic
64     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 31 acquire acquire
65     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 32 acquire seq_cst
66     let _ = w.compare_exchange_weak(1, 30, Acquire, Relaxed);
67     let _ = w.compare_exchange_weak(1, 31, Acquire, Acquire);
68     let _ = w.compare_exchange_weak(1, 32, Acquire, SeqCst);
69
70     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 40 acq_rel monotonic
71     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 41 acq_rel acquire
72     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 42 acq_rel seq_cst
73     let _ = w.compare_exchange_weak(1, 40, AcqRel, Relaxed);
74     let _ = w.compare_exchange_weak(1, 41, AcqRel, Acquire);
75     let _ = w.compare_exchange_weak(1, 42, AcqRel, SeqCst);
76
77     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 50 seq_cst monotonic
78     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 51 seq_cst acquire
79     // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 52 seq_cst seq_cst
80     let _ = w.compare_exchange_weak(1, 50, SeqCst, Relaxed);
81     let _ = w.compare_exchange_weak(1, 51, SeqCst, Acquire);
82     let _ = w.compare_exchange_weak(1, 52, SeqCst, SeqCst);
83 }