Skip to content

Commit 3eca39f

Browse files
taiki-eAmanieu
authored andcommitted
std_detect: Remove /proc/cpuinfo-based detection
1 parent 8795aeb commit 3eca39f

File tree

8 files changed

+7
-508
lines changed

8 files changed

+7
-508
lines changed

crates/std_detect/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ is undefined.
4141
have the minimum supported API level higher than [Android 4.3 (API level 18) that added `getauxval`](https://github.com/aosp-mirror/platform_bionic/blob/d3ebc2f7c49a9893b114124d4a6b315f3a328764/libc/include/sys/auxv.h#L49).
4242

4343
* `std_detect_file_io` (enabled by default, requires `std`): Enable to perform run-time feature
44-
detection using file APIs (e.g. `/proc/cpuinfo`, etc.) if other more performant
44+
detection using file APIs (e.g. `/proc/self/auxv`, etc.) if other more performant
4545
methods fail. This feature requires `libstd` as a dependency, preventing the
4646
crate from working on applications in which `std` is not available.
4747

@@ -58,7 +58,7 @@ crate from working on applications in which `std` is not available.
5858
* Linux/Android:
5959
* `arm{32, 64}`, `mips{32,64}{,el}`, `powerpc{32,64}{,le}`, `loongarch64`, `s390x`:
6060
`std_detect` supports these on Linux by querying ELF auxiliary vectors (using `getauxval`
61-
when available), and if that fails, by querying `/proc/cpuinfo`.
61+
when available), and if that fails, by querying `/proc/self/auxv`.
6262
* `arm64`: partial support for doing run-time feature detection by directly
6363
querying `mrs` is implemented for Linux >= 4.11, but not enabled by default.
6464
* `riscv{32,64}`:

crates/std_detect/src/detect/os/linux/aarch64.rs

+1-118
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use super::auxvec;
44
use crate::detect::{Feature, bit, cache};
55

6-
/// Try to read the features from the auxiliary vector, and if that fails, try
7-
/// to read them from /proc/cpuinfo.
6+
/// Try to read the features from the auxiliary vector.
87
pub(crate) fn detect_features() -> cache::Initializer {
98
#[cfg(target_os = "android")]
109
let is_exynos9810 = {
@@ -27,11 +26,6 @@ pub(crate) fn detect_features() -> cache::Initializer {
2726
let hwcap: AtHwcap = auxv.into();
2827
return hwcap.cache(is_exynos9810);
2928
}
30-
#[cfg(feature = "std_detect_file_io")]
31-
if let Ok(c) = super::cpuinfo::CpuInfo::new() {
32-
let hwcap: AtHwcap = c.into();
33-
return hwcap.cache(is_exynos9810);
34-
}
3529
cache::Initializer::default()
3630
}
3731

@@ -249,117 +243,6 @@ impl From<auxvec::AuxVec> for AtHwcap {
249243
}
250244
}
251245

