Fixed hang on ARM platforms in Integer::DivideThreeWordsByTwo

pull/3/head
Jeffrey Walton 2016-01-08 06:53:27 -05:00
parent 6d2bacf9ec
commit 3941be1889
3 changed files with 7 additions and 73 deletions

View File

@ -28,7 +28,7 @@
# error "IS_LITTLE_ENDIAN is set, but __BYTE_ORDER__ does not equal __ORDER_LITTLE_ENDIAN__" # error "IS_LITTLE_ENDIAN is set, but __BYTE_ORDER__ does not equal __ORDER_LITTLE_ENDIAN__"
#endif #endif
// define this if you want to disable all OS-dependent features, // Define this if you want to disable all OS-dependent features,
// such as sockets and OS-provided random number generators // such as sockets and OS-provided random number generators
// #define NO_OS_DEPENDENCE // #define NO_OS_DEPENDENCE
@ -222,40 +222,26 @@ const lword LWORD_MAX = W64LIT(0xffffffffffffffff);
// define hword, word, and dword. these are used for multiprecision integer arithmetic // define hword, word, and dword. these are used for multiprecision integer arithmetic
// Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx // Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx
#if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1000) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__)) #if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__))
typedef word32 hword; typedef word32 hword;
typedef word64 word; typedef word64 word;
#else #else
#define CRYPTOPP_NATIVE_DWORD_AVAILABLE #define CRYPTOPP_NATIVE_DWORD_AVAILABLE
#if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc64__) #if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc64__)
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !(CRYPTOPP_GCC_VERSION == 40001 && defined(__APPLE__)) && (CRYPTOPP_GCC_VERSION >= 30400) #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !(CRYPTOPP_GCC_VERSION == 40001 && defined(__APPLE__)) && CRYPTOPP_GCC_VERSION >= 30400
// GCC 4.0.1 on MacOS X is missing __umodti3 and __udivti3 // GCC 4.0.1 on MacOS X is missing __umodti3 and __udivti3
// mode(TI) division broken on amd64 with GCC earlier than GCC 3.4 // mode(TI) division broken on amd64 with GCC earlier than GCC 3.4
#define CRYPTOPP_WORD128_AVAILABLE
typedef word32 hword; typedef word32 hword;
typedef word64 word; typedef word64 word;
typedef __uint128_t dword; typedef __uint128_t dword;
typedef __uint128_t word128; typedef __uint128_t word128;
#elif defined(__GNUC__) && (__SIZEOF_INT128__ >= 16)
// Detect availabliltiy of int128_t and uint128_t in preprocessor, http://gcc.gnu.org/ml/gcc-help/2015-08/msg00185.html.
#define CRYPTOPP_WORD128_AVAILABLE #define CRYPTOPP_WORD128_AVAILABLE
typedef word32 hword;
typedef word64 word;
typedef __uint128_t dword;
typedef __uint128_t word128;
#else #else
// if we're here, it means we're on a 64-bit CPU but we don't have a way to obtain 128-bit multiplication results // if we're here, it means we're on a 64-bit CPU but we don't have a way to obtain 128-bit multiplication results
typedef word16 hword; typedef word16 hword;
typedef word32 word; typedef word32 word;
typedef word64 dword; typedef word64 dword;
#endif #endif
#elif defined(__GNUC__) && (__SIZEOF_INT128__ >= 16)
// Detect availabliltiy of int128_t and uint128_t in preprocessor, http://gcc.gnu.org/ml/gcc-help/2015-08/msg00185.html.
#define CRYPTOPP_WORD128_AVAILABLE
typedef word32 hword;
typedef word64 word;
typedef __uint128_t dword;
typedef __uint128_t word128;
#else #else
// being here means the native register size is probably 32 bits or less // being here means the native register size is probably 32 bits or less
#define CRYPTOPP_BOOL_SLOW_WORD64 1 #define CRYPTOPP_BOOL_SLOW_WORD64 1
@ -268,11 +254,6 @@ const lword LWORD_MAX = W64LIT(0xffffffffffffffff);
#define CRYPTOPP_BOOL_SLOW_WORD64 0 #define CRYPTOPP_BOOL_SLOW_WORD64 0
#endif #endif
// Produce a compiler error. It can be commented out, but you may not get the benefit of the fastest integers.
#if (__SIZEOF_INT128__ >= 16) && !defined(CRYPTOPP_WORD128_AVAILABLE) && !defined(__aarch64__)
# error "An int128_t and uint128_t are available, but CRYPTOPP_WORD128_AVAILABLE is not defined"
#endif
const unsigned int WORD_SIZE = sizeof(word); const unsigned int WORD_SIZE = sizeof(word);
const unsigned int WORD_BITS = WORD_SIZE * 8; const unsigned int WORD_BITS = WORD_SIZE * 8;

