Intel helpfully provides a prefetch pragma; for example
#pragma prefetch a
for(i=0; i<m; i++)
a[i]=b[i]+1;
will prefetch a
a certain number of loop cycles ahead, as determined by the compiler.
But what if a
is not an array but a class with []
overridden? If operator[]
does a simple array access, can prefetch still be used in this way?
(Presumably the question applies to std::vectors
as well).
One way to find out is to try it and look at the assembly. And if anything else, just benchmark it with and without the pragma. However, I'm not sure if the prefetch pragma is what you want:
The prefetch pragma is supported by Intel® Itanium® processors only.
http://software.intel.com/sites/products/documentation/studio/composer/en-us/2011/compiler_c/cref_cls/common/cppref_pragma_prefetch_noprefetch.htm
Are you really writing this for an Itanium?
On x86/x64 systems, simple loops like that with sequential memory access are already well handled by the hardware prefetcher. So it may not help at all to do manual prefetching.
See here for a prefetching example: Prefetching Examples?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With