aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-09-29 19:04:53 +0000
committerlloyd <[email protected]>2009-09-29 19:04:53 +0000
commit096ed3cfa340aa7c917da7a92ddade6dd69ab758 (patch)
treef5c9a1bf25fc2eb722dc002953d8ba846261ce6b
parenta5e83abdf7d63dd52147ff72bfb15593dcf63046 (diff)
Change the prefetching interface; move to PREFETCH namespace, and add a
helper function for fetching both inputs and outputs of block ciphers.
-rw-r--r--src/utils/prefetch.h34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/utils/prefetch.h b/src/utils/prefetch.h
index 100829dce..72b6de689 100644
--- a/src/utils/prefetch.h
+++ b/src/utils/prefetch.h
@@ -12,28 +12,44 @@
namespace Botan {
-inline void prefetch_readonly(const void* addr_void, u32bit length)
+namespace PREFETCH {
+
+template<typename T>
+inline void readonly(const T* addr, u32bit length)
{
#if defined(__GNUG__)
- const byte* addr = static_cast<const byte*>(addr_void);
- const u32bit cl_size = CPUID::cache_line_size();
+ const u32bit Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T);
- for(u32bit i = 0; i <= length; i += cl_size)
+ for(u32bit i = 0; i <= length; i += Ts_per_cache_line)
__builtin_prefetch(addr + i, 0);
#endif
}
-inline void prefetch_readwrite(const void* addr_void, u32bit length)
+template<typename T>
+inline void readwrite(const T* addr, u32bit length)
{
#if defined(__GNUG__)
- const byte* addr = static_cast<const byte*>(addr_void);
- const u32bit cl_size = CPUID::cache_line_size();
+ const u32bit Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T);
- for(u32bit i = 0; i <= length; i += cl_size)
- __builtin_prefetch(addr + i, 1);
+ for(u32bit i = 0; i <= length; i += Ts_per_cache_line)
+ __builtin_prefetch(addr + i, 0);
#endif
}
+inline void cipher_fetch(const byte* in_block,
+ const byte* out_block,
+ u32bit blocks,
+ u32bit block_size)
+ {
+ // Only prefetch input specifically if in != out
+ if(in_block != out_block)
+ readonly(in_block, blocks * block_size);
+
+ readwrite(out_block, blocks * block_size);
+ }
+
+}
+
}
#endif