aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-09-29 20:54:15 +0000
committerlloyd <[email protected]>2008-09-29 20:54:15 +0000
commit94fe6344ba012e78283b0b847adb0bc34ce4379d (patch)
tree415574072eccd33e748780f462400ccf41966ad7
parent4f5482b113907d8cf3b39532a61daf2b4653574c (diff)
Directly inline x86-64 asm into bswap.h
-rw-r--r--src/utils/bswap.h14
-rw-r--r--src/utils/bswap_amd64.h36
2 files changed, 12 insertions, 38 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
}
}
diff --git a/src/utils/bswap_amd64.h b/src/utils/bswap_amd64.h
deleted file mode 100644
index 3c77b460c..000000000
--- a/src/utils/bswap_amd64.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*************************************************
-* Byte Swapping Operations Header File *
-* (C) 1999-2008 Jack Lloyd *
-*************************************************/
-
-#ifndef BOTAN_BSWAP_H__
-#define BOTAN_BSWAP_H__
-
-#include <botan/types.h>
-#include <botan/rotate.h>
-
-namespace Botan {
-
-/*************************************************
-* Byte Swapping Functions *
-*************************************************/
-inline u16bit reverse_bytes(u16bit input)
- {
- return rotate_left(input, 8);
- }
-
-inline u32bit reverse_bytes(u32bit input)
- {
- asm("bswapl %0" : "=r" (input) : "0" (input));
- return input;
- }
-
-inline u64bit reverse_bytes(u64bit input)
- {
- asm("bswapq %0" : "=r" (input) : "0" (input));
- return input;
- }
-
-}
-
-#endif