Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cpufeatures/src/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ macro_rules! __expand_check_macro {
#[cfg(any(target_os = "linux", target_os = "android"))]
__expand_check_macro! {
("aes", AES), // Enable AES support.
("dit", DIT), // Enable DIT support.
("dit", DIT), // Enable Data-Independent Timing support.
("sha2", SHA2), // Enable SHA1 and SHA256 support.
("sha3", SHA3), // Enable SHA512 and SHA3 support.
("sm4", SM4), // Enable SM3 and SM4 support.
("sb", SB), // Enable Speculation Barrier support
}

/// Linux hardware capabilities mapped to target features.
Expand All @@ -89,6 +90,7 @@ pub mod hwcaps {
pub const SHA2: c_ulong = libc::HWCAP_SHA2;
pub const SHA3: c_ulong = libc::HWCAP_SHA3 | libc::HWCAP_SHA512;
pub const SM4: c_ulong = libc::HWCAP_SM3 | libc::HWCAP_SM4;
pub const SB: c_ulong = libc::HWCAP_SB;
Comment on lines 74 to +93

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: it's unclear to what extent either DIT or SB are helpful on non-Apple targets, as covered in #1472, but they've been added here (i.e. Linux) for completeness

}

// Apple OS (macOS, iOS, watchOS, and tvOS) `check!` macro.
Expand Down Expand Up @@ -128,6 +130,12 @@ macro_rules! check {
("sm4") => {
false
};
("sb") => {
// https://support.arm.com/documentation/ddi0487/mb/-Part-B-The-AArch64-Application-Level-Architecture/-Chapter-B2-The-AArch64-Application-Level-Memory-Model/-B2-6-Memory-barriers/-B2-6-3-Speculation-Barrier
unsafe {
$crate::aarch64::sysctlbyname(b"hw.optional.arm.FEAT_SB\0")
}
};
}

/// Apple helper function for calling `sysctlbyname`.
Expand Down