Skip to content

Commit 1f19317

Browse files
committed
Run-time feature detection for Aarch64 on Windows.
1 parent 6a016c7 commit 1f19317

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

crates/std_detect/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ maintenance = { status = "experimental" }
2525
libc = { version = "0.2", optional = true, default-features = false }
2626
cfg-if = "0.1.10"
2727

28+
[target.'cfg(target_os="windows")'.dependencies]
29+
winapi = {version = "0.3.8", features = ["processthreadsapi"]}
30+
2831
[dev-dependencies]
2932
auxv = "0.3.3"
3033
cupid = "0.6.0"

crates/std_detect/src/detect/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ cfg_if! {
106106
mod aarch64;
107107
#[path = "os/freebsd/mod.rs"]
108108
mod os;
109+
} else if #[cfg(all(target_os = "windows", target_arch = "aarch64"))] {
110+
#[path = "os/windows/aarch64.rs"]
111+
mod os;
109112
} else {
110113
#[path = "os/other.rs"]
111114
mod os;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! Run-time feature detection for Aarch64 on Windows.
2+
3+
use crate::detect::{cache, Feature};
4+
use winapi::um::processthreadsapi::IsProcessorFeaturePresent;
5+
use winapi::um::winnt::*;
6+
7+
/// Try to read the features from OS API.
8+
pub(crate) fn detect_features() -> cache::Initializer {
9+
let mut value = cache::Initializer::default();
10+
{
11+
let mut enable_feature = |f, enable| {
12+
if enable {
13+
value.set(f as u32);
14+
}
15+
};
16+
enable_feature(Feature::asimd, unsafe {
17+
IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0
18+
});
19+
enable_feature(Feature::crc, unsafe {
20+
IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) != 0
21+
});
22+
enable_feature(Feature::crypto, unsafe {
23+
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0
24+
});
25+
enable_feature(Feature::pmull, unsafe {
26+
IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0
27+
});
28+
}
29+
value
30+
}

0 commit comments

Comments
 (0)