[#absl-PrefetchToLocalCache] = xref:absl.adoc[absl]::PrefetchToLocalCache :relfileprefix: ../ :mrdocs: Moves data into the L1 cache before it is read, or "prefetches" it. == Synopsis Declared in `<absl/base/prefetch.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- void PrefetchToLocalCache(void const* addr); ---- == Description The value of `addr` is the address of the memory to prefetch. If the target and compiler support it, data prefetch instructions are generated. If the prefetch is done some time before the memory is read, it may be in the cache by the time the read occurs. This method prefetches data with the highest degree of temporal locality; data is prefetched where possible into all levels of the cache. Incorrect or gratuitous use of this function can degrade performance. Use this function only when representative benchmarks show an improvement. Example: // Computes incremental checksum for `data`. int ComputeChecksum(int sum, absl::string_view data); // Computes cumulative checksum for all values in `data` int ComputeChecksum(absl::Span<const std::string> data) { int sum = 0; auto it = data.begin(); auto pit = data.begin(); auto end = data.end(); for (int dist = 8; dist > 0 && pit != data.end(); ‐‐dist, ++pit) { absl::PrefetchToLocalCache(pit‐>data()); } for (; pit != end; ++pit, ++it) { sum = ComputeChecksum(sum, *it); absl::PrefetchToLocalCache(pit‐>data()); } for (; it != end; ++it) { sum = ComputeChecksum(sum, *it); } return sum; } == Parameters [cols="1,4"] |=== | Name| Description | *addr* | The address of the memory to prefetch. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#