Skip to content

Commit 3f5396c

Browse files
committed
Update ARM feature detection macros
Cross your fingers... This is an absolute mess...
1 parent 75376f1 commit 3f5396c

File tree

2 files changed

+37
-35
lines changed

2 files changed

+37
-35
lines changed

config_asm.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -287,26 +287,26 @@
287287
# endif // Platforms
288288
#endif
289289

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

302-
// ARMv8 and AES. -march=armv8-a+crypto or above must be present
302+
// ARMv8 and PMULL. -march=armv8-a+crypto or above must be present
303303
// Requires GCC 4.8, Clang 3.3 or Visual Studio 2017
304304
// Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
305-
#if !defined(CRYPTOPP_ARM_AES_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_AES)
305+
#if !defined(CRYPTOPP_ARM_PMULL_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_PMULL)
306306
# if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
307307
# if defined(__ARM_FEATURE_CRYPTO) || (CRYPTOPP_GCC_VERSION >= 40800) || \
308308
(CRYPTOPP_LLVM_CLANG_VERSION >= 30300) || (CRYPTOPP_MSC_VERSION >= 1916)
309-
# define CRYPTOPP_ARM_AES_AVAILABLE 1
309+
# define CRYPTOPP_ARM_PMULL_AVAILABLE 1
310310
# endif // Compilers
311311
# endif // Platforms
312312
#endif
@@ -329,7 +329,7 @@
329329
// Do not use APPLE_CLANG_VERSION; use __ARM_FEATURE_XXX instead.
330330
#if !defined(CRYPTOPP_ARM_SHA3_AVAILABLE) && !defined(CRYPTOPP_DISABLE_ARM_SHA)
331331
# if defined(__aarch32__) || defined(__aarch64__) || defined(_M_ARM64)
332-
# if defined(__ARM_FEATURE_SHA3) || (CRYPTOPP_GCC_VERSION >= 80000)
332+
# if defined(__ARM_FEATURE_SHA3) || (CRYPTOPP_GCC_VERSION >= 80000) || (CRYPTOPP_APPLE_CLANG_VERSION >= 120000) || (CRYPTOPP_LLVM_CLANG_VERSION >= 110000)
333333
# define CRYPTOPP_ARM_SHA512_AVAILABLE 1
334334
# define CRYPTOPP_ARM_SHA3_AVAILABLE 1
335335
# endif // Compilers

cpu.h

