about summary refs log tree commit diff
path: root/library/stdarch/crates/std_detect/src
diff options
context:
space:
mode:
authorTaiki Endo <te316e89@gmail.com>2023-03-02 03:21:34 +0900
committerAmanieu d'Antras <amanieu@gmail.com>2023-03-01 19:58:15 +0100
commitba58f917696d4ca2a18ab01177b19c35c3bc8b91 (patch)
tree2a409124b80075a4d93556c6c23dfef087eede14 /library/stdarch/crates/std_detect/src
parent8f9ed37be7c9e9cf2bb9e427d1c1f5a793a0f2e8 (diff)
downloadrust-ba58f917696d4ca2a18ab01177b19c35c3bc8b91.tar.gz
rust-ba58f917696d4ca2a18ab01177b19c35c3bc8b91.zip
std_detect: Support run-time detection of crc/aes/sha2/crypto on arm FreeBSD
Diffstat (limited to 'library/stdarch/crates/std_detect/src')
-rw-r--r--library/stdarch/crates/std_detect/src/detect/os/freebsd/arm.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/library/stdarch/crates/std_detect/src/detect/os/freebsd/arm.rs b/library/stdarch/crates/std_detect/src/detect/os/freebsd/arm.rs
index 4c9d763b446..97ede1d26b7 100644
--- a/library/stdarch/crates/std_detect/src/detect/os/freebsd/arm.rs
+++ b/library/stdarch/crates/std_detect/src/detect/os/freebsd/arm.rs
@@ -3,6 +3,15 @@
 use super::auxvec;
 use crate::detect::{cache, Feature};
 
+// Defined in machine/elf.h.
+// https://github.com/freebsd/freebsd-src/blob/deb63adf945d446ed91a9d84124c71f15ae571d1/sys/arm/include/elf.h
+const HWCAP_NEON: usize = 0x00001000;
+const HWCAP2_AES: usize = 0x00000001;
+const HWCAP2_PMULL: usize = 0x00000002;
+const HWCAP2_SHA1: usize = 0x00000004;
+const HWCAP2_SHA2: usize = 0x00000008;
+const HWCAP2_CRC32: usize = 0x00000010;
+
 /// Try to read the features from the auxiliary vector
 pub(crate) fn detect_features() -> cache::Initializer {
     let mut value = cache::Initializer::default();
@@ -13,8 +22,17 @@ pub(crate) fn detect_features() -> cache::Initializer {
     };
 
     if let Ok(auxv) = auxvec::auxv() {
-        enable_feature(&mut value, Feature::neon, auxv.hwcap & 0x00001000 != 0);
-        enable_feature(&mut value, Feature::pmull, auxv.hwcap2 & 0x00000002 != 0);
+        enable_feature(&mut value, Feature::neon, auxv.hwcap & HWCAP_NEON != 0);
+        let pmull = auxv.hwcap2 & HWCAP2_PMULL != 0;
+        enable_feature(&mut value, Feature::pmull, pmull);
+        enable_feature(&mut value, Feature::crc, auxv.hwcap2 & HWCAP2_CRC32 != 0);
+        let aes = auxv.hwcap2 & HWCAP2_AES != 0;
+        enable_feature(&mut value, Feature::aes, aes);
+        // SHA2 requires SHA1 & SHA2 features
+        let sha1 = auxv.hwcap2 & HWCAP2_SHA1 != 0;
+        let sha2 = auxv.hwcap2 & HWCAP2_SHA2 != 0;
+        enable_feature(&mut value, Feature::sha2, sha1 && sha2);
+        enable_feature(&mut value, Feature::crypto, aes && pmull && sha1 && sha2);
         return value;
     }
     value