Master the fundamental concepts of cache optimization through this focused micro-challenge.
__builtin_prefetch (GCC/Clang) and _mm_prefetch (Intel intrinsics) hint that the CPU should load a cache line before the load instruction executes. Compilers use this in hand-tuned memcpy and graph traversals when access patterns are predictable but not contiguous enough for hardware stride prefetchers.
Prefetch roughly 64/128 iterations ahead for memory-bound loops. Too early evicts useful lines; too late misses RAM latency hiding.
cLoading…
Keep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will add __builtin_prefetch to a memory-bound loop and compare timings with and without hints. This exercise asks you to find the prefetch distance that helps without polluting cache.
Demonstrate explicit prefetch with __builtin_prefetch.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github