Skip to content

Commit b8b1c5f

Browse files
gnzlbgalexcrichton
authored andcommitted
add run-time feature detection for powerpc (rust-lang#452)
1 parent 38ed665 commit b8b1c5f

File tree

10 files changed

+126
-12
lines changed

10 files changed

+126
-12
lines changed

Diff for: coresimd/powerpc/altivec.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,14 @@ where
330330
a.vec_add(b)
331331
}
332332

333-
#[cfg(all(test, target_arch = "powerpc64"))]
333+
#[cfg(test)]
334334
mod tests {
335+
#[cfg(target_arch = "powerpc")]
336+
use coresimd::arch::powerpc::*;
337+
335338
#[cfg(target_arch = "powerpc64")]
336339
use coresimd::arch::powerpc64::*;
340+
337341
use simd::*;
338342
use stdsimd_test::simd_test;
339343

Diff for: crates/simd-test-macro/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn simd_test(
6868
"i686" | "x86_64" | "i586" => "is_x86_feature_detected",
6969
"arm" | "armv7" => "is_arm_feature_detected",
7070
"aarch64" => "is_aarch64_feature_detected",
71+
"powerpc" | "powerpcle" => "is_powerpc_feature_detected",
7172
"powerpc64" | "powerpc64le" => "is_powerpc64_feature_detected",
7273
"mips" | "mipsel" => {
7374
// FIXME:

Diff for: crates/stdsimd/tests/cpu-detection.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#[cfg(any(target_arch = "arm", target_arch = "aarch64",
77
target_arch = "x86", target_arch = "x86_64",
8-
target_arch = "powerpc64"))]
8+
target_arch = "powerpc", target_arch = "powerpc64"))]
99
#[macro_use]
1010
extern crate stdsimd;
1111

@@ -41,6 +41,20 @@ fn aarch64_linux() {
4141
);
4242
}
4343

44+
#[test]
45+
#[cfg(all(target_arch = "powerpc", target_os = "linux"))]
46+
fn powerpc_linux() {
47+
println!(
48+
"altivec: {}",
49+
is_powerpc_feature_detected!("altivec")
50+
);
51+
println!("vsx: {}", is_powerpc_feature_detected!("vsx"));
52+
println!(
53+
"power8: {}",
54+
is_powerpc_feature_detected!("power8")
55+
);
56+
}
57+
4458
#[test]
4559
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
4660
fn powerpc64_linux() {

Diff for: stdsimd/arch/detect/arch/powerpc.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//! Run-time feature detection on PowerPC.
2+
3+
#[macro_export]
4+
#[unstable(feature = "stdsimd", issue = "0")]
5+
#[allow_internal_unstable]
6+
macro_rules! is_powerpc_feature_detected {
7+
("altivec") => {
8+
cfg!(target_feature = "altivec") ||
9+
$crate::arch::detect::check_for($crate::arch::detect::Feature::altivec)
10+
};
11+
("vsx") => {
12+
cfg!(target_feature = "vsx") ||
13+
$crate::arch::detect::check_for($crate::arch::detect::Feature::vsx)
14+
};
15+
("power8") => {
16+
cfg!(target_feature = "power8") ||
17+
$crate::arch::detect::check_for($crate::arch::detect::Feature::power8)
18+
};
19+
($t:tt) => { compile_error!(concat!("unknown powerpc target feature: ", $t)) };
20+
}
21+
22+
23+
/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset
24+
/// for a particular feature.
25+
///
26+
/// PLEASE: do not use this, it is an implementation detail subject to change.
27+
#[doc(hidden)]
28+
#[allow(non_camel_case_types)]
29+
#[repr(u8)]
30+
#[unstable(feature = "stdsimd_internal", issue = "0")]
31+
pub enum Feature {
32+
/// Altivec
33+
altivec,
34+
/// VSX
35+
vsx,
36+
/// Power8
37+
power8,
38+
}

Diff for: stdsimd/arch/detect/arch/powerpc64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ macro_rules! is_powerpc64_feature_detected {
2020
}
2121

2222

23-
/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset
23+
/// PowerPC64 CPU Feature enum. Each variant denotes a position in a bitset
2424
/// for a particular feature.
2525
///
2626
/// PLEASE: do not use this, it is an implementation detail subject to change.

Diff for: stdsimd/arch/detect/error_macros.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ macro_rules! is_x86_feature_detected {
1212
is_x86_feature_detected can only be used on x86 and x86_64 targets.
1313
You can prevent it from being used in other architectures by
1414
guarding it behind a cfg(target_arch) as follows:
15-
15+
1616
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
1717
if is_x86_feature_detected(...) { ... }
1818
}
@@ -31,7 +31,7 @@ macro_rules! is_arm_feature_detected {
3131
is_arm_feature_detected can only be used on ARM targets.
3232
You can prevent it from being used in other architectures by
3333
guarding it behind a cfg(target_arch) as follows:
34-
34+
3535
#[cfg(target_arch = "arm")] {
3636
if is_arm_feature_detected(...) { ... }
3737
}
@@ -50,7 +50,7 @@ macro_rules! is_aarch64_feature_detected {
5050
is_aarch64_feature_detected can only be used on AArch64 targets.
5151
You can prevent it from being used in other architectures by
5252
guarding it behind a cfg(target_arch) as follows:
53-
53+
5454
#[cfg(target_arch = "aarch64")] {
5555
if is_aarch64_feature_detected(...) { ... }
5656
}
@@ -59,6 +59,23 @@ macro_rules! is_aarch64_feature_detected {
5959
};
6060
}
6161

