Skip to content

Commit f1c12ac

Browse files
authored
Merge branch 'rust-lang:master' into arm64ec
2 parents 7f0a106 + 6381cf7 commit f1c12ac

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

crates/std_detect/src/detect/arch/loongarch.rs

+15-27
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,29 @@ features! {
88
/// Checks if `loongarch` feature is enabled.
99
/// Supported arguments are:
1010
///
11-
/// * `"lam"`
12-
/// * `"ual"`
13-
/// * `"fpu"`
11+
/// * `"f"`
12+
/// * `"d"`
13+
/// * `"frecipe"`
1414
/// * `"lsx"`
1515
/// * `"lasx"`
16-
/// * `"crc32"`
17-
/// * `"complex"`
18-
/// * `"crypto"`
16+
/// * `"lbt"`
1917
/// * `"lvz"`
20-
/// * `"lbtx86"`
21-
/// * `"lbtarm"`
22-
/// * `"lbtmips"`
18+
/// * `"ual"`
2319
#[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")]
24-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lam: "lam";
25-
/// LAM
26-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] ual: "ual";
27-
/// UAL
28-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] fpu: "fpu";
29-
/// FPU
20+
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] f: "f";
21+
/// F
22+
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] d: "d";
23+
/// D
24+
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] frecipe: "frecipe";
25+
/// Frecipe
3026
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lsx: "lsx";
3127
/// LSX
3228
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lasx: "lasx";
3329
/// LASX
34-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] crc32: "crc32";
35-
/// FPU
36-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] complex: "complex";
37-
/// Complex
38-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] crypto: "crypto";
39-
/// Crypto
30+
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbt: "lbt";
31+
/// LBT
4032
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lvz: "lvz";
4133
/// LVZ
42-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbtx86: "lbtx86";
43-
/// LBT.X86
44-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbtarm: "lbtarm";
45-
/// LBT.ARM
46-
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbtmips: "lbtmips";
47-
/// LBT.MIPS
34+
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] ual: "ual";
35+
/// UAL
4836
}

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

+30-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use super::auxvec;
44
use crate::detect::{bit, cache, Feature};
5+
use core::arch::asm;
56

67
/// Try to read the features from the auxiliary vector.
78
pub(crate) fn detect_features() -> cache::Initializer {
@@ -12,22 +13,42 @@ pub(crate) fn detect_features() -> cache::Initializer {
1213
}
1314
};
1415

16+
// The values are part of the platform-specific [cpucfg]
17+
//
18+
// [cpucfg]: LoongArch Reference Manual Volume 1: Basic Architecture v1.1
19+
let cpucfg2: usize;
20+
unsafe {
21+
asm!(
22+
"cpucfg {}, {}",
23+
out(reg) cpucfg2, in(reg) 2,
24+
options(pure, nomem, preserves_flags, nostack)
25+
);
26+
}
27+
enable_feature(&mut value, Feature::frecipe, bit::test(cpucfg2, 25));
28+
1529
// The values are part of the platform-specific [asm/hwcap.h][hwcap]
1630
//
1731
// [hwcap]: https://github.com/torvalds/linux/blob/master/arch/loongarch/include/uapi/asm/hwcap.h
1832
if let Ok(auxv) = auxvec::auxv() {
19-
enable_feature(&mut value, Feature::lam, bit::test(auxv.hwcap, 1));
20-
enable_feature(&mut value, Feature::ual, bit::test(auxv.hwcap, 2));
21-
enable_feature(&mut value, Feature::fpu, bit::test(auxv.hwcap, 3));
33+
enable_feature(
34+
&mut value,
35+
Feature::f,
36+
bit::test(cpucfg2, 1) && bit::test(auxv.hwcap, 3),
37+
);
38+
enable_feature(
39+
&mut value,
40+
Feature::d,
41+
bit::test(cpucfg2, 2) && bit::test(auxv.hwcap, 3),
42+
);
2243
enable_feature(&mut value, Feature::lsx, bit::test(auxv.hwcap, 4));
2344
enable_feature(&mut value, Feature::lasx, bit::test(auxv.hwcap, 5));
24-
enable_feature(&mut value, Feature::crc32, bit::test(auxv.hwcap, 6));
25-
enable_feature(&mut value, Feature::complex, bit::test(auxv.hwcap, 7));
26-
enable_feature(&mut value, Feature::crypto, bit::test(auxv.hwcap, 8));
45+
enable_feature(
46+
&mut value,
47+
Feature::lbt,
48+
bit::test(auxv.hwcap, 10) && bit::test(auxv.hwcap, 11) && bit::test(auxv.hwcap, 12),
49+
);
2750
enable_feature(&mut value, Feature::lvz, bit::test(auxv.hwcap, 9));
28-
enable_feature(&mut value, Feature::lbtx86, bit::test(auxv.hwcap, 10));
29-
enable_feature(&mut value, Feature::lbtarm, bit::test(auxv.hwcap, 11));
30-
enable_feature(&mut value, Feature::lbtmips, bit::test(auxv.hwcap, 12));
51+
enable_feature(&mut value, Feature::ual, bit::test(auxv.hwcap, 2));
3152
return value;
3253
}
3354
value

0 commit comments

Comments
 (0)