diff options
author | lloyd <[email protected]> | 2008-09-29 20:54:15 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-29 20:54:15 +0000 |
commit | 94fe6344ba012e78283b0b847adb0bc34ce4379d (patch) | |
tree | 415574072eccd33e748780f462400ccf41966ad7 /src/utils/bswap.h | |
parent | 4f5482b113907d8cf3b39532a61daf2b4653574c (diff) |
Directly inline x86-64 asm into bswap.h
Diffstat (limited to 'src/utils/bswap.h')
-rw-r--r-- | src/utils/bswap.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/utils/bswap.h b/src/utils/bswap.h index e38d3c6fa..8fb5ed12f 100644 --- a/src/utils/bswap.h +++ b/src/utils/bswap.h @@ -3,8 +3,8 @@ * (C) 1999-2008 Jack Lloyd * *************************************************/ -#ifndef BOTAN_BSWAP_H__ -#define BOTAN_BSWAP_H__ +#ifndef BOTAN_BYTE_SWAP_H__ +#define BOTAN_BYTE_SWAP_H__ #include <botan/types.h> #include <botan/rotate.h> @@ -21,17 +21,27 @@ inline u16bit reverse_bytes(u16bit input) inline u32bit reverse_bytes(u32bit input) { +#if defined(BOTAN_TARGET_ARCH_IS_AMD64) + asm("bswapl %0" : "=r" (input) : "0" (input)); + return input; +#else input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8); return rotate_left(input, 16); +#endif } inline u64bit reverse_bytes(u64bit input) { +#if defined(BOTAN_TARGET_ARCH_IS_AMD64) + asm("bswapq %0" : "=r" (input) : "0" (input)); + return input; +#else u32bit hi = ((input >> 40) & 0x00FF00FF) | ((input >> 24) & 0xFF00FF00); u32bit lo = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8); hi = (hi << 16) | (hi >> 16); lo = (lo << 16) | (lo >> 16); return (static_cast<u64bit>(lo) << 32) | hi; +#endif } } |