Skip to content

Commit 59b9d60

Browse files
committed
add rt-detection for 32-bit mips
1 parent 08c32d5 commit 59b9d60

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

ci/run.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ case ${TARGET} in
1313
aarch*)
1414
export RUSTFLAGS="${RUSTFLAGS} -C target-feature=+neon"
1515
;;
16-
mips64*)
17-
export RUSTFLAGS="${RUSTFLAGS} -C target-cpu=mips64r6"
18-
;;
1916
*)
2017
;;
2118
esac

crates/simd-test-macro/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,20 @@ pub fn simd_test(
7272
.expect(&format!("target triple contained no \"-\": {}", target)) {
7373
"i686" | "x86_64" | "i586" => "is_x86_feature_detected",
7474
"arm" => "is_arm_feature_detected",
75-
"aarch64" => "is_aarch64_feature_detected",
75+
"aarch64" => "is_aarch64_feature_detected",
7676
"powerpc64" => "is_powerpc64_feature_detected",
77-
"mips64" | "mips64el" => {
77+
"mips" | "mipsel" => {
78+
// FIXME:
7879
// On MIPS CI run-time feature detection always returns false due to
7980
// this qemu bug: https://bugs.launchpad.net/qemu/+bug/1754372
8081
//
8182
// This is a workaround to force the MIPS tests to always run on CI.
8283
force_test = true;
84+
"is_mips_feature_detected"
85+
},
86+
"mips64" | "mips64el" => {
87+
// FIXME: see above
88+
force_test = true;
8389
"is_mips64_feature_detected"
8490
},
8591
t => panic!("unknown target: {}", t),

stdsimd/arch/detect/mips.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Run-time feature detection on MIPS.
2+
3+
use super::cache;
4+
5+
#[cfg(target_os = "linux")]
6+
use super::{bit, linux};
7+
8+
#[macro_export]
9+
#[unstable(feature = "stdsimd", issue = "0")]
10+
macro_rules! is_mips_feature_detected {
11+
("msa") => {
12+
cfg!(target_feature = "msa") ||
13+
$crate::arch::detect::check_for($crate::arch::detect::Feature::msa)
14+
};
15+
($t:tt) => { compile_error!(concat!("unknown mips target feature: ", $t)) };
16+
}
17+
18+
/// MIPS CPU Feature enum. Each variant denotes a position in a bitset for a
19+
/// particular feature.
20+
///
21+
/// PLEASE: do not use this, it is an implementation detail subject to change.
22+
#[doc(hidden)]
23+
#[allow(non_camel_case_types)]
24+
#[repr(u8)]
25+
pub enum Feature {
26+
/// MIPS SIMD Architecture (MSA)
27+
msa,
28+
}
29+
30+
pub fn detect_features() -> cache::Initializer {
31+
let mut value = cache::Initializer::default();
32+
fill_features(&mut value);
33+
value
34+
}
35+
36+
#[cfg(not(target_os = "linux"))]
37+
fn fill_features(_value: &mut cache::Initializer) {}
38+
39+
#[cfg(target_os = "linux")]
40+
fn fill_features(value: &mut cache::Initializer) {
41+
let mut enable_feature = |f, enable| {
42+
if enable {
43+
value.set(f as u32);
44+
}
45+
};
46+
47+
// The values are part of the platform-specific [asm/cputable.h][cputable]
48+
//
49+
// [cputable]: https://github.com/torvalds/linux/blob/master/arch/mips/include/uapi/asm/hwcap.h
50+
if let Ok(auxv) = linux::auxvec::auxv() {
51+
enable_feature(Feature::msa, bit::test(auxv.hwcap, 1));
52+
return
53+
}
54+
55+
// TODO: fall back via cpuinfo
56+
}

0 commit comments

Comments
 (0)