suppress USE_AVX, make it autodetectable on runtime

Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
R4SAS 2020-11-10 20:57:22 +03:00
parent 7e874eaa7c
commit 07ff165a8f
10 changed files with 17 additions and 41 deletions

View file

@ -14,7 +14,6 @@ DAEMON_SRC_DIR := daemon
include filelist.mk include filelist.mk
USE_AESNI := yes USE_AESNI := yes
USE_AVX := yes
USE_STATIC := no USE_STATIC := no
USE_MESHNET := no USE_MESHNET := no
USE_UPNP := no USE_UPNP := no

View file

@ -37,9 +37,6 @@ endif
ifeq ($(USE_AESNI),yes) ifeq ($(USE_AESNI),yes)
CXXFLAGS += -maes CXXFLAGS += -maes
endif endif
ifeq ($(USE_AVX),1)
CXXFLAGS += -mavx
endif
install: all install: all
install -d ${PREFIX}/bin ${PREFIX}/etc/i2pd ${PREFIX}/share/doc/i2pd ${PREFIX}/share/i2pd ${PREFIX}/share/man/man1 ${PREFIX}/var/lib/i2pd install -d ${PREFIX}/bin ${PREFIX}/etc/i2pd ${PREFIX}/share/doc/i2pd ${PREFIX}/share/i2pd ${PREFIX}/share/man/man1 ${PREFIX}/var/lib/i2pd

View file

@ -68,10 +68,3 @@ ifneq ($(shell $(GREP) -c aes /proc/cpuinfo),0)
endif endif
endif endif
endif endif
ifeq ($(USE_AVX),yes)
#check if AVX supported by CPU
ifneq ($(shell $(GREP) -c avx /proc/cpuinfo),0)
CPU_FLAGS += -mavx
endif
endif

View file

@ -52,15 +52,8 @@ ifeq ($(USE_WINXP_FLAGS), yes)
CXXFLAGS += -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 CXXFLAGS += -DWINVER=0x0501 -D_WIN32_WINNT=0x0501
endif endif
# don't change following line to ifeq ($(USE_AESNI),yes) !!! ifeq ($(USE_AESNI),yes)
ifeq ($(USE_AESNI),1)
CPU_FLAGS += -maes CPU_FLAGS += -maes
else
CPU_FLAGS += -msse
endif
ifeq ($(USE_AVX),1)
CPU_FLAGS += -mavx
endif endif
ifeq ($(USE_ASLR),yes) ifeq ($(USE_ASLR),yes)

View file

@ -27,7 +27,3 @@ ifeq ($(USE_AESNI),1)
else else
CXXFLAGS += -msse CXXFLAGS += -msse
endif endif
ifeq ($(USE_AVX),1)
CXXFLAGS += -mavx
endif

View file

@ -11,7 +11,7 @@ DefaultGroupName=I2Pd
UninstallDisplayIcon={app}\I2Pd.exe UninstallDisplayIcon={app}\I2Pd.exe
OutputDir=. OutputDir=.
LicenseFile=../LICENSE LicenseFile=../LICENSE
OutputBaseFilename=setup_{#I2Pd_AppName}_v{#I2Pd_ver} OutputBaseFilename=../build/setup_{#I2Pd_AppName}_v{#I2Pd_ver}
SetupIconFile=mask.ico SetupIconFile=mask.ico
InternalCompressLevel=ultra64 InternalCompressLevel=ultra64
Compression=lzma/ultra64 Compression=lzma/ultra64

View file

@ -12,8 +12,8 @@ if(WIN32 OR MSVC OR MSYS OR MINGW)
endif() endif()
# configurale options # configurale options
option(WITH_AESNI "Use AES-NI instructions set" OFF) option(WITH_AESNI "Use AES-NI instructions set" ON)
option(WITH_AVX "Use AVX instructions" OFF) option(WITH_AVX "deprecated" OFF)
option(WITH_HARDENING "Use hardening compiler flags" OFF) option(WITH_HARDENING "Use hardening compiler flags" OFF)
option(WITH_LIBRARY "Build library" ON) option(WITH_LIBRARY "Build library" ON)
option(WITH_BINARY "Build binary" ON) option(WITH_BINARY "Build binary" ON)
@ -194,10 +194,6 @@ if(WITH_AESNI)
add_definitions(-DAESNI) add_definitions(-DAESNI)
endif() endif()
if(WITH_AVX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
endif()
if(WITH_ADDRSANITIZER) if(WITH_ADDRSANITIZER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
@ -309,7 +305,6 @@ message(STATUS "Architecture : ${ARCHITECTURE}")
message(STATUS "Install prefix: : ${CMAKE_INSTALL_PREFIX}") message(STATUS "Install prefix: : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Options:") message(STATUS "Options:")
message(STATUS " AESNI : ${WITH_AESNI}") message(STATUS " AESNI : ${WITH_AESNI}")
message(STATUS " AVX : ${WITH_AVX}")
message(STATUS " HARDENING : ${WITH_HARDENING}") message(STATUS " HARDENING : ${WITH_HARDENING}")
message(STATUS " LIBRARY : ${WITH_LIBRARY}") message(STATUS " LIBRARY : ${WITH_LIBRARY}")
message(STATUS " BINARY : ${WITH_BINARY}") message(STATUS " BINARY : ${WITH_BINARY}")

View file

@ -29,6 +29,7 @@ namespace cpu
void Detect() void Detect()
{ {
__builtin_cpu_init();
#if defined(__AES__) || defined(__AVX__) #if defined(__AES__) || defined(__AVX__)
#if defined(__x86_64__) || defined(__i386__) #if defined(__x86_64__) || defined(__i386__)
@ -37,11 +38,13 @@ namespace cpu
if (info[0] >= 0x00000001) { if (info[0] >= 0x00000001) {
__cpuid(0x00000001, info[0], info[1], info[2], info[3]); __cpuid(0x00000001, info[0], info[1], info[2], info[3]);
#ifdef __AES__ #ifdef __AES__
aesni = info[2] & bit_AES; // AESNI if (__builtin_cpu_supports("aes")) {
aesni = info[2] & bit_AES; // AESNI
}
#endif // __AES__ #endif // __AES__
#ifdef __AVX__ if (__builtin_cpu_supports("avx")) {
avx = info[2] & bit_AVX; // AVX avx = info[2] & bit_AVX; // AVX
#endif // __AVX__ }
} }
#endif // defined(__x86_64__) || defined(__i386__) #endif // defined(__x86_64__) || defined(__i386__)
@ -51,12 +54,10 @@ namespace cpu
LogPrint(eLogInfo, "AESNI enabled"); LogPrint(eLogInfo, "AESNI enabled");
} }
#endif // __AES__ #endif // __AES__
#ifdef __AVX__
if(avx) if(avx)
{ {
LogPrint(eLogInfo, "AVX enabled"); LogPrint(eLogInfo, "AVX enabled");
} }
#endif // __AVX__
#endif // defined(__AES__) || defined(__AVX__) #endif // defined(__AES__) || defined(__AVX__)
} }
} }

View file

@ -631,6 +631,9 @@ namespace crypto
static const uint64_t ipads[] = { IPAD, IPAD, IPAD, IPAD }; static const uint64_t ipads[] = { IPAD, IPAD, IPAD, IPAD };
static const uint64_t opads[] = { OPAD, OPAD, OPAD, OPAD }; static const uint64_t opads[] = { OPAD, OPAD, OPAD, OPAD };
#if defined(__x86_64__) || defined(__i386__)
#pragma GCC target("avx")
#endif
void HMACMD5Digest (uint8_t * msg, size_t len, const MACKey& key, uint8_t * digest) void HMACMD5Digest (uint8_t * msg, size_t len, const MACKey& key, uint8_t * digest)
// key is 32 bytes // key is 32 bytes
// digest is 16 bytes // digest is 16 bytes
@ -638,7 +641,6 @@ namespace crypto
{ {
uint64_t buf[256]; uint64_t buf[256];
uint64_t hash[12]; // 96 bytes uint64_t hash[12]; // 96 bytes
#ifdef __AVX__
if(i2p::cpu::avx) if(i2p::cpu::avx)
{ {
__asm__ __asm__
@ -661,7 +663,6 @@ namespace crypto
); );
} }
else else
#endif
{ {
// ikeypad // ikeypad
buf[0] = key.GetLL ()[0] ^ IPAD; buf[0] = key.GetLL ()[0] ^ IPAD;

View file

@ -825,10 +825,12 @@ namespace data
return key; return key;
} }
#if defined(__x86_64__) || defined(__i386__)
#pragma GCC target("avx")
#endif
XORMetric operator^(const IdentHash& key1, const IdentHash& key2) XORMetric operator^(const IdentHash& key1, const IdentHash& key2)
{ {
XORMetric m; XORMetric m;
#ifdef __AVX__
if(i2p::cpu::avx) if(i2p::cpu::avx)
{ {
__asm__ __asm__
@ -843,7 +845,6 @@ namespace data
); );
} }
else else
#endif
{ {
const uint64_t * hash1 = key1.GetLL (), * hash2 = key2.GetLL (); const uint64_t * hash1 = key1.GetLL (), * hash2 = key2.GetLL ();
m.metric_ll[0] = hash1[0] ^ hash2[0]; m.metric_ll[0] = hash1[0] ^ hash2[0];