aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2013-12-31 14:59:48 +0000
committerlloyd <[email protected]>2013-12-31 14:59:48 +0000
commit98991e5c9326a480b890ef7ce112ebfb1216f1ae (patch)
tree829715d1432a39824368617048e8ee63f63f34d0
parentabefc88850c37fe97b4a8588aa13fcdefd9f7b5e (diff)
Add CPUID::print
-rw-r--r--doc/examples/cpuid.cpp34
-rw-r--r--src/utils/cpuid.cpp26
-rw-r--r--src/utils/cpuid.h3
3 files changed, 30 insertions, 33 deletions
diff --git a/doc/examples/cpuid.cpp b/doc/examples/cpuid.cpp
index c231397e4..0a94d8717 100644
--- a/doc/examples/cpuid.cpp
+++ b/doc/examples/cpuid.cpp
@@ -10,41 +10,9 @@
using namespace Botan;
-namespace {
-
-void print_if_feature(const std::string& feature_name, bool exists)
- {
- std::cout << (exists ? '+' : '-') << " " << feature_name << "\n";
- }
-
-void print_header(const std::string& descr)
- {
- std::cout << "\n" << descr << "\n-----\n";
- }
-
-}
-
int main()
{
CPUID::initialize();
- std::cout << "Cache line size = " << CPUID::cache_line_size() << "\n";
-
- print_header("SIMD instruction sets");
- print_if_feature("SSE2", CPUID::has_sse2());
- print_if_feature("SSSE3", CPUID::has_ssse3());
- print_if_feature("SSE4.1", CPUID::has_sse41());
- print_if_feature("SSE4.2", CPUID::has_sse42());
- print_if_feature("AVX2", CPUID::has_avx2());
- print_if_feature("AVX-512F", CPUID::has_avx512f());
- print_if_feature("AltiVec", CPUID::has_altivec());
-
- print_header("Other extensions");
- print_if_feature("RDTSC", CPUID::has_rdtsc());
- print_if_feature("BMI2", CPUID::has_bmi2());
- print_if_feature("PCMUL", CPUID::has_pcmuludq());
- print_if_feature("AES-NI", CPUID::has_aes_ni());
- print_if_feature("RDRAND", CPUID::has_rdrand());
- print_if_feature("RDSEED", CPUID::has_rdseed());
- print_if_feature("SHA", CPUID::has_intel_sha());
+ CPUID::print(std::cout);
}
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp
index c727471bc..75a88c6b8 100644
--- a/src/utils/cpuid.cpp
+++ b/src/utils/cpuid.cpp
@@ -9,6 +9,7 @@
#include <botan/types.h>
#include <botan/get_byte.h>
#include <botan/mem_ops.h>
+#include <ostream>
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
@@ -153,6 +154,31 @@ bool altivec_check_pvr_emul()
}
+void CPUID::print(std::ostream& o)
+ {
+ o << "CPUID flags: ";
+
+#define CPUID_PRINT(flag) do { if(has_##flag()) o << #flag << " "; } while(0)
+ CPUID_PRINT(sse2);
+ CPUID_PRINT(ssse3);
+ CPUID_PRINT(sse41);
+ CPUID_PRINT(sse42);
+ CPUID_PRINT(avx2);
+ CPUID_PRINT(avx512f);
+ CPUID_PRINT(altivec);
+
+ CPUID_PRINT(rdtsc);
+ CPUID_PRINT(bmi2);
+ CPUID_PRINT(clmul);
+ CPUID_PRINT(aes_ni);
+ CPUID_PRINT(rdrand);
+ CPUID_PRINT(rdseed);
+ CPUID_PRINT(intel_sha);
+ CPUID_PRINT(adx);
+#undef CPUID_PRINT
+ o << "\n";
+ }
+
void CPUID::initialize()
{
#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
diff --git a/src/utils/cpuid.h b/src/utils/cpuid.h
index 67657d2ee..1c4c1df0b 100644
--- a/src/utils/cpuid.h
+++ b/src/utils/cpuid.h
@@ -9,6 +9,7 @@
#define BOTAN_CPUID_H__
#include <botan/types.h>
+#include <iosfwd>
namespace Botan {
@@ -116,6 +117,8 @@ class BOTAN_DLL CPUID
* Check if the processor supports AltiVec/VMX
*/
static bool has_altivec() { return m_altivec_capable; }
+
+ static void print(std::ostream& o);
private:
enum CPUID_bits {
CPUID_RDTSC_BIT = 4,