Botan: src/utils/prefetch.h Source File

Botan 1.10.16

prefetch.h
Go to the documentation of this file.
1 /*
2 * Prefetching Operations
3 * (C) 2009 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_PREFETCH_H__
9 #define BOTAN_PREFETCH_H__
10
11 #include <botan/cpuid.h>
12
13 namespace Botan {
14
15 template<typename T>
16 inline void prefetch_readonly(const T* addr, size_t length)
17 {
18 #if defined(__GNUG__)
19 const size_t Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T);
20
21 for(size_t i = 0; i <= length; i += Ts_per_cache_line)
22 __builtin_prefetch(addr + i, 0);
23 #endif
24 }
25
26 template<typename T>
27 inline void prefetch_readwrite(const T* addr, size_t length)
28 {
29 #if defined(__GNUG__)
30 const size_t Ts_per_cache_line = CPUID::cache_line_size() / sizeof(T);
31
32 for(size_t i = 0; i <= length; i += Ts_per_cache_line)
33 __builtin_prefetch(addr + i, 1);
34 #endif
35 }
36
37 }
38
39 #endif
Botan::prefetch_readonly
void prefetch_readonly(const T *addr, size_t length)
Definition: prefetch.h:16
Botan::CPUID::cache_line_size
static size_t cache_line_size()
Definition: cpuid.h:29
Botan
Definition: algo_base.h:14
Botan::prefetch_readwrite
void prefetch_readwrite(const T *addr, size_t length)
Definition: prefetch.h:27