Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ pub mod arch {
pub use std_detect::is_arm_feature_detected;
#[stable(feature = "stdarch_loongarch_feature", since = "1.89.0")]
pub use std_detect::is_loongarch_feature_detected;
#[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
pub use std_detect::is_powerpc_feature_detected;
#[stable(feature = "riscv_ratified", since = "1.78.0")]
pub use std_detect::is_riscv_feature_detected;
#[stable(feature = "stdarch_s390x_feature_detection", since = "1.93.0")]
Expand All @@ -719,8 +721,6 @@ pub mod arch {
pub use std_detect::is_x86_feature_detected;
#[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")]
pub use std_detect::{is_mips_feature_detected, is_mips64_feature_detected};
#[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
pub use std_detect::{is_powerpc_feature_detected, is_powerpc64_feature_detected};
}

// This was stabilized in the crate root so we have to keep it there.
Expand Down
21 changes: 8 additions & 13 deletions library/std/tests/run-time-detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
feature(stdarch_aarch64_feature_detection)
)]
#![cfg_attr(
all(target_arch = "powerpc", target_os = "linux"),
all(
any(target_arch = "powerpc", target_arch = "powerpc64"),
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
),
feature(stdarch_powerpc_feature_detection)
)]
#![cfg_attr(
Expand Down Expand Up @@ -111,7 +114,10 @@ fn aarch64_linux() {
}

