diff --git a/GNUmakefile b/GNUmakefile index f4977358..0b573acb 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -104,6 +104,16 @@ ifeq ($(IS_AIX),1) endif endif +# Hack to skip CPU feature tests for some recipes +DETECT_FEATURES ?= 1 +ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),-DCRYPTOPP_DISABLE_ASM) + DETECT_FEATURES := 0 +else ifeq ($(findstring clean,$(MAKECMDGOALS)),clean) + DETECT_FEATURES := 0 +else ifeq ($(findstring distclean,$(MAKECMDGOALS)),distclean) + DETECT_FEATURES := 0 +endif + ########################################################### ##### General Variables ##### ########################################################### @@ -190,7 +200,7 @@ ifneq ($(IS_X86)$(IS_X64),00) # Begin GCC and compatibles ifneq ($(GCC_COMPILER)$(CLANG_COMPILER)$(INTEL_COMPILER),000) -ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) +ifeq ($(DETECT_FEATURES),1) # Tell MacPorts and Homebrew GCC to use Clang integrated assembler # http://github.com/weidai11/cryptopp/issues/190 @@ -301,7 +311,7 @@ ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) # https://github.com/weidai11/cryptopp/issues/738 UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/) -# CRYPTOPP_DISABLE_ASM +# DETECT_FEATURES endif # End GCC and compatibles @@ -309,7 +319,7 @@ endif # Begin SunCC ifeq ($(SUN_COMPILER),1) -ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) +ifeq ($(DETECT_FEATURES),1) TPROG = TestPrograms/test_sse2.cxx TOPT = -xarch=sse2 @@ -417,7 +427,7 @@ ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) # https://github.com/weidai11/cryptopp/issues/738 UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/) -# CRYPTOPP_DISABLE_ASM +# DETECT_FEATURES endif # End SunCC @@ -451,11 +461,11 @@ endif ########################################################### ifneq ($(IS_ARM32)$(IS_ARMV8)$(IS_NEON),000) -ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) +ifeq ($(DETECT_FEATURES),1) ifeq ($(IS_ARM32)$(IS_NEON),11) - TPROG = TestPrograms/test_neon.cxx + TPROG = TestPrograms/test_arm_neon.cxx TOPT = -march=armv7-a -mfloat-abi=$(FP_ABI) -mfpu=neon HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) ifeq ($(HAVE_OPT),0) @@ -488,16 +498,18 @@ endif ifeq ($(IS_ARMV8),1) - TPROG = TestPrograms/test_asimd.cxx + TPROG = TestPrograms/test_arm_acle.cxx TOPT = -march=armv8-a HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) - ifneq ($(HAVE_OPT),0) + ifeq ($(HAVE_OPT),0) + ACLE_FLAG += -DCRYPTOPP_ARM_ACLE_AVAILABLE=1 + else CXXFLAGS += -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 endif - TPROG = TestPrograms/test_asimd.cxx + TPROG = TestPrograms/test_arm_asimd.cxx TOPT = -march=armv8-a - HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) + HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) ifeq ($(HAVE_OPT),0) ASIMD_FLAG = -march=armv8-a ARIA_FLAG = -march=armv8-a @@ -518,26 +530,46 @@ ifeq ($(IS_ARMV8),1) endif ifneq ($(ASIMD_FLAG),) - TPROG = TestPrograms/test_crc.cxx - TOPT = -march=armv8-a+crc - HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) + TPROG = TestPrograms/test_arm_crc.cxx + TOPT = -march=armv8.1-a+crc + HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) ifeq ($(HAVE_OPT),0) - CRC_FLAG = -march=armv8-a+crc + CRC_FLAG = -march=armv8.1-a+crc + else + CXXFLAGS += -DCRYPTOPP_ARM_CRC32_AVAILABLE=0 endif - TPROG = TestPrograms/test_crypto_v81.cxx - TOPT = -march=armv8-a+crypto - HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) + TPROG = TestPrograms/test_arm_aes.cxx + TOPT = -march=armv8.1-a+crypto + HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) ifeq ($(HAVE_OPT),0) - AES_FLAG = -march=armv8-a+crypto - GCM_FLAG = -march=armv8-a+crypto - SHA_FLAG = -march=armv8-a+crypto + AES_FLAG = -march=armv8.1-a+crypto + else + CXXFLAGS += -DCRYPTOPP_ARM_AES_AVAILABLE=0 + endif + + TPROG = TestPrograms/test_arm_pmull.cxx + TOPT = -march=armv8.1-a+crypto + HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) + ifeq ($(HAVE_OPT),0) + GCM_FLAG = -march=armv8.1-a+crypto + else + CXXFLAGS += -DCRYPTOPP_ARM_PMULL_AVAILABLE=0 + endif + + TPROG = TestPrograms/test_arm_sha.cxx + TOPT = -march=armv8.1-a+crypto + HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) + ifeq ($(HAVE_OPT),0) + SHA_FLAG = -march=armv8.1-a+crypto + else + CXXFLAGS += -DCRYPTOPP_ARM_SHA_AVAILABLE=0 endif ifneq ($(AES_FLAG),) TPROG = TestPrograms/test_crypto_v84.cxx TOPT = -march=armv8.4-a+crypto - HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) + HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ACLE_FLAG) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT)) ifeq ($(HAVE_OPT),0) SM3_FLAG = -march=armv8.4-a+crypto SM4_FLAG = -march=armv8.4-a+crypto @@ -551,7 +583,7 @@ ifeq ($(IS_ARMV8),1) # IS_ARMV8 endif -# CRYPTOPP_DISABLE_ASM +# DETECT_FEATURES endif # IS_ARM32, IS_ARMV8, IS_NEON @@ -566,7 +598,7 @@ endif # front-end. XLC/LLVM only supplies POWER8 so we have to set the flags for # XLC/LLVM to POWER8. I've got a feeling LLVM is going to cause trouble. ifneq ($(IS_PPC32)$(IS_PPC64),00) -ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) +ifeq ($(DETECT_FEATURES),1) # LLVM front-ends only provide POWER8 and need special options to # get XLC defines. The POWER8 really jambs us up for ppc_simd.cpp @@ -722,7 +754,7 @@ ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) # https://github.com/weidai11/cryptopp/issues/738 UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/) -# CRYPTOPP_DISABLE_ASM +# DETECT_FEATURES endif # IBM XL C/C++ compiler diff --git a/TestPrograms/test_arm_acle.cxx b/TestPrograms/test_arm_acle.cxx new file mode 100644 index 00000000..e03010bc --- /dev/null +++ b/TestPrograms/test_arm_acle.cxx @@ -0,0 +1,6 @@ +#include + +int main(int argc, char* argv[]) +{ + return 0; +} diff --git a/TestPrograms/test_arm_aes.cxx b/TestPrograms/test_arm_aes.cxx new file mode 100644 index 00000000..b87cdf19 --- /dev/null +++ b/TestPrograms/test_arm_aes.cxx @@ -0,0 +1,19 @@ +#include +#include + +// test_acle.h determines if this is available. Then, +// -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS +// if the ACLE header is not available. +#if (CRYPTOPP_ARM_ACLE_AVAILABLE) +# include +#endif + +int main(int argc, char* argv[]) +{ + uint8x16_t x; + x=vaeseq_u8(x,x); + x=vaesmcq_u8(x); + x=vaesdq_u8(x,x); + x=vaesimcq_u8(x); + return 0; +} diff --git a/TestPrograms/test_arm_asimd.cxx b/TestPrograms/test_arm_asimd.cxx new file mode 100644 index 00000000..3037b769 --- /dev/null +++ b/TestPrograms/test_arm_asimd.cxx @@ -0,0 +1,16 @@ +#include +#include + +// test_acle.h determines if this is available. Then, +// -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS +// if the ACLE header is not available. +#if (CRYPTOPP_ARM_ACLE_AVAILABLE) +# include +#endif + +int main(int argc, char* argv[]) +{ + uint32x4_t x; + x=veorq_u32(x,x); + return 0; +} diff --git a/TestPrograms/test_crc.cxx b/TestPrograms/test_arm_crc.cxx similarity index 56% rename from TestPrograms/test_crc.cxx rename to TestPrograms/test_arm_crc.cxx index d8629efb..ddee813a 100644 --- a/TestPrograms/test_crc.cxx +++ b/TestPrograms/test_arm_crc.cxx @@ -1,11 +1,11 @@ #include #include -// This is how config.h includes it. -#if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) -# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) +// test_acle.h determines if this is available. Then, +// -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS +// if the ACLE header is not available. +#if (CRYPTOPP_ARM_ACLE_AVAILABLE) # include -# endif #endif int main(int argc, char* argv[]) diff --git a/TestPrograms/test_neon.cxx b/TestPrograms/test_arm_neon.cxx similarity index 65% rename from TestPrograms/test_neon.cxx rename to TestPrograms/test_arm_neon.cxx index 7e293633..c5407a40 100644 --- a/TestPrograms/test_neon.cxx +++ b/TestPrograms/test_arm_neon.cxx @@ -1,10 +1,6 @@ #include #include -#if (CRYPTOPP_ARM_ACLE_AVAILABLE) -# include -#endif - int main(int argc, char* argv[]) { uint32x4_t x; diff --git a/TestPrograms/test_arm_pmull.cxx b/TestPrograms/test_arm_pmull.cxx new file mode 100644 index 00000000..83d2c9f4 --- /dev/null +++ b/TestPrograms/test_arm_pmull.cxx @@ -0,0 +1,23 @@ +#include +#include + +// test_acle.h determines if this is available. Then, +// -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS +// if the ACLE header is not available. +#if (CRYPTOPP_ARM_ACLE_AVAILABLE) +# include +#endif + +int main(int argc, char* argv[]) +{ + poly64_t a1={0x9090909090909090}, b1={0xb0b0b0b0b0b0b0b0}; + poly8x16_t a2={0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, + 0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0,0xa0}, + b2={0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0, + 0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0}; + + poly128_t r1 = vmull_p64(a1, b1); + poly128_t r2 = vmull_high_p64((poly64x2_t)(a2), (poly64x2_t)(b2)); + + return 0; +} diff --git a/TestPrograms/test_arm_sha.cxx b/TestPrograms/test_arm_sha.cxx new file mode 100644 index 00000000..526dd34a --- /dev/null +++ b/TestPrograms/test_arm_sha.cxx @@ -0,0 +1,21 @@ +#include +#include + +// test_acle.h determines if this is available. Then, +// -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS +// if the ACLE header is not available. +#if (CRYPTOPP_ARM_ACLE_AVAILABLE) +# include +#endif + +int main(int argc, char* argv[]) +{ + uint32x4_t y; + y=vsha1cq_u32(y,0,y); + y=vsha1mq_u32(y,1,y); + y=vsha1pq_u32(y,2,y); + y = vsha256hq_u32(y, y, y); + y = vsha256h2q_u32(y, y, y); + y = vsha256su1q_u32(y, y, y); + return 0; +} diff --git a/TestPrograms/test_asimd.cxx b/TestPrograms/test_asimd.cxx deleted file mode 100644 index 2940bb4b..00000000 --- a/TestPrograms/test_asimd.cxx +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -// This is how config.h includes it. -#if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) -# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) -# include -# endif -#endif - -int main(int argc, char* argv[]) -{ - uint32x4_t x; - x=veorq_u32(x,x); - return 0; -} diff --git a/TestPrograms/test_crypto_v81.cxx b/TestPrograms/test_crypto_v81.cxx deleted file mode 100644 index d0e440e0..00000000 --- a/TestPrograms/test_crypto_v81.cxx +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -// This is how config.h includes it. -#if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) -# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) -# include -# endif -#endif - -int main(int argc, char* argv[]) -{ - uint8x16_t x; - x=vaeseq_u8(x,x); - x=vaesdq_u8(x,x); - - uint32x4_t y; - y=vsha1cq_u32(y,0,y); - y=vsha1mq_u32(y,1,y); - y=vsha1pq_u32(y,2,y); - - return 0; -} diff --git a/TestPrograms/test_crypto_v84.cxx b/TestPrograms/test_crypto_v84.cxx index 8ce696fc..533b4039 100644 --- a/TestPrograms/test_crypto_v84.cxx +++ b/TestPrograms/test_crypto_v84.cxx @@ -1,11 +1,11 @@ #include #include -// This is how config.h includes it. -#if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) -# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) +// test_acle.h determines if this is available. Then, +// -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS +// if the ACLE header is not available. +#if (CRYPTOPP_ARM_ACLE_AVAILABLE) # include -# endif #endif int main(int argc, char* argv[]) diff --git a/config.h b/config.h index 774c4815..0a10fecc 100644 --- a/config.h +++ b/config.h @@ -729,9 +729,11 @@ NAMESPACE_END #endif // Limit the include. -#if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) -# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) -# define CRYPTOPP_ARM_ACLE_AVAILABLE 1 +#if !defined(CRYPTOPP_ARM_ACLE_AVAILABLE) +# if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) +# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) +# define CRYPTOPP_ARM_ACLE_AVAILABLE 1 +# endif # endif #endif