Re: restricted pointers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



void vecmult(int n, int * restrict a, int * restrict b, int * restrict c)
{
  int i;
  for (i=0; i<n; ++i) {
    a[i] = b[i] * c[i];
  }
}

but the times with or without restrict are the same. Why isn't it
improving performance, am I doing something wrong?

Well, no matter what, the program will have to perform n reads of
elements of b[] and c[], and perform n writes to elements of a[].

You could try adding -O3 and/or some of the vectorisation options.

Also, you could test something like

void vecmult(int n, int * restrict a, int * restrict b, int * restrict c)
{
  int i;
  for (i=0; i<n; ++i) {
    a[i] = b[0] * c[i];
  }
}

which has a much bigger opportunity for optimisation (no need to load
from b[0] more than once, only if there is a restrict on b[]).


Segher


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux