From 59ba360d0a142b06b5738f247d31226d1caa74a3 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Mon, 25 Jan 2016 14:35:15 +0100 Subject: [PATCH] Generic atomic v2 --- text/0000-generic-atomic.md | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 text/0000-generic-atomic.md diff --git a/text/0000-generic-atomic.md b/text/0000-generic-atomic.md new file mode 100644 index 00000000000..eceada84c8d --- /dev/null +++ b/text/0000-generic-atomic.md @@ -0,0 +1,80 @@ +- Feature Name: +- Start Date: 2016-01-22 +- RFC PR: (leave this empty) +- Rust Issue: (leave this empty) + +# Summary +[summary]: #summary + +Add compiler support for generic atomic operations. + +# Motivation +[motivation]: #motivation + +It is sometimes necessary or useful to use atomic operations in a generic +context. + +```rust +Atomic +``` + +where `T` is any type. This is currently possible but fails to compile if `T` is +too large for the native atomic operations of the target architecture. + +# Detailed design +[design]: #detailed-design + +The behavior of each of the atomic intrinsics in appendix A is changed as +follows: When a call to one of the atomic intrinsics cannot be translated to a +native operation, it is translated to an unspecified but valid instruction. If +it is executed, the behavior is undefined at runtime. + +One intrinsic is added: + +```rust +fn has_native_atomic_ops() -> bool; +``` + +This intrinsic returns `false` iff a call to one of the aforementioned atomic +operations cannot be translated to a native operation. + +# Drawbacks +[drawbacks]: #drawbacks + +None. + +# Alternatives +[alternatives]: #alternatives + +None. + +# Unresolved questions +[unresolved]: #unresolved-questions + +None. + +# Appendix A + +```rust +fn atomic_cxchg(dst: *mut T, old: T, src: T) -> T; +fn atomic_cxchg_acq(dst: *mut T, old: T, src: T) -> T; +fn atomic_cxchg_rel(dst: *mut T, old: T, src: T) -> T; +fn atomic_cxchg_acqrel(dst: *mut T, old: T, src: T) -> T; +fn atomic_cxchg_relaxed(dst: *mut T, old: T, src: T) -> T; + +fn atomic_load(src: *const T) -> T; +fn atomic_load_acq(src: *const T) -> T; +fn atomic_load_relaxed(src: *const T) -> T; +fn atomic_load_unordered(src: *const T) -> T; + +fn atomic_store(dst: *mut T, val: T); +fn atomic_store_rel(dst: *mut T, val: T); +fn atomic_store_relaxed(dst: *mut T, val: T); +fn atomic_store_unordered(dst: *mut T, val: T); + +fn atomic_xchg(dst: *mut T, src: T) -> T; +fn atomic_xchg_acq(dst: *mut T, src: T) -> T; +fn atomic_xchg_rel(dst: *mut T, src: T) -> T; +fn atomic_xchg_acqrel(dst: *mut T, src: T) -> T; +fn atomic_xchg_relaxed(dst: *mut T, src: T) -> T; +```