2020-05-22 16:18:41 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013-2020, The PurpleI2P Project
|
|
|
|
*
|
|
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
|
|
*
|
|
|
|
* See full license text in LICENSE file at top of project tree
|
|
|
|
*/
|
|
|
|
|
2018-02-16 19:01:04 +03:00
|
|
|
#include "CPU.h"
|
|
|
|
#if defined(__x86_64__) || defined(__i386__)
|
|
|
|
#include <cpuid.h>
|
|
|
|
#endif
|
|
|
|
#include "Log.h"
|
2018-02-19 18:15:39 +03:00
|
|
|
|
|
|
|
#ifndef bit_AES
|
|
|
|
#define bit_AES (1 << 25)
|
|
|
|
#endif
|
|
|
|
#ifndef bit_AVX
|
|
|
|
#define bit_AVX (1 << 28)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-02-16 19:01:04 +03:00
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace cpu
|
|
|
|
{
|
|
|
|
bool aesni = false;
|
|
|
|
bool avx = false;
|
|
|
|
|
2020-11-15 01:31:20 +03:00
|
|
|
void Detect(bool AesSwitch, bool AvxSwitch, bool force)
|
2018-02-16 19:01:04 +03: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]);
|
2020-11-16 03:38:52 +03:00
|
|
|
#if defined (_WIN32) && (WINVER == 0x0501) // WinXP
|
|
|
|
if (AesSwitch && force) { // only if forced
|
|
|
|
#else
|
2020-11-15 01:31:20 +03:00
|
|
|
if ((info[2] & bit_AES && AesSwitch) || (AesSwitch && force)) {
|
2020-11-16 03:38:52 +03:00
|
|
|
#endif
|
2020-11-15 01:31:20 +03:00
|
|
|
aesni = true;
|
|
|
|
}
|
2020-11-16 03:38:52 +03:00
|
|
|
#if defined (_WIN32) && (WINVER == 0x0501) // WinXP
|
|
|
|
if (AvxSwitch && force) { // only if forced
|
|
|
|
#else
|
2020-11-15 01:31:20 +03:00
|
|
|
if ((info[2] & bit_AVX && AvxSwitch) || (AvxSwitch && force)) {
|
2020-11-16 03:38:52 +03:00
|
|
|
#endif
|
2020-11-15 01:31:20 +03:00
|
|
|
avx = true;
|
|
|
|
}
|
2018-02-16 19:01:04 +03:00
|
|
|
}
|
2020-11-15 01:31:20 +03:00
|
|
|
#endif // defined(__x86_64__) || defined(__i386__)
|
2018-06-27 12:09:46 +03:00
|
|
|
|
2020-11-15 01:31:20 +03:00
|
|
|
LogPrint(eLogInfo, "AESNI ", (aesni ? "enabled" : "disabled"));
|
|
|
|
LogPrint(eLogInfo, "AVX ", (avx ? "enabled" : "disabled"));
|
2018-02-16 19:01:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|