Skip to content

Commit 0e04692

Browse files
taiki-eAmanieu
authored andcommitted
std_detect: Support run-time detection of fp on aarch64 Windows
According to google/cpu_features, IsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE) returns whether fp is available. https://github.com/google/cpu_features/blob/a6bf4f9031ec601f905660b8cef82d7478b33d64/src/impl_aarch64_windows.c#L112-L113
1 parent 307c42f commit 0e04692

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

crates/std_detect/src/detect/os/windows/aarch64.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub(crate) fn detect_features() -> cache::Initializer {
1111
// The following Microsoft documents isn't updated for aarch64.
1212
// https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent
1313
// These are defined in winnt.h of Windows SDK
14+
const PF_ARM_VFP_32_REGISTERS_AVAILABLE: u32 = 18;
1415
const PF_ARM_NEON_INSTRUCTIONS_AVAILABLE: u32 = 19;
1516
const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE: u32 = 30;
1617
const PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE: u32 = 31;
@@ -31,10 +32,14 @@ pub(crate) fn detect_features() -> cache::Initializer {
3132
}
3233
};
3334

34-
// Some features such Feature::fp may be supported on current CPU,
35+
// Some features may be supported on current CPU,
3536
// but no way to detect it by OS API.
3637
// Also, we require unsafe block for the extern "system" calls.
3738
unsafe {
39+
enable_feature(
40+
Feature::fp,
41+
IsProcessorFeaturePresent(PF_ARM_VFP_32_REGISTERS_AVAILABLE) != FALSE,
42+
);
3843
enable_feature(
3944
Feature::asimd,
4045
IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != FALSE,
@@ -61,18 +66,11 @@ pub(crate) fn detect_features() -> cache::Initializer {
6166
);
6267
// PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE means aes, sha1, sha2 and
6368
// pmull support
64-
enable_feature(
65-
Feature::aes,
66-
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != FALSE,
67-
);
68-
enable_feature(
69-
Feature::pmull,
70-
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != FALSE,
71-
);
72-
enable_feature(
73-
Feature::sha2,
74-
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != FALSE,
75-
);
69+
let crypto =
70+
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != FALSE;
71+
enable_feature(Feature::aes, crypto);
72+
enable_feature(Feature::pmull, crypto);
73+
enable_feature(Feature::sha2, crypto);
7674
}
7775
}
7876
value

crates/std_detect/tests/cpu-detection.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ fn aarch64_linux() {
8787
#[cfg(all(target_arch = "aarch64", target_os = "windows"))]
8888
fn aarch64_windows() {
8989
println!("asimd: {:?}", is_aarch64_feature_detected!("asimd"));
90+
println!("fp: {:?}", is_aarch64_feature_detected!("fp"));
9091
println!("crc: {:?}", is_aarch64_feature_detected!("crc"));
9192
println!("lse: {:?}", is_aarch64_feature_detected!("lse"));
9293
println!("dotprod: {:?}", is_aarch64_feature_detected!("dotprod"));

0 commit comments

Comments
 (0)