Skip to content

Commit

Permalink
x86_64: Do not use outline-atomics on targets where cpuid is not avai…
Browse files Browse the repository at this point in the history
…lable
  • Loading branch information
taiki-e committed Feb 28, 2023
1 parent bdcf02c commit a1ae85e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/imp/atomic128/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,12 @@ unsafe fn atomic_load(src: *mut u128, order: Ordering) -> u128 {

// Do not use vector registers on targets such as x86_64-unknown-none unless SSE is explicitly enabled.
// https://doc.rust-lang.org/nightly/rustc/platform-support/x86_64-unknown-none.html
// sgx doesn't support `cpuid`.
// Miri and Sanitizer do not support inline assembly.
#[cfg(any(
portable_atomic_no_outline_atomics,
not(target_feature = "sse"),
target_env = "sgx",
miri,
portable_atomic_sanitize_thread,
))]
Expand All @@ -287,6 +289,7 @@ unsafe fn atomic_load(src: *mut u128, order: Ordering) -> u128 {
#[cfg(not(any(
portable_atomic_no_outline_atomics,
not(target_feature = "sse"),
target_env = "sgx",
miri,
portable_atomic_sanitize_thread,
)))]
Expand Down Expand Up @@ -316,10 +319,12 @@ unsafe fn atomic_store(dst: *mut u128, val: u128, order: Ordering) {

// Do not use vector registers on targets such as x86_64-unknown-none unless SSE is explicitly enabled.
// https://doc.rust-lang.org/nightly/rustc/platform-support/x86_64-unknown-none.html
// sgx doesn't support `cpuid`.
// Miri and Sanitizer do not support inline assembly.
#[cfg(any(
portable_atomic_no_outline_atomics,
not(target_feature = "sse"),
target_env = "sgx",
miri,
portable_atomic_sanitize_thread,
))]
Expand All @@ -330,6 +335,7 @@ unsafe fn atomic_store(dst: *mut u128, val: u128, order: Ordering) {
#[cfg(not(any(
portable_atomic_no_outline_atomics,
not(target_feature = "sse"),
target_env = "sgx",
miri,
portable_atomic_sanitize_thread,
)))]
Expand Down
1 change: 1 addition & 0 deletions src/imp/fallback/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
target_arch = "x86_64",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
allow(dead_code)
)]
Expand Down
1 change: 1 addition & 0 deletions src/imp/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub(crate) use seq_lock::imp::{AtomicI64, AtomicU64};
target_arch = "x86_64",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
allow(unused_imports)
Expand Down
3 changes: 3 additions & 0 deletions src/imp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod aarch64;
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
))]
#[cfg(target_arch = "x86_64")]
Expand Down Expand Up @@ -323,6 +324,7 @@ pub(crate) use self::aarch64::{AtomicI128, AtomicU128};
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
target_arch = "x86_64",
Expand Down Expand Up @@ -353,6 +355,7 @@ pub(crate) use self::s390x::{AtomicI128, AtomicU128};
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
target_arch = "x86_64",
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ See also [the `atomic128` module's readme](https://github.com/taiki-e/portable-a
target_arch = "x86_64",
portable_atomic_unstable_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
feature = "fallback",
),
feature(cmpxchg16b_target_feature)
Expand Down Expand Up @@ -4597,6 +4598,7 @@ atomic_int!(AtomicU64, u64, 8);
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
target_arch = "x86_64",
Expand Down Expand Up @@ -4649,6 +4651,7 @@ atomic_int!(AtomicI128, i128, 16);
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
),
),
target_arch = "x86_64",
Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fn test_is_lock_free() {
feature = "fallback",
portable_atomic_cmpxchg16b_target_feature,
not(portable_atomic_no_outline_atomics),
not(target_env = "sgx"),
)) && std::is_x86_feature_detected!("cmpxchg16b");
assert_eq!(AtomicI128::is_lock_free(), has_cmpxchg16b);
assert_eq!(AtomicU128::is_lock_free(), has_cmpxchg16b);
Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ macro_rules! serde_impls {
// Adapted from https://github.com/BurntSushi/memchr/blob/2.4.1/src/memchr/x86/mod.rs#L9-L71.
#[allow(unused_macros)]
#[cfg(not(portable_atomic_no_outline_atomics))]
#[cfg(any(target_arch = "aarch64", all(target_arch = "x86_64", not(target_env = "sgx"))))]
macro_rules! ifunc {
// if the functions are unsafe, this macro is also unsafe.
(unsafe fn($($arg_pat:ident: $arg_ty:ty),*) $(-> $ret_ty:ty)? { $($if_block:tt)* }) => {{
Expand Down

0 comments on commit a1ae85e

Please sign in to comment.