www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - align(16) struct member throws an exception with movdqa

reply "ixid" <nuaccount gmail.com> writes:
     struct a
     {   align(16) int[4] test = [1,2,3,4];
     }
     a test;

     asm
     {
             movdqa XMM0, test   ;
             addps XMM0, XMM0    ;
             movdpa test, XMM0   ;
     }

This works fine with unaligned movdqu but throws an access 
violation exception with movdqa. Why isn't align letting me do an 
aligned read? How should I do an aligned read?
Jun 10 2012
next sibling parent reply "jerro" <a a.com> writes:
On Monday, 11 June 2012 at 03:19:08 UTC, ixid wrote:
     struct a
     {   align(16) int[4] test = [1,2,3,4];
     }
     a test;

     asm
     {
             movdqa XMM0, test   ;
             addps XMM0, XMM0    ;
             movdpa test, XMM0   ;
     }

 This works fine with unaligned movdqu but throws an access 
 violation exception with movdqa. Why isn't align letting me do 
 an aligned read? How should I do an aligned read?

One way would be to a vector type: import core.simd; int4 test;
Jun 10 2012
parent Sean Cavanaugh <WorksOnMyMachine gmail.com> writes:
On 6/11/2012 7:15 AM, Trass3r wrote:
 I think it has been fixed for the next version of DMD already. Any
 idea why align isn't letting me use movdqa?

Cause align doesn't work the way you think it does. In fact I still don't understand how it works at all.

The language align keyword can only reduce the alignment from the platform default (typically 8). A serious flaw if you ask me . . . .
Jun 13 2012
prev sibling next sibling parent "ixid" <nuaccount gmail.com> writes:
That doesn't work for me, hence using assembler. I get:
Internal error: ..\ztc\cgcod.c 1447
Jun 10 2012
prev sibling next sibling parent Trass3r <un known.com> writes:
test code please
Jun 11 2012
prev sibling next sibling parent "ixid" <nuaccount gmail.com> writes:
import std.stdio, core.simd;

void main()
{   int4 v;
}

Internal error: ..\ztc\cgcod.c 1447
Building Debug\dtest1.exe failed!
Jun 11 2012
prev sibling next sibling parent Trass3r <un known.com> writes:
 import std.stdio, core.simd;

 void main()
 {   int4 v;
 }

 Internal error: ..\ztc\cgcod.c 1447
 Building Debug\dtest1.exe failed!

Works fine on Linux. Maybe the 32Bit check doesn't work for Windoze? -m32 on Linux yields Error: SIMD vector types not supported on this platform
Jun 11 2012
prev sibling next sibling parent "ixid" <nuaccount gmail.com> writes:
I think it has been fixed for the next version of DMD already. 
Any idea why align isn't letting me use movdqa?
Jun 11 2012
prev sibling next sibling parent reply Trass3r <un known.com> writes:
 I think it has been fixed for the next version of DMD already. Any idea  
 why align isn't letting me use movdqa?

Cause align doesn't work the way you think it does. In fact I still don't understand how it works at all.
Jun 11 2012
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Thursday, June 14, 2012 00:17:25 Sean Cavanaugh wrote:
 On 6/11/2012 7:15 AM, Trass3r wrote:
 I think it has been fixed for the next version of DMD already. Any
 idea why align isn't letting me use movdqa?

Cause align doesn't work the way you think it does. In fact I still don't understand how it works at all.

The language align keyword can only reduce the alignment from the platform default (typically 8). A serious flaw if you ask me . . . .

Then open an enhancement request. If there's a good enough reason that align should work the way that you want it to and not a sufficiently good reason why it shouldn't, then Walter may be willing to make the change. It may be that nothing will change, but it doesn't hurt to ask. - Jonathan M Davis
Jun 13 2012
prev sibling next sibling parent Trass3r <un known.com> writes:
 Cause align doesn't work the way you think it does.
 In fact I still don't understand how it works at all.

The language align keyword can only reduce the alignment from the platform default (typically 8). A serious flaw if you ask me . . . .

The doc page doesn't even clearly state this, it is incomprehensible imo: http://dlang.org/attribute.html#align "align by itself sets it to the default, which matches the default member alignment of the companion C compiler. Integer specifies the alignment which matches the behavior of the companion C compiler when non-default alignments are used." What the heck is this supposed to mean? It sounds like in any case the C compiler's value is used and the attribute is completely superfluous/useless.
Jun 14 2012
prev sibling next sibling parent "Kagamin" <spam here.lot> writes:
On Thursday, 14 June 2012 at 12:02:02 UTC, Trass3r wrote:
 What the heck is this supposed to mean? It sounds like in any 
 case the C compiler's value is used and the attribute is 
 completely superfluous/useless.

It means it works like C's _Alignas ( constant-expression ) (C11, 6.7.5).
Jun 14 2012
prev sibling parent "Kapps" <opantm2+spam gmail.com> writes:
On Monday, 11 June 2012 at 03:19:08 UTC, ixid wrote:
     struct a
     {   align(16) int[4] test = [1,2,3,4];
     }
     a test;

     asm
     {
             movdqa XMM0, test   ;
             addps XMM0, XMM0    ;
             movdpa test, XMM0   ;
     }

 This works fine with unaligned movdqu but throws an access 
 violation exception with movdqa. Why isn't align letting me do 
 an aligned read? How should I do an aligned read?

IIRC, you're supposed to be able to do something like align(16) struct a, but it doesn't work when a is created on the stack. That was the conclusion I found when trying to implement my own vector type a year ago anyways.
Jun 16 2012