Merge branch 'master' into windows-store

This commit is contained in:
Jeffrey Walton 2016-05-15 08:25:45 -04:00
commit 1f70c6aecc
4 changed files with 61 additions and 10 deletions

View File

@ -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

View File

@ -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

21
cpu.cpp
View File

@ -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;
}

24
cpu.h
View File

@ -20,7 +20,7 @@
# if CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE
# include <arm_neon.h>
# endif
# if defined(__ARM_FEATURE_CRC32) || (__ARM_ACLE >= 200)
# if (defined(__ARM_FEATURE_CRC32) || defined(__ARM_FEATURE_CRYPTO) || (__ARM_ACLE >= 200)) && !defined(__APPLE__)
# include <arm_acle.h>
# 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 <tt>-mfpu=neon</tt> (32-bit) or <tt>-march=armv8-a</tt>
//! (64-bit). Also see ARM's <tt>__ARM_NEON</tt> 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 <tt>-march=armv8-a+crc</tt>.
//! need to compile with <tt>-march=armv8-a+crc</tt>. Also see ARM's <tt>__ARM_FEATURE_CRC32</tt>
//! 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 <tt>-march=armv8-a+crypto</tt>; while Apple requires
//! <tt>-arch armv7s</tt> or <tt>-arch arm64</tt>. Also see ARM's <tt>__ARM_FEATURE_CRYPTO</tt>
//! 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.