+30-28
Original file line numberDiff line numberDiff line change
@@ -469,30 +469,12 @@ inline bool HasARMv7()
469469
inline bool HasNEON()
470470
{
471471
// ASIMD is a core feature on Aarch32 and Aarch64 like SSE2 is a core feature on x86_64
472-
#if defined(__aarch32__) || defined(__aarch64__)
472+
#if defined(CRYPTOPP_ARM_ASIMD_AVAILABLE)
473473
return true;
474-
#else
474+
#elif defined(CRYPTOPP_ARM_NEON_AVAILABLE)
475475
if (!g_ArmDetectionDone)
476476
DetectArmFeatures();
477477
return g_hasNEON;
478-
#endif
479-
}
480-
481-
/// \brief Determine if an ARM processor provides Polynomial Multiplication
482-
/// \return true if the hardware is capable of polynomial multiplications at runtime,
483-
/// false otherwise.
484-
/// \details The multiplication instructions are available under Aarch32 and Aarch64.
485-
/// \details Runtime support requires compile time support. When compiling with GCC,
486-
/// you may need to compile with <tt>-march=armv8-a+crypto</tt>; while Apple requires
487-
/// <tt>-arch arm64</tt>. Also see ARM's <tt>__ARM_FEATURE_CRYPTO</tt> preprocessor macro.
488-
/// \since Crypto++ 5.6.4
489-
/// \note This function is only available on Aarch32 and Aarch64 platforms
490-
inline bool HasPMULL()
491-
{
492-
#if defined(__aarch32__) || defined(__aarch64__)
493-
if (!g_ArmDetectionDone)
494-
DetectArmFeatures();
495-
return g_hasPMULL;
496478
#else
497479
return false;
498480
#endif
@@ -510,7 +492,7 @@ inline bool HasPMULL()
510492
/// \note This function is only available on Aarch32 and Aarch64 platforms
511493
inline bool HasCRC32()
512494
{
513-
#if defined(__aarch32__) || defined(__aarch64__)
495+
#if defined(CRYPTOPP_ARM_CRC32_AVAILABLE)
514496
if (!g_ArmDetectionDone)
515497
DetectArmFeatures();
516498
return g_hasCRC32;
@@ -530,7 +512,7 @@ inline bool HasCRC32()
530512
/// \note This function is only available on Aarch32 and Aarch64 platforms
531513
inline bool HasAES()
532514
{
533-
#if defined(__aarch32__) || defined(__aarch64__)
515+
#if defined(CRYPTOPP_ARM_AES_AVAILABLE)
534516
if (!g_ArmDetectionDone)
535517
DetectArmFeatures();
536518
return g_hasAES;
@@ -539,6 +521,26 @@ inline bool HasAES()
539521
#endif
540522
}
541523

524+
/// \brief Determine if an ARM processor provides Polynomial Multiplication
525+
/// \return true if the hardware is capable of polynomial multiplications at runtime,
526+
/// false otherwise.
527+
/// \details The multiplication instructions are available under Aarch32 and Aarch64.
528+
/// \details Runtime support requires compile time support. When compiling with GCC,
529+
/// you may need to compile with <tt>-march=armv8-a+crypto</tt>; while Apple requires
530+
/// <tt>-arch arm64</tt>. Also see ARM's <tt>__ARM_FEATURE_CRYPTO</tt> preprocessor macro.
531+
/// \since Crypto++ 5.6.4
532+
/// \note This function is only available on Aarch32 and Aarch64 platforms
533+
inline bool HasPMULL()
534+
{
535+
#if defined(CRYPTOPP_ARM_PMULL_AVAILABLE)
536+
if (!g_ArmDetectionDone)
537+
DetectArmFeatures();
538+
return g_hasPMULL;
539+
#else
540+
return false;
541+
#endif
542+
}
543+
542544
/// \brief Determine if an ARM processor has SHA1 available
543545
/// \return true if the hardware is capable of SHA1 at runtime, false otherwise.
544546
/// \details SHA1 is part of the optional Crypto extensions on Aarch32 and Aarch64. They are
@@ -550,7 +552,7 @@ inline bool HasAES()
550552
/// \note This function is only available on Aarch32 and Aarch64 platforms
551553
inline bool HasSHA1()
552554
{
553-
#if defined(__aarch32__) || defined(__aarch64__)
555+
#if defined(CRYPTOPP_ARM_SHA1_AVAILABLE)
554556
if (!g_ArmDetectionDone)
555557
DetectArmFeatures();
556558
return g_hasSHA1;
@@ -570,7 +572,7 @@ inline bool HasSHA1()
570572
/// \note This function is only available on Aarch32 and Aarch64 platforms
571573
inline bool HasSHA2()
572574
{
573-
#if defined(__aarch32__) || defined(__aarch64__)
575+
#if defined(CRYPTOPP_ARM_SHA2_AVAILABLE)
574576
if (!g_ArmDetectionDone)
575577
DetectArmFeatures();
576578
return g_hasSHA2;
@@ -590,7 +592,7 @@ inline bool HasSHA2()
590592
/// \note This function is only available on Aarch32 and Aarch64 platforms
591593
inline bool HasSHA3()
592594
{
593-
#if defined(__aarch32__) || defined(__aarch64__)
595+
#if defined(CRYPTOPP_ARM_SHA3_AVAILABLE)
594596
if (!g_ArmDetectionDone)
595597
DetectArmFeatures();
596598
return g_hasSHA3;
@@ -610,7 +612,7 @@ inline bool HasSHA3()
610612
/// \note This function is only available on Aarch32 and Aarch64 platforms
611613
inline bool HasSHA512()
612614
{
613-
#if defined(__aarch32__) || defined(__aarch64__)
615+
#if defined(CRYPTOPP_ARM_SHA512_AVAILABLE)
614616
if (!g_ArmDetectionDone)
615617
DetectArmFeatures();
616618
return g_hasSHA512;
@@ -630,7 +632,7 @@ inline bool HasSHA512()
630632
/// \note This function is only available on Aarch32 and Aarch64 platforms
631633
inline bool HasSM3()
632634
{
633-
#if defined(__aarch32__) || defined(__aarch64__)
635+
#if defined(CRYPTOPP_ARM_SM3_AVAILABLE)
634636
if (!g_ArmDetectionDone)
635637
DetectArmFeatures();
636638
return g_hasSM3;
@@ -650,7 +652,7 @@ inline bool HasSM3()
650652
/// \note This function is only available on Aarch32 and Aarch64 platforms
651653
inline bool HasSM4()
652654
{
653-
#if defined(__aarch32__) || defined(__aarch64__)
655+
#if defined(CRYPTOPP_ARM_SM4_AVAILABLE)
654656
if (!g_ArmDetectionDone)
655657
DetectArmFeatures();
656658
return g_hasSM4;

0 commit comments

Comments
 (0)