aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/cpuid
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2020-12-27 16:23:22 -0500
committerJack Lloyd <[email protected]>2020-12-27 16:29:15 -0500
commitf8491f9c586348cef06a22f81ad544b8727f3a0f (patch)
tree513332685146e358764e89937a177daa890e9058 /src/lib/utils/cpuid
parentac815e1714a350a89aa71e8a4a7706f320a11630 (diff)
Add BMI2 3DES implementation
Diffstat (limited to 'src/lib/utils/cpuid')
-rw-r--r--src/lib/utils/cpuid/cpuid.h7
-rw-r--r--src/lib/utils/cpuid/cpuid_x86.cpp13
2 files changed, 20 insertions, 0 deletions
diff --git a/src/lib/utils/cpuid/cpuid.h b/src/lib/utils/cpuid/cpuid.h
index db0bfe1a9..102ed9593 100644
--- a/src/lib/utils/cpuid/cpuid.h
+++ b/src/lib/utils/cpuid/cpuid.h
@@ -115,6 +115,7 @@ class BOTAN_PUBLIC_API(2,1) CPUID final
CPUID_ADX_BIT = (1ULL << 49),
CPUID_BMI1_BIT = (1ULL << 50),
CPUID_BMI2_BIT = (1ULL << 51),
+ CPUID_FAST_PDEP_BIT = (1ULL << 52),
#endif
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
@@ -310,6 +311,12 @@ class BOTAN_PUBLIC_API(2,1) CPUID final
{ return has_cpuid_bit(CPUID_BMI2_BIT); }
/**
+ * Check if the processor supports fast PDEP/PEXT from BMI2
+ */
+ static bool has_fast_pdep()
+ { return has_cpuid_bit(CPUID_FAST_PDEP_BIT); }
+
+ /**
* Check if the processor supports AES-NI
*/
static bool has_aes_ni()
diff --git a/src/lib/utils/cpuid/cpuid_x86.cpp b/src/lib/utils/cpuid/cpuid_x86.cpp
index b8ae54f87..51e51fa8e 100644
--- a/src/lib/utils/cpuid/cpuid_x86.cpp
+++ b/src/lib/utils/cpuid/cpuid_x86.cpp
@@ -152,7 +152,20 @@ uint64_t CPUID::CPUID_Data::detect_cpu_features(size_t* cache_line_size)
implements BMI2 but not BMI1.
*/
if(flags7 & x86_CPUID_7_bits::BMI2)
+ {
features_detected |= CPUID::CPUID_BMI2_BIT;
+
+ /*
+ Up until Zen3, AMD CPUs with BMI2 support had microcoded
+ pdep/pext, which works but is very slow.
+
+ TODO: check for Zen3 here
+ */
+ if(is_intel)
+ {
+ features_detected |= CPUID::CPUID_FAST_PDEP_BIT;
+ }
+ }
}
if(flags7 & x86_CPUID_7_bits::AVX512_F)