PDA

View Full Version : vector alignment


c94wjpn
10-Nov-2007, 23:44
yo ho folks.
I have a problem with my vectors on the SPU. They just aren't interpreting the bits correctly and I think it's an alignment issue.
Here is my code:

float * pf;
vectorfloat4 pvf;

pf = (float*)p;
pvf = (vectorfloat4*)p;

if(fabs(*pf - spu_extract(*pvf,0))>1e-4)
printf("values differ: %f vs %f\n", *pf, spu_extract(*pvf, 0));

which demonstrates that spu_extract(o,*pvf) is just not returning correct values.
I think the problem is that my pointer p is not divisible by, say, 32.
Can anyone give me some advice on the alignment you need on your vectorfloat4*s to make it work ok?

cheers!

Npl
11-Nov-2007, 10:35
yo ho folks.
I have a problem with my vectors on the SPU. They just aren't interpreting the bits correctly and I think it's an alignment issue.
Here is my code:

float * pf;
vectorfloat4 pvf;

pf = (float*)p;
pvf = (vectorfloat4*)p;

if(fabs(*pf - spu_extract(*pvf,0))>1e-4)
printf("values differ: %f vs %f\n", *pf, spu_extract(*pvf, 0));

which demonstrates that spu_extract(o,*pvf) is just not returning correct values.
I think the problem is that my pointer p is not divisible by, say, 32.
Can anyone give me some advice on the alignment you need on your vectorfloat4*s to make it work ok?

You need 128bit alignment on the SPU (thats 16bytes), but the compiler might automagically generate code to load floats from any 4byte aligned address.
Your problem could be that scalars have a prefered spot, ie. a single float in a 128 bit vector takes the last Spot, not the first. Try spu_extract(*pvf,3) and see if that fixes it.
The only way to know for sure what happens would be to output the assembler-code from the compiler and look what it generates when you load scalars from pointers (-S switch for gcc)