View File

@ -58,7 +58,7 @@
// define this to retain (as much as possible) old deprecated function and class names // define this to retain (as much as possible) old deprecated function and class names
// #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY // #define CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY
// define this to retain (as much as possible) ABI and binary compatibility with Crypto++ 5.6.2. // Define this to retain (as much as possible) ABI and binary compatibility with Crypto++ 5.6.2.
// Also see https://cryptopp.com/wiki/Config.h#Avoid_MAINTAIN_BACKWARDS_COMPATIBILITY // Also see https://cryptopp.com/wiki/Config.h#Avoid_MAINTAIN_BACKWARDS_COMPATIBILITY
#if (CRYPTOPP_VERSION <= 600) #if (CRYPTOPP_VERSION <= 600)
# if !defined(CRYPTOPP_NO_BACKWARDS_COMPATIBILITY_562) && !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562) # if !defined(CRYPTOPP_NO_BACKWARDS_COMPATIBILITY_562) && !defined(CRYPTOPP_MAINTAIN_BACKWARDS_COMPATIBILITY_562)
@ -222,40 +222,26 @@ const lword LWORD_MAX = W64LIT(0xffffffffffffffff);
// define hword, word, and dword. these are used for multiprecision integer arithmetic // define hword, word, and dword. these are used for multiprecision integer arithmetic
// Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx // Intel compiler won't have _umul128 until version 10.0. See http://softwarecommunity.intel.com/isn/Community/en-US/forums/thread/30231625.aspx
#if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1000) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__)) #if (defined(_MSC_VER) && (!defined(__INTEL_COMPILER) || __INTEL_COMPILER >= 1000) && (defined(_M_X64) || defined(_M_IA64))) || (defined(__DECCXX) && defined(__alpha__)) || (defined(__INTEL_COMPILER) && defined(__x86_64__)) || (defined(__SUNPRO_CC) && defined(__x86_64__))
typedef word32 hword; typedef word32 hword;
typedef word64 word; typedef word64 word;
#else #else
#define CRYPTOPP_NATIVE_DWORD_AVAILABLE #define CRYPTOPP_NATIVE_DWORD_AVAILABLE
#if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc64__) #if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc64__)
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !(CRYPTOPP_GCC_VERSION == 40001 && defined(__APPLE__)) && (CRYPTOPP_GCC_VERSION >= 30400) #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !(CRYPTOPP_GCC_VERSION == 40001 && defined(__APPLE__)) && CRYPTOPP_GCC_VERSION >= 30400
// GCC 4.0.1 on MacOS X is missing __umodti3 and __udivti3 // GCC 4.0.1 on MacOS X is missing __umodti3 and __udivti3
// mode(TI) division broken on amd64 with GCC earlier than GCC 3.4 // mode(TI) division broken on amd64 with GCC earlier than GCC 3.4
#define CRYPTOPP_WORD128_AVAILABLE
typedef word32 hword; typedef word32 hword;
typedef word64 word; typedef word64 word;
typedef __uint128_t dword; typedef __uint128_t dword;
typedef __uint128_t word128; typedef __uint128_t word128;
#elif defined(__GNUC__) && (__SIZEOF_INT128__ >= 16)
// Detect availabliltiy of int128_t and uint128_t in preprocessor, http://gcc.gnu.org/ml/gcc-help/2015-08/msg00185.html.
#define CRYPTOPP_WORD128_AVAILABLE #define CRYPTOPP_WORD128_AVAILABLE
typedef word32 hword;
typedef word64 word;
typedef __uint128_t dword;
typedef __uint128_t word128;
#else #else
// if we're here, it means we're on a 64-bit CPU but we don't have a way to obtain 128-bit multiplication results // if we're here, it means we're on a 64-bit CPU but we don't have a way to obtain 128-bit multiplication results
typedef word16 hword; typedef word16 hword;
typedef word32 word; typedef word32 word;
typedef word64 dword; typedef word64 dword;
#endif #endif
#elif defined(__GNUC__) && (__SIZEOF_INT128__ >= 16)
// Detect availabliltiy of int128_t and uint128_t in preprocessor, http://gcc.gnu.org/ml/gcc-help/2015-08/msg00185.html.
#define CRYPTOPP_WORD128_AVAILABLE
typedef word32 hword;
typedef word64 word;
typedef __uint128_t dword;
typedef __uint128_t word128;
#else #else
// being here means the native register size is probably 32 bits or less // being here means the native register size is probably 32 bits or less
#define CRYPTOPP_BOOL_SLOW_WORD64 1 #define CRYPTOPP_BOOL_SLOW_WORD64 1
@ -268,11 +254,6 @@ const lword LWORD_MAX = W64LIT(0xffffffffffffffff);
#define CRYPTOPP_BOOL_SLOW_WORD64 0 #define CRYPTOPP_BOOL_SLOW_WORD64 0
#endif #endif
// Produce a compiler error. It can be commented out, but you may not get the benefit of the fastest integers.
#if (__SIZEOF_INT128__ >= 16) && !defined(CRYPTOPP_WORD128_AVAILABLE) && !defined(__aarch64__)
# error "An int128_t and uint128_t are available, but CRYPTOPP_WORD128_AVAILABLE is not defined"
#endif
const unsigned int WORD_SIZE = sizeof(word); const unsigned int WORD_SIZE = sizeof(word);
const unsigned int WORD_BITS = WORD_SIZE * 8; const unsigned int WORD_BITS = WORD_SIZE * 8;