62+
#[cfg(not(target_arch = "powerpc"))]
63+
#[macro_export]
64+
#[unstable(feature = "stdsimd", issue = "0")]
65+
macro_rules! is_powerpc_feature_detected {
66+
($t:tt) => {
67+
compile_error!(r#"
68+
is_powerpc_feature_detected can only be used on PowerPC targets.
69+
You can prevent it from being used in other architectures by
70+
guarding it behind a cfg(target_arch) as follows:
71+
72+
#[cfg(target_arch = "powerpc")] {
73+
if is_powerpc_feature_detected(...) { ... }
74+
}
75+
"#)
76+
};
77+
}
78+
6279
#[cfg(not(target_arch = "powerpc64"))]
6380
#[macro_export]
6481
#[unstable(feature = "stdsimd", issue = "0")]
@@ -86,7 +103,7 @@ macro_rules! is_mips_feature_detected {
86103
is_mips_feature_detected can only be used on MIPS targets.
87104
You can prevent it from being used in other architectures by
88105
guarding it behind a cfg(target_arch) as follows:
89-
106+
90107
#[cfg(target_arch = "mips")] {
91108
if is_mips_feature_detected(...) { ... }
92109
}
@@ -105,7 +122,7 @@ macro_rules! is_mips64_feature_detected {
105122
is_mips64_feature_detected can only be used on MIPS64 targets.
106123
You can prevent it from being used in other architectures by
107124
guarding it behind a cfg(target_arch) as follows:
108-
125+
109126
#[cfg(target_arch = "mips64")] {
110127
if is_mips64_feature_detected(...) { ... }
111128
}

Diff for: stdsimd/arch/detect/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ cfg_if! {
3333
#[path = "arch/aarch64.rs"]
3434
#[macro_use]
3535
mod arch;
36+
} else if #[cfg(target_arch = "powerpc")] {
37+
#[path = "arch/powerpc.rs"]
38+
#[macro_use]
39+
mod arch;
3640
} else if #[cfg(target_arch = "powerpc64")] {
3741
#[path = "arch/powerpc64.rs"]
3842
#[macro_use]