252-
#[cfg(feature = "std_detect_file_io")]
253-
impl From<super::cpuinfo::CpuInfo> for AtHwcap {
254-
/// Reads AtHwcap from /proc/cpuinfo .
255-
fn from(c: super::cpuinfo::CpuInfo) -> Self {
256-
let f = &c.field("Features");
257-
AtHwcap {
258-
// 64-bit names. FIXME: In 32-bit compatibility mode /proc/cpuinfo will
259-
// map some of the 64-bit names to some 32-bit feature names. This does not
260-
// cover that yet.
261-
fp: f.has("fp"),
262-
asimd: f.has("asimd"),
263-
// evtstrm: f.has("evtstrm"),
264-
aes: f.has("aes"),
265-
pmull: f.has("pmull"),
266-
sha1: f.has("sha1"),
267-
sha2: f.has("sha2"),
268-
crc32: f.has("crc32"),
269-
atomics: f.has("atomics"),
270-
fphp: f.has("fphp"),
271-
asimdhp: f.has("asimdhp"),
272-
// cpuid: f.has("cpuid"),
273-
asimdrdm: f.has("asimdrdm"),
274-
jscvt: f.has("jscvt"),
275-
fcma: f.has("fcma"),
276-
lrcpc: f.has("lrcpc"),
277-
dcpop: f.has("dcpop"),
278-
sha3: f.has("sha3"),
279-
sm3: f.has("sm3"),
280-
sm4: f.has("sm4"),
281-
asimddp: f.has("asimddp"),
282-
sha512: f.has("sha512"),
283-
sve: f.has("sve"),
284-
fhm: f.has("asimdfhm"),
285-
dit: f.has("dit"),
286-
uscat: f.has("uscat"),
287-
ilrcpc: f.has("ilrcpc"),
288-
flagm: f.has("flagm"),
289-
ssbs: f.has("ssbs"),
290-
sb: f.has("sb"),
291-
paca: f.has("paca"),
292-
pacg: f.has("pacg"),
293-
294-
// AT_HWCAP2
295-
dcpodp: f.has("dcpodp"),
296-
sve2: f.has("sve2"),
297-
sveaes: f.has("sveaes"),
298-
svepmull: f.has("svepmull"),
299-
svebitperm: f.has("svebitperm"),
300-
svesha3: f.has("svesha3"),
301-
svesm4: f.has("svesm4"),
302-
flagm2: f.has("flagm2"),
303-
frint: f.has("frint"),
304-
// svei8mm: f.has("svei8mm"),
305-
svef32mm: f.has("svef32mm"),
306-
svef64mm: f.has("svef64mm"),
307-
// svebf16: f.has("svebf16"),
308-
i8mm: f.has("i8mm"),
309-
bf16: f.has("bf16"),
310-
// dgh: f.has("dgh"),
311-
rng: f.has("rng"),
312-
bti: f.has("bti"),
313-
mte: f.has("mte"),
314-
ecv: f.has("ecv"),
315-
// afp: f.has("afp"),
316-
// rpres: f.has("rpres"),
317-
// mte3: f.has("mte3"),
318-
sme: f.has("sme"),
319-
smei16i64: f.has("smei16i64"),
320-
smef64f64: f.has("smef64f64"),
321-
// smei8i32: f.has("smei8i32"),
322-
// smef16f32: f.has("smef16f32"),
323-
// smeb16f32: f.has("smeb16f32"),
324-
// smef32f32: f.has("smef32f32"),
325-
smefa64: f.has("smefa64"),
326-
wfxt: f.has("wfxt"),
327-
// ebf16: f.has("ebf16"),
328-
// sveebf16: f.has("sveebf16"),
329-
cssc: f.has("cssc"),
330-
// rprfm: f.has("rprfm"),
331-
sve2p1: f.has("sve2p1"),
332-
sme2: f.has("sme2"),
333-
sme2p1: f.has("sme2p1"),
334-
// smei16i32: f.has("smei16i32"),
335-
// smebi32i32: f.has("smebi32i32"),
336-
smeb16b16: f.has("smeb16b16"),
337-
smef16f16: f.has("smef16f16"),
338-
mops: f.has("mops"),
339-
hbc: f.has("hbc"),
340-
sveb16b16: f.has("sveb16b16"),
341-
lrcpc3: f.has("lrcpc3"),
342-
lse128: f.has("lse128"),
343-
fpmr: f.has("fpmr"),
344-
lut: f.has("lut"),
345-
faminmax: f.has("faminmax"),
346-
f8cvt: f.has("f8cvt"),
347-
f8fma: f.has("f8fma"),
348-
f8dp4: f.has("f8dp4"),
349-
f8dp2: f.has("f8dp2"),
350-
f8e4m3: f.has("f8e4m3"),
351-
f8e5m2: f.has("f8e5m2"),
352-
smelutv2: f.has("smelutv2"),
353-
smef8f16: f.has("smef8f16"),
354-
smef8f32: f.has("smef8f32"),
355-
smesf8fma: f.has("smesf8fma"),
356-
smesf8dp4: f.has("smesf8dp4"),
357-
smesf8dp2: f.has("smesf8dp2"),
358-
// pauthlr: f.has("pauthlr"),
359-
}
360-
}
361-
}
362-
363246
impl AtHwcap {
364247
/// Initializes the cache from the feature -bits.
365248
///

crates/std_detect/src/detect/os/linux/arm.rs

+1-38
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
use super::auxvec;
44
use crate::detect::{Feature, bit, cache};
55

6-
/// Try to read the features from the auxiliary vector, and if that fails, try
7-
/// to read them from /proc/cpuinfo.
6+
/// Try to read the features from the auxiliary vector.
87
pub(crate) fn detect_features() -> cache::Initializer {
98
let mut value = cache::Initializer::default();
109
let enable_feature = |value: &mut cache::Initializer, f, enable| {
@@ -31,41 +30,5 @@ pub(crate) fn detect_features() -> cache::Initializer {
3130
);
3231
return value;
3332
}
34-
35-
#[cfg(feature = "std_detect_file_io")]
36-
if let Ok(c) = super::cpuinfo::CpuInfo::new() {
37-
enable_feature(
38-
&mut value,
39-
Feature::neon,
40-
c.field("Features").has("neon") && !has_broken_neon(&c),
41-
);
42-
enable_feature(&mut value, Feature::i8mm, c.field("Features").has("i8mm"));
43-
enable_feature(
44-
&mut value,
45-
Feature::dotprod,
46-
c.field("Features").has("asimddp"),
47-
);
48-
enable_feature(&mut value, Feature::pmull, c.field("Features").has("pmull"));
49-
enable_feature(&mut value, Feature::crc, c.field("Features").has("crc32"));
50-
enable_feature(&mut value, Feature::aes, c.field("Features").has("aes"));
51-
enable_feature(
52-
&mut value,
53-
Feature::sha2,
54-
c.field("Features").has("sha1") && c.field("Features").has("sha2"),
55-
);
56-
return value;
57-
}
5833
value
5934
}
60-
61-
/// Is the CPU known to have a broken NEON unit?
62-
///
63-
/// See https://crbug.com/341598.
64-
#[cfg(feature = "std_detect_file_io")]
65-
fn has_broken_neon(cpuinfo: &super::cpuinfo::CpuInfo) -> bool {
66-
cpuinfo.field("CPU implementer") == "0x51"
67-
&& cpuinfo.field("CPU architecture") == "7"
68-
&& cpuinfo.field("CPU variant") == "0x1"
69-
&& cpuinfo.field("CPU part") == "0x04d"
70-
&& cpuinfo.field("CPU revision") == "0"
71-
}

crates/std_detect/src/detect/os/linux/auxvec.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ pub(crate) struct AuxVec {
5353
/// - If that fails, this function returns an error.
5454
///
5555
/// Note that run-time feature detection is not invoked for features that can
56-
/// be detected at compile-time. Also note that if this function returns an
57-
/// error, cpuinfo still can (and will) be used to try to perform run-time
58-
/// feature detection on some platforms.
56+
/// be detected at compile-time.
5957
///
6058
/// Note: The `std_detect_dlsym_getauxval` cargo feature is ignored on
6159
/// `*-linux-{gnu,musl,ohos}*` and `*-android*` targets because we can safely assume `getauxval`

0 commit comments

Comments
 (0)