3 ms·
The instruction this is based on is prefetch; which is essentially the only relevant instruction when doing manual cache optimization on x86/x64. It's not a pa
by PoignardAzur 6y ago
The instruction this is based on is prefetch; which is essentially the only relevant instruction when doing manual cache optimization on x86/x64.
It's not a panacea though; naive usage of prefetch will actually decrease performance [0], because the hardware already does a lot of prefetching on its own and you're messing with that.
From what little research I've done, prefetch mostly improves performance when accessing data in a hot loop, in a non-linear pattern (eg nextAddress isn't just prevAdress + constantValue), 3-4 loop iterations ahead of the execution. Eg
doThings(myArrayOfPointers[i]);
__builtin_prefetch(myArrayOfPointers[i + 4]);
(though the above code might be undefined behavior if i + 4 is bigger than the array size, I'm not sure)
[0]: https://lwn.net/Articles/444336/ https://lwn.net/Articles/444336/