Skip to content

Commit

Permalink
Tweak run-time feature detection related code
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 22, 2023
1 parent dc3b11c commit 477099c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 25 deletions.
27 changes: 17 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,33 @@ jobs:
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD $REPORT_TIME
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD $REPORT_TIME
env:
# Note: This cfg is intended to make it easy for portable-atomic developers
# to test has_cmpxchg16b == false, has_vmovdqa_atomic = false, has_lse == false, or __kuser_helper_version < 5 cases,
# and is not a public API.
# Note: detect_false cfg is intended to make it easy for portable-atomic developers to
# test cases such as has_cmpxchg16b == false, has_lse == false,
# __kuser_helper_version < 5, etc., and is not a public API.
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} --cfg portable_atomic_test_outline_atomics_detect_false
RUSTFLAGS: ${{ env.RUSTFLAGS }} --cfg portable_atomic_test_outline_atomics_detect_false
# outline-atomics is disabled by default on aarch64 musl with static linking
if: (matrix.target == '' || startsWith(matrix.target, 'x86_64')) || startsWith(matrix.target, 'aarch64') && !contains(matrix.target, '-musl') || startsWith(matrix.target, 'armv5te') || matrix.target == 'arm-linux-androideabi'
# -crt-static
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD $REPORT_TIME
env:
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=-crt-static
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=-crt-static
if: contains(matrix.target, '-musl')
# +crt-static + outline-atomics
# outline-atomics is disabled by default on aarch64 musl with static linking
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD $REPORT_TIME
env:
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} --cfg portable_atomic_outline_atomics
RUSTFLAGS: ${{ env.RUSTFLAGS }} --cfg portable_atomic_outline_atomics
if: startsWith(matrix.target, 'aarch64') && contains(matrix.target, '-musl')
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD $REPORT_TIME
env:
# Note: detect_false cfg is intended to make it easy for portable-atomic developers to
# test cases such as has_cmpxchg16b == false, has_lse == false,
# __kuser_helper_version < 5, etc., and is not a public API.
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} --cfg portable_atomic_outline_atomics --cfg portable_atomic_test_outline_atomics_detect_false
RUSTFLAGS: ${{ env.RUSTFLAGS }} --cfg portable_atomic_outline_atomics --cfg portable_atomic_test_outline_atomics_detect_false
if: startsWith(matrix.target, 'aarch64') && contains(matrix.target, '-musl')
# -crt-static
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD $REPORT_TIME
env:
RUSTDOCFLAGS: ${{ env.RUSTDOCFLAGS }} -C target-feature=-crt-static
RUSTFLAGS: ${{ env.RUSTFLAGS }} -C target-feature=-crt-static
if: contains(matrix.target, '-musl')
# +cmpxchg16b
- run: tools/test.sh -vv $TARGET $DOCTEST_XCOMPILE $BUILD_STD $REPORT_TIME
env:
Expand Down
5 changes: 3 additions & 2 deletions src/imp/arm_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ fn __kuser_helper_version() -> i32 {
}
#[inline]
fn has_kuser_cmpxchg64() -> bool {
// Note: This cfg is intended to make it easy for portable-atomic developers
// to test __kuser_helper_version < 5 cases, and is not a public API.
// Note: detect_false cfg is intended to make it easy for portable-atomic developers to
// test cases such as has_cmpxchg16b == false, has_lse == false,
// __kuser_helper_version < 5, etc., and is not a public API.
if cfg!(portable_atomic_test_outline_atomics_detect_false) {
return false;
}
Expand Down
44 changes: 32 additions & 12 deletions src/imp/atomic128/detect/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub(crate) fn detect() -> CpuInfo {
return info;
}
info.set(CpuInfo::INIT);
// Note: This cfg is intended to make it easy for portable-atomic developers
// to test has_cmpxchg16b == false or has_lse == false cases,
// and is not a public API.
// Note: detect_false cfg is intended to make it easy for portable-atomic developers to
// test cases such as has_cmpxchg16b == false, has_lse == false,
// __kuser_helper_version < 5, etc., and is not a public API.
if !cfg!(portable_atomic_test_outline_atomics_detect_false) {
_detect(&mut info);
}
Expand Down Expand Up @@ -229,20 +229,40 @@ mod tests_common {
use std::{fmt::Write as _, io::Write, string::String};

let mut features = String::new();
macro_rules! print_feature {
($name:expr, $enabled:expr $(,)?) => {{
let _ = writeln!(features, " {}: {}", $name, $enabled);
}};
}
#[cfg(target_arch = "aarch64")]
{
let _ = writeln!(features, "lse: {}", detect().test(CpuInfo::HAS_LSE));
let _ = writeln!(features, "lse2: {}", detect().test(CpuInfo::HAS_LSE2));
let _ = writeln!(features, "lse128: {}", detect().test(CpuInfo::HAS_LSE128));
let _ = writeln!(features, "rcpc3: {}", detect().test(CpuInfo::HAS_RCPC3));
features.push_str("run-time:\n");
print_feature!("lse", detect().test(CpuInfo::HAS_LSE));
print_feature!("lse2", detect().test(CpuInfo::HAS_LSE2));
print_feature!("lse128", detect().test(CpuInfo::HAS_LSE128));
print_feature!("rcpc3", detect().test(CpuInfo::HAS_RCPC3));
features.push_str("compile-time:\n");
print_feature!(
"lse",
cfg!(any(target_feature = "lse", portable_atomic_target_feature = "lse")),
);
print_feature!(
"lse2",
cfg!(any(target_feature = "lse2", portable_atomic_target_feature = "lse2")),
);
}
#[cfg(target_arch = "x86_64")]
{
let _ = writeln!(features, "cmpxchg16b: {}", detect().test(CpuInfo::HAS_CMPXCHG16B));
let _ = writeln!(
features,
"vmovdqa-atomic: {}",
detect().test(CpuInfo::HAS_VMOVDQA_ATOMIC)
features.push_str("run-time:\n");
print_feature!("cmpxchg16b", detect().test(CpuInfo::HAS_CMPXCHG16B));
print_feature!("vmovdqa-atomic", detect().test(CpuInfo::HAS_VMOVDQA_ATOMIC));
features.push_str("compile-time:\n");
print_feature!(
"cmpxchg16b",
cfg!(any(
target_feature = "cmpxchg16b",
portable_atomic_target_feature = "cmpxchg16b",
)),
);
}
let stdout = std::io::stderr();
Expand Down
6 changes: 5 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ macro_rules! ifunc {

#[allow(unused_macros)]
#[cfg(not(portable_atomic_no_outline_atomics))]
#[cfg(any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86_64"))]
#[cfg(any(
target_arch = "aarch64",
target_arch = "arm",
all(target_arch = "x86_64", not(target_env = "sgx")),
))]
macro_rules! fn_alias {
(
$(#[$($fn_attr:tt)*])*
Expand Down

0 comments on commit 477099c

Please sign in to comment.