How to use prefetch pragma for reference when data is hidden inside an object?

Intellectually provides pragma prefetching; eg

#pragma prefetch a for(i=0; i<m; i++) a[i]=b[i]+1; 

preprograms a specific number of loop cycles, as determined by the compiler.

But what if a not an array, but a class with [] overridden? If operator[] performs simple array access, can prefetching still be used that way?

(Presumably, the question applies to std::vectors ).

+7
source share
1 answer

One way to find out is to try and look at the assembly. And if something else, just compare it with a pragma and without it. However, I'm not sure if the prefetch pragma is what you want:

Prefetch pragma is supported only by Intel® Itanium® processors.

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 Itanium?

On x86 / x64 systems, simple loops, such as sequential memory access, are already handled well by a hardware prereader. Therefore, it may not help to perform manual prefetching at all.

See here an example of prefetching: Examples of prefetching?

+2
source

All Articles