Skip to content

Commit

Permalink
Update ARM feature detection macros
Browse files Browse the repository at this point in the history
Cross your fingers... This is an absolute mess...
  • Loading branch information
noloader committed Mar 8, 2021
1 parent 75376f1 commit 3f5396c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
14 changes: 7 additions & 7 deletions config_asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,26 +287,26 @@
# endif // Platforms
#endif

// ARMv8 and ASIMD. -march=armv8-a+crypto or above must be present
// ARMv8 and AES. -march=armv8-a+crypto or above must be present
// Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
// Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
#if !defined(CRYPTOPP_ARM_PMULL_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_PMULL)
#if !defined(CRYPTOPP_ARM_AES_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_AES)
# if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
# if defined(__ARM_FEATURE_CRYPTO) || (CRYPTOPP_GCC_VERSION >= 40800) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_MSC_VERSION >= 1916)
# define CRYPTOPP_ARM_PMULL_AVAILABLE 1
# define CRYPTOPP_ARM_AES_AVAILABLE 1
# endif // Compilers
# endif // Platforms
#endif

// ARMv8 and AES. -march=armv8-a+crypto or above must be present
// ARMv8 and PMULL. -march=armv8-a+crypto or above must be present
// Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
// Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
#if !defined(CRYPTOPP_ARM_AES_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_AES)
#if !defined(CRYPTOPP_ARM_PMULL_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_PMULL)
# if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
# if defined(__ARM_FEATURE_CRYPTO) || (CRYPTOPP_GCC_VERSION >= 40800) || \
(CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_MSC_VERSION >= 1916)
# define CRYPTOPP_ARM_AES_AVAILABLE 1
# define CRYPTOPP_ARM_PMULL_AVAILABLE 1
# endif // Compilers
# endif // Platforms
#endif
Expand All @@ -329,7 +329,7 @@
// Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
#if !defined(CRYPTOPP_ARM_SHA3_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_SHA)
# if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
# if defined(__ARM_FEATURE_SHA3) || (CRYPTOPP_GCC_VERSION >= 80000)
# if defined(__ARM_FEATURE_SHA3) || (CRYPTOPP_GCC_VERSION >= 80000) || (CRYPTOPP_APPLE_CLANG_VERSION >= 120000) || (CRYPTOPP_LLVM_CLANG_VERSION >= 110000)
# define CRYPTOPP_ARM_SHA512_AVAILABLE 1
# define CRYPTOPP_ARM_SHA3_AVAILABLE 1
# endif // Compilers
Expand Down
58 changes: 30 additions & 28 deletions cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,30 +469,12 @@ inline bool HasARMv7()
inline bool HasNEON()
{
// ASIMD is a core feature on Aarch32 and Aarch64 like SSE2 is a core feature on x86_64
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_ASIMD_AVAILABLE)
return true;
#else
#elif defined(CRYPTOPP_ARM_NEON_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasNEON;
#endif
}

/// \brief Determine if an ARM processor provides Polynomial Multiplication
/// \return true if the hardware is capable of polynomial multiplications at runtime,
/// false otherwise.
/// \details The multiplication instructions are available under Aarch32 and Aarch64.
/// \details Runtime support requires compile time support. When compiling with GCC,
/// you may need to compile with <tt>-march=armv8-a+crypto</tt>; while Apple requires
/// <tt>-arch arm64</tt>. Also see ARM's <tt>__ARM_FEATURE_CRYPTO</tt> preprocessor macro.
/// \since Crypto++ 5.6.4
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasPMULL()
{
#if defined(__aarch32__) || defined(__aarch64__)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasPMULL;
#else
return false;
#endif
Expand All @@ -510,7 +492,7 @@ inline bool HasPMULL()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasCRC32()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_CRC32_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasCRC32;
Expand All @@ -530,7 +512,7 @@ inline bool HasCRC32()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasAES()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_AES_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasAES;
Expand All @@ -539,6 +521,26 @@ inline bool HasAES()
#endif
}

/// \brief Determine if an ARM processor provides Polynomial Multiplication
/// \return true if the hardware is capable of polynomial multiplications at runtime,
/// false otherwise.
/// \details The multiplication instructions are available under Aarch32 and Aarch64.
/// \details Runtime support requires compile time support. When compiling with GCC,
/// you may need to compile with <tt>-march=armv8-a+crypto</tt>; while Apple requires
/// <tt>-arch arm64</tt>. Also see ARM's <tt>__ARM_FEATURE_CRYPTO</tt> preprocessor macro.
/// \since Crypto++ 5.6.4
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasPMULL()
{
#if defined(CRYPTOPP_ARM_PMULL_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasPMULL;
#else
return false;
#endif
}

/// \brief Determine if an ARM processor has SHA1 available
/// \return true if the hardware is capable of SHA1 at runtime, false otherwise.
/// \details SHA1 is part of the optional Crypto extensions on Aarch32 and Aarch64. They are
Expand All @@ -550,7 +552,7 @@ inline bool HasAES()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasSHA1()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_SHA1_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasSHA1;
Expand All @@ -570,7 +572,7 @@ inline bool HasSHA1()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasSHA2()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_SHA2_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasSHA2;
Expand All @@ -590,7 +592,7 @@ inline bool HasSHA2()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasSHA3()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_SHA3_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasSHA3;
Expand All @@ -610,7 +612,7 @@ inline bool HasSHA3()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasSHA512()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_SHA512_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasSHA512;
Expand All @@ -630,7 +632,7 @@ inline bool HasSHA512()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasSM3()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_SM3_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasSM3;
Expand All @@ -650,7 +652,7 @@ inline bool HasSM3()
/// \note This function is only available on Aarch32 and Aarch64 platforms
inline bool HasSM4()
{
#if defined(__aarch32__) || defined(__aarch64__)
#if defined(CRYPTOPP_ARM_SM4_AVAILABLE)
if (!g_ArmDetectionDone)
DetectArmFeatures();
return g_hasSM4;
Expand Down

0 comments on commit 3f5396c

Please sign in to comment.