diff options
author | Jack Lloyd <[email protected]> | 2017-09-16 12:17:54 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-09-16 12:17:54 -0400 |
commit | e3f2528713840b128ab7645ef826f331ad7cbb29 (patch) | |
tree | d49fed2fdfad126d333188fb5f821e1ff8e93fd3 /src/lib | |
parent | 5ca7d7d15d410ddd07acedcafa53cb7c6f40d45b (diff) |
Merge duplicated logic for clearing CPUID bits
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/utils/cpuid.cpp | 40 | ||||
-rw-r--r-- | src/lib/utils/cpuid.h | 2 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/lib/utils/cpuid.cpp b/src/lib/utils/cpuid.cpp index ed3fbc4b2..82654b9b4 100644 --- a/src/lib/utils/cpuid.cpp +++ b/src/lib/utils/cpuid.cpp @@ -458,4 +458,44 @@ CPUID::Endian_status CPUID::runtime_check_endian() return endian; } +std::vector<Botan::CPUID::CPUID_bits> +CPUID::bit_from_string(const std::string& tok) + { +#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) + if(tok == "sse2" || tok == "simd") + return {Botan::CPUID::CPUID_SSE2_BIT}; + if(tok == "ssse3") + return {Botan::CPUID::CPUID_SSSE3_BIT}; + if(tok == "aesni") + return {Botan::CPUID::CPUID_AESNI_BIT}; + if(tok == "clmul") + return {Botan::CPUID::CPUID_CLMUL_BIT}; + if(tok == "avx2") + return {Botan::CPUID::CPUID_AVX2_BIT}; + if(tok == "sha") + return {Botan::CPUID::CPUID_SHA_BIT}; + +#elif defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY) + if(tok == "altivec" || tok == "simd") + return {Botan::CPUID::CPUID_ALTIVEC_BIT}; + +#elif defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY) + if(tok == "neon" || tok == "simd") + return {Botan::CPUID::CPUID_ARM_NEON_BIT}; + if(tok == "armv8sha1") + return {Botan::CPUID::CPUID_ARM_SHA1_BIT}; + if(tok == "armv8sha2") + return {Botan::CPUID::CPUID_ARM_SHA2_BIT}; + if(tok == "armv8aes") + return {Botan::CPUID::CPUID_ARM_AES_BIT}; + if(tok == "armv8pmull") + return {Botan::CPUID::CPUID_ARM_PMULL_BIT}; + +#else + BOTAN_UNUSED(tok); +#endif + + return {}; + } + } diff --git a/src/lib/utils/cpuid.h b/src/lib/utils/cpuid.h index c27390729..119395c0d 100644 --- a/src/lib/utils/cpuid.h +++ b/src/lib/utils/cpuid.h @@ -9,6 +9,7 @@ #define BOTAN_CPUID_H__ #include <botan/types.h> +#include <vector> #include <string> #include <iosfwd> @@ -272,6 +273,7 @@ class BOTAN_DLL CPUID return ((g_processor_features & static_cast<uint64_t>(elem)) != 0); } + static std::vector<CPUID::CPUID_bits> bit_from_string(const std::string& tok); private: enum Endian_status : uint32_t { ENDIAN_UNKNOWN = 0x00000000, |