diff options
author | lloyd <[email protected]> | 2009-09-29 18:37:08 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-09-29 18:37:08 +0000 |
commit | 093f98e42a3ba6d51a6c676070090dd06cc39bc7 (patch) | |
tree | a61fb7fb68985ffc35826063fc3c7f5337d75abc /src/utils | |
parent | 18d48581310d60e3c9cd0fbdc0a574d8ebaaeed4 (diff) |
Add some basic prefetching support (only supported with GNU C++ or things
that claim to be by defining __GNUG__ (such as Intel C++)) in new utils
header prefetch.h
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/cpuid.cpp | 6 | ||||
-rw-r--r-- | src/utils/info.txt | 1 | ||||
-rw-r--r-- | src/utils/loadstor.h | 1 | ||||
-rw-r--r-- | src/utils/prefetch.h | 39 |
4 files changed, 44 insertions, 3 deletions
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp index 4f22ef867..d5149e2e5 100644 --- a/src/utils/cpuid.cpp +++ b/src/utils/cpuid.cpp @@ -31,12 +31,12 @@ u64bit x86_processor_flags() #if defined(BOTAN_TARGET_ARCH_IS_X86) || defined(BOTAN_TARGET_ARCH_IS_AMD64) -#if defined(__GNUG__) +#if defined(BOTAN_BUILD_COMPILER_IS_GCC) u32bit a = 1, b = 0, c = 0, d = 0; #if defined(__i386__) && defined(__PIC__) - // ebx is used in PIC on 32-bit x86, so save and restore it + // ebx is reserved for PIC on 32-bit x86, so save and restore it asm("xchgl %%ebx, %1\n\t" "cpuid\n\t" "xchgl %%ebx, %1\n\t" @@ -49,7 +49,7 @@ u64bit x86_processor_flags() proc_flags = ((u64bit)c << 32) | d; -#elif defined(_MSC_VER) +#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) int cpuinfo[4] = { 0 }; __cpuid(cpuinfo, 1); diff --git a/src/utils/info.txt b/src/utils/info.txt index f530fb03a..c9648af51 100644 --- a/src/utils/info.txt +++ b/src/utils/info.txt @@ -23,6 +23,7 @@ mlock.h mlock.cpp parsing.cpp parsing.h +prefetch.h rotate.h rounding.h stl_util.h diff --git a/src/utils/loadstor.h b/src/utils/loadstor.h index 77ed1554e..8c64deaee 100644 --- a/src/utils/loadstor.h +++ b/src/utils/loadstor.h @@ -12,6 +12,7 @@ #include <botan/types.h> #include <botan/bswap.h> #include <botan/rotate.h> +#include <botan/prefetch.h> #if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK diff --git a/src/utils/prefetch.h b/src/utils/prefetch.h new file mode 100644 index 000000000..100829dce --- /dev/null +++ b/src/utils/prefetch.h @@ -0,0 +1,39 @@ +/* +* Prefetching Operations +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_PREFETCH_H__ +#define BOTAN_PREFETCH_H__ + +#include <botan/cpuid.h> + +namespace Botan { + +inline void prefetch_readonly(const void* addr_void, u32bit length) + { +#if defined(__GNUG__) + const byte* addr = static_cast<const byte*>(addr_void); + const u32bit cl_size = CPUID::cache_line_size(); + + for(u32bit i = 0; i <= length; i += cl_size) + __builtin_prefetch(addr + i, 0); +#endif + } + +inline void prefetch_readwrite(const void* addr_void, u32bit length) + { +#if defined(__GNUG__) + const byte* addr = static_cast<const byte*>(addr_void); + const u32bit cl_size = CPUID::cache_line_size(); + + for(u32bit i = 0; i <= length; i += cl_size) + __builtin_prefetch(addr + i, 1); +#endif + } + +} + +#endif |