9 #ifndef BOTAN_BYTE_SWAP_H__
10 #define BOTAN_BYTE_SWAP_H__
12 #include <botan/types.h>
13 #include <botan/rotate.h>
15 #if defined(BOTAN_TARGET_CPU_HAS_SSE2) && !defined(BOTAN_NO_SSE_INTRINSICS)
16 #include <emmintrin.h>
34 #if BOTAN_GCC_VERSION >= 430 && !defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
42 return __builtin_bswap32(val);
44 #elif BOTAN_USE_GCC_INLINE_ASM && defined(BOTAN_TARGET_CPU_IS_X86_FAMILY)
47 asm(
"bswapl %0" :
"=r" (val) :
"0" (val));
50 #elif BOTAN_USE_GCC_INLINE_ASM && defined(BOTAN_TARGET_CPU_IS_ARM_FAMILY)
52 asm (
"eor r3, %1, %1, ror #16\n\t"
53 "bic r3, r3, #0x00FF0000\n\t"
54 "mov %0, %1, ror #8\n\t"
55 "eor %0, %0, r3, lsr #8"
62 #elif defined(_MSC_VER) && defined(BOTAN_TARGET_ARCH_IS_X86_32)
82 #if BOTAN_GCC_VERSION >= 430
85 return __builtin_bswap64(val);
87 #elif BOTAN_USE_GCC_INLINE_ASM && defined(BOTAN_TARGET_ARCH_IS_X86_64)
89 asm(
"bswapq %0" :
"=r" (val) :
"0" (val));
104 return (static_cast<u64bit>(lo) << 32) | hi;
120 #if defined(BOTAN_TARGET_CPU_HAS_SSE2) && !defined(BOTAN_NO_SSE_INTRINSICS)
128 __m128i T = _mm_loadu_si128(reinterpret_cast<const __m128i*>(x));
130 T = _mm_shufflehi_epi16(T, _MM_SHUFFLE(2, 3, 0, 1));
131 T = _mm_shufflelo_epi16(T, _MM_SHUFFLE(2, 3, 0, 1));
133 T = _mm_or_si128(_mm_srli_epi16(T, 8), _mm_slli_epi16(T, 8));
135 _mm_storeu_si128(reinterpret_cast<__m128i*>(x), T);
T rotate_left(T input, size_t rot)
unsigned long long u64bit
T rotate_right(T input, size_t rot)
u16bit reverse_bytes(u16bit val)