File: atomic-operations.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (84 lines) | stat: -rw-r--r-- 4,177 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Code generation of atomic operations.
//@ compile-flags: -O
#![crate_type = "lib"]

use std::sync::atomic::AtomicI32;
use std::sync::atomic::Ordering::*;

// CHECK-LABEL: @compare_exchange
#[no_mangle]
pub fn compare_exchange(a: &AtomicI32) {
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 10 monotonic monotonic
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 11 monotonic acquire
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 12 monotonic seq_cst
    let _ = a.compare_exchange(0, 10, Relaxed, Relaxed);
    let _ = a.compare_exchange(0, 11, Relaxed, Acquire);
    let _ = a.compare_exchange(0, 12, Relaxed, SeqCst);

    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 20 release monotonic
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 21 release acquire
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 22 release seq_cst
    let _ = a.compare_exchange(0, 20, Release, Relaxed);
    let _ = a.compare_exchange(0, 21, Release, Acquire);
    let _ = a.compare_exchange(0, 22, Release, SeqCst);

    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 30 acquire monotonic
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 31 acquire acquire
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 32 acquire seq_cst
    let _ = a.compare_exchange(0, 30, Acquire, Relaxed);
    let _ = a.compare_exchange(0, 31, Acquire, Acquire);
    let _ = a.compare_exchange(0, 32, Acquire, SeqCst);

    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 40 acq_rel monotonic
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 41 acq_rel acquire
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 42 acq_rel seq_cst
    let _ = a.compare_exchange(0, 40, AcqRel, Relaxed);
    let _ = a.compare_exchange(0, 41, AcqRel, Acquire);
    let _ = a.compare_exchange(0, 42, AcqRel, SeqCst);

    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 50 seq_cst monotonic
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 51 seq_cst acquire
    // CHECK: cmpxchg ptr %{{.*}}, i32 0, i32 52 seq_cst seq_cst
    let _ = a.compare_exchange(0, 50, SeqCst, Relaxed);
    let _ = a.compare_exchange(0, 51, SeqCst, Acquire);
    let _ = a.compare_exchange(0, 52, SeqCst, SeqCst);
}

// CHECK-LABEL: @compare_exchange_weak
#[no_mangle]
pub fn compare_exchange_weak(w: &AtomicI32) {
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 10 monotonic monotonic
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 11 monotonic acquire
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 12 monotonic seq_cst
    let _ = w.compare_exchange_weak(1, 10, Relaxed, Relaxed);
    let _ = w.compare_exchange_weak(1, 11, Relaxed, Acquire);
    let _ = w.compare_exchange_weak(1, 12, Relaxed, SeqCst);

    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 20 release monotonic
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 21 release acquire
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 22 release seq_cst
    let _ = w.compare_exchange_weak(1, 20, Release, Relaxed);
    let _ = w.compare_exchange_weak(1, 21, Release, Acquire);
    let _ = w.compare_exchange_weak(1, 22, Release, SeqCst);

    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 30 acquire monotonic
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 31 acquire acquire
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 32 acquire seq_cst
    let _ = w.compare_exchange_weak(1, 30, Acquire, Relaxed);
    let _ = w.compare_exchange_weak(1, 31, Acquire, Acquire);
    let _ = w.compare_exchange_weak(1, 32, Acquire, SeqCst);

    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 40 acq_rel monotonic
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 41 acq_rel acquire
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 42 acq_rel seq_cst
    let _ = w.compare_exchange_weak(1, 40, AcqRel, Relaxed);
    let _ = w.compare_exchange_weak(1, 41, AcqRel, Acquire);
    let _ = w.compare_exchange_weak(1, 42, AcqRel, SeqCst);

    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 50 seq_cst monotonic
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 51 seq_cst acquire
    // CHECK: cmpxchg weak ptr %{{.*}}, i32 1, i32 52 seq_cst seq_cst
    let _ = w.compare_exchange_weak(1, 50, SeqCst, Relaxed);
    let _ = w.compare_exchange_weak(1, 51, SeqCst, Acquire);
    let _ = w.compare_exchange_weak(1, 52, SeqCst, SeqCst);
}