diff options
author | Jack Lloyd <[email protected]> | 2017-10-11 21:48:53 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-10-12 11:13:11 -0400 |
commit | d11f369b6a72f584499a883e0ee7cbb63723dc93 (patch) | |
tree | b67fc3bb76d462f54b074e20e5bd6b74aa96ae43 /src/lib | |
parent | 175f09ffd806f2f19cd509017a67ae1384f29ae1 (diff) |
Ugh, the GCC/Clang trick triggers C4146 under MSVC
And rotate.h is a visible header.
Blerg. Inline asm it is.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/utils/rotate.h | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/lib/utils/rotate.h b/src/lib/utils/rotate.h index adc620feb..4bb76c9ed 100644 --- a/src/lib/utils/rotate.h +++ b/src/lib/utils/rotate.h @@ -45,13 +45,7 @@ inline T rotr(T input) template<typename T> inline T rotl_var(T input, size_t rot) { - /* - * This is a strange way of expressing the rotation operation but it - * so happens that both GCC and Clang will recognize it and turn it - * into a rotation, which cannot be said for many other forms. See - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82498 - */ - return static_cast<T>((input << rot) | (input >> (-rot % (8*sizeof(T))))); + return rot ? static_cast<T>((input << rot) | (input >> (sizeof(T)*8 - rot))) : input; } /** @@ -63,9 +57,32 @@ inline T rotl_var(T input, size_t rot) template<typename T> inline T rotr_var(T input, size_t rot) { - return static_cast<T>((input >> rot) | (input << (-rot % (8*sizeof(T))))); + return rot ? static_cast<T>((input >> rot) | (input << (sizeof(T)*8 - rot))) : input; } +#if BOTAN_USE_GCC_INLINE_ASM + +#if defined(BOTAN_TARGET_ARCH_IS_X86_64) || defined(BOTAN_TARGET_ARCH_IS_X86_32) + +template<> +inline uint32_t rotl_var(uint32_t input, size_t rot) + { + asm("roll %1,%0" : "+r" (input) : "c" (static_cast<uint8_t>(rot))); + return input; + } + +template<> +inline uint32_t rotr_var(uint32_t input, size_t rot) + { + asm("rorl %1,%0" : "+r" (input) : "c" (static_cast<uint8_t>(rot))); + return input; + } + +#endif + +#endif + + template<typename T> BOTAN_DEPRECATED("Use rotl<N> or rotl_var") inline T rotate_left(T input, size_t rot) |