I am just starting working with processors and can't understand the following.
Asume that we have an array declared as
static double x
that we access in a function
double up (double *a, int i)
int main(int argc, char *argv)
static double x;
for (int i=0;i<10;i++)
In this case, what is loaded into cache memory - actual values that a pointer is pointing to or only addresses? If addresses - does it mean there will be another cycle to load actual values? Is it all-in-all good for cache utilisation with respect to this loop?
Best How To :
The exact answer is platform specific, but generally speaking, three things cause data in external memory to be loaded into the processor cache.
The most obvious is an actual instruction that accesses the memory in the ordinary way. If that memory address is not resident in processor cache, the processor will have to acquire it. The second way is speculative prefetching. Some processors will acquire memory into cache if they believe the code might access it. Lastly, compilers can actually emit instructions to put things into cache.
All your operations are on pointers, so that's all they'll load, except this one:
double t=*(a+i*3);. That actually dereferences a pointer and accesses its value. So unless the compiler is smart enough to optimize the access away (because you never use the result) that is likely the only part of your code that will result in something other than a pointer being read from main memory into cache. (Assuming it ever gets to main memory, which depends on your cache size.)