[PATCH] Matrix Flattening and Transposing optimizations

Razya Ladelsky RAZYA@il.ibm.com
Wed Mar 28 10:45:00 GMT 2007


"Richard Guenther" <richard.guenther@gmail.com> wrote on 27/03/2007 
23:31:13:

> On 3/27/07, Richard Guenther <richard.guenther@gmail.com> wrote:
> > On 3/27/07, Richard Henderson <rth@redhat.com> wrote:
> > > On Sun, Mar 25, 2007 at 01:21:32PM +0200, Razya Ladelsky wrote:
> > > >     a = (int **)  malloc(dim1 * sizeof(int *));
> > > >     for (i=0; i<dim1; i++)
> > > >        a[i] = (int *) malloc (dim2 * sizeof(int));
> > >
> > > Do people really do this...
> > >
> > > >     a = (int *) malloc (dim1 * dim2 *sizeof(int));
> > >
> > > ... as opposed to this?
> >
> > Of course they do.  Like for 456.hmmer or a CFD code I know of, even
> > for three dimensions(!) (no, not tramp3d ;))
> 
> Ok, I got this wrong, actually it looks like
> 
> /* ALLOCATION OF DOUBLE RANK-3 TENSOR */
> double ***mat3(int l, int m, int n)
> { double ***mat,*ptr;
>   int i,j;
> 
> l++,m++,n++;
> if((ptr=calloc(l*m*n,SD))==NULL)
>   terminate(ERROR,"mat3: memory allocation failed.");
> if((mat=(double ***)malloc(l*sizeof(double **)+l*m*sizeof(double 
*)))==NULL)
>   terminate(ERROR,"mat3: memory allocation failed.");
> for(i=0; i<l; i++)
>   { mat[i]=(double **)(mat+l+i*m);
> /*voption vec*/
>     for(j=0; j<m; j++)
>       mat[i][j]=(ptr+i*m*n+j*n);
>   }
> 
> return mat;
> }
> 
> I suppose this is not covered by the optimization.
> 
> Richard.

Yes, currently such pattern is not supported, but even for such cases
these optmizations may help.

Thanks,
Razya





More information about the Gcc-patches mailing list