Browse Source

[cpu] use cpuid on gcc < 5

Signed-off-by: r4sas <r4sas@i2pmail.org>
cpu
R4SAS 1 year ago
parent
commit
c53ad2012c
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 24
      libi2pd/CPU.cpp

24
libi2pd/CPU.cpp

@ -9,12 +9,16 @@
#include "CPU.h" #include "CPU.h"
#include "Log.h" #include "Log.h"
#if defined(_MSC_VER)
#include <intrin.h>
#ifndef bit_AES #ifndef bit_AES
#define bit_AES (1 << 25) #define bit_AES (1 << 25)
#endif #endif
#if (defined(__GNUC__) && __GNUC__ < 5)
#include <cpuid.h>
#endif
#ifdef _MSC_VER
#include <intrin.h>
#endif #endif
namespace i2p namespace i2p
@ -26,18 +30,18 @@ namespace cpu
inline bool cpu_support_aes() inline bool cpu_support_aes()
{ {
#if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_IX86) || defined(__i386__)) #if (defined(_M_AMD64) || defined(__x86_64__)) || (defined(_M_IX86) || defined(__i386__))
#if defined(_MSC_VER) #if (defined(__GNUC__) && __GNUC__ > 4)
int cpu_info[4]; __builtin_cpu_init();
__cpuid(cpu_info, 1); return __builtin_cpu_supports("aes");
return ((cpu_info[2] & bit_AES) != 0);
#elif defined(__clang__) #elif defined(__clang__)
#if __clang_major__ >= 6 #if __clang_major__ >= 6
__builtin_cpu_init(); __builtin_cpu_init();
#endif #endif
return __builtin_cpu_supports("aes"); return __builtin_cpu_supports("aes");
#elif defined(__GNUC__) #elif (defined(_MSC_VER) || (defined(__GNUC__) && __GNUC__ < 5))
__builtin_cpu_init(); int cpu_info[4];
return __builtin_cpu_supports("aes"); __cpuid(cpu_info, 1);
return ((cpu_info[2] & bit_AES) != 0);
#else #else
return false; return false;
#endif #endif

Loading…
Cancel
Save