Diff for: stdsimd/arch/detect/os/linux/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ cfg_if! {
1313
} else if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] {
1414
mod mips;
1515
pub use self::mips::check_for;
16-
} else if #[cfg(target_arch = "powerpc64")] {
17-
mod powerpc64;
18-
pub use self::powerpc64::check_for;
16+
} else if #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] {
17+
mod powerpc;
18+
pub use self::powerpc::check_for;
1919
} else {
2020
use arch::detect::Feature;
2121
/// Performs run-time feature detection.

Diff for: stdsimd/arch/detect/os/linux/powerpc64.rs renamed to stdsimd/arch/detect/os/linux/powerpc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Run-time feature detection for ARM on Linux.
1+
//! Run-time feature detection for PowerPC on Linux.
22
33
use arch::detect::Feature;
44
use arch::detect::cache;

Diff for: stdsimd/mod.rs

+36
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,17 @@
187187
/// * [`aarch64`]
188188
/// * [`mips`]
189189
/// * [`mips64`]
190+
/// * [`powerpc`]
191+
/// * [`powerpc64`]
190192
///
191193
/// [`x86`]: https://rust-lang-nursery.github.io/stdsimd/i686/stdsimd/arch/x86/index.html
192194
/// [`x86_64`]: https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/arch/x86_64/index.html
193195
/// [`arm`]: https://rust-lang-nursery.github.io/stdsimd/arm/stdsimd/arch/arm/index.html
194196
/// [`aarch64`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/aarch64/index.html
195197
/// [`mips`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/mips/index.html
196198
/// [`mips64`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/mips64/index.html
199+
/// [`powerpc`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/powerpc/index.html
200+
/// [`powerpc64`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/powerpc64/index.html
197201
///
198202
/// # Examples
199203
///
@@ -370,6 +374,14 @@ pub mod arch {
370374
#[unstable(feature = "stdsimd", issue = "0")]
371375
pub use coresimd::arch::mips64;
372376

377+
#[cfg(all(not(dox), target_arch = "powerpc"))]
378+
#[unstable(feature = "stdsimd", issue = "0")]
379+
pub use coresimd::arch::powerpc;
380+
381+
#[cfg(all(not(dox), target_arch = "powerpc64"))]
382+
#[unstable(feature = "stdsimd", issue = "0")]
383+
pub use coresimd::arch::powerpc64;
384+
373385
#[doc(hidden)] // unstable implementation detail
374386
#[unstable(feature = "stdsimd", issue = "0")]
375387
pub mod detect;
@@ -445,6 +457,30 @@ pub mod arch {
445457
#[doc(cfg(target_arch = "mips64"))]
446458
#[unstable(feature = "stdsimd", issue = "0")]
447459
pub mod mips64 {}
460+
461+
/// Platform-specific intrinsics for the `powerpc` platform.
462+
///
463+
/// The documentation with the full listing of `powerpc` intrinsics is
464+
/// available in [libcore], but the module is re-exported here in std
465+
/// as well.
466+
///
467+
/// [libcore]: ../../../core/arch/powerpc/index.html
468+
#[cfg(dox)]
469+
#[doc(cfg(target_arch = "powerpc"))]
470+
#[unstable(feature = "stdsimd", issue = "0")]
471+
pub mod powerpc {}
472+
473+
/// Platform-specific intrinsics for the `powerpc64` platform.
474+
///
475+
/// The documentation with the full listing of `powerpc64` intrinsics is
476+
/// available in [libcore], but the module is re-exported here in std
477+
/// as well.
478+
///
479+
/// [libcore]: ../../../core/arch/powerpc64/index.html
480+
#[cfg(dox)]
481+
#[doc(cfg(target_arch = "powerpc64"))]
482+
#[unstable(feature = "stdsimd", issue = "0")]
483+
pub mod powerpc64 {}
448484
}
449485

450486
#[unstable(feature = "stdsimd", issue = "0")]

0 commit comments

Comments
 (0)