Skip to content

Commit bdd3bc8

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

File tree

6 files changed

+14
-7
lines changed

6 files changed

+14
-7
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
277277
{
278278
None
279279
}
280+
("loongarch32" | "loongarch64", "32s") if get_version().0 < 21 => None,
280281
// Filter out features that are not supported by the current LLVM version
281282
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
282283
(

compiler/rustc_target/src/target_features.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ static CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
767767

768768
static LOONGARCH_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
769769
// tidy-alphabetical-start
770+
("32s", Unstable(sym::loongarch_target_feature), &[]),
770771
("d", Stable, &["f"]),
771772
("div32", Unstable(sym::loongarch_target_feature), &[]),
772773
("f", Stable, &[]),

library/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";

library/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));

library/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
}

tests/ui/check-cfg/target_feature.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ LL | cfg!(target_feature = "_UNEXPECTED_VALUE");
66
|
77
= note: expected values for `target_feature` are: `10e60`
88
`2e3`
9+
`32s`
910
`3e3r1`
1011
`3e3r2`
1112
`3e3r3`

0 commit comments

Comments
 (0)