[PATCH] Matrix Flattening and Transposing optimizations

Paolo Bonzini paolo.bonzini@lu.unisi.ch
Wed Mar 28 10:49:00 GMT 2007

>>     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?
> In what sorts of contexts do you expect this to trigger?

Any code written:

1) for portability with MS-DOS, where you couldn't malloc more than 64kb
in one shot;

2) for compilers which could not do decent strength reduction, by people
who didn't bother doing the strength reduction themselves and just thought
"oh, it's faster this way"; double indirection is faster even with GCC at
-O0 (I didn't test -O2 -fno-ivopts or something like that).

3) by people who got accustomed to that idiom because of 1) or 2) above,
and didn't bother to revisit their assumptions.


More information about the Gcc-patches mailing list