3 ms·
> The only way to prevent cache misses is to make the memory accesses more ordered. Or prefetch. Not enough people know about prefetch.
by veltas 2y ago
> The only way to prevent cache misses is to make the memory accesses more ordered.
Or prefetch. Not enough people know about prefetch.
- adrian_b 2y agoAll modern CPUs have powerful hardware prefetchers, which are insufficiently documented. On any modern CPU (i.e. from the last 20 years), explicit prefetching is very seldom useful. What is important is to organize your memory accesses in such orders so that they will occur in one of the patterns that triggers the hardware prefetcher, which will then take care to provide the data on time. The patterns recognized by the hardware prefetchers vary from CPU to CPU, but all of them include the accesses where the addresses are in arithmetic progressions, going either forwards or backwards, so usually all array operations will be accelerated automatically by the hardware prefetchers.
- veltas 2y agoThere are situations where it's faster to prefetch manually than to rearrange and rely on the hardware prefetcher. Yes, even on modern CPU's.
- menaerus 2y agoI agree that they can be powerful but I guess, as always, it doesn't apply in the general case. For example, AFAIK hw prefetcher runs at 32B or 64B per cycle which basically means that you're only going to see a benefit from it if the code you're running is CPU bound, no?