4
4
//! unprivileged userspace code, so this implementation relies on OS-specific
5
5
//! APIs for feature detection.
6
6
7
+ // Evaluate the given `$body` expression any of the supplied target features
8
+ // are not enabled. Otherwise returns true.
7
9
#[ macro_export]
8
10
#[ doc( hidden) ]
9
11
macro_rules! __unless_target_features {
@@ -18,6 +20,7 @@ macro_rules! __unless_target_features {
18
20
} ;
19
21
}
20
22
23
+ // Linux runtime detection of target CPU features using `getauxval`.
21
24
#[ cfg( target_os = "linux" ) ]
22
25
#[ macro_export]
23
26
#[ doc( hidden) ]
@@ -34,6 +37,7 @@ pub fn getauxval_hwcap() -> u64 {
34
37
unsafe { libc:: getauxval ( libc:: AT_HWCAP ) }
35
38
}
36
39
40
+ // MacOS runtime detection of target CPU features using `sysctlbyname`.
37
41
#[ cfg( target_os = "macos" ) ]
38
42
#[ macro_export]
39
43
#[ doc( hidden) ]
@@ -43,39 +47,43 @@ macro_rules! __detect_target_features {
43
47
} } ;
44
48
}
45
49
46
- /// Linux `expand_check_macro`
50
+ // Linux `expand_check_macro`
47
51
#[ cfg( target_os = "linux" ) ]
48
52
macro_rules! __expand_check_macro {
49
- ( $( ( $name: tt, $hwcap: expr) ) ,* $( , ) ?) => {
53
+ ( $( ( $name: tt, $hwcap: ident) ) ,* $( , ) ?) => {
54
+ $(
55
+ pub use libc:: $hwcap;
56
+ ) *
57
+
50
58
#[ macro_export]
51
59
#[ doc( hidden) ]
52
60
macro_rules! check {
53
61
$(
54
- ( $hwcaps: expr, $name) => { ( ( $hwcaps & libc :: $hwcap) != 0 ) } ;
62
+ ( $hwcaps: expr, $name) => { ( ( $hwcaps & $crate :: aarch64 :: $hwcap) != 0 ) } ;
55
63
) *
56
64
}
57
65
} ;
58
66
}
59
67
60
- /// Linux `expand_check_macro`
68
+ // Linux `expand_check_macro`
61
69
#[ cfg( target_os = "linux" ) ]
62
70
__expand_check_macro ! {
63
71
( "aes" , HWCAP_AES ) , // Enable AES support.
64
72
( "sha2" , HWCAP_SHA2 ) , // Enable SHA1 and SHA256 support.
65
73
( "sha3" , HWCAP_SHA3 ) , // Enable SHA512 and SHA3 support.
66
74
}
67
75
68
- /// macOS `check!` macro.
69
- ///
70
- /// NOTE: several of these instructions (e.g. `aes`, `sha2`) can be assumed to
71
- /// be present on all Apple ARM64 hardware.
72
- ///
73
- /// Newer CPU instructions now have nodes within sysctl's `hw.optional`
74
- /// namespace, however the ones that do not can safely be assumed to be
75
- /// present on all Apple ARM64 devices, now and for the foreseeable future.
76
- ///
77
- /// See discussion on this issue for more information:
78
- /// <https://github.com/RustCrypto/utils/issues/378>
76
+ // macOS `check!` macro.
77
+ //
78
+ // NOTE: several of these instructions (e.g. `aes`, `sha2`) can be assumed to
79
+ // be present on all Apple ARM64 hardware.
80
+ //
81
+ // Newer CPU instructions now have nodes within sysctl's `hw.optional`
82
+ // namespace, however the ones that do not can safely be assumed to be
83
+ // present on all Apple ARM64 devices, now and for the foreseeable future.
84
+ //
85
+ // See discussion on this issue for more information:
86
+ // <https://github.com/RustCrypto/utils/issues/378>
79
87
#[ cfg( target_os = "macos" ) ]
80
88
#[ macro_export]
81
89
#[ doc( hidden) ]
0 commit comments