|
| 1 | +//! Run-time feature detection for Aarch64 on Windows. |
| 2 | +
|
| 3 | +use crate::detect::{cache, Feature}; |
| 4 | + |
| 5 | +/// Try to read the features from OS API. |
| 6 | +pub(crate) fn detect_features() -> cache::Initializer { |
| 7 | + const PF_ARM_NEON_INSTRUCTIONS_AVAILABLE: u32 = 19; |
| 8 | + const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE: u32 = 30; |
| 9 | + const PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE: u32 = 31; |
| 10 | + |
| 11 | + extern "system" { |
| 12 | + pub fn IsProcessorFeaturePresent(ProcessorFeature: u32) -> u32; |
| 13 | + } |
| 14 | + |
| 15 | + let mut value = cache::Initializer::default(); |
| 16 | + { |
| 17 | + let mut enable_feature = |f, enable| { |
| 18 | + if enable { |
| 19 | + value.set(f as u32); |
| 20 | + } |
| 21 | + }; |
| 22 | + |
| 23 | + // Some features such Feature::fp may be supported on current CPU, |
| 24 | + // but no way to detect it by OS API. |
| 25 | + |
| 26 | + enable_feature(Feature::asimd, unsafe { |
| 27 | + IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE) != 0 |
| 28 | + }); |
| 29 | + enable_feature(Feature::crc, unsafe { |
| 30 | + IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE) != 0 |
| 31 | + }); |
| 32 | + // PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE means aes, sha1, sha2 and |
| 33 | + // pmull supprot |
| 34 | + enable_feature(Feature::crypto, unsafe { |
| 35 | + IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0 |
| 36 | + }); |
| 37 | + enable_feature(Feature::pmull, unsafe { |
| 38 | + IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE) != 0 |
| 39 | + }); |
| 40 | + } |
| 41 | + value |
| 42 | +} |
0 commit comments