[−][src]Crate cpuid_bool
Macro for checking CPU capabilities at runtime.
Example
// This macro creates `cpuid_aes_sha` module cpuid_bool::new!(cpuid_aes_sha, "aes", "sha"); // `token` is a Zero Sized Type value, which guarantees // that underlying static storage got properly initialized, // which allows to omit initialization branch let token: cpuid_aes_sha::InitToken = cpuid_aes_sha::init(); if token.get() { println!("CPU supports both SHA and AES extensions"); } else { println!("SHA and AES extensions are not supported"); } // If stored value needed only once you can get stored value // omitting the token let val = cpuid_aes_sha::get(); assert_eq!(val, token.get()); // Additionally you can get both token and value let (token, val) = cpuid_aes_sha::init_get(); assert_eq!(val, token.get());
Note that if all tested target features are enabled via compiler options
(e.g. by using RUSTFLAGS
), the get
method will always return true
and init
will not use CPUID instruction. Such behavior allows
compiler to completely eliminate fallback code.
After first call macro caches result and returns it in subsequent calls, thus runtime overhead for them is minimal.
Macros
new | Create module with CPUID bool code. |