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/prefetch.h | |
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/prefetch.h')
-rw-r--r-- | src/utils/prefetch.h | 39 |
1 files changed, 39 insertions, 0 deletions
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 |