Botan 3.9.0
Crypto and TLS for C&
cpuid_features.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_features.h>
8
9#include <botan/exceptn.h>
10
11namespace Botan {
12
13std::string CPUFeature::to_string() const {
14 switch(m_bit) {
15 case CPUFeature::Bit::NEON:
16 return "neon";
17 case CPUFeature::Bit::SVE:
18 return "sve";
19 case CPUFeature::Bit::SHA1:
20 return "armv8sha1";
21 case CPUFeature::Bit::SHA2:
22 return "armv8sha2";
23 case CPUFeature::Bit::AES:
24 return "armv8aes";
25 case CPUFeature::Bit::PMULL:
26 return "armv8pmull";
27 case CPUFeature::Bit::SHA3:
28 return "armv8sha3";
29 case CPUFeature::Bit::SHA2_512:
30 return "armv8sha2_512";
31 case CPUFeature::Bit::SM3:
32 return "armv8sm3";
33 case CPUFeature::Bit::SM4:
34 return "armv8sm4";
35 }
36 throw Invalid_State("CPUFeature invalid bit");
37}
38
39//static
40std::optional<CPUFeature> CPUFeature::from_string(std::string_view tok) {
41 // TODO(Botan4) remove the "arm_xxx" strings here
42 if(tok == "neon" || tok == "simd") {
43 return CPUFeature::Bit::NEON;
44 } else if(tok == "sve" || tok == "arm_sve") {
45 return CPUFeature::Bit::SVE;
46 } else if(tok == "armv8sha1" || tok == "arm_sha1") {
47 return CPUFeature::Bit::SHA1;
48 } else if(tok == "armv8sha2" || tok == "arm_sha2") {
49 return CPUFeature::Bit::SHA2;
50 } else if(tok == "armv8aes" || tok == "arm_aes") {
51 return CPUFeature::Bit::AES;
52 } else if(tok == "armv8pmull" || tok == "arm_pmull") {
53 return CPUFeature::Bit::PMULL;
54 } else if(tok == "armv8sha3" || tok == "arm_sha3") {
55 return CPUFeature::Bit::SHA3;
56 } else if(tok == "armv8sha2_512" || tok == "arm_sha2_512") {
57 return CPUFeature::Bit::SHA2_512;
58 } else if(tok == "armv8sm3" || tok == "arm_sm3") {
59 return CPUFeature::Bit::SM3;
60 } else if(tok == "armv8sm4" || tok == "arm_sm4") {
61 return CPUFeature::Bit::SM4;
62 } else {
63 return {};
64 }
65}
66
67} // namespace Botan
static std::optional< CPUFeature > from_string(std::string_view)
Definition cpuid.cpp:24
std::string to_string() const
Definition cpuid.cpp:28