Avoid ARM rev on Aarch64

This broke Aarch64
pull/853/head
Jeffrey Walton 2019-06-04 21:17:13 -04:00
parent 6c009ddf43
commit d8122cec16
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 16 additions and 20 deletions

34
misc.h
View File

@ -62,18 +62,18 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#if defined(__GNUC__) && defined(__linux__) #if (defined(__GNUC__) || defined(__clang__)) && defined(__linux__)
#define CRYPTOPP_BYTESWAP_AVAILABLE 1 #define CRYPTOPP_BYTESWAP_AVAILABLE 1
#include <byteswap.h> #include <byteswap.h>
#endif #endif
// Apple Clang does not consume the GCC inline assembly as expected // Limit to ARM A-32. Aarch64 is failing self tests.
#if (defined(__GNUC__) && !defined(__clang__)) && (__ARM_ARCH >= 6) #if defined(__arm__) && (defined(__GNUC__) || defined(__clang__)) && (__ARM_ARCH >= 6)
#define CRYPTOPP_ARM_BYTEREV_AVAILABLE 1 #define CRYPTOPP_ARM_BYTEREV_AVAILABLE 1
#endif #endif
// Apple Clang does not consume the GCC inline assembly as expected // Limit to ARM A-32. Aarch64 is failing self tests.
#if (defined(__GNUC__) && !defined(__clang__)) && (__ARM_ARCH >= 7) #if defined(__arm__) && (defined(__GNUC__) || defined(__clang__)) && (__ARM_ARCH >= 7)
#define CRYPTOPP_ARM_BITREV_AVAILABLE 1 #define CRYPTOPP_ARM_BITREV_AVAILABLE 1
#endif #endif
@ -109,7 +109,7 @@
/// defined, then SIZE_T_MAX is tried. If neither __SIZE_MAX__ nor SIZE_T_MAX is /// defined, then SIZE_T_MAX is tried. If neither __SIZE_MAX__ nor SIZE_T_MAX is
/// is defined, the library uses std::numeric_limits<size_t>::max(). The library /// is defined, the library uses std::numeric_limits<size_t>::max(). The library
/// prefers __SIZE_MAX__ because its a constexpr that is optimized well /// prefers __SIZE_MAX__ because its a constexpr that is optimized well
/// by all compilers. std::numeric_limits<size_t>::max() is not a constexpr, /// by all compilers. std::numeric_limits<size_t>::max() is not always a constexpr,
/// and it is not always optimized well. /// and it is not always optimized well.
# define SIZE_MAX ... # define SIZE_MAX ...
#else #else
@ -2025,11 +2025,7 @@ inline byte ByteReverse(byte value)
/// performs a 8-bit rotate on the word16. /// performs a 8-bit rotate on the word16.
inline word16 ByteReverse(word16 value) inline word16 ByteReverse(word16 value)
{ {
#if defined(CRYPTOPP_ARM_BYTEREV_AVAILABLE) #if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
word16 rvalue;
__asm__ ("rev16 %0, %1" : "=r" (rvalue) : "r" (value));
return rvalue;
#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)
return bswap_16(value); return bswap_16(value);
#elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL)) #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
return _byteswap_ushort(value); return _byteswap_ushort(value);
@ -2044,15 +2040,15 @@ inline word16 ByteReverse(word16 value)
/// a combination of rotates on the word32. /// a combination of rotates on the word32.
inline word32 ByteReverse(word32 value) inline word32 ByteReverse(word32 value)
{ {
#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) #if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
__asm__ ("bswap %0" : "=r" (value) : "0" (value)); return bswap_32(value);
return value;
#elif defined(CRYPTOPP_ARM_BYTEREV_AVAILABLE) #elif defined(CRYPTOPP_ARM_BYTEREV_AVAILABLE)
word32 rvalue; word32 rvalue;
__asm__ ("rev %0, %1" : "=r" (rvalue) : "r" (value)); __asm__ ("rev %0, %1" : "=r" (rvalue) : "r" (value));
return rvalue; return rvalue;
#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE) #elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)
return bswap_32(value); __asm__ ("bswap %0" : "=r" (value) : "0" (value));
return value;
#elif defined(__MWERKS__) && TARGET_CPU_PPC #elif defined(__MWERKS__) && TARGET_CPU_PPC
return (word32)__lwbrx(&value,0); return (word32)__lwbrx(&value,0);
#elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL)) #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
@ -2073,11 +2069,11 @@ inline word32 ByteReverse(word32 value)
/// a combination of rotates on the word64. /// a combination of rotates on the word64.
inline word64 ByteReverse(word64 value) inline word64 ByteReverse(word64 value)
{ {
#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__) #if defined(CRYPTOPP_BYTESWAP_AVAILABLE)
return bswap_64(value);
#elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
__asm__ ("bswap %0" : "=r" (value) : "0" (value)); __asm__ ("bswap %0" : "=r" (value) : "0" (value));
return value; return value;
#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)
return bswap_64(value);
#elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL)) #elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
return _byteswap_uint64(value); return _byteswap_uint64(value);
#elif CRYPTOPP_BOOL_SLOW_WORD64 #elif CRYPTOPP_BOOL_SLOW_WORD64