Help needed on inline assembly
downs
default_357-line at yahoo.de
Wed Jan 30 06:06:31 PST 2008
The problem is that parameters to movaps need to be aligned on a 16-byte boundary. That's what the 'a' in movaps means, "aligned".
So you can either use movups (unaligned), which is slower, or explicitly allocate your memory to lie on a 16-byte boundary.
Example:
> > import std.gc, std.stdio;
> > void* malloc_align16(size_t count) {
> > void* res = malloc(count+15).ptr;
> > return cast(void*) ((cast(size_t)(res + 15))&(0xFFFFFFFF - 15));
> > }
> >
> > float[4] array = [ 1f, 2f, 3f, 4f ];
> >
> > void main()
> > {
> > auto _array = (cast(float*)malloc_align16(4*float.sizeof))[0 .. 4];
> > _array[] = array;
> > auto a = &_array[0];
> > asm
> > {
> > mov EAX, a;
> > movaps XMM1, [EAX];
> > }
> > writefln("Done");
> > }
Hope it helps.
--downs
More information about the Digitalmars-d-learn
mailing list