Re: restrict on casted pointers

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

 



On Wed, 28 Aug 2013, Paulo Matos wrote:

Hello,

I have the feeling this is a problem with my understand of restrict so bear with me.
Consider the following:
typedef short int16_t;

typedef int16_t c16mat4by4[10/*rows*/][10/*columns*/];

void nofmat4x4mul_v6(c16mat4by4 C_out[], c16mat4by4 D_out[], c16mat4by4 A[], c16mat4by4 B[])
{
 c16mat4by4 * restrict arow_p = (c16mat4by4 *)&(A[0][0][0]);
 c16mat4by4 * restrict brow_p = (c16mat4by4 *)&(B[0][0][0]);
 c16mat4by4 * restrict crow_p = (c16mat4by4 *)&(C_out[0][0][0]);
 c16mat4by4 * restrict drow_p = (c16mat4by4 *)&(D_out[0][0][0]);

 for (int i = 0; i < 4; i++)
   for (int j = 0; j < 5; j++)
     for (int z = 0; z < 5; z++)
       {
         crow_p[i][j][z] = brow_p[i][j][z] + arow_p[i][j][z];
         drow_p[i][j][z] = brow_p[i][j][z];
       }
}

I would assume that at each cycle brow_p[i][j][z] would only be loaded once due to brow_p and crow_p being marked as restrict. However, this doesn't happen under my port on 4.8.1. I confirmed it doesn't happen either on v850 (compiled with `gcc-v850/gcc/cc1 -O2 -std=c99 -o- restrict.c -fpreprocessed'):
.L5:
       lh      %r2,0(%r4,%r1)
       ah      %r2,0(%r12,%r1)
       sth     %r2,0(%r11,%r1)
       lh      %r2,0(%r4,%r1)
       sth     %r2,0(%r5,%r1)

I would have thought the second lh would have been unnecessary.
This means either alias analysis is wrong or my understanding of restrict in this case is wrong. I bet on the latter and that's why this is in gcc-help.

You are using int16_t***restrict, and the restrict only goes one layer of pointer deep, maybe? (I didn't look very closely)

--
Marc Glisse




[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