aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/cpuid.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/cpuid.h')
-rw-r--r--src/utils/cpuid.h53
1 files changed, 41 insertions, 12 deletions
diff --git a/src/utils/cpuid.h b/src/utils/cpuid.h
index 14ac6ad39..eaf1c1330 100644
--- a/src/utils/cpuid.h
+++ b/src/utils/cpuid.h
@@ -1,6 +1,6 @@
/*
* Runtime CPU detection
-* (C) 2009-2010 Jack Lloyd
+* (C) 2009-2010,2013 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -26,7 +26,7 @@ class BOTAN_DLL CPUID
/**
* Return a best guess of the cache line size
*/
- static size_t cache_line_size() { return cache_line; }
+ static size_t cache_line_size() { return m_cache_line_size; }
/**
* Check if the processor supports RDTSC
@@ -59,10 +59,16 @@ class BOTAN_DLL CPUID
{ return x86_processor_flags_has(CPUID_SSE42_BIT); }
/**
- * Check if the processor supports extended AVX vector instructions
+ * Check if the processor supports AVX2
*/
- static bool has_avx()
- { return x86_processor_flags_has(CPUID_AVX_BIT); }
+ static bool has_avx2()
+ { return x86_processor_flags_has(CPUID_AVX2_BIT); }
+
+ /**
+ * Check if the processor supports BMI2
+ */
+ static bool has_bmi2()
+ { return x86_processor_flags_has(CPUID_BMI2_BIT); }
/**
* Check if the processor supports AES-NI
@@ -77,15 +83,33 @@ class BOTAN_DLL CPUID
{ return x86_processor_flags_has(CPUID_PCMUL_BIT); }
/**
+ * Check if the processor supports Intel SHA extension
+ */
+ static bool has_intel_sha()
+ { return x86_processor_flags_has(CPUID_SHA_BIT); }
+
+ /**
+ * Check if the processor supports ADX extension
+ */
+ static bool has_adx()
+ { return x86_processor_flags_has(CPUID_ADX_BIT); }
+
+ /**
* Check if the processor supports RDRAND
*/
static bool has_rdrand()
{ return x86_processor_flags_has(CPUID_RDRAND_BIT); }
/**
+ * Check if the processor supports RDSEED
+ */
+ static bool has_rdseed()
+ { return x86_processor_flags_has(CPUID_RDSEED_BIT); }
+
+ /**
* Check if the processor supports AltiVec/VMX
*/
- static bool has_altivec() { return altivec_capable; }
+ static bool has_altivec() { return m_altivec_capable; }
private:
enum CPUID_bits {
CPUID_RDTSC_BIT = 4,
@@ -95,18 +119,23 @@ class BOTAN_DLL CPUID
CPUID_SSE41_BIT = 51,
CPUID_SSE42_BIT = 52,
CPUID_AESNI_BIT = 57,
- CPUID_AVX_BIT = 60,
- CPUID_RDRAND_BIT = 62
+ CPUID_RDRAND_BIT = 62,
+
+ CPUID_AVX2_BIT = 64+5,
+ CPUID_BMI2_BIT = 64+8,
+ CPUID_RDSEED_BIT = 64+18,
+ CPUID_ADX_BIT = 64+19,
+ CPUID_SHA_BIT = 64+29,
};
static bool x86_processor_flags_has(u64bit bit)
{
- return ((x86_processor_flags >> bit) & 1);
+ return ((m_x86_processor_flags[bit/64] >> (bit % 64)) & 1);
}
- static u64bit x86_processor_flags;
- static size_t cache_line;
- static bool altivec_capable;
+ static u64bit m_x86_processor_flags[2];
+ static size_t m_cache_line_size;
+ static bool m_altivec_capable;
};
}