#[inline]
#[must_use]
pub fn has_aes() -> bool {
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), feature = "std"))]
{
std::arch::is_x86_feature_detected!("aes")
}
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(feature = "std"),
target_feature = "aes"
))]
{
true
}
#[cfg(not(all(
any(target_arch = "x86", target_arch = "x86_64"),
any(feature = "std", target_feature = "aes")
)))]
{
false
}
}
#[inline]
#[must_use]
pub fn has_pclmulqdq() -> bool {
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), feature = "std"))]
{
std::arch::is_x86_feature_detected!("pclmulqdq")
}
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(feature = "std"),
target_feature = "pclmulqdq"
))]
{
true
}
#[cfg(not(all(
any(target_arch = "x86", target_arch = "x86_64"),
any(feature = "std", target_feature = "pclmulqdq")
)))]
{
false
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn detection_is_total_and_stable() {
let a = has_aes();
let b = has_pclmulqdq();
for _ in 0..8 {
assert_eq!(has_aes(), a);
assert_eq!(has_pclmulqdq(), b);
}
}
#[test]
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
fn non_x86_reports_no_acceleration() {
assert!(!has_aes());
assert!(!has_pclmulqdq());
}
}