1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use super::bit;
use super::cache;
use super::linux;
#[macro_export]
#[unstable(feature = "stdsimd", issue = "0")]
macro_rules! is_arm_feature_detected {
("neon") => {
cfg!(target_feature = "neon") ||
$crate::arch::detect::check_for($crate::arch::detect::Feature::neon)
};
("pmull") => {
cfg!(target_feature = "pmull") ||
$crate::arch::detect::check_for($crate::arch::detect::Feature::pmull)
};
($t:tt) => { compile_error!(concat!("unknown arm target feature: ", $t)) };
}
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[repr(u8)]
pub enum Feature {
neon,
pmull,
}
pub fn detect_features() -> cache::Initializer {
let mut value = cache::Initializer::default();
fill_features(&mut value);
return value
}
fn fill_features(value: &mut cache::Initializer) {
let mut enable_feature = |f, enable| {
if enable {
value.set(f as u32);
}
};
if let Ok(auxv) = linux::auxv() {
enable_feature(Feature::neon, bit::test(auxv.hwcap, 12));
enable_feature(Feature::pmull, bit::test(auxv.hwcap2, 1));
return
}
if let Ok(c) = linux::CpuInfo::new() {
enable_feature(Feature::neon, c.field("Features").has("neon") &&
!has_broken_neon(&c));
enable_feature(Feature::pmull, c.field("Features").has("pmull"));
return
}
fn has_broken_neon(cpuinfo: &linux::CpuInfo) -> bool {
cpuinfo.field("CPU implementer") == "0x51"
&& cpuinfo.field("CPU architecture") == "7"
&& cpuinfo.field("CPU variant") == "0x1"
&& cpuinfo.field("CPU part") == "0x04d"
&& cpuinfo.field("CPU revision") == "0"
}
}