[Bf-committers] Code optimisation

Alejandro Conty Estevez bf-committers@blender.org
Fri, 23 Apr 2004 08:58:50 +0200


I've been studing gcc optimization for vector operations. It looks quite
interesting to me, and this is what I know by the moment. For sse vector
instructions for instance, if you write a code like this:

float a,b,c,d;

and you do some operation like this:

a+=x;
b+=y;
c+=z;
d+=w;

Gcc compiler will still put there 4 add instructions even if you select
sse as the fpu. But, if you write your code like this:

float a[4];

and do an operation like this:

for(int i=0;i<4;++i)
	a[i]+=x[i];

The compiler detects it and puts just 1, yes ONE add instruction.
Interesting, isn't it? Have to think of how to improve code for this
optimizations without making it unreadable. One would have to change the
tipical struct:

struct point
{
	float x,y,x;
}

by

struct point
{
	float p[3];
};

And do operations always with a loop. But it could worth it, I'm not
sure.

jandro