Botan 3.9.0
Crypto and TLS for C&
cpuid_loongarch64.cpp
Go to the documentation of this file.
1/*
2* (C) 2025 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/cpuid.h>
8
9#include <botan/assert.h>
10#include <botan/internal/target_info.h>
11
12#if defined(BOTAN_HAS_OS_UTILS)
13 #include <botan/internal/os_utils.h>
14#endif
15
16namespace Botan {
17
18uint32_t CPUID::CPUID_Data::detect_cpu_features(uint32_t allowed) {
19 uint32_t feat = 0;
20
21#if defined(BOTAN_HAS_OS_UTILS)
22
23 if(auto auxval = OS::get_auxval_hwcap()) {
24 enum class LoongArch64_hwcap_bit : uint64_t {
25 LSX_bit = (1 << 4),
26 LASX_bit = (1 << 5),
27 CRYPTO_bit = (1 << 8),
28 };
29
30 const auto hwcap = auxval->first;
31
32 feat |= if_set(hwcap, LoongArch64_hwcap_bit::LSX_bit, CPUFeature::Bit::LSX, allowed);
33 feat |= if_set(hwcap, LoongArch64_hwcap_bit::LASX_bit, CPUFeature::Bit::LASX, allowed);
34 feat |= if_set(hwcap, LoongArch64_hwcap_bit::CRYPTO_bit, CPUFeature::Bit::CRYPTO, allowed);
35 }
36#endif
37
38 return feat;
39}
40
41} // namespace Botan
static uint32_t if_set(uint64_t cpuid, T flag, CPUID::Feature bit, uint32_t allowed)
Definition cpuid.h:117
std::optional< std::pair< unsigned long, unsigned long > > get_auxval_hwcap()
Definition os_utils.cpp:136