mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-23 17:36:37 +02:00
[cpu] perform check in separate function
Signed-off-by: r4sas <r4sas@i2pmail.org>
This commit is contained in:
parent
239a93485c
commit
968c6fee5b
1 changed files with 33 additions and 8 deletions
|
@ -9,24 +9,49 @@
|
||||||
#include "CPU.h"
|
#include "CPU.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include <intrin.h>
|
||||||
|
|
||||||
|
#ifndef bit_AES
|
||||||
|
#define bit_AES (1 << 25)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
{
|
{
|
||||||
namespace cpu
|
namespace cpu
|
||||||
{
|
{
|
||||||
bool aesni = false;
|
bool aesni = false;
|
||||||
|
|
||||||
|
inline bool cpu_support_aes()
|
||||||
|
{
|
||||||
|
#if (_M_AMD64 || __x86_64__) || (_M_IX86 || __i386__)
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
int cpu_info[4];
|
||||||
|
__cpuid(cpu_info, 1);
|
||||||
|
return ((cpu_info[2] & bit_AES) != 0)
|
||||||
|
#elif defined(__clang__)
|
||||||
|
#if __clang_major__ >= 6
|
||||||
|
__builtin_cpu_init();
|
||||||
|
#endif
|
||||||
|
return __builtin_cpu_supports("aes");
|
||||||
|
#elif defined(__GNUC__)
|
||||||
|
__builtin_cpu_init();
|
||||||
|
return __builtin_cpu_supports("aes");
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void Detect(bool AesSwitch, bool force)
|
void Detect(bool AesSwitch, bool force)
|
||||||
{
|
{
|
||||||
#if defined(__x86_64__) || defined(__i386__)
|
if ((cpu_support_aes() && AesSwitch) || (AesSwitch && force)) {
|
||||||
__builtin_cpu_init ();
|
|
||||||
#if defined (_WIN32) && (WINVER == 0x0501) // WinXP
|
|
||||||
if (AesSwitch && force) { // only if forced
|
|
||||||
#else
|
|
||||||
if ((__builtin_cpu_supports ("aes") && AesSwitch) || (AesSwitch && force)) {
|
|
||||||
#endif
|
|
||||||
aesni = true;
|
aesni = true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
LogPrint(eLogInfo, "AESNI ", (aesni ? "enabled" : "disabled"));
|
LogPrint(eLogInfo, "AESNI ", (aesni ? "enabled" : "disabled"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue