aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-12-21 13:51:05 +0000
committerlloyd <[email protected]>2009-12-21 13:51:05 +0000
commit75f32d61c6a78e4e63cfadd084730f20b5896493 (patch)
tree4a52d3009f012ec5761f1c1218e18efbe07eef0b /src/utils
parentf3f36611db8c3f6c67c818d454973a0165b0fcf2 (diff)
Un-internal loadstor.h (and its header deps, rotate.h and
bswap.h); too many external apps rely on loadstor.h existing. Define 64-bit generic bswap in terms of 32-bit bswap, since it's not much slower if 32-bit is also generic, and much faster if it's not. This may be quite helpful on 32-bit x86 in particular. Change formulation of generic 32-bit bswap. It may be faster or slower depending on the CPU, especially the latency and throuput of rotate instructions, but should be faster on an ideally superscalar processor with rotate instructions (ie, what I expect future CPUs to look more like).
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/bswap.h33
-rw-r--r--src/utils/cpuid.cpp2
-rw-r--r--src/utils/info.txt6
-rw-r--r--src/utils/loadstor.h4
-rw-r--r--src/utils/parsing.cpp2
5 files changed, 27 insertions, 20 deletions
diff --git a/src/utils/bswap.h b/src/utils/bswap.h
index 3294111a0..1a5349fd0 100644
--- a/src/utils/bswap.h
+++ b/src/utils/bswap.h
@@ -10,7 +10,7 @@
#define BOTAN_BYTE_SWAP_H__
#include <botan/types.h>
-#include <botan/internal/rotate.h>
+#include <botan/rotate.h>
namespace Botan {
@@ -24,35 +24,44 @@ inline u16bit reverse_bytes(u16bit input)
inline u32bit reverse_bytes(u32bit input)
{
-#if BOTAN_USE_GCC_INLINE_ASM && \
- (defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64))
+#if BOTAN_USE_GCC_INLINE_ASM && (defined(BOTAN_TARGET_ARCH_IS_IA32) || \
+ defined(BOTAN_TARGET_ARCH_IS_AMD64))
- /* GCC-style inline assembly for x86 or x86-64 */
+ // GCC-style inline assembly for x86 or x86-64
asm("bswapl %0" : "=r" (input) : "0" (input));
return input;
#elif defined(_MSC_VER) && defined(BOTAN_TARGET_ARCH_IS_IA32)
- /* Visual C++ inline asm for 32-bit x86, by Yves Jerschow */
+ // Visual C++ inline asm for 32-bit x86, by Yves Jerschow
__asm mov eax, input;
__asm bswap eax;
#else
- /* Generic implementation */
- input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
- return rotate_left(input, 16);
+ // Generic implementation
+ return (rotate_right(input, 8) & 0xFF00FF00) |
+ (rotate_left (input, 8) & 0x00FF00FF);
#endif
}
inline u64bit reverse_bytes(u64bit input)
{
#if BOTAN_USE_GCC_INLINE_ASM && defined(BOTAN_TARGET_ARCH_IS_AMD64)
+ // GCC-style inline assembly for x86-64
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);
+ /* Generic implementation. Defined in terms of 32-bit bswap so any
+ * optimizations in that version can help here (particularly
+ * useful for 32-bit x86).
+ */
+
+ u32bit hi = static_cast<u32bit>(input >> 32);
+ u32bit lo = static_cast<u32bit>(input);
+
+ hi = reverse_bytes(hi);
+ lo = reverse_bytes(lo);
+
return (static_cast<u64bit>(lo) << 32) | hi;
#endif
}
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp
index a6f40f53c..2ba7f9b77 100644
--- a/src/utils/cpuid.cpp
+++ b/src/utils/cpuid.cpp
@@ -7,7 +7,7 @@
#include <botan/cpuid.h>
#include <botan/types.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
#include <botan/mem_ops.h>
#if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64)
diff --git a/src/utils/info.txt b/src/utils/info.txt
index edeeb1cf9..93ece2e78 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -15,22 +15,22 @@ version.cpp
<header:internal>
bit_ops.h
-bswap.h
-loadstor.h
mlock.h
prefetch.h
-rotate.h
rounding.h
stl_util.h
xor_buf.h
</header:internal>
<header:public>
+bswap.h
charset.h
cpuid.h
exceptn.h
+loadstor.h
mem_ops.h
parsing.h
+rotate.h
time.h
types.h
ui.h
diff --git a/src/utils/loadstor.h b/src/utils/loadstor.h
index fa2e36c1e..77a6e846c 100644
--- a/src/utils/loadstor.h
+++ b/src/utils/loadstor.h
@@ -10,9 +10,7 @@
#define BOTAN_LOAD_STORE_H__
#include <botan/types.h>
-#include <botan/internal/bswap.h>
-#include <botan/internal/rotate.h>
-#include <botan/internal/prefetch.h>
+#include <botan/bswap.h>
#include <cstring>
#if BOTAN_TARGET_UNALIGNED_MEMORY_ACCESS_OK
diff --git a/src/utils/parsing.cpp b/src/utils/parsing.cpp
index 0ccd8a312..58a8e0b38 100644
--- a/src/utils/parsing.cpp
+++ b/src/utils/parsing.cpp
@@ -8,7 +8,7 @@
#include <botan/parsing.h>
#include <botan/exceptn.h>
#include <botan/charset.h>
-#include <botan/internal/loadstor.h>
+#include <botan/loadstor.h>
namespace Botan {