2018-02-16 16:01:04 +00:00
|
|
|
#include "CPU.h"
|
|
|
|
#if defined(__x86_64__) || defined(__i386__)
|
|
|
|
#include <cpuid.h>
|
|
|
|
#endif
|
|
|
|
#include "Log.h"
|
2018-02-19 15:15:39 +00:00
|
|
|
|
|
|
|
#ifndef bit_AES
|
|
|
|
#define bit_AES (1 << 25)
|
|
|
|
#endif
|
|
|
|
#ifndef bit_AVX
|
|
|
|
#define bit_AVX (1 << 28)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-02-16 16:01:04 +00:00
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace cpu
|
|
|
|
{
|
|
|
|
bool aesni = false;
|
|
|
|
bool avx = false;
|
|
|
|
|
|
|
|
void Detect()
|
|
|
|
{
|
2018-06-27 09:09:46 +00:00
|
|
|
#if defined(__AES__) || defined(__AVX__)
|
|
|
|
|
2018-02-16 16:01:04 +00:00
|
|
|
#if defined(__x86_64__) || defined(__i386__)
|
|
|
|
int info[4];
|
|
|
|
__cpuid(0, info[0], info[1], info[2], info[3]);
|
|
|
|
if (info[0] >= 0x00000001) {
|
|
|
|
__cpuid(0x00000001, info[0], info[1], info[2], info[3]);
|
2018-06-27 09:09:46 +00:00
|
|
|
#ifdef __AES__
|
2018-02-16 16:01:04 +00:00
|
|
|
aesni = info[2] & bit_AES; // AESNI
|
2018-06-27 09:09:46 +00:00
|
|
|
#endif // __AES__
|
|
|
|
#ifdef __AVX__
|
2018-02-16 16:01:04 +00:00
|
|
|
avx = info[2] & bit_AVX; // AVX
|
2018-06-27 09:09:46 +00:00
|
|
|
#endif // __AVX__
|
2018-02-16 16:01:04 +00:00
|
|
|
}
|
2018-06-27 09:09:46 +00:00
|
|
|
#endif // defined(__x86_64__) || defined(__i386__)
|
|
|
|
|
|
|
|
#ifdef __AES__
|
2018-02-16 16:01:04 +00:00
|
|
|
if(aesni)
|
|
|
|
{
|
|
|
|
LogPrint(eLogInfo, "AESNI enabled");
|
|
|
|
}
|
2018-06-27 09:09:46 +00:00
|
|
|
#endif // __AES__
|
|
|
|
#ifdef __AVX__
|
2018-02-16 16:01:04 +00:00
|
|
|
if(avx)
|
|
|
|
{
|
|
|
|
LogPrint(eLogInfo, "AVX enabled");
|
|
|
|
}
|
2018-06-27 09:09:46 +00:00
|
|
|
#endif // __AVX__
|
|
|
|
#endif // defined(__AES__) || defined(__AVX__)
|
2018-02-16 16:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|