Help needed on inline assembly
Jarrett Billingsley
kb3ctd2 at yahoo.com
Wed Jan 30 06:49:45 PST 2008
"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message
news:fnq21n$mvk$1 at digitalmars.com...
> 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.
A third way is to wrap the second way in a function, allowing you to
allocate statically-sized arrays directly:
T* alloc(T)()
{
struct S
{
T t;
}
return &(new S).t;
}
void main()
{
float[4]* array = alloc!(float[4]);
float* a = array.ptr;
asm
{
mov EAX, a;
movaps XMM1, [EAX];
}
}
More information about the Digitalmars-d-learn
mailing list