Skip to content

Commit c491839

Browse files
committed
Initial PowerPC support
1 parent 59a4ca8 commit c491839

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

src/runtime/linux/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ fn detect_features_impl<T: FeatureQuery>(x: T) -> usize {
2020
{
2121
super::aarch64::detect_features(x)
2222
}
23+
#[cfg(target_arch = "powerpc64")]
24+
{
25+
super::powerpc64::detect_features(x)
26+
}
2327
}
2428

2529
/// Detects ARM features:

src/runtime/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ mod aarch64;
1717
#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
1818
pub use self::aarch64::__Feature;
1919

20+
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
21+
#[macro_use]
22+
mod powerpc64;
23+
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
24+
pub use self::powerpc64::__Feature;
25+
2026
#[cfg(all(target_os = "linux",
21-
any(target_arch = "arm", target_arch = "aarch64")))]
27+
any(target_arch = "arm", target_arch = "aarch64", target_arch = "powerpc64")))]
2228
mod linux;
2329

2430
#[cfg(all(target_os = "linux",
25-
any(target_arch = "arm", target_arch = "aarch64")))]
31+
any(target_arch = "arm", target_arch = "aarch64", target_arch = "powerpc64")))]
2632
pub use self::linux::detect_features;
2733

2834
/// Performs run-time feature detection.

src/runtime/powerpc64.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//! Run-time feature detection on PowerPC64.
2+
use super::{bit, linux};
3+
4+
#[macro_export]
5+
#[doc(hidden)]
6+
macro_rules! __unstable_detect_feature {
7+
("altivec") => {
8+
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::altivec{})
9+
};
10+
("vsx") => {
11+
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::vsx{})
12+
};
13+
("power8") => {
14+
$crate::vendor::__unstable_detect_feature($crate::vendor::__Feature::power8{})
15+
};
16+
($t:tt) => { compile_error!(concat!("unknown PowerPC target feature: ", $t)) };
17+
}
18+
19+
/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset
20+
/// for a particular feature.
21+
///
22+
/// PLEASE: do not use this, it is an implementation detail subject to change.
23+
#[doc(hidden)]
24+
#[allow(non_camel_case_types)]
25+
#[repr(u8)]
26+
pub enum __Feature {
27+
/// Altivec
28+
altivec,
29+
/// VSX
30+
vsx,
31+
/// Power8
32+
power8,
33+
}
34+
35+
pub fn detect_features<T: linux::FeatureQuery>(mut x: T) -> usize {
36+
let mut value: usize = 0;
37+
{
38+
let mut enable_feature = |f| {
39+
if x.has_feature(&f) {
40+
value = bit::set(value, f as u32);
41+
}
42+
};
43+
enable_feature(__Feature::altivec);
44+
enable_feature(__Feature::vsx);
45+
enable_feature(__Feature::power8);
46+
}
47+
value
48+
}
49+
50+
impl linux::FeatureQuery for linux::AuxVec {
51+
fn has_feature(&mut self, x: &__Feature) -> bool {
52+
use self::__Feature::*;
53+
match *x {
54+
altivec => self.lookup(linux::AT::HWCAP)
55+
.map(|caps| caps & 0x10000000 != 0)
56+
.unwrap_or(false),
57+
vsx => self.lookup(linux::AT::HWCAP)
58+
.map(|caps| caps & 0x00000080 != 0)
59+
.unwrap_or(false),
60+
power8 => self.lookup(linux::AT::HWCAP2)
61+
.map(|caps| caps & 0x80000000 != 0)
62+
.unwrap_or(false),
63+
}
64+
}
65+
}
66+
67+
// TODO: This is a dummy linux on ppc does not provide this information
68+
impl linux::FeatureQuery for linux::CpuInfo {
69+
fn has_feature(&mut self, x: &__Feature) -> bool {
70+
use self::__Feature::*;
71+
match *x {
72+
altivec => self.field("Features").has("altivec"),
73+
vsx => self.field("Features").has("vsx"),
74+
power8 => self.field("Features").has("isa2_7"),
75+
}
76+
}
77+
}
78+
79+
#[cfg(test)]
80+
mod tests {
81+
#[test]
82+
fn detect_feature() {
83+
println!("altivec {}", __unstable_detect_feature!("altivec"));
84+
println!("vsx {}", __unstable_detect_feature!("vsx"));
85+
println!("power8 {}", __unstable_detect_feature!("power8"));
86+
}
87+
}

0 commit comments

Comments
 (0)