Botan  1.11.15
Static Public Member Functions
Botan::CPUID Class Reference

#include <cpuid.h>

List of all members.

Static Public Member Functions

static size_t cache_line_size ()
static bool has_adx ()
static bool has_aes_ni ()
static bool has_altivec ()
static bool has_avx2 ()
static bool has_avx512f ()
static bool has_bmi2 ()
static bool has_clmul ()
static bool has_intel_sha ()
static bool has_rdrand ()
static bool has_rdseed ()
static bool has_rdtsc ()
static bool has_sse2 ()
static bool has_sse41 ()
static bool has_sse42 ()
static bool has_ssse3 ()
static void initialize ()
static void print (std::ostream &o)

Detailed Description

A class handling runtime CPU feature detection

Definition at line 19 of file cpuid.h.


Member Function Documentation

static size_t Botan::CPUID::cache_line_size ( ) [inline, static]

Return a best guess of the cache line size

Definition at line 30 of file cpuid.h.

Referenced by Botan::prefetch_readonly(), and Botan::prefetch_readwrite().

{ initialize(); return g_cache_line_size; }
static bool Botan::CPUID::has_adx ( ) [inline, static]

Check if the processor supports ADX extension

Definition at line 106 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_ADX_BIT); }
static bool Botan::CPUID::has_aes_ni ( ) [inline, static]

Check if the processor supports AES-NI

Definition at line 88 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_AESNI_BIT); }
static bool Botan::CPUID::has_altivec ( ) [inline, static]

Check if the processor supports AltiVec/VMX

Definition at line 35 of file cpuid.h.

{ initialize(); return g_altivec_capable; }
static bool Botan::CPUID::has_avx2 ( ) [inline, static]

Check if the processor supports AVX2

Definition at line 70 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_AVX2_BIT); }
static bool Botan::CPUID::has_avx512f ( ) [inline, static]

Check if the processor supports AVX-512F

Definition at line 76 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_AVX512F_BIT); }
static bool Botan::CPUID::has_bmi2 ( ) [inline, static]

Check if the processor supports BMI2

Definition at line 82 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_BMI2_BIT); }
static bool Botan::CPUID::has_clmul ( ) [inline, static]

Check if the processor supports CLMUL

Definition at line 94 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_CLMUL_BIT); }
static bool Botan::CPUID::has_intel_sha ( ) [inline, static]

Check if the processor supports Intel SHA extension

Definition at line 100 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_SHA_BIT); }
static bool Botan::CPUID::has_rdrand ( ) [inline, static]

Check if the processor supports RDRAND

Definition at line 112 of file cpuid.h.

Referenced by Botan::Intel_Rdrand::poll().

         { return x86_processor_flags_has(CPUID_RDRAND_BIT); }
static bool Botan::CPUID::has_rdseed ( ) [inline, static]

Check if the processor supports RDSEED

Definition at line 118 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_RDSEED_BIT); }
static bool Botan::CPUID::has_rdtsc ( ) [inline, static]

Check if the processor supports RDTSC

Definition at line 40 of file cpuid.h.

Referenced by Botan::High_Resolution_Timestamp::poll().

         { return x86_processor_flags_has(CPUID_RDTSC_BIT); }
static bool Botan::CPUID::has_sse2 ( ) [inline, static]

Check if the processor supports SSE2

Definition at line 46 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_SSE2_BIT); }
static bool Botan::CPUID::has_sse41 ( ) [inline, static]

Check if the processor supports SSE4.1

Definition at line 58 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_SSE41_BIT); }
static bool Botan::CPUID::has_sse42 ( ) [inline, static]

Check if the processor supports SSE4.2

Definition at line 64 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_SSE42_BIT); }
static bool Botan::CPUID::has_ssse3 ( ) [inline, static]

Check if the processor supports SSSE3

Definition at line 52 of file cpuid.h.

         { return x86_processor_flags_has(CPUID_SSSE3_BIT); }
void Botan::CPUID::initialize ( ) [static]

Probe the CPU and see what extensions are supported

Definition at line 185 of file cpuid.cpp.

References Botan::clear_mem(), Botan::get_byte(), and Botan::same_mem().

   {
   if(g_initialized)
      return;

#if defined(BOTAN_TARGET_CPU_IS_PPC_FAMILY)
      if(altivec_check_sysctl() || altivec_check_pvr_emul())
         g_altivec_capable = true;
#endif

#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
   const u32bit INTEL_CPUID[3] = { 0x756E6547, 0x6C65746E, 0x49656E69 };
   const u32bit AMD_CPUID[3] = { 0x68747541, 0x444D4163, 0x69746E65 };

   u32bit cpuid[4] = { 0 };
   X86_CPUID(0, cpuid);

   const u32bit max_supported_sublevel = cpuid[0];

   if(max_supported_sublevel == 0)
      return;

   const bool is_intel = same_mem(cpuid + 1, INTEL_CPUID, 3);
   const bool is_amd = same_mem(cpuid + 1, AMD_CPUID, 3);

   X86_CPUID(1, cpuid);

   g_x86_processor_flags[0] = (static_cast<u64bit>(cpuid[2]) << 32) | cpuid[3];

   if(is_intel)
      g_cache_line_size = 8 * get_byte(2, cpuid[1]);

   if(max_supported_sublevel >= 7)
      {
      clear_mem(cpuid, 4);
      X86_CPUID_SUBLEVEL(7, 0, cpuid);
      g_x86_processor_flags[1] = (static_cast<u64bit>(cpuid[2]) << 32) | cpuid[1];
      }

   if(is_amd)
      {
      X86_CPUID(0x80000005, cpuid);
      g_cache_line_size = get_byte(3, cpuid[2]);
      }

#endif

#if defined(BOTAN_TARGET_ARCH_IS_X86_64)
   /*
   * If we don't have access to CPUID, we can still safely assume that
   * any x86-64 processor has SSE2 and RDTSC
   */
   if(g_x86_processor_flags[0] == 0)
      g_x86_processor_flags[0] = (1 << CPUID_SSE2_BIT) | (1 << CPUID_RDTSC_BIT);
#endif

   g_initialized = true;
   }
void Botan::CPUID::print ( std::ostream &  o) [static]

Definition at line 160 of file cpuid.cpp.

References CPUID_PRINT.

   {
   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";
   }

The documentation for this class was generated from the following files: