From 8d984173064b360af57f60932bd7b4d3c3312eb4 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 13 Sep 2017 17:16:57 -0400 Subject: [PATCH] Add Aarch64 specific defines to Android cross-compile Move logic into "sonfig.h". Detecting when we can/should include is proving to be troublesome --- GNUmakefile-cross | 66 ++++++++++++++++++++++++++++++++++++++++++++--- aria-simd.cpp | 4 +-- blake2-simd.cpp | 6 ++--- config.h | 14 ++++++++-- crc-simd.cpp | 6 +---- gcm-simd.cpp | 6 +---- neon-simd.cpp | 4 +++ rijndael-simd.cpp | 6 +---- sha-simd.cpp | 6 +---- shacal2-simd.cpp | 6 +---- 10 files changed, 88 insertions(+), 36 deletions(-) diff --git a/GNUmakefile-cross b/GNUmakefile-cross index ab5c7481..45ac5661 100755 --- a/GNUmakefile-cross +++ b/GNUmakefile-cross @@ -11,7 +11,9 @@ MKDIR ?= mkdir EGREP ?= egrep LN ?= ln -sf -CLANG_COMPILER = $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang") +$(info "EGREP: $(EGREP)") +IS_ARMV8 := $(shell $(CXX) -dumpmachine 2>&1 | $(EGREP) -i -c 'aarch32|aarch64') +CLANG_COMPILER := $(shell $(CXX) --version 2>&1 | $(EGREP) -i -c "clang") IS_IOS ?= 0 IS_ANDROID ?= 0 @@ -176,6 +178,26 @@ ifeq ($(findstring lean,$(MAKECMDGOALS)),lean) endif # MAKECMDGOALS endif # Dead code stripping +# ARMv8-a +ifeq ($(IS_ARMV8),1) + HAVE_NEON := $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a -dM -E - 2>/dev/null | $(EGREP) -i -c __ARM_NEON) + ifeq ($(HAVE_NEON),1) + ARIA_FLAG = -march=armv8-a + BLAKE2_FLAG = -march=armv8-a + NEON_FLAG = -march=armv8-a + endif + HAVE_CRC := $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a+crc -dM -E - 2>/dev/null | $(EGREP) -i -c __ARM_FEATURE_CRC32) + ifeq ($(HAVE_CRC),1) + CRC_FLAG = -march=armv8-a+crc + endif + HAVE_CRYPTO := $(shell echo | $(CXX) -x c++ $(CXXFLAGS) -march=armv8-a+crypto -dM -E - 2>/dev/null | $(EGREP) -i -c __ARM_FEATURE_CRYPTO) + ifeq ($(HAVE_CRYPTO),1) + AES_FLAG = -march=armv8-a+crypto + GCM_FLAG = -march=armv8-a+crypto + SHA_FLAG = -march=armv8-a+crypto + endif +endif + # List cryptlib.cpp first, then cpu.cpp, then integer.cpp to tame C++ static initialization problems. SRCS := cryptlib.cpp cpu.cpp integer.cpp $(filter-out cryptlib.cpp cpu.cpp integer.cpp pch.cpp simple.cpp winpipes.cpp cryptlib_bds.cpp,$(sort $(wildcard *.cpp))) @@ -329,10 +351,46 @@ ifeq ($(wildcard GNUmakefile.deps),GNUmakefile.deps) endif # Dependencies cpu-features.o: cpu-features.h cpu-features.c - $(CXX) $(strip $(CXXFLAGS) -fpermissive) -c cpu-features.c + $(CXX) $(strip $(CXXFLAGS) -fpermissive -c) cpu-features.c + +# SSE4.2 or NEON available +aria-simd.o : aria-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(ARIA_FLAG) -c) $< + +# SSE4.2 or ARMv8a available +blake2-simd.o : blake2-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(BLAKE2_FLAG) -c) $< + +# SSE2 on i586 +cpu.o : cpu.cpp + $(CXX) $(strip $(CXXFLAGS) $(CPU_FLAG) -c) $< + +# SSE4.2 or ARMv8a available +crc-simd.o : crc-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(CRC_FLAG) -c) $< + +# PCLMUL or ARMv7a/ARMv8a available +gcm-simd.o : gcm-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(GCM_FLAG) -c) $< + +# NEON available +neon-simd.o : neon-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(NEON_FLAG) -c) $< + +# AESNI or ARMv7a/ARMv8a available +rijndael-simd.o : rijndael-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(AES_FLAG) -c) $< + +# SSE4.2/SHA-NI or ARMv8a available +sha-simd.o : sha-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $< + +# SSE4.2/SHA-NI or ARMv8a available +shacal2-simd.o : shacal2-simd.cpp + $(CXX) $(strip $(CXXFLAGS) $(SHA_FLAG) -c) $< %.o : %.cpp - $(CXX) $(strip $(CXXFLAGS)) -c $< + $(CXX) $(strip $(CXXFLAGS) -c) $< GNUmakefile.deps: - $(CXX) $(strip $(CXXFLAGS)) -MM *.cpp > GNUmakefile.deps + $(CXX) $(strip $(CXXFLAGS) -MM) *.cpp > GNUmakefile.deps diff --git a/aria-simd.cpp b/aria-simd.cpp index 51ccecfd..0d89b049 100644 --- a/aria-simd.cpp +++ b/aria-simd.cpp @@ -11,11 +11,11 @@ #include "misc.h" #if (CRYPTOPP_ARM_NEON_AVAILABLE) -# include "arm_neon.h" +# include #endif #if (CRYPTOPP_SSSE3_AVAILABLE) -# include "tmmintrin.h" +# include #endif NAMESPACE_BEGIN(CryptoPP) diff --git a/blake2-simd.cpp b/blake2-simd.cpp index f437bc4e..45834c85 100644 --- a/blake2-simd.cpp +++ b/blake2-simd.cpp @@ -12,12 +12,12 @@ #include "blake2.h" #if (CRYPTOPP_SSE42_AVAILABLE) -# include "emmintrin.h" -# include "nmmintrin.h" +# include +# include #endif #if (CRYPTOPP_ARM_NEON_AVAILABLE) -# include "arm_neon.h" +# include #endif #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY diff --git a/config.h b/config.h index 14641ccc..17dd6d21 100644 --- a/config.h +++ b/config.h @@ -548,13 +548,23 @@ NAMESPACE_END # endif #endif +// Don't include when using Apple Clang. Early Apple compilers +// fail to compile with included. Later Apple compilers compile +// intrinsics without included. Also avoid it with GCC 4.8, +// and avoid it on Android, too. +#if defined(__ARM_ACLE) && !defined(CRYPTOPP_APPLE_CLANG_VERSION) && \ + (!defined(CRYPTOPP_GCC_VERSION) || (CRYPTOPP_GCC_VERSION >= 40900)) && \ + !defined(__ANDROID__) +# define CRYPTOPP_ARM_ACLE_AVAILABLE 1 +#endif + // Requires ARMv8 and ACLE 2.0. GCC requires 4.8 and above. // LLVM Clang requires 3.5. Apple Clang is unknown at the moment. // Microsoft plans to support ARM-64, but its not clear how to detect it. // TODO: Add MSC_VER and ARM-64 platform define when available #if !defined(CRYPTOPP_ARM_CRC32_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ASM) && !defined(__apple_build_version__) -# if defined(__ARM_FEATURE_CRC32) || (CRYPTOPP_MSC_VERSION >= 1910) || \ - defined(__aarch32__) || defined(__aarch64__) +# if (defined(__ARM_FEATURE_CRC32) || (CRYPTOPP_MSC_VERSION >= 1910) || \ + defined(__aarch32__) || defined(__aarch64__)) && !defined(__ANDROID__) # define CRYPTOPP_ARM_CRC32_AVAILABLE 1 # endif #endif diff --git a/crc-simd.cpp b/crc-simd.cpp index 029dd9ae..fe287279 100644 --- a/crc-simd.cpp +++ b/crc-simd.cpp @@ -24,11 +24,7 @@ # include #endif -// Don't include when using Apple Clang. Early Apple compilers -// fail to compile with included. Later Apple compilers compile -// intrinsics without included. Also avoid it with GCC 4.8. -#if (CRYPTOPP_ARM_CRC32_AVAILABLE) && !defined(CRYPTOPP_APPLE_CLANG_VERSION) && \ - (!defined(CRYPTOPP_GCC_VERSION) || (CRYPTOPP_GCC_VERSION >= 40900)) +#if defined(CRYPTOPP_ARM_ACLE_AVAILABLE) # include #endif diff --git a/gcm-simd.cpp b/gcm-simd.cpp index e9a30eb3..5e200087 100644 --- a/gcm-simd.cpp +++ b/gcm-simd.cpp @@ -39,11 +39,7 @@ # include #endif -// Don't include when using Apple Clang. Early Apple compilers -// fail to compile with included. Later Apple compilers compile -// intrinsics without included. Also avoid it with GCC 4.8. -#if (CRYPTOPP_ARM_PMULL_AVAILABLE) && !defined(CRYPTOPP_APPLE_CLANG_VERSION) && \ - (!defined(CRYPTOPP_GCC_VERSION) || (CRYPTOPP_GCC_VERSION >= 40900)) +#if defined(CRYPTOPP_ARM_ACLE_AVAILABLE) # include #endif diff --git a/neon-simd.cpp b/neon-simd.cpp index 46064ac8..88d06cce 100644 --- a/neon-simd.cpp +++ b/neon-simd.cpp @@ -14,6 +14,10 @@ # include #endif +#if defined(CRYPTOPP_ARM_ACLE_AVAILABLE) +# include +#endif + #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY # include # include diff --git a/rijndael-simd.cpp b/rijndael-simd.cpp index b9f272ee..ac7cda9a 100644 --- a/rijndael-simd.cpp +++ b/rijndael-simd.cpp @@ -43,11 +43,7 @@ # include #endif -// Don't include when using Apple Clang. Early Apple compilers -// fail to compile with included. Later Apple compilers compile -// intrinsics without included. Also avoid it with GCC 4.8. -#if (CRYPTOPP_ARM_AES_AVAILABLE) && !defined(CRYPTOPP_APPLE_CLANG_VERSION) && \ - (!defined(CRYPTOPP_GCC_VERSION) || (CRYPTOPP_GCC_VERSION >= 40900)) +#if defined(CRYPTOPP_ARM_ACLE_AVAILABLE) # include #endif diff --git a/sha-simd.cpp b/sha-simd.cpp index c756a4c6..d3a869d6 100644 --- a/sha-simd.cpp +++ b/sha-simd.cpp @@ -26,11 +26,7 @@ # include #endif -// Don't include when using Apple Clang. Early Apple compilers -// fail to compile with included. Later Apple compilers compile -// intrinsics without included. Also avoid it with GCC 4.8. -#if (CRYPTOPP_ARM_SHA_AVAILABLE) && !defined(CRYPTOPP_APPLE_CLANG_VERSION) && \ - (!defined(CRYPTOPP_GCC_VERSION) || (CRYPTOPP_GCC_VERSION >= 40900)) +#if defined(CRYPTOPP_ARM_ACLE_AVAILABLE) # include #endif diff --git a/shacal2-simd.cpp b/shacal2-simd.cpp index 6bb80bd7..0eb18d3a 100644 --- a/shacal2-simd.cpp +++ b/shacal2-simd.cpp @@ -31,11 +31,7 @@ # include #endif -// Don't include when using Apple Clang. Early Apple compilers -// fail to compile with included. Later Apple compilers compile -// intrinsics without included. Also avoid it with GCC 4.8. -#if (CRYPTOPP_ARM_SHA_AVAILABLE) && !defined(CRYPTOPP_APPLE_CLANG_VERSION) && \ - (!defined(CRYPTOPP_GCC_VERSION) || (CRYPTOPP_GCC_VERSION >= 40900)) +#if defined(CRYPTOPP_ARM_ACLE_AVAILABLE) # include #endif