Skip to content

Commit c932034

Browse files
authored
Rollup merge of rust-lang#145099 - heiher:loong-32s, r=folkertdev
rustc_target: Add the `32s` target feature for LoongArch LLVM: llvm/llvm-project#139695
2 parents b682e04 + c6c6866 commit c932034

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

std_detect/src/detect/arch/loongarch.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ features! {
88
/// Checks if `loongarch` feature is enabled.
99
/// Supported arguments are:
1010
///
11+
/// * `"32s"`
1112
/// * `"f"`
1213
/// * `"d"`
1314
/// * `"frecipe"`
@@ -22,6 +23,8 @@ features! {
2223
/// * `"lvz"`
2324
/// * `"ual"`
2425
#[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")]
26+
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] _32s: "32s";
27+
/// 32S
2528
@FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] f: "f";
2629
/// F
2730
@FEATURE: #[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")] d: "d";

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ pub(crate) fn detect_features() -> cache::Initializer {
1717
// The values are part of the platform-specific [cpucfg]
1818
//
1919
// [cpucfg]: LoongArch Reference Manual Volume 1: Basic Architecture v1.1
20+
let cpucfg1: usize;
2021
let cpucfg2: usize;
21-
unsafe {
22-
asm!(
23-
"cpucfg {}, {}",
24-
out(reg) cpucfg2, in(reg) 2,
25-
options(pure, nomem, preserves_flags, nostack)
26-
);
27-
}
2822
let cpucfg3: usize;
2923
unsafe {
3024
asm!(
3125
"cpucfg {}, {}",
26+
"cpucfg {}, {}",
27+
"cpucfg {}, {}",
28+
out(reg) cpucfg1, in(reg) 1,
29+
out(reg) cpucfg2, in(reg) 2,
3230
out(reg) cpucfg3, in(reg) 3,
3331
options(pure, nomem, preserves_flags, nostack)
3432
);
3533
}
34+
enable_feature(&mut value, Feature::_32s, bit::test(cpucfg1, 0) || bit::test(cpucfg1, 1));
3635
enable_feature(&mut value, Feature::frecipe, bit::test(cpucfg2, 25));
3736
enable_feature(&mut value, Feature::div32, bit::test(cpucfg2, 26));
3837
enable_feature(&mut value, Feature::lam_bh, bit::test(cpucfg2, 27));

std_detect/tests/macro_trailing_commas.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ fn aarch64() {
6969
#[test]
7070
#[cfg(any(target_arch = "loongarch32", target_arch = "loongarch64"))]
7171
fn loongarch() {
72+
let _ = is_loongarch_feature_detected!("32s");
73+
let _ = is_loongarch_feature_detected!("32s",);
7274
let _ = is_loongarch_feature_detected!("lsx");
7375
let _ = is_loongarch_feature_detected!("lsx",);
7476
}

0 commit comments

Comments
 (0)