Botan  1.11.15
src/lib/utils/prefetch.h
Go to the documentation of this file.
00001 /*
00002 * Prefetching Operations
00003 * (C) 2009 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_PREFETCH_H__
00009 #define BOTAN_PREFETCH_H__
00010 
00011 #include <botan/cpuid.h>
00012 
00013 namespace Botan {
00014 
00015 template<typename T>
00016 inline void prefetch_readonly(const T* addr, size_t length)
00017    {
00018 #if defined(__GNUG__)
00019    const size_t Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T);
00020 
00021    for(size_t i = 0; i <= length; i += Ts_per_cache_line)
00022       __builtin_prefetch(addr + i, 0);
00023 #endif
00024    }
00025 
00026 template<typename T>
00027 inline void prefetch_readwrite(const T* addr, size_t length)
00028    {
00029 #if defined(__GNUG__)
00030    const size_t Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T);
00031 
00032    for(size_t i = 0; i <= length; i += Ts_per_cache_line)
00033       __builtin_prefetch(addr + i, 1);
00034 #endif
00035    }
00036 
00037 }
00038 
00039 #endif