Help needed on inline assembly

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Jan 30 06:36:41 PST 2008


"Hendrik Renken" <funsheep at -[no-spam]-gmx.net> wrote in message 
news:fnprum$6oh$1 at digitalmars.com...
>
> float[4] array = [ 1f, 2f, 3f, 4f ];
>
> void main()
> {
> float* a = &array[0];
>
> asm
> {
> mov EAX, a;
> movaps XMM1, [EAX];
> }
> }

If you're using the newest DMD, this should work, it does for me.  If you're 
using anything older than 1.023 (like, hm, 1.015?  GRRGH), this will 
probably fail.  1.023 made anything in the static data segment >= 16 bytes 
paragraph aligned, so that data is already aligned properly.

I don't know what GDC does in this case.

Another way to get an aligned allocation is to use a struct with the 
float[4] in it.

struct vec
{
    float[4] array;
}

void main()
{
    vec* v = new vec;

    // ptr will get you the pointer to the 0th element too
    float* a = v.array.ptr;

    asm
    {
        mov EAX, a;
        movaps XMM1, [EAX];
    }
}

This also doesn't rely on any standard library stuff. 




More information about the Digitalmars-d-learn mailing list