I have some code that operates on 4D vectors and I'm currently trying to convert it to use SSE. I'm using both clang and gcc on 64b linux.
Operating only on vectors is all fine -grasped that. But now comes a part where i have to multiply an entire vector by a single constant - Something like this:
float y[4];
float a1 = 25.0/216.0;
for(j=0; j<4; j++){
y[j] = a1 * x[j];
}
to something like this:
float4 y;
float a1 = 25.0/216.0;
y = a1 * x;
where:
typedef double v4sf __attribute__ ((vector_size(4*sizeof(float))));
typedef union float4{
v4sf v;
float x,y,z,w;
} float4;
This of course will not work because I'm trying to do a multiplication of incompatiple data types.
Now, i could do something like:
float4 a1 = (v4sf){25.0/216.0, 25.0/216.0, 25.0/216.0, 25.0/216.0}
but just makes me feel silly, even if if i write a macro to do this.
Also, I'm pretty certain that will not result in very efficient code.
Googling this brought no clear answers ( see Load constant floats into SSE registers).
So what is the best way to multiply an entire vector by the same constant?