std_detect/detect/os/linux/
powerpc.rs

1//! Run-time feature detection for PowerPC on Linux.
2
3use super::auxvec;
4use crate::detect::{Feature, cache};
5
6/// Try to read the features from the auxiliary vector.
7pub(crate) fn detect_features() -> cache::Initializer {
8    let mut value = cache::Initializer::default();
9    let enable_feature = |value: &mut cache::Initializer, f, enable| {
10        if enable {
11            value.set(f as u32);
12        }
13    };
14
15    // The values are part of the platform-specific [asm/cputable.h][cputable]
16    //
17    // [cputable]: https://github.com/torvalds/linux/blob/master/arch/powerpc/include/uapi/asm/cputable.h
18    if let Ok(auxv) = auxvec::auxv() {
19        // note: the PowerPC values are the mask to do the test (instead of the
20        // index of the bit to test like in ARM and Aarch64)
21        enable_feature(&mut value, Feature::altivec, auxv.hwcap & 0x10000000 != 0);
22        enable_feature(&mut value, Feature::vsx, auxv.hwcap & 0x00000080 != 0);
23        let power8_features = auxv.hwcap2 & 0x80000000 != 0;
24        enable_feature(&mut value, Feature::power8, power8_features);
25        enable_feature(&mut value, Feature::power8_altivec, power8_features);
26        enable_feature(&mut value, Feature::power8_crypto, power8_features);
27        enable_feature(&mut value, Feature::power8_vector, power8_features);
28        let power9_features = auxv.hwcap2 & 0x00800000 != 0;
29        enable_feature(&mut value, Feature::power9, power9_features);
30        enable_feature(&mut value, Feature::power9_altivec, power9_features);
31        enable_feature(&mut value, Feature::power9_vector, power9_features);
32        return value;
33    }
34    value
35}