[#absl-PrefetchToLocalCache]
= xref:absl.adoc[absl]::PrefetchToLocalCache
:relfileprefix: ../
:mrdocs:

Moves data into the L1 cache before it is read, or &quot;prefetches&quot; it&period;

== Synopsis

Declared in `&lt;absl&sol;base&sol;prefetch&period;h&gt;`

[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&period; If the target and compiler support it, data prefetch instructions are generated&period; If the prefetch is done some time before the memory is read, it may be in the cache by the time the read occurs&period;

This method prefetches data with the highest degree of temporal locality&semi; data is prefetched where possible into all levels of the cache&period;

Incorrect or gratuitous use of this function can degrade performance&period; Use this function only when representative benchmarks show an improvement&period;

Example&colon;

&sol;&sol; Computes incremental checksum for `data`&period; int ComputeChecksum(int sum, absl&colon;&colon;string&lowbar;view data)&semi;

&sol;&sol; Computes cumulative checksum for all values in `data` int ComputeChecksum(absl&colon;&colon;Span&lt;const std&colon;&colon;string&gt; data) &lcub; int sum &equals; 0&semi; auto it &equals; data&period;begin()&semi; auto pit &equals; data&period;begin()&semi; auto end &equals; data&period;end()&semi; for (int dist &equals; 8&semi; dist &gt; 0 &amp;&amp; pit !&equals; data&period;end()&semi; &hyphen;&hyphen;dist, &plus;&plus;pit) &lcub; absl&colon;&colon;PrefetchToLocalCache(pit&hyphen;&gt;data())&semi; &rcub; for (&semi; pit !&equals; end&semi; &plus;&plus;pit, &plus;&plus;it) &lcub; sum &equals; ComputeChecksum(sum, &ast;it)&semi; absl&colon;&colon;PrefetchToLocalCache(pit&hyphen;&gt;data())&semi; &rcub; for (&semi; it !&equals; end&semi; &plus;&plus;it) &lcub; sum &equals; ComputeChecksum(sum, &ast;it)&semi; &rcub; return sum&semi; &rcub;

== Parameters

[cols="1,4"]
|===
| Name| Description
| *addr*
| The address of the memory to prefetch&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
