diff --git a/config.h b/config.h index 9ddb6d19..9a9a1baa 100644 --- a/config.h +++ b/config.h @@ -535,16 +535,25 @@ NAMESPACE_END #endif #if !defined(CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE) -# if (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) && ((CRYPTOPP_GCC_VERSION >= 40400) || (CRYPTOPP_CLANG_VERSION >= 20800) || (CRYPTOPP_MSC_VERSION >= 1700)) -# if defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(_M_ARM) +# if (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) && ((CRYPTOPP_GCC_VERSION >= 40400) || (CRYPTOPP_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 60000) || (CRYPTOPP_MSC_VERSION >= 1700)) +# if defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(_M_ARM) || (__ARM_ARCH >= 8) # define CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE 1 # endif # endif #endif +#if !defined(CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE) +# if (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) && ((CRYPTOPP_GCC_VERSION >= 40400) || (CRYPTOPP_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 60000)) +# if defined(__ARM_FEATURE_CRYPTO) +# define CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE 1 +# endif +# endif +#endif + #ifndef CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE # define CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE 0 #endif + #if !defined(CRYPTOPP_NO_UNALIGNED_DATA_ACCESS) && !defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || defined(__powerpc__) || (__ARM_FEATURE_UNALIGNED >= 1)) #define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS diff --git a/config.recommend b/config.recommend index e0d5df1e..983f8a41 100644 --- a/config.recommend +++ b/config.recommend @@ -535,16 +535,25 @@ NAMESPACE_END #endif #if !defined(CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE) -# if (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) && ((CRYPTOPP_GCC_VERSION >= 40400) || (CRYPTOPP_CLANG_VERSION >= 20800) || (CRYPTOPP_MSC_VERSION >= 1700)) -# if defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(_M_ARM) +# if (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) && ((CRYPTOPP_GCC_VERSION >= 40400) || (CRYPTOPP_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 60000) || (CRYPTOPP_MSC_VERSION >= 1700)) +# if defined(__ARM_NEON__) || defined(__ARM_NEON) || defined(_M_ARM) || (__ARM_ARCH >= 8) # define CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE 1 # endif # endif #endif +#if !defined(CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE) +# if (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) && ((CRYPTOPP_GCC_VERSION >= 40400) || (CRYPTOPP_CLANG_VERSION >= 20800) || (CRYPTOPP_APPLE_CLANG_VERSION >= 60000)) +# if defined(__ARM_FEATURE_CRYPTO) +# define CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE 1 +# endif +# endif +#endif + #ifndef CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE # define CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE 0 #endif + #if !defined(CRYPTOPP_NO_UNALIGNED_DATA_ACCESS) && !defined(CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS) #if (CRYPTOPP_BOOL_X64 || CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || defined(__powerpc__) || (__ARM_FEATURE_UNALIGNED >= 1)) #define CRYPTOPP_ALLOW_UNALIGNED_DATA_ACCESS diff --git a/cpu.cpp b/cpu.cpp index b6454953..bdbd06e4 100644 --- a/cpu.cpp +++ b/cpu.cpp @@ -256,7 +256,7 @@ void DetectX86Features() #elif (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) bool g_ArmDetectionDone = false; -bool g_hasNEON = false, g_hasCRC32 = false; +bool g_hasNEON = false, g_hasCRC32 = false, g_hasCrypto = false; // This is avaiable in a status register, but we need privileged code to perform the read word32 g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE; @@ -285,9 +285,26 @@ void DetectArmFeatures() # else g_hasCRC32 = false; # endif -#elif defined(_WIN32) && defined(_M_ARM) // Microsoft ARM +#elif defined(__APPLE__) + g_hasNEON = true; +# if defined(__ARM_FEATURE_CRC32) + g_hasCRC32 = true; +# else + g_hasCRC32 = false; +# endif +# if defined(__ARM_FEATURE_CRYPTO) + g_hasCrypto = true; +# else + g_hasCrypto = false; +# endif +#elif defined(_WIN32) g_hasNEON = true; g_hasCRC32 = false; + g_hasCrypto = false; +#else + g_hasNEON = false; + g_hasCRC32 = false; + g_hasCrypto = false; #endif *((volatile bool*)&g_ArmDetectionDone) = true; } diff --git a/cpu.h b/cpu.h index ede40de9..98f4e6d5 100644 --- a/cpu.h +++ b/cpu.h @@ -20,7 +20,7 @@ # if CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE # include # endif -# if defined(__ARM_FEATURE_CRC32) || (__ARM_ACLE >= 200) +# if (defined(__ARM_FEATURE_CRC32) || defined(__ARM_FEATURE_CRYPTO) || (__ARM_ACLE >= 200)) && !defined(__APPLE__) # include # endif #endif // ARM-32 or ARM-64 @@ -237,12 +237,14 @@ inline int GetCacheLineSize() #elif (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64) extern bool g_ArmDetectionDone; -extern bool g_hasNEON, g_hasCRC32; +extern bool g_hasNEON, g_hasCRC32, g_hasCrypto; void CRYPTOPP_API DetectArmFeatures(); //! \brief Determine if an ARM processor has Advanced SIMD available //! \returns true if the hardware is capable of Advanced SIMD at runtime, false otherwise. -//! \details Runtime support requires compile time support. +//! \details Runtime support requires compile time support. When compiling with GCC, you may +//! need to compile with -mfpu=neon (32-bit) or -march=armv8-a +//! (64-bit). Also see ARM's __ARM_NEON preprocessor macro. inline bool HasNEON() { if (!g_ArmDetectionDone) @@ -253,7 +255,8 @@ inline bool HasNEON() //! \brief Determine if an ARM processor has CRC32 available //! \returns true if the hardware is capable of CRC32 at runtime, false otherwise. //! \details Runtime support requires compile time support. When compiling with GCC, you may -//! need to compile with -march=armv8-a+crc. +//! need to compile with -march=armv8-a+crc. Also see ARM's __ARM_FEATURE_CRC32 +//! preprocessor macro. inline bool HasCRC32() { if (!g_ArmDetectionDone) @@ -261,6 +264,19 @@ inline bool HasCRC32() return g_hasCRC32; } +//! \brief Determine if an ARM processor has Crypto available +//! \returns true if the hardware is capable of Crypto at runtime, false otherwise. +//! \details Runtime support requires compile time support. When compiling with GCC, you may +//! need to compile with -march=armv8-a+crypto; while Apple requires +//! -arch armv7s or -arch arm64. Also see ARM's __ARM_FEATURE_CRYPTO +//! preprocessor macro. +inline bool HasCrypto() +{ + if (!g_ArmDetectionDone) + DetectArmFeatures(); + return g_hasCrypto; +} + //! \brief Provides the cache line size at runtime //! \returns true if the hardware is capable of CRC32 at runtime, false otherwise. //! \details GetCacheLineSize() provides is an estimate using CRYPTOPP_L1_CACHE_LINE_SIZE.