1 //! Run-time feature detection for Aarch64 on Windows.
3 use crate::detect
::{cache, Feature}
;
5 /// Try to read the features using IsProcessorFeaturePresent.
6 pub(crate) fn detect_features() -> cache
::Initializer
{
10 const FALSE
: BOOL
= 0;
11 // The following Microsoft documents isn't updated for aarch64.
12 // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent
13 // These are defined in winnt.h of Windows SDK
14 const PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
: u32 = 19;
15 const PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
: u32 = 30;
16 const PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
: u32 = 31;
19 pub fn IsProcessorFeaturePresent(ProcessorFeature
: DWORD
) -> BOOL
;
22 let mut value
= cache
::Initializer
::default();
24 let mut enable_feature
= |f
, enable
| {
30 // Some features such Feature::fp may be supported on current CPU,
31 // but no way to detect it by OS API.
32 // Also, we require unsafe block for the extern "system" calls.
36 IsProcessorFeaturePresent(PF_ARM_NEON_INSTRUCTIONS_AVAILABLE
) != FALSE
,
40 IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE
) != FALSE
,
42 // PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE means aes, sha1, sha2 and
46 IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
) != FALSE
,
50 IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
) != FALSE
,
54 IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE
) != FALSE
,