Botan 2.19.2
Crypto and TLS for C&
prefetch.h
Go to the documentation of this file.
1/*
2* Prefetching Operations
3* (C) 2009 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_PREFETCH_H_
9#define BOTAN_PREFETCH_H_
10
11#include <botan/cpuid.h>
12
13namespace Botan {
14
15template<typename T>
16inline 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
26template<typename T>
27inline 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
static size_t cache_line_size()
Definition: cpuid.h:68
fe T
Definition: ge.cpp:37
Definition: alg_id.cpp:13
void prefetch_readwrite(const T *addr, size_t length)
Definition: prefetch.h:27
void prefetch_readonly(const T *addr, size_t length)
Definition: prefetch.h:16