vector alignment

Discussion in 'CellPerformance@B3D' started by c94wjpn, Nov 10, 2007.

  1. c94wjpn


    Nov 7, 2007
    Likes Received:
    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?

    #1 c94wjpn, Nov 10, 2007
    Last edited by a moderator: Nov 11, 2007
  2. Npl


    Dec 19, 2004
    Likes Received:
    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)
    #2 Npl, Nov 11, 2007
    Last edited by a moderator: Nov 11, 2007

Share This Page

  • About Us

    Beyond3D has been around for over a decade and prides itself on being the best place on the web for in-depth, technically-driven discussion and analysis of 3D graphics hardware. If you love pixels and transistors, you've come to the right place!

    Beyond3D is proudly published by GPU Tools Ltd.