View File

@ -60,26 +60,6 @@
NAMESPACE_BEGIN(CryptoPP) NAMESPACE_BEGIN(CryptoPP)
// Debian QEMU/ARMEL issue in MultiplyTop; see http://github.com/weidai11/cryptopp/issues/31.
#if __ARMEL__ && (CRYPTOPP_GCC_VERSION >= 50200) && (CRYPTOPP_GCC_VERSION < 50300) && __OPTIMIZE__
# define WORKAROUND_ARMEL_BUG 1
#endif
// Debian QEMU/ARM64 issue in Integer or ModularArithmetic; see http://github.com/weidai11/cryptopp/issues/61.
#if (__aarch64__ || __AARCH64EL__) && (CRYPTOPP_GCC_VERSION >= 50200) && (CRYPTOPP_GCC_VERSION < 50300)
# define WORKAROUND_ARM64_BUG 1
#endif
#if WORKAROUND_ARMEL_BUG
# pragma GCC push_options
# pragma GCC optimize("O1")
#endif
#if WORKAROUND_ARM64_BUG
# pragma GCC push_options
# pragma GCC optimize("no-devirtualize")
#endif
bool AssignIntToInteger(const std::type_info &valueType, void *pInteger, const void *pInt) bool AssignIntToInteger(const std::type_info &valueType, void *pInteger, const void *pInt)
{ {
if (valueType != typeid(Integer)) if (valueType != typeid(Integer))
@ -4393,12 +4373,4 @@ std::string IntToString<unsigned long long>(unsigned long long value, unsigned i
NAMESPACE_END NAMESPACE_END
#if WORKAROUND_ARMEL_BUG
# pragma GCC pop_options
#endif
#if WORKAROUND_ARM64_BUG
# pragma GCC pop_options
#endif
#endif #endif