From 3f5396cf9e3b1ba860fc06f856c5910fcb541c98 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 7 Mar 2021 19:51:14 -0500 Subject: Update ARM feature detection macros Cross your fingers... This is an absolute mess... --- cpu.h | 58 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'cpu.h') diff --git a/cpu.h b/cpu.h index 3da38bd6..c6f83667 100644 --- a/cpu.h +++ b/cpu.h @@ -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 -march=armv8-a+crypto; while Apple requires -/// -arch arm64. Also see ARM's __ARM_FEATURE_CRYPTO 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 @@ -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; @@ -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; @@ -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 -march=armv8-a+crypto; while Apple requires +/// -arch arm64. Also see ARM's __ARM_FEATURE_CRYPTO 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 @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; -- cgit v1.2.1