Skip to content

Commit 2aeb0a2

Browse files
committed
aarch64-apple-darwin: Always do dynamic detection of "sha3" feature.
Make it easy to test the dynamic detection for other aarch64-apple-* targets.
1 parent 20aad7f commit 2aeb0a2

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/cpu/arm.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ fn detect_features() -> u32 {
180180
features
181181
}
182182

183-
#[cfg(all(target_os = "ios", target_arch = "aarch64"))]
183+
#[cfg(all(
184+
target_arch = "aarch64",
185+
any(target_os = "ios", target_os = "macos", target_os = "tvos")
186+
))]
184187
fn detect_features() -> u32 {
185188
let mut features = ARMCAP_STATIC;
186189

@@ -219,7 +222,7 @@ fn detect_features() -> u32 {
219222
target_os = "fuchsia",
220223
all(target_os = "linux", not(target_env = "uclibc")),
221224
target_os = "windows",
222-
target_os = "ios"
225+
any(target_os = "ios", target_os = "macos", target_os = "tvos"),
223226
))
224227
))]
225228
fn detect_features() -> u32 {
@@ -242,7 +245,9 @@ macro_rules! features {
242245
};
243246
)+
244247

245-
const ARMCAP_STATIC: u32 = 0
248+
// See const assertions below.
249+
const ARMCAP_STATIC: u32 = ARMCAP_STATIC_DETECTED & ARMCAP_STATIC_FILTER;
250+
const ARMCAP_STATIC_DETECTED: u32 = 0
246251
$(
247252
| (
248253
if cfg!(all(any(target_arch = "aarch64", target_arch = "arm"),
@@ -251,8 +256,13 @@ macro_rules! features {
251256
} else {
252257
0
253258
}
254-
)
259+
)
255260
)+;
261+
const ARMCAP_STATIC_FILTER: u32 = if cfg!(all(target_arch = "aarch64", target_os = "macos")) {
262+
AARCH64_APPLE_FEATURES
263+
} else {
264+
!0
265+
};
256266

257267
#[cfg(all(test, any(target_arch = "arm", target_arch = "aarch64")))]
258268
const ALL_FEATURES: [Feature; 5] = [
@@ -389,20 +399,25 @@ prefixed_extern! {
389399
// target_feature="neon"
390400
// target_feature="sha2"
391401
// target_feature="sha3"
402+
//
403+
// XXX/TODO(coverage)/TODO(size): aarch64-apple-darwin is statically guaranteed to have "sha3" but
404+
// other aarch64-apple-* targets require dynamic detection. Since we don't have test coverage for
405+
// the other targets yet, we wouldn't have a way of testing the dynamic detection if we statically
406+
// enabled `SHA512` for -darwin. So instead, temporarily, we statically ignore the static
407+
// availability of the feature on -darwin so that it runs the dynamic detection.
392408
// ```
393409
#[allow(clippy::assertions_on_constants)]
394410
const _AARCH64_HAS_NEON: () =
395411
assert!(((ARMCAP_STATIC & NEON.mask) == NEON.mask) || !cfg!(target_arch = "aarch64"));
396-
#[allow(clippy::assertions_on_constants)]
397-
const _AARCH64_APPLE_FEATURES: u32 = NEON.mask | AES.mask | SHA256.mask | PMULL.mask;
412+
const AARCH64_APPLE_FEATURES: u32 = NEON.mask | AES.mask | SHA256.mask | PMULL.mask;
398413
#[allow(clippy::assertions_on_constants)]
399414
const _AARCH64_APPLE_TARGETS_EXPECTED_FEATURES: () = assert!(
400415
((ARMCAP_STATIC & _AARCH64_APPLE_FEATURES) == _AARCH64_APPLE_FEATURES)
401416
|| !cfg!(all(target_arch = "aarch64", target_vendor = "apple"))
402417
);
403418
#[allow(clippy::assertions_on_constants)]
404419
const _AARCH64_APPLE_DARWIN_TARGETS_EXPECTED_FEATURES: () = assert!(
405-
((ARMCAP_STATIC & SHA512.mask) == SHA512.mask)
420+
(ARMCAP_STATIC == AARCH64_APPLE_FEATURES)
406421
|| !cfg!(all(target_arch = "aarch64", target_os = "macos"))
407422
);
408423

0 commit comments

Comments
 (0)