core/stdarch/crates/core_arch/src/x86_64/
cmpxchg16b.rs1use crate::sync::atomic::Ordering;
2
3#[cfg(test)]
4use stdarch_test::assert_instr;
5
6#[inline]
40#[cfg_attr(miri, track_caller)] #[cfg_attr(test, assert_instr(cmpxchg16b, success = Ordering::SeqCst, failure = Ordering::SeqCst))]
42#[target_feature(enable = "cmpxchg16b")]
43#[stable(feature = "cmpxchg16b_intrinsic", since = "1.67.0")]
44pub unsafe fn cmpxchg16b(
45 dst: *mut u128,
46 old: u128,
47 new: u128,
48 success: Ordering,
49 failure: Ordering,
50) -> u128 {
51 use crate::{intrinsics, sync::atomic::Ordering::*};
52
53 debug_assert!(dst as usize % 16 == 0);
54
55 let (val, _ok) = match (success, failure) {
58 (Relaxed, Relaxed) => intrinsics::atomic_cxchg_relaxed_relaxed(dst, old, new),
59 (Relaxed, Acquire) => intrinsics::atomic_cxchg_relaxed_acquire(dst, old, new),
60 (Relaxed, SeqCst) => intrinsics::atomic_cxchg_relaxed_seqcst(dst, old, new),
61 (Acquire, Relaxed) => intrinsics::atomic_cxchg_acquire_relaxed(dst, old, new),
62 (Acquire, Acquire) => intrinsics::atomic_cxchg_acquire_acquire(dst, old, new),
63 (Acquire, SeqCst) => intrinsics::atomic_cxchg_acquire_seqcst(dst, old, new),
64 (Release, Relaxed) => intrinsics::atomic_cxchg_release_relaxed(dst, old, new),
65 (Release, Acquire) => intrinsics::atomic_cxchg_release_acquire(dst, old, new),
66 (Release, SeqCst) => intrinsics::atomic_cxchg_release_seqcst(dst, old, new),
67 (AcqRel, Relaxed) => intrinsics::atomic_cxchg_acqrel_relaxed(dst, old, new),
68 (AcqRel, Acquire) => intrinsics::atomic_cxchg_acqrel_acquire(dst, old, new),
69 (AcqRel, SeqCst) => intrinsics::atomic_cxchg_acqrel_seqcst(dst, old, new),
70 (SeqCst, Relaxed) => intrinsics::atomic_cxchg_seqcst_relaxed(dst, old, new),
71 (SeqCst, Acquire) => intrinsics::atomic_cxchg_seqcst_acquire(dst, old, new),
72 (SeqCst, SeqCst) => intrinsics::atomic_cxchg_seqcst_seqcst(dst, old, new),
73 (_, AcqRel) => panic!("there is no such thing as an acquire-release failure ordering"),
74 (_, Release) => panic!("there is no such thing as a release failure ordering"),
75
76 #[allow(unreachable_patterns)]
78 (_, _) => unreachable!(),
79 };
80 val
81}