8#include <botan/internal/cpuid.h>
10#include <botan/internal/os_utils.h>
11#include <botan/internal/target_info.h>
15uint32_t CPUID::CPUID_Data::detect_cpu_features([[maybe_unused]] uint32_t allowed) {
19 const auto [hwcap, hwcap2] = *auxval;
21 enum class PPC_hwcap_bit : uint64_t {
25 enum class PPC_hwcap2_bit : uint64_t {
26 ARCH_2_07_bit = (1U << 31),
27 CRYPTO_bit = (1 << 25),
32 if((hwcap2 &
static_cast<uint64_t
>(PPC_hwcap2_bit::ARCH_2_07_bit)) != 0) {
33 feat |=
if_set(hwcap, PPC_hwcap_bit::VSX_bit, CPUFeature::Bit::VSX, allowed);
36 if(is_set(feat, CPUFeature::Bit::VSX)) {
37 feat |=
if_set(hwcap2, PPC_hwcap2_bit::CRYPTO_bit, CPUFeature::Bit::POWER_CRYPTO, allowed);
41 feat |=
if_set(hwcap2, PPC_hwcap2_bit::DARN_bit, CPUFeature::Bit::DARN, allowed);
46#if defined(BOTAN_USE_GCC_INLINE_ASM)
56 if(is_set(allowed, CPUFeature::Bit::VSX)) {
58 auto vsx_probe = []()
noexcept ->
int {
59 asm volatile(
"vaddudm 0, 0, 0" :::
"v0");
64 feat |= CPUFeature::Bit::VSX;
68 if(is_set(feat, CPUFeature::Bit::VSX) && is_set(allowed, CPUFeature::Bit::POWER_CRYPTO)) {
69 auto vcipher_probe = []()
noexcept ->
int {
70 asm volatile(
"vcipher 0, 0, 0" :::
"v0");
75 feat |= CPUFeature::Bit::POWER_CRYPTO;
80 if(is_set(allowed, CPUFeature::Bit::DARN)) {
81 auto darn_probe = []()
noexcept ->
int {
88 for(
size_t i = 0; i != 10; ++i) {
90 asm volatile(
"darn %0, 1" :
"=r"(output));
99 feat |= CPUFeature::Bit::DARN;
static uint32_t if_set(uint64_t cpuid, T flag, CPUID::Feature bit, uint32_t allowed)
std::optional< std::pair< unsigned long, unsigned long > > get_auxval_hwcap()
int BOTAN_TEST_API run_cpu_instruction_probe(const std::function< int()> &probe_fn)