#[test]
#[cfg(all(target_arch = "powerpc", target_os = "linux"))]
#[cfg(all(
any(target_arch = "powerpc", target_arch = "powerpc64"),
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
))]
fn powerpc_linux() {
use std::arch::is_powerpc_feature_detected;
// tidy-alphabetical-start
Expand All @@ -121,17 +127,6 @@ fn powerpc_linux() {
// tidy-alphabetical-end
}

#[test]
#[cfg(all(target_arch = "powerpc64", target_os = "linux"))]
fn powerpc64_linux() {
use std::arch::is_powerpc64_feature_detected;
// tidy-alphabetical-start
println!("altivec: {}", is_powerpc64_feature_detected!("altivec"));
println!("power8: {}", is_powerpc64_feature_detected!("power8"));
println!("vsx: {}", is_powerpc64_feature_detected!("vsx"));
// tidy-alphabetical-end
}

#[test]
#[cfg(all(target_arch = "s390x", target_os = "linux"))]
fn s390x_linux() {
Expand Down
8 changes: 1 addition & 7 deletions library/std_detect/src/detect/arch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ mod riscv;
#[macro_use]
mod powerpc;
#[macro_use]
mod powerpc64;
#[macro_use]
mod mips;
#[macro_use]
mod mips64;
Expand All @@ -39,14 +37,10 @@ cfg_select! {
#[unstable(feature = "stdarch_riscv_feature_detection", issue = "111192")]
pub use riscv::*;
}
target_arch = "powerpc" => {
any(target_arch = "powerpc", target_arch = "powerpc64") => {
#[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
pub use powerpc::*;
}
target_arch = "powerpc64" => {
#[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
pub use powerpc64::*;
}
target_arch = "mips" => {
#[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")]
pub use mips::*;
Expand Down
2 changes: 1 addition & 1 deletion library/std_detect/src/detect/arch/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

features! {
@TARGET: powerpc;
@CFG: target_arch = "powerpc";
@CFG: any(target_arch = "powerpc", target_arch = "powerpc64");
@MACRO_NAME: is_powerpc_feature_detected;
@MACRO_ATTRS:
/// Check for the presence of a CPU feature at runtime.
Expand Down
33 changes: 0 additions & 33 deletions library/std_detect/src/detect/arch/powerpc64.rs

This file was deleted.

14 changes: 11 additions & 3 deletions library/std_detect/src/detect/os/freebsd/powerpc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
//! Run-time feature detection for PowerPC on FreeBSD.
//!
//! Constants for both 32- and 64-bit come from
//! <https://github.com/freebsd/freebsd-src/blob/main/sys/powerpc/include/cpu.h>.

use super::auxvec;
use crate::detect::{Feature, cache};

const PPC_FEATURE_HAS_ALTIVEC: usize = 0x10000000;
const PPC_FEATURE_HAS_VSX: usize = 0x00000080;
/// ISA 2.07, typically power8
const PPC_FEATURE2_ARCH_2_07: usize = 0x80000000;

pub(crate) fn detect_features() -> cache::Initializer {
let mut value = cache::Initializer::default();
let enable_feature = |value: &mut cache::Initializer, f, enable| {
Expand All @@ -12,9 +20,9 @@ pub(crate) fn detect_features() -> cache::Initializer {
};

if let Ok(auxv) = auxvec::auxv() {
enable_feature(&mut value, Feature::altivec, auxv.hwcap & 0x10000000 != 0);
enable_feature(&mut value, Feature::vsx, auxv.hwcap & 0x00000080 != 0);
enable_feature(&mut value, Feature::power8, auxv.hwcap2 & 0x80000000 != 0);
enable_feature(&mut value, Feature::altivec, auxv.hwcap & PPC_FEATURE_HAS_ALTIVEC != 0);
enable_feature(&mut value, Feature::vsx, auxv.hwcap & PPC_FEATURE_HAS_VSX != 0);
enable_feature(&mut value, Feature::power8, auxv.hwcap2 & PPC_FEATURE2_ARCH_2_07 != 0);
return value;
}
value
Expand Down
24 changes: 17 additions & 7 deletions library/std_detect/src/detect/os/linux/powerpc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
//! Run-time feature detection for PowerPC on Linux.
//!
//! Constants for both 32- and 64-bit come from
//! <https://github.com/torvalds/linux/blob/master/arch/powerpc/include/uapi/asm/cputable.h>.

use super::auxvec;
use crate::detect::{Feature, cache};

const PPC_FEATURE_HAS_ALTIVEC: usize = 0x10000000;
const PPC_FEATURE_HAS_VSX: usize = 0x00000080;
/// ISA 2.07, typically power8
const PPC_FEATURE2_ARCH_2_07: usize = 0x80000000;
/// ISA 3.00, typically power9
const PPC_FEATURE2_ARCH_3_00: usize = 0x00800000;

/// Try to read the features from the auxiliary vector.
pub(crate) fn detect_features() -> cache::Initializer {
let mut value = cache::Initializer::default();
Expand All @@ -12,20 +22,20 @@ pub(crate) fn detect_features() -> cache::Initializer {
}
};

// The values are part of the platform-specific [asm/cputable.h][cputable]
//
// [cputable]: https://github.com/torvalds/linux/blob/master/arch/powerpc/include/uapi/asm/cputable.h
if let Ok(auxv) = auxvec::auxv() {
// note: the PowerPC values are the mask to do the test (instead of the
// index of the bit to test like in ARM and Aarch64)
enable_feature(&mut value, Feature::altivec, auxv.hwcap & 0x10000000 != 0);
enable_feature(&mut value, Feature::vsx, auxv.hwcap & 0x00000080 != 0);
let power8_features = auxv.hwcap2 & 0x80000000 != 0;
enable_feature(&mut value, Feature::altivec, auxv.hwcap & PPC_FEATURE_HAS_ALTIVEC != 0);
enable_feature(&mut value, Feature::vsx, auxv.hwcap & PPC_FEATURE_HAS_VSX != 0);
// FIXME(powerpc_target_feature): this code assumes the ISA hwcaps imply vsx/altivec, but
// this is not a correct assumption. See rust-lang/compiler-team#1046 for
// a possible resolution.
let power8_features = auxv.hwcap2 & PPC_FEATURE2_ARCH_2_07 != 0;
enable_feature(&mut value, Feature::power8, power8_features);
enable_feature(&mut value, Feature::power8_altivec, power8_features);

@programmerjake programmerjake Oct 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add some comments that this is wrong (it needs to also check altivec) but you have a MCP to fix it and you're leaving the feature test logic how it was for now.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, added a comment

enable_feature(&mut value, Feature::power8_crypto, power8_features);
enable_feature(&mut value, Feature::power8_vector, power8_features);
let power9_features = auxv.hwcap2 & 0x00800000 != 0;
let power9_features = auxv.hwcap2 & PPC_FEATURE2_ARCH_3_00 != 0;
enable_feature(&mut value, Feature::power9, power9_features);
enable_feature(&mut value, Feature::power9_altivec, power9_features);
enable_feature(&mut value, Feature::power9_vector, power9_features);
Expand Down
17 changes: 14 additions & 3 deletions library/std_detect/src/detect/os/openbsd/powerpc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
//! Run-time feature detection for PowerPC on OpenBSD.
//!
//! Constants for 32-bit are located at
//! <https://github.com/openbsd/src/blob/master/sys/arch/powerpc/include/elf.h>, and for 64-bit
//! <https://github.com/openbsd/src/blob/master/sys/arch/powerpc64/include/elf.h>.

use super::auxvec;
use crate::detect::{Feature, cache};

/* Note that most constants are the same for 32- and 64-bit, but not all are */

const PPC_FEATURE_HAS_ALTIVEC: usize = 0x10000000;
const PPC_FEATURE_HAS_VSX: usize = 0x00000080;
/// ISA 2.07, typically power8
const PPC_FEATURE2_ARCH_2_07: usize = 0x80000000;

pub(crate) fn detect_features() -> cache::Initializer {
let mut value = cache::Initializer::default();
let enable_feature = |value: &mut cache::Initializer, f, enable| {
Expand All @@ -12,9 +23,9 @@ pub(crate) fn detect_features() -> cache::Initializer {
};

if let Ok(auxv) = auxvec::auxv() {
enable_feature(&mut value, Feature::altivec, auxv.hwcap & 0x10000000 != 0);
enable_feature(&mut value, Feature::vsx, auxv.hwcap & 0x00000080 != 0);
enable_feature(&mut value, Feature::power8, auxv.hwcap2 & 0x80000000 != 0);
enable_feature(&mut value, Feature::altivec, auxv.hwcap & PPC_FEATURE_HAS_ALTIVEC != 0);
enable_feature(&mut value, Feature::vsx, auxv.hwcap & PPC_FEATURE_HAS_VSX != 0);
enable_feature(&mut value, Feature::power8, auxv.hwcap2 & PPC_FEATURE2_ARCH_2_07 != 0);
return value;
}
value
Expand Down
1 change: 0 additions & 1 deletion library/std_detect/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//! * `mips`: [`is_mips_feature_detected`]
//! * `mips64`: [`is_mips64_feature_detected`]
//! * `powerpc`: [`is_powerpc_feature_detected`]
//! * `powerpc64`: [`is_powerpc64_feature_detected`]
//! * `loongarch`: [`is_loongarch_feature_detected`]
//! * `s390x`: [`is_s390x_feature_detected`]

Expand Down
20 changes: 6 additions & 14 deletions library/std_detect/tests/cpu-detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,24 +317,16 @@ fn riscv_linux() {
println!("p: {}", is_riscv_feature_detected!("p"));
}

#[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",
any(target_arch = "powerpc", target_arch = "powerpc64"),
any(target_os = "linux", target_os = "freebsd", target_os = "openbsd"),
))]
fn powerpc64_linux_or_bsd() {
println!("altivec: {}", is_powerpc64_feature_detected!("altivec"));
println!("vsx: {}", is_powerpc64_feature_detected!("vsx"));
println!("power8: {}", is_powerpc64_feature_detected!("power8"));
println!("power9: {}", is_powerpc64_feature_detected!("power9"));
fn powerpc_linux_or_bsd() {
println!("altivec: {}", is_powerpc_feature_detected!("altivec"));
println!("vsx: {}", is_powerpc_feature_detected!("vsx"));
println!("power8: {}", is_powerpc_feature_detected!("power8"));
println!("power9: {}", is_powerpc_feature_detected!("power9"));
}

#[test]
Expand Down
9 changes: 1 addition & 8 deletions library/std_detect/tests/macro_trailing_commas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,12 @@ fn loongarch() {
}

#[test]
#[cfg(target_arch = "powerpc")]
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
fn powerpc() {
let _ = is_powerpc_feature_detected!("altivec");
let _ = is_powerpc_feature_detected!("altivec",);
}

#[test]
#[cfg(target_arch = "powerpc64")]
fn powerpc64() {
let _ = is_powerpc64_feature_detected!("altivec");
let _ = is_powerpc64_feature_detected!("altivec",);
}

#[test]
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
fn riscv() {
Expand Down
3 changes: 1 addition & 2 deletions library/stdarch/crates/simd-test-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ pub fn simd_test(
"arm" | "armv7" | "thumbv7neon" => "is_arm_feature_detected",
"aarch64" | "arm64ec" | "aarch64_be" => "is_aarch64_feature_detected",
maybe_riscv if maybe_riscv.starts_with("riscv") => "is_riscv_feature_detected",
"powerpc" | "powerpcle" => "is_powerpc_feature_detected",
"powerpc64" | "powerpc64le" => "is_powerpc64_feature_detected",
"powerpc" | "powerpcle" | "powerpc64" | "powerpc64le" => "is_powerpc_feature_detected",
"loongarch32" | "loongarch64" => "is_loongarch_feature_detected",
"s390x" => "is_s390x_feature_detected",
"mips64" | "mips64el" => "is_mips64_feature_detected",
Expand Down
Loading