cache optimization

£ukasz blurrpp@yahoo.com
Thu Nov 26 13:14:00 GMT 2009


Hi I want to learn how to optimaze cache usage in gcc. I find builtin function __builtin_prefetch which should prefetch datas to cache .. so i use cannonical :) example of vector addition.

for (i = 0; i < n; i++)
  {
    a[i] = a[i] + b[i];
    __builtin_prefetch (&a[i+1], 1, 1);
    __builtin_prefetch (&b[i+1], 0, 1);
    /* ... */
  }

and compile it with gcc without special options .... but its slower than

for (i = 0; i < n; i++)
  {
    a[i] = a[i] + b[i];
    /* ... */
  }

so maybe I should compile it with soem extra options to have advantage of cache prefatching ?(-fprefetch-loop-array doenst works )






More information about the Gcc-help mailing list