Botan 3.9.0
Crypto and TLS for C&
prefetch.h
Go to the documentation of this file.
1/*
2* (C) 2023 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_PREFETCH_UTILS_H_
8#define BOTAN_PREFETCH_UTILS_H_
9
10#include <botan/types.h>
11#include <concepts>
12#include <type_traits>
13
14namespace Botan {
15
16/**
17* Prefetch an array
18*
19* This function returns a uint64_t which is accumulated from values
20* read from the array. This may help confuse the compiler sufficiently
21* to not elide otherwise "useless" reads. The return value will always
22* be zero.
23*/
24uint64_t prefetch_array_raw(size_t bytes, const void* array) noexcept;
25
26/**
27* Prefetch several arrays
28*
29* This function returns a uint64_t which is accumulated from values
30* read from the array. This may help confuse the compiler sufficiently
31* to not elide otherwise "useless" reads. The return value will always
32* be zero.
33*/
34template <std::unsigned_integral T, size_t... Ns>
35T prefetch_arrays(T (&... arr)[Ns]) noexcept {
36 return (static_cast<T>(prefetch_array_raw(sizeof(T) * Ns, arr)) & ...);
37}
38
39} // namespace Botan
40
41#endif
uint64_t prefetch_array_raw(size_t bytes, const void *arrayv) noexcept
Definition prefetch.cpp:14
T prefetch_arrays(T(&... arr)[Ns]) noexcept
Definition prefetch.h:35