Skip to content

Commit

Permalink
Add MOVBE support
Browse files Browse the repository at this point in the history
MOVBE is a modest gain over BSWAP. Though its guarded by CRYPTOPP_MOVBE_AVAILABLE, we cannot detect availability with a preprocessor macro. That is, GCC does not provide __MOVBE__ or similar. It has to be enabled manually
  • Loading branch information
noloader committed Jan 24, 2017
1 parent 3dbf6e7 commit d4c247a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,10 @@ inline byte ByteReverse(byte value)
//! \details ByteReverse calls bswap if available. Otherwise the function performs a 8-bit rotate on the word16
inline word16 ByteReverse(word16 value)
{
#ifdef CRYPTOPP_BYTESWAP_AVAILABLE
#if defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(CRYPTOPP_MOVBE_AVAILABLE)
__asm__ ("movbe %1, %0" : "=m" (value) : "q" (value));
return value;
#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)
return bswap_16(value);
#elif (_MSC_VER >= 1400) || (defined(_MSC_VER) && !defined(_DLL))
return _byteswap_ushort(value);
Expand All @@ -1739,7 +1742,10 @@ inline word16 ByteReverse(word16 value)
//! \details ByteReverse calls bswap if available. Otherwise the function uses a combination of rotates on the word32
inline word32 ByteReverse(word32 value)
{
#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)
#if defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(CRYPTOPP_MOVBE_AVAILABLE)
__asm__ ("movbe %1, %0" : "=m" (value) : "q" (value));
return value;
#elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE)
__asm__ ("bswap %0" : "=r" (value) : "0" (value));
return value;
#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)
Expand All @@ -1764,7 +1770,10 @@ inline word32 ByteReverse(word32 value)
//! \details ByteReverse calls bswap if available. Otherwise the function uses a combination of rotates on the word64
inline word64 ByteReverse(word64 value)
{
#if defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
#if defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(CRYPTOPP_MOVBE_AVAILABLE) && defined(__x86_64__)
__asm__ ("movbe %1, %0" : "=m" (value) : "q" (value));
return value;
#elif defined(__GNUC__) && defined(CRYPTOPP_X86_ASM_AVAILABLE) && defined(__x86_64__)
__asm__ ("bswap %0" : "=r" (value) : "0" (value));
return value;
#elif defined(CRYPTOPP_BYTESWAP_AVAILABLE)
Expand Down

0 comments on commit d4c247a

Please sign in to comment.