Skip to content

Commit

Permalink
Merge branch 'rust-lang:master' into arm64ec
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaoliello authored Mar 9, 2024
2 parents 7f0a106 + 6381cf7 commit f1c12ac
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 36 deletions.
42 changes: 15 additions & 27 deletions crates/std_detect/src/detect/arch/loongarch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,29 @@ features! {
/// Checks if `loongarch` feature is enabled.
/// Supported arguments are:
///
/// * `"lam"`
/// * `"ual"`
/// * `"fpu"`
/// * `"f"`
/// * `"d"`
/// * `"frecipe"`
/// * `"lsx"`
/// * `"lasx"`
/// * `"crc32"`
/// * `"complex"`
/// * `"crypto"`
/// * `"lbt"`
/// * `"lvz"`
/// * `"lbtx86"`
/// * `"lbtarm"`
/// * `"lbtmips"`
/// * `"ual"`
#[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")]
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lam: "lam";
/// LAM
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] ual: "ual";
/// UAL
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] fpu: "fpu";
/// FPU
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] f: "f";
/// F
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] d: "d";
/// D
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] frecipe: "frecipe";
/// Frecipe
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lsx: "lsx";
/// LSX
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lasx: "lasx";
/// LASX
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] crc32: "crc32";
/// FPU
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] complex: "complex";
/// Complex
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] crypto: "crypto";
/// Crypto
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbt: "lbt";
/// LBT
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lvz: "lvz";
/// LVZ
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbtx86: "lbtx86";
/// LBT.X86
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbtarm: "lbtarm";
/// LBT.ARM
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] lbtmips: "lbtmips";
/// LBT.MIPS
@FEATURE: #[unstable(feature = "stdarch_loongarch_feature_detection", issue = "117425")] ual: "ual";
/// UAL
}
39 changes: 30 additions & 9 deletions crates/std_detect/src/detect/os/linux/loongarch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use super::auxvec;
use crate::detect::{bit, cache, Feature};
use core::arch::asm;

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

// The values are part of the platform-specific [cpucfg]
//
// [cpucfg]: LoongArch Reference Manual Volume 1: Basic Architecture v1.1
let cpucfg2: usize;
unsafe {
asm!(
"cpucfg {}, {}",
out(reg) cpucfg2, in(reg) 2,
options(pure, nomem, preserves_flags, nostack)
);
}
enable_feature(&mut value, Feature::frecipe, bit::test(cpucfg2, 25));

// The values are part of the platform-specific [asm/hwcap.h][hwcap]
//
// [hwcap]: https://github.com/torvalds/linux/blob/master/arch/loongarch/include/uapi/asm/hwcap.h
if let Ok(auxv) = auxvec::auxv() {
enable_feature(&mut value, Feature::lam, bit::test(auxv.hwcap, 1));
enable_feature(&mut value, Feature::ual, bit::test(auxv.hwcap, 2));
enable_feature(&mut value, Feature::fpu, bit::test(auxv.hwcap, 3));
enable_feature(
&mut value,
Feature::f,
bit::test(cpucfg2, 1) && bit::test(auxv.hwcap, 3),
);
enable_feature(
&mut value,
Feature::d,
bit::test(cpucfg2, 2) && bit::test(auxv.hwcap, 3),
);
enable_feature(&mut value, Feature::lsx, bit::test(auxv.hwcap, 4));
enable_feature(&mut value, Feature::lasx, bit::test(auxv.hwcap, 5));
enable_feature(&mut value, Feature::crc32, bit::test(auxv.hwcap, 6));
enable_feature(&mut value, Feature::complex, bit::test(auxv.hwcap, 7));
enable_feature(&mut value, Feature::crypto, bit::test(auxv.hwcap, 8));
enable_feature(
&mut value,
Feature::lbt,
bit::test(auxv.hwcap, 10) && bit::test(auxv.hwcap, 11) && bit::test(auxv.hwcap, 12),
);
enable_feature(&mut value, Feature::lvz, bit::test(auxv.hwcap, 9));
enable_feature(&mut value, Feature::lbtx86, bit::test(auxv.hwcap, 10));
enable_feature(&mut value, Feature::lbtarm, bit::test(auxv.hwcap, 11));
enable_feature(&mut value, Feature::lbtmips, bit::test(auxv.hwcap, 12));
enable_feature(&mut value, Feature::ual, bit::test(auxv.hwcap, 2));
return value;
}
value
Expand Down

0 comments on commit f1c12ac

Please sign in to comment.