Quick question (hopefully it is clear).
I was told that performance when considering speed can be drastically improved if you handle the problem of pointer aliasing (always reloading values from memory because compiler isn't sure the value pointed to hasn't been changed by another pointer). This could be resolved by making pointers constant for example:
void multiply (float a[2][2],float b[2][2], float c[2][2]){
a[0][0] = b[0][0]*c[1][1];
a[0][1] = b[1][1]*c[0][0];
a[1][0] = b[0][1]*c[1][0];
a[1][1] = b[1][0]*c[0][1];
}
// function below is supposedly much faster
void multiply (float a[2][2],float b[2][2], float c[2][2]){
const float b00(b[0][0]),b01(b[0][1]),b10([1][0]),b11([1][1]);
const float c00(c[0][0]),c01([0][1]),c10(c[1][0]),c11(c[1][1]);
a[0][0] = b00*c11;
a[0][1] = b11*c00;
a[1][0] = b02*c10;
a[1][1] = b10*c01;
}
My question is how to implement this feature for a much larger array of data in a loop such as:
void multiply (float a[100][100],float b[100][100], float c[100][100]){
// cant possibly declare 100 pointer here
const float b00(b[0][0]),b01(b[0][1]),b10([1][0]),b11([1][1]).......
const float c00(c[0][0]),c01([0][1]),c10(c[1][0]),c11(c[1][1])......
for(i=0;1<100;i+=3){
for(i=0;1<100;i+=3){
a[i][j+1] = b[i][j]*c[i][j];
a[i][j+2] = b[i][j+1]*c[i][j+1];
a[i][j+3] = b[i][j+2]*c[i][j+2];
a[i+1][j+1] = b[i+1][j]*c[i+1][j];
a[i+2][j+2] = b[i+1][j+1]*c[i+1][j+1];
// and so on..
}
}
}