Fix ARM A-32 and Aarch64 feature tests (PR #737)

pull/739/head
Jeffrey Walton 2018-11-12 14:59:36 -05:00
parent 886fd7903d
commit 41639e5ec6
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
12 changed files with 154 additions and 78 deletions

View File

@ -104,6 +104,16 @@ ifeq ($(IS_AIX),1)
endif endif
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 ##### ##### General Variables #####
########################################################### ###########################################################
@ -190,7 +200,7 @@ ifneq ($(IS_X86)$(IS_X64),00)
# Begin GCC and compatibles # Begin GCC and compatibles
ifneq ($(GCC_COMPILER)$(CLANG_COMPILER)$(INTEL_COMPILER),000) 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 # Tell MacPorts and Homebrew GCC to use Clang integrated assembler
# http://github.com/weidai11/cryptopp/issues/190 # http://github.com/weidai11/cryptopp/issues/190
@ -301,7 +311,7 @@ ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
# https://github.com/weidai11/cryptopp/issues/738 # https://github.com/weidai11/cryptopp/issues/738
UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/) UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/)
# CRYPTOPP_DISABLE_ASM # DETECT_FEATURES
endif endif
# End GCC and compatibles # End GCC and compatibles
@ -309,7 +319,7 @@ endif
# Begin SunCC # Begin SunCC
ifeq ($(SUN_COMPILER),1) ifeq ($(SUN_COMPILER),1)
ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) ifeq ($(DETECT_FEATURES),1)
TPROG = TestPrograms/test_sse2.cxx TPROG = TestPrograms/test_sse2.cxx
TOPT = -xarch=sse2 TOPT = -xarch=sse2
@ -417,7 +427,7 @@ ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)
# https://github.com/weidai11/cryptopp/issues/738 # https://github.com/weidai11/cryptopp/issues/738
UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/) UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/)
# CRYPTOPP_DISABLE_ASM # DETECT_FEATURES
endif endif
# End SunCC # End SunCC
@ -451,11 +461,11 @@ endif
########################################################### ###########################################################
ifneq ($(IS_ARM32)$(IS_ARMV8)$(IS_NEON),000) ifneq ($(IS_ARM32)$(IS_ARMV8)$(IS_NEON),000)
ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) ifeq ($(DETECT_FEATURES),1)
ifeq ($(IS_ARM32)$(IS_NEON),11) 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 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)) HAVE_OPT = $(shell $(CXX) $(CXXFLAGS) $(ZOPT) $(TOPT) $(TPROG) 2>&1 | $(GREP) -i -c -E $(BAD_RESULT))
ifeq ($(HAVE_OPT),0) ifeq ($(HAVE_OPT),0)
@ -488,16 +498,18 @@ endif
ifeq ($(IS_ARMV8),1) ifeq ($(IS_ARMV8),1)
TPROG = TestPrograms/test_asimd.cxx TPROG = TestPrograms/test_arm_acle.cxx
TOPT = -march=armv8-a 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) $(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 CXXFLAGS += -DCRYPTOPP_ARM_ACLE_AVAILABLE=0
endif endif
TPROG = TestPrograms/test_asimd.cxx TPROG = TestPrograms/test_arm_asimd.cxx
TOPT = -march=armv8-a 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) ifeq ($(HAVE_OPT),0)
ASIMD_FLAG = -march=armv8-a ASIMD_FLAG = -march=armv8-a
ARIA_FLAG = -march=armv8-a ARIA_FLAG = -march=armv8-a
@ -518,26 +530,46 @@ ifeq ($(IS_ARMV8),1)
endif endif
ifneq ($(ASIMD_FLAG),) ifneq ($(ASIMD_FLAG),)
TPROG = TestPrograms/test_crc.cxx TPROG = TestPrograms/test_arm_crc.cxx
TOPT = -march=armv8-a+crc TOPT = -march=armv8.1-a+crc
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) 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 endif
TPROG = TestPrograms/test_crypto_v81.cxx TPROG = TestPrograms/test_arm_aes.cxx
TOPT = -march=armv8-a+crypto TOPT = -march=armv8.1-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) ifeq ($(HAVE_OPT),0)
AES_FLAG = -march=armv8-a+crypto AES_FLAG = -march=armv8.1-a+crypto
GCM_FLAG = -march=armv8-a+crypto else
SHA_FLAG = -march=armv8-a+crypto 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 endif
ifneq ($(AES_FLAG),) ifneq ($(AES_FLAG),)
TPROG = TestPrograms/test_crypto_v84.cxx TPROG = TestPrograms/test_crypto_v84.cxx
TOPT = -march=armv8.4-a+crypto 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) ifeq ($(HAVE_OPT),0)
SM3_FLAG = -march=armv8.4-a+crypto SM3_FLAG = -march=armv8.4-a+crypto
SM4_FLAG = -march=armv8.4-a+crypto SM4_FLAG = -march=armv8.4-a+crypto
@ -551,7 +583,7 @@ ifeq ($(IS_ARMV8),1)
# IS_ARMV8 # IS_ARMV8
endif endif
# CRYPTOPP_DISABLE_ASM # DETECT_FEATURES
endif endif
# IS_ARM32, IS_ARMV8, IS_NEON # 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 # 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. # XLC/LLVM to POWER8. I've got a feeling LLVM is going to cause trouble.
ifneq ($(IS_PPC32)$(IS_PPC64),00) 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 # LLVM front-ends only provide POWER8 and need special options to
# get XLC defines. The POWER8 really jambs us up for ppc_simd.cpp # 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 # https://github.com/weidai11/cryptopp/issues/738
UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/) UNUSED := $(shell rm -f a.out && rm -rf a.out.dSYM/)
# CRYPTOPP_DISABLE_ASM # DETECT_FEATURES
endif endif
# IBM XL C/C++ compiler # IBM XL C/C++ compiler

