From 096ed3cfa340aa7c917da7a92ddade6dd69ab758 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 29 Sep 2009 19:04:53 +0000 Subject: Change the prefetching interface; move to PREFETCH namespace, and add a helper function for fetching both inputs and outputs of block ciphers. --- src/utils/prefetch.h | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'src/utils') 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 +inline void readonly(const T* addr, u32bit length) { #if defined(__GNUG__) - const byte* addr = static_cast(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 +inline void readwrite(const T* addr, u32bit length) { #if defined(__GNUG__) - const byte* addr = static_cast(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 -- cgit v1.2.3