diff --git a/library/stdarch/coresimd/powerpc/altivec.rs b/library/stdarch/coresimd/powerpc/altivec.rs index dbe5237730b9..0a362d9d4d32 100644 --- a/library/stdarch/coresimd/powerpc/altivec.rs +++ b/library/stdarch/coresimd/powerpc/altivec.rs @@ -330,10 +330,14 @@ where a.vec_add(b) } -#[cfg(all(test, target_arch = "powerpc64"))] +#[cfg(test)] mod tests { + #[cfg(target_arch = "powerpc")] + use coresimd::arch::powerpc::*; + #[cfg(target_arch = "powerpc64")] use coresimd::arch::powerpc64::*; + use simd::*; use stdsimd_test::simd_test; diff --git a/library/stdarch/crates/simd-test-macro/src/lib.rs b/library/stdarch/crates/simd-test-macro/src/lib.rs index 58aa8a474def..cb8a10d2a404 100644 --- a/library/stdarch/crates/simd-test-macro/src/lib.rs +++ b/library/stdarch/crates/simd-test-macro/src/lib.rs @@ -68,6 +68,7 @@ pub fn simd_test( "i686" | "x86_64" | "i586" => "is_x86_feature_detected", "arm" | "armv7" => "is_arm_feature_detected", "aarch64" => "is_aarch64_feature_detected", + "powerpc" | "powerpcle" => "is_powerpc_feature_detected", "powerpc64" | "powerpc64le" => "is_powerpc64_feature_detected", "mips" | "mipsel" => { // FIXME: diff --git a/library/stdarch/crates/stdsimd/tests/cpu-detection.rs b/library/stdarch/crates/stdsimd/tests/cpu-detection.rs index 62c04656d15a..775b9774f10c 100644 --- a/library/stdarch/crates/stdsimd/tests/cpu-detection.rs +++ b/library/stdarch/crates/stdsimd/tests/cpu-detection.rs @@ -5,7 +5,7 @@ #[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64", - target_arch = "powerpc64"))] + target_arch = "powerpc", target_arch = "powerpc64"))] #[macro_use] extern crate stdsimd; @@ -41,6 +41,20 @@ fn aarch64_linux() { ); } +#[test] +#[cfg(all(target_arch = "powerpc", target_os = "linux"))] +fn powerpc_linux() { + println!( + "altivec: {}", + is_powerpc_feature_detected!("altivec") + ); + println!("vsx: {}", is_powerpc_feature_detected!("vsx")); + println!( + "power8: {}", + is_powerpc_feature_detected!("power8") + ); +} + #[test] #[cfg(all(target_arch = "powerpc64", target_os = "linux"))] fn powerpc64_linux() { diff --git a/library/stdarch/stdsimd/arch/detect/arch/powerpc.rs b/library/stdarch/stdsimd/arch/detect/arch/powerpc.rs new file mode 100644 index 000000000000..8e5db3c8065e --- /dev/null +++ b/library/stdarch/stdsimd/arch/detect/arch/powerpc.rs @@ -0,0 +1,38 @@ +//! Run-time feature detection on PowerPC. + +#[macro_export] +#[unstable(feature = "stdsimd", issue = "0")] +#[allow_internal_unstable] +macro_rules! is_powerpc_feature_detected { + ("altivec") => { + cfg!(target_feature = "altivec") || + $crate::arch::detect::check_for($crate::arch::detect::Feature::altivec) + }; + ("vsx") => { + cfg!(target_feature = "vsx") || + $crate::arch::detect::check_for($crate::arch::detect::Feature::vsx) + }; + ("power8") => { + cfg!(target_feature = "power8") || + $crate::arch::detect::check_for($crate::arch::detect::Feature::power8) + }; + ($t:tt) => { compile_error!(concat!("unknown powerpc target feature: ", $t)) }; +} + + +/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset +/// for a particular feature. +/// +/// PLEASE: do not use this, it is an implementation detail subject to change. +#[doc(hidden)] +#[allow(non_camel_case_types)] +#[repr(u8)] +#[unstable(feature = "stdsimd_internal", issue = "0")] +pub enum Feature { + /// Altivec + altivec, + /// VSX + vsx, + /// Power8 + power8, +} diff --git a/library/stdarch/stdsimd/arch/detect/arch/powerpc64.rs b/library/stdarch/stdsimd/arch/detect/arch/powerpc64.rs index 81f861b81fd0..752d33e4e242 100644 --- a/library/stdarch/stdsimd/arch/detect/arch/powerpc64.rs +++ b/library/stdarch/stdsimd/arch/detect/arch/powerpc64.rs @@ -20,7 +20,7 @@ macro_rules! is_powerpc64_feature_detected { } -/// PowerPC CPU Feature enum. Each variant denotes a position in a bitset +/// PowerPC64 CPU Feature enum. Each variant denotes a position in a bitset /// for a particular feature. /// /// PLEASE: do not use this, it is an implementation detail subject to change. diff --git a/library/stdarch/stdsimd/arch/detect/error_macros.rs b/library/stdarch/stdsimd/arch/detect/error_macros.rs index 2b48033a9992..590356bc40e3 100644 --- a/library/stdarch/stdsimd/arch/detect/error_macros.rs +++ b/library/stdarch/stdsimd/arch/detect/error_macros.rs @@ -12,7 +12,7 @@ macro_rules! is_x86_feature_detected { is_x86_feature_detected can only be used on x86 and x86_64 targets. You can prevent it from being used in other architectures by guarding it behind a cfg(target_arch) as follows: - + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { if is_x86_feature_detected(...) { ... } } @@ -31,7 +31,7 @@ macro_rules! is_arm_feature_detected { is_arm_feature_detected can only be used on ARM targets. You can prevent it from being used in other architectures by guarding it behind a cfg(target_arch) as follows: - + #[cfg(target_arch = "arm")] { if is_arm_feature_detected(...) { ... } } @@ -50,7 +50,7 @@ macro_rules! is_aarch64_feature_detected { is_aarch64_feature_detected can only be used on AArch64 targets. You can prevent it from being used in other architectures by guarding it behind a cfg(target_arch) as follows: - + #[cfg(target_arch = "aarch64")] { if is_aarch64_feature_detected(...) { ... } } @@ -59,6 +59,23 @@ macro_rules! is_aarch64_feature_detected { }; } +#[cfg(not(target_arch = "powerpc"))] +#[macro_export] +#[unstable(feature = "stdsimd", issue = "0")] +macro_rules! is_powerpc_feature_detected { + ($t:tt) => { + compile_error!(r#" +is_powerpc_feature_detected can only be used on PowerPC targets. +You can prevent it from being used in other architectures by +guarding it behind a cfg(target_arch) as follows: + + #[cfg(target_arch = "powerpc")] { + if is_powerpc_feature_detected(...) { ... } + } +"#) + }; +} + #[cfg(not(target_arch = "powerpc64"))] #[macro_export] #[unstable(feature = "stdsimd", issue = "0")] @@ -86,7 +103,7 @@ macro_rules! is_mips_feature_detected { is_mips_feature_detected can only be used on MIPS targets. You can prevent it from being used in other architectures by guarding it behind a cfg(target_arch) as follows: - + #[cfg(target_arch = "mips")] { if is_mips_feature_detected(...) { ... } } @@ -105,7 +122,7 @@ macro_rules! is_mips64_feature_detected { is_mips64_feature_detected can only be used on MIPS64 targets. You can prevent it from being used in other architectures by guarding it behind a cfg(target_arch) as follows: - + #[cfg(target_arch = "mips64")] { if is_mips64_feature_detected(...) { ... } } diff --git a/library/stdarch/stdsimd/arch/detect/mod.rs b/library/stdarch/stdsimd/arch/detect/mod.rs index 11526f8e7e3d..7ed397171106 100644 --- a/library/stdarch/stdsimd/arch/detect/mod.rs +++ b/library/stdarch/stdsimd/arch/detect/mod.rs @@ -33,6 +33,10 @@ cfg_if! { #[path = "arch/aarch64.rs"] #[macro_use] mod arch; + } else if #[cfg(target_arch = "powerpc")] { + #[path = "arch/powerpc.rs"] + #[macro_use] + mod arch; } else if #[cfg(target_arch = "powerpc64")] { #[path = "arch/powerpc64.rs"] #[macro_use] diff --git a/library/stdarch/stdsimd/arch/detect/os/linux/mod.rs b/library/stdarch/stdsimd/arch/detect/os/linux/mod.rs index 31c84ac83c2b..11ac012e24dd 100644 --- a/library/stdarch/stdsimd/arch/detect/os/linux/mod.rs +++ b/library/stdarch/stdsimd/arch/detect/os/linux/mod.rs @@ -13,9 +13,9 @@ cfg_if! { } else if #[cfg(any(target_arch = "mips", target_arch = "mips64"))] { mod mips; pub use self::mips::check_for; - } else if #[cfg(target_arch = "powerpc64")] { - mod powerpc64; - pub use self::powerpc64::check_for; + } else if #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] { + mod powerpc; + pub use self::powerpc::check_for; } else { use arch::detect::Feature; /// Performs run-time feature detection. diff --git a/library/stdarch/stdsimd/arch/detect/os/linux/powerpc64.rs b/library/stdarch/stdsimd/arch/detect/os/linux/powerpc.rs similarity index 96% rename from library/stdarch/stdsimd/arch/detect/os/linux/powerpc64.rs rename to library/stdarch/stdsimd/arch/detect/os/linux/powerpc.rs index 9666996ed63d..8289c098167a 100644 --- a/library/stdarch/stdsimd/arch/detect/os/linux/powerpc64.rs +++ b/library/stdarch/stdsimd/arch/detect/os/linux/powerpc.rs @@ -1,4 +1,4 @@ -//! Run-time feature detection for ARM on Linux. +//! Run-time feature detection for PowerPC on Linux. use arch::detect::Feature; use arch::detect::cache; diff --git a/library/stdarch/stdsimd/mod.rs b/library/stdarch/stdsimd/mod.rs index c167fb106b39..976f8bed44ff 100644 --- a/library/stdarch/stdsimd/mod.rs +++ b/library/stdarch/stdsimd/mod.rs @@ -187,6 +187,8 @@ /// * [`aarch64`] /// * [`mips`] /// * [`mips64`] +/// * [`powerpc`] +/// * [`powerpc64`] /// /// [`x86`]: https://rust-lang-nursery.github.io/stdsimd/i686/stdsimd/arch/x86/index.html /// [`x86_64`]: https://rust-lang-nursery.github.io/stdsimd/x86_64/stdsimd/arch/x86_64/index.html @@ -194,6 +196,8 @@ /// [`aarch64`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/aarch64/index.html /// [`mips`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/mips/index.html /// [`mips64`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/mips64/index.html +/// [`powerpc`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/powerpc/index.html +/// [`powerpc64`]: https://rust-lang-nursery.github.io/stdsimd/aarch64/stdsimd/arch/powerpc64/index.html /// /// # Examples /// @@ -370,6 +374,14 @@ pub mod arch { #[unstable(feature = "stdsimd", issue = "0")] pub use coresimd::arch::mips64; + #[cfg(all(not(dox), target_arch = "powerpc"))] + #[unstable(feature = "stdsimd", issue = "0")] + pub use coresimd::arch::powerpc; + + #[cfg(all(not(dox), target_arch = "powerpc64"))] + #[unstable(feature = "stdsimd", issue = "0")] + pub use coresimd::arch::powerpc64; + #[doc(hidden)] // unstable implementation detail #[unstable(feature = "stdsimd", issue = "0")] pub mod detect; @@ -445,6 +457,30 @@ pub mod arch { #[doc(cfg(target_arch = "mips64"))] #[unstable(feature = "stdsimd", issue = "0")] pub mod mips64 {} + + /// Platform-specific intrinsics for the `powerpc` platform. + /// + /// The documentation with the full listing of `powerpc` intrinsics is + /// available in [libcore], but the module is re-exported here in std + /// as well. + /// + /// [libcore]: ../../../core/arch/powerpc/index.html + #[cfg(dox)] + #[doc(cfg(target_arch = "powerpc"))] + #[unstable(feature = "stdsimd", issue = "0")] + pub mod powerpc {} + + /// Platform-specific intrinsics for the `powerpc64` platform. + /// + /// The documentation with the full listing of `powerpc64` intrinsics is + /// available in [libcore], but the module is re-exported here in std + /// as well. + /// + /// [libcore]: ../../../core/arch/powerpc64/index.html + #[cfg(dox)] + #[doc(cfg(target_arch = "powerpc64"))] + #[unstable(feature = "stdsimd", issue = "0")] + pub mod powerpc64 {} } #[unstable(feature = "stdsimd", issue = "0")]