fix 64-bit CPU issues

This commit is contained in:
weidai 2003-07-19 05:16:49 +00:00
parent ae4d479537
commit 4e67d23468
4 changed files with 17 additions and 11 deletions

View File

@ -108,9 +108,13 @@ typedef unsigned short word16;
# define W64LIT(x) x##ui64
#endif
// defined this if your CPU is not 64-bit
#if defined(WORD64_AVAILABLE) && !defined(__alpha)
# define SLOW_WORD64
#if defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64) || defined(__sparc_v9__) || defined(__sparcv9) || defined(__sparc_v8__) || defined(__sparcv8)
# define CRYPTOPP_64BIT_CPU
#endif
// defined this if your CPU is not 64-bit to use alternative code that avoids word64
#if defined(WORD64_AVAILABLE) && !defined(CRYPTOPP_64BIT_CPU)
# define CRYPTOPP_SLOW_WORD64
#endif
// word should have the same size as your CPU registers

View File

@ -1703,18 +1703,20 @@ void PentiumOptimized::Multiply8(word* Z, const word* X, const word* Y)
);
}
#elif defined(__GNUC__) && (defined(__alpha__) || defined(__ia64__) || defined(_ARCH_PPC64) || defined(__x86_64__) || defined(__mips64))
#elif defined(__GNUC__) && defined(CRYPTOPP_64BIT_CPU)
#ifdef __alpha__
#define MUL64x64(a, b, c, d) c = a*b; __asm__("umulh %1,%2,%0" : "=r" (d) : "r" (a), "r" (b))
#else defined(__ia64__)
#elif defined(__ia64__)
#define MUL64x64(a, b, c, d) c = a*b; __asm__("xmpy.hu %0=%1,%2" : "=f" (d) : "f" (a), "f" (b))
#else defined(_ARCH_PPC64)
#elif defined(_ARCH_PPC64)
#define MUL64x64(a, b, c, d) c = a*b; __asm__("mulhdu %0,%1,%2" : "=r" (d) : "r" (a), "r" (b) : "cc")
#else defined(__x86_64__)
#elif defined(__x86_64__)
#define MUL64x64(a, b, c, d) __asm__("mulq %3" : "=d" (d), "=a" (c) : "a" (a), "rm" (b) : "cc")
#else defined(__mips64)
#elif defined(__mips64)
#define MUL64x64(a, b, c, d) __asm__("dmultu %2,%3" : "=h" (d), "=l" (c) : "r" (a), "r" (b))
#elif defined(__sparc_v9__) || defined(__sparcv9) || defined(__sparc_v8__) || defined(__sparcv8)
#define MUL64x64(a, b, c, d) __asm__("umul %2,%3,%1;rd %%y,%0" : "=r" (d), "=r" (c) : "r" (a), "r" (b))
#endif
class OptimizedFor64BitCPU : public Portable

4
misc.h
View File

@ -383,7 +383,7 @@ inline word32 ByteReverse(word32 value)
#ifdef WORD64_AVAILABLE
inline word64 ByteReverse(word64 value)
{
#ifdef SLOW_WORD64
#ifdef CRYPTOPP_SLOW_WORD64
return (word64(ByteReverse(word32(value))) << 32) | ByteReverse(word32(value>>32));
#else
value = ((value & W64LIT(0xFF00FF00FF00FF00)) >> 8) | ((value & W64LIT(0x00FF00FF00FF00FF)) << 8);
@ -419,7 +419,7 @@ inline word32 BitReverse(word32 value)
#ifdef WORD64_AVAILABLE
inline word64 BitReverse(word64 value)
{
#ifdef SLOW_WORD64
#ifdef CRYPTOPP_SLOW_WORD64
return (word64(BitReverse(word32(value))) << 32) | BitReverse(word32(value>>32));
#else
value = ((value & W64LIT(0xAAAAAAAAAAAAAAAA)) >> 1) | ((value & W64LIT(0x5555555555555555)) << 1);

View File

@ -34,7 +34,7 @@ std::vector<word> * NewPrimeTable()
if (j == testEntriesEnd)
{
primeTable.push_back(p);
testEntriesEnd = STDMIN(54U, primeTable.size());
testEntriesEnd = STDMIN((size_t)54U, primeTable.size());
}
}