8#include <botan/internal/cpuid.h>
10#include <botan/internal/os_utils.h>
12#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
16uint32_t CPUID::CPUID_Data::detect_cpu_features() {
17 uint32_t detected_features = 0;
19 #if(defined(BOTAN_TARGET_OS_HAS_GETAUXVAL) || defined(BOTAN_TARGET_HAS_ELF_AUX_INFO)) && \
20 defined(BOTAN_TARGET_ARCH_IS_PPC64)
23 ALTIVEC_bit = (1 << 28),
24 CRYPTO_bit = (1 << 25),
27 ARCH_hwcap_altivec = 16,
28 ARCH_hwcap_crypto = 26,
31 const unsigned long hwcap_altivec =
OS::get_auxval(PPC_hwcap_bit::ARCH_hwcap_altivec);
32 if(hwcap_altivec & PPC_hwcap_bit::ALTIVEC_bit) {
33 detected_features |= CPUID::CPUID_ALTIVEC_BIT;
35 const unsigned long hwcap_crypto =
OS::get_auxval(PPC_hwcap_bit::ARCH_hwcap_crypto);
36 if(hwcap_crypto & PPC_hwcap_bit::CRYPTO_bit)
37 detected_features |= CPUID::CPUID_POWER_CRYPTO_BIT;
38 if(hwcap_crypto & PPC_hwcap_bit::DARN_bit)
39 detected_features |= CPUID::CPUID_DARN_BIT;
44 auto vmx_probe = []()
noexcept ->
int {
50 detected_features |= CPUID::CPUID_ALTIVEC_BIT;
52 #if defined(BOTAN_TARGET_ARCH_IS_PPC64)
53 auto vcipher_probe = []()
noexcept ->
int {
54 asm(
"vcipher 0, 0, 0");
59 detected_features |= CPUID::CPUID_POWER_CRYPTO_BIT;
61 auto darn_probe = []()
noexcept ->
int {
63 asm volatile(
"darn %0, 1" :
"=r"(output));
64 return (~output) != 0;
68 detected_features |= CPUID::CPUID_DARN_BIT;
74 return detected_features;
int BOTAN_TEST_API run_cpu_instruction_probe(const std::function< int()> &probe_fn)
unsigned long get_auxval(unsigned long id)