/src/test/codegen/atomic-operations.rs

https://gitlab.com/rust-lang/rust · Rust · 60 lines · 26 code · 11 blank · 23 comment · 0 complexity · 172aeb007e071bb3a9f93b37105518f1 MD5 · raw file

  1. // Code generation of atomic operations.
  2. //
  3. // compile-flags: -O
  4. #![crate_type = "lib"]
  5. use std::sync::atomic::{AtomicI32, Ordering::*};
  6. // CHECK-LABEL: @compare_exchange
  7. #[no_mangle]
  8. pub fn compare_exchange(a: &AtomicI32) {
  9. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 10 monotonic monotonic
  10. let _ = a.compare_exchange(0, 10, Relaxed, Relaxed);
  11. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 20 release monotonic
  12. let _ = a.compare_exchange(0, 20, Release, Relaxed);
  13. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 30 acquire monotonic
  14. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 31 acquire acquire
  15. let _ = a.compare_exchange(0, 30, Acquire, Relaxed);
  16. let _ = a.compare_exchange(0, 31, Acquire, Acquire);
  17. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 40 acq_rel monotonic
  18. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 41 acq_rel acquire
  19. let _ = a.compare_exchange(0, 40, AcqRel, Relaxed);
  20. let _ = a.compare_exchange(0, 41, AcqRel, Acquire);
  21. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 50 seq_cst monotonic
  22. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 51 seq_cst acquire
  23. // CHECK: cmpxchg {{i32\*|ptr}} %{{.*}}, i32 0, i32 52 seq_cst seq_cst
  24. let _ = a.compare_exchange(0, 50, SeqCst, Relaxed);
  25. let _ = a.compare_exchange(0, 51, SeqCst, Acquire);
  26. let _ = a.compare_exchange(0, 52, SeqCst, SeqCst);
  27. }
  28. // CHECK-LABEL: @compare_exchange_weak
  29. #[no_mangle]
  30. pub fn compare_exchange_weak(w: &AtomicI32) {
  31. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 10 monotonic monotonic
  32. let _ = w.compare_exchange_weak(1, 10, Relaxed, Relaxed);
  33. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 20 release monotonic
  34. let _ = w.compare_exchange_weak(1, 20, Release, Relaxed);
  35. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 30 acquire monotonic
  36. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 31 acquire acquire
  37. let _ = w.compare_exchange_weak(1, 30, Acquire, Relaxed);
  38. let _ = w.compare_exchange_weak(1, 31, Acquire, Acquire);
  39. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 40 acq_rel monotonic
  40. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 41 acq_rel acquire
  41. let _ = w.compare_exchange_weak(1, 40, AcqRel, Relaxed);
  42. let _ = w.compare_exchange_weak(1, 41, AcqRel, Acquire);
  43. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 50 seq_cst monotonic
  44. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 51 seq_cst acquire
  45. // CHECK: cmpxchg weak {{i32\*|ptr}} %{{.*}}, i32 1, i32 52 seq_cst seq_cst
  46. let _ = w.compare_exchange_weak(1, 50, SeqCst, Relaxed);
  47. let _ = w.compare_exchange_weak(1, 51, SeqCst, Acquire);
  48. let _ = w.compare_exchange_weak(1, 52, SeqCst, SeqCst);
  49. }