ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Prefetch.h File Reference

The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring the line that holds the byte at \( p \) into its caches, and returns at once, so that a load issued later finds the line there instead of waiting for the memory. More...

#include "ADS/Capabilities.h"

Go to the source code of this file.

Namespaces

namespace  ADS

Enumerations

enum class  ADS::Locality : int { ADS::Locality::None = 0 , ADS::Locality::Low = 1 , ADS::Locality::Moderate = 2 , ADS::Locality::High = 3 }
 how soon and how often a prefetched line is read again: None once (keep it out of the caches it would pollute), Low once more soon, Moderate a few times, High (the default) often, in every level More...

Detailed description

The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring the line that holds the byte at \( p \) into its caches, and returns at once, so that a load issued later finds the line there instead of waiting for the memory.

It is a hint: it never faults, whatever \( p \) points to (a null pointer, a place past an array, memory freed), it changes nothing that the program can read, and the processor may ignore it. The structures of ADS issue it where they know the next address before they need it (the slots of a group of a hash table while its control bytes are compared, the next node of a search, the item a few steps ahead of a scan), and this is the one place of ADS that issues it. ADS::prefetch is the customization point of Capabilities.h, whose form prefetch( s , k ) asks a structure \( s \) for the places of a key \( k \), and whose forms on a pointer, which this header adds, ask for a line of memory; both are noexcept. The structures of ADS call detail::prefetchLine(), which the forms on a pointer call, so that a header may issue a prefetch before Capabilities.h is complete.

With ADS_WITH_HIGHWAY the prefetch is hwy::Prefetch() of Google Highway, which keeps the line in every level of the cache; without it, prefetch() does nothing, which changes the time of a search and never its result. The locality of the second form tells how soon and how often the line will be read again, as the levels of the prefetch of the processors do; Highway gives a single level, so that every locality issues the same prefetch for now, and a structure that knows it reads a line only once still says so, for the backends that tell them apart.

Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa