aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils/cpuid.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-01-28 04:32:10 +0000
committerlloyd <[email protected]>2015-01-28 04:32:10 +0000
commit7b56f1bd570dc684ffd7c945dee0d9b5480354ff (patch)
tree0c50ad534280a292a1b76daee9a19b34cfd96367 /src/lib/utils/cpuid.h
parentb8fa304ec981d273c45d7ef31705d65ccfb00cc1 (diff)
Add a runtime map of string->func() which when called return
Transforms and BlockCiphers. Registration for all types is done at startup but is very cheap as just a std::function and a std::map entry are created, no actual objects are created until needed. This is a huge improvement over Algorithm_Factory which used T::clone() as the function and thus kept a prototype object of each type in memory. Replace existing lookup mechanisms for ciphers, AEADs, and compression to use the transform lookup. The existing Engine framework remains in place for BlockCipher, but the engines now just call to the registry instead of having hardcoded lookups. s/Transformation/Transform/ with typedefs for compatability. Remove lib/selftest code (for runtime selftesting): not the right approach.
Diffstat (limited to 'src/lib/utils/cpuid.h')
-rw-r--r--src/lib/utils/cpuid.h15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/lib/utils/cpuid.h b/src/lib/utils/cpuid.h
index cbbdcad6d..14901199c 100644
--- a/src/lib/utils/cpuid.h
+++ b/src/lib/utils/cpuid.h
@@ -27,7 +27,7 @@ class BOTAN_DLL CPUID
/**
* Return a best guess of the cache line size
*/
- static size_t cache_line_size() { return m_cache_line_size; }
+ static size_t cache_line_size() { return g_cache_line_size; }
/**
* Check if the processor supports RDTSC
@@ -116,7 +116,7 @@ class BOTAN_DLL CPUID
/**
* Check if the processor supports AltiVec/VMX
*/
- static bool has_altivec() { return m_altivec_capable; }
+ static bool has_altivec() { return g_altivec_capable; }
static void print(std::ostream& o);
private:
@@ -140,12 +140,15 @@ class BOTAN_DLL CPUID
static bool x86_processor_flags_has(u64bit bit)
{
- return ((m_x86_processor_flags[bit/64] >> (bit % 64)) & 1);
+ if(!g_initialized)
+ initialize();
+ return ((g_x86_processor_flags[bit/64] >> (bit % 64)) & 1);
}
- static u64bit m_x86_processor_flags[2];
- static size_t m_cache_line_size;
- static bool m_altivec_capable;
+ static bool g_initialized;
+ static u64bit g_x86_processor_flags[2];
+ static size_t g_cache_line_size;
+ static bool g_altivec_capable;
};
}