Re: Restrict qualified pointers in C



Your example didn't look like a good candidate for aggressive
optimization. How about this:

/* not tested */
void smear(int n, const float * restrict in, float * restrict out)
{
int i;
out[0]= ( in[0] + 2*in[1] )/3.f;
for(i= 1; i<n-1; i++) {
out[i]= ( in[i-1] + in[i] + in[i + 1] )/3.f;
}
out[n-1]= ( 2*in[n-2] + in[n-1] )/3.f;
}

(I think the "in" pointer doesn't need restrict, but I don't want
to spend time thinking about it.)

--
pa at panix dot com
.



Relevant Pages

  • Re: Inconsistent Program Results
    ... void rdinput; ... you need to test that restrict is not NULL before ... Don't cast the result of malloc(). ...
    (comp.lang.c)
  • Re: What does restrict mean?
    ... but what does the keyword 'restrict' mean? ... void copy ... return pDest; ... void *pTemp = malloc; ...
    (comp.lang.c)
  • Re: Inconsistent Program Results
    ... void rdinpt; ... The return type of main is int, so this should be int main, ... to increment a NULL pointer, that's undefined behavior, so anything can ... against this by making sure that restrict is not NULL, ...
    (comp.lang.c)
  • Re: Help with reading this line of code -- thanks!
    ... Notice that memcpy takes void* parameters, ... void *memcpy(void * restrict s1, ... In general casts in C source are bad, preventing error messages, ... The exception is variadic function parameters, ...
    (comp.lang.c)
  • Re: What is this noalias thing Dennis Ritchie is railing about ?
    ... And IF it were written as: void Func(int *restrict p), ... The 'restrict' keywords allow the compiler to assume that p and q do ...
    (comp.lang.c)