From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/intrinsics/intrinsic-atomics.rs | 102 ++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/test/ui/intrinsics/intrinsic-atomics.rs (limited to 'src/test/ui/intrinsics/intrinsic-atomics.rs') diff --git a/src/test/ui/intrinsics/intrinsic-atomics.rs b/src/test/ui/intrinsics/intrinsic-atomics.rs new file mode 100644 index 000000000..b17f4347b --- /dev/null +++ b/src/test/ui/intrinsics/intrinsic-atomics.rs @@ -0,0 +1,102 @@ +// run-pass +#![feature(intrinsics)] + +mod rusti { + extern "rust-intrinsic" { + pub fn atomic_cxchg_seqcst_seqcst(dst: *mut T, old: T, src: T) -> (T, bool); + pub fn atomic_cxchg_acquire_acquire(dst: *mut T, old: T, src: T) -> (T, bool); + pub fn atomic_cxchg_release_relaxed(dst: *mut T, old: T, src: T) -> (T, bool); + + pub fn atomic_cxchgweak_seqcst_seqcst(dst: *mut T, old: T, src: T) -> (T, bool); + pub fn atomic_cxchgweak_acquire_acquire(dst: *mut T, old: T, src: T) -> (T, bool); + pub fn atomic_cxchgweak_release_relaxed(dst: *mut T, old: T, src: T) -> (T, bool); + + pub fn atomic_load_seqcst(src: *const T) -> T; + pub fn atomic_load_acquire(src: *const T) -> T; + + pub fn atomic_store_seqcst(dst: *mut T, val: T); + pub fn atomic_store_release(dst: *mut T, val: T); + + pub fn atomic_xchg_seqcst(dst: *mut T, src: T) -> T; + pub fn atomic_xchg_acquire(dst: *mut T, src: T) -> T; + pub fn atomic_xchg_release(dst: *mut T, src: T) -> T; + + pub fn atomic_xadd_seqcst(dst: *mut T, src: T) -> T; + pub fn atomic_xadd_acquire(dst: *mut T, src: T) -> T; + pub fn atomic_xadd_release(dst: *mut T, src: T) -> T; + + pub fn atomic_xsub_seqcst(dst: *mut T, src: T) -> T; + pub fn atomic_xsub_acquire(dst: *mut T, src: T) -> T; + pub fn atomic_xsub_release(dst: *mut T, src: T) -> T; + } +} + +pub fn main() { + unsafe { + let mut x: Box<_> = Box::new(1); + + assert_eq!(rusti::atomic_load_seqcst(&*x), 1); + *x = 5; + assert_eq!(rusti::atomic_load_acquire(&*x), 5); + + rusti::atomic_store_seqcst(&mut *x,3); + assert_eq!(*x, 3); + rusti::atomic_store_release(&mut *x,1); + assert_eq!(*x, 1); + + assert_eq!(rusti::atomic_cxchg_seqcst_seqcst(&mut *x, 1, 2), (1, true)); + assert_eq!(*x, 2); + + assert_eq!(rusti::atomic_cxchg_acquire_acquire(&mut *x, 1, 3), (2, false)); + assert_eq!(*x, 2); + + assert_eq!(rusti::atomic_cxchg_release_relaxed(&mut *x, 2, 1), (2, true)); + assert_eq!(*x, 1); + + assert_eq!(rusti::atomic_xchg_seqcst(&mut *x, 0), 1); + assert_eq!(*x, 0); + + assert_eq!(rusti::atomic_xchg_acquire(&mut *x, 1), 0); + assert_eq!(*x, 1); + + assert_eq!(rusti::atomic_xchg_release(&mut *x, 0), 1); + assert_eq!(*x, 0); + + assert_eq!(rusti::atomic_xadd_seqcst(&mut *x, 1), 0); + assert_eq!(rusti::atomic_xadd_acquire(&mut *x, 1), 1); + assert_eq!(rusti::atomic_xadd_release(&mut *x, 1), 2); + assert_eq!(*x, 3); + + assert_eq!(rusti::atomic_xsub_seqcst(&mut *x, 1), 3); + assert_eq!(rusti::atomic_xsub_acquire(&mut *x, 1), 2); + assert_eq!(rusti::atomic_xsub_release(&mut *x, 1), 1); + assert_eq!(*x, 0); + + loop { + let res = rusti::atomic_cxchgweak_seqcst_seqcst(&mut *x, 0, 1); + assert_eq!(res.0, 0); + if res.1 { + break; + } + } + assert_eq!(*x, 1); + + loop { + let res = rusti::atomic_cxchgweak_acquire_acquire(&mut *x, 1, 2); + assert_eq!(res.0, 1); + if res.1 { + break; + } + } + assert_eq!(*x, 2); + + loop { + let res = rusti::atomic_cxchgweak_release_relaxed(&mut *x, 2, 3); + assert_eq!(res.0, 2); + if res.1 { + break; + } + } + assert_eq!(*x, 3); + } +} -- cgit v1.2.3