c++ - How can I prefetch infrequently used code? -
i want prefetch code instruction cache. code path used infrequently need in instruction cache or @ least in l2 rare cases used. have advance notice of these rare cases. _mm_prefetch work code? there way infrequently used code in cache? problem don't care portability asm do.
the answer depends on cpu architecture.
that said, if using gcc or clang, can use __builtin_prefetch
instruction try generate prefetch instruction. on pentium 3 , later x86-type architectures, generate prefetchh
instruction, requests load data cache hierarchy. since these architectures have unified l2 , higher caches, may help.
the function looks this:
__builtin_prefetch(const void *address, int locality);
the locality
argument should in range 0...3. assuming locality
maps directly h
part of prefetchh
instruction, want pass 1 or 2, ask data loaded l2 , higher caches. see intel® 64 , ia-32 architectures software developer's manual volume 2b: instruction set reference, m-z (pdf) page 4-277. (find other volumes here.)
if you're using compiler doesn't have __builtin_prefetch
, see whether has _mm_prefetch
function. may need include header file function. example, on os x, function, , constants locality
argument, declared in xmmintrin.h
.