View File

@ -0,0 +1,6 @@
#include <arm_acle.h>
int main(int argc, char* argv[])
{
return 0;
}

View File

@ -0,0 +1,19 @@
#include <arm_neon.h>
#include <stdint.h>
// 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 <arm_acle.h>
#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;
}

View File

@ -0,0 +1,16 @@
#include <arm_neon.h>
#include <stdint.h>
// 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 <arm_acle.h>
#endif
int main(int argc, char* argv[])
{
uint32x4_t x;
x=veorq_u32(x,x);
return 0;
}

View File

@ -1,12 +1,12 @@
#include <arm_neon.h> #include <arm_neon.h>
#include <stdint.h> #include <stdint.h>
// This is how config.h includes it. // test_acle.h determines if this is available. Then,
#if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) // -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS
# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) // if the ACLE header is not available.
#if (CRYPTOPP_ARM_ACLE_AVAILABLE)
# include <arm_acle.h> # include <arm_acle.h>
#endif #endif
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {

View File

@ -1,10 +1,6 @@
#include <arm_neon.h> #include <arm_neon.h>
#include <stdint.h> #include <stdint.h>
#if (CRYPTOPP_ARM_ACLE_AVAILABLE)
# include <arm_acle.h>
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
uint32x4_t x; uint32x4_t x;

View File

@ -0,0 +1,23 @@
#include <arm_neon.h>
#include <stdint.h>
// 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 <arm_acle.h>
#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;
}

View File

@ -0,0 +1,21 @@
#include <arm_neon.h>
#include <stdint.h>
// 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 <arm_acle.h>
#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;
}

View File

@ -1,16 +0,0 @@
#include <arm_neon.h>
#include <stdint.h>
// 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 <arm_acle.h>
# endif
#endif
int main(int argc, char* argv[])
{
uint32x4_t x;
x=veorq_u32(x,x);
return 0;
}

View File

@ -1,23 +0,0 @@
#include <arm_neon.h>
#include <stdint.h>
// 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 <arm_acle.h>
# 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;
}

View File

@ -1,12 +1,12 @@
#include <arm_neon.h> #include <arm_neon.h>
#include <stdint.h> #include <stdint.h>
// This is how config.h includes it. // test_acle.h determines if this is available. Then,
#if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) // -DCRYPTOPP_ARM_ACLE_AVAILABLE=0 is added to CXXFLAGS
# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) // if the ACLE header is not available.
#if (CRYPTOPP_ARM_ACLE_AVAILABLE)
# include <arm_acle.h> # include <arm_acle.h>
#endif #endif
#endif
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {

View File

@ -729,11 +729,13 @@ NAMESPACE_END
#endif #endif
// Limit the <arm_acle.h> include. // Limit the <arm_acle.h> include.
#if !defined(CRYPTOPP_ARM_ACLE_AVAILABLE)
# if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE) # if defined(__aarch32__) || defined(__aarch64__) || (__ARM_ARCH >= 8) || defined(__ARM_ACLE)
# if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__) # if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__APPLE__)
# define CRYPTOPP_ARM_ACLE_AVAILABLE 1 # define CRYPTOPP_ARM_ACLE_AVAILABLE 1
# endif # endif
# endif # endif
#endif
// Fixup Apple Clang and PMULL. Apple defines __ARM_FEATURE_CRYPTO for Xcode 6 // Fixup Apple Clang and PMULL. Apple defines __ARM_FEATURE_CRYPTO for Xcode 6
// but does not provide PMULL. TODO: determine when PMULL is available. // but does not provide PMULL. TODO: determine when PMULL is available.