Is placing data with align(32) on the stack with 16-byte alignment an error?
Marco Leise via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 29 09:29:41 PDT 2016
Am Sun, 29 May 2016 13:20:12 +0000
schrieb Johan Engelen <j at j.nl>:
> On Sunday, 29 May 2016 at 12:07:02 UTC, Marco Leise wrote:
> >
> > void main() {
> > import core.simd;
> > Matrix4x4 matrix; // No warning
> > float8 vector; // No warning
> > }
>
> Did you do some LDC IR/asm testing?
No :)
> With LDC, the type `float8` has 32-byte alignment and so will be
> placed with that alignment on the stack.
Ok, so practically all compilers honor the alignment attribute
and DMD should follow suit. If I'm not mistaken, this is also
a C interop ABI issue now.
> For your Matrix4x4 user
> type (I'll assume you meant to write `align(64)`), that alignment
> becomes part of the type and will be put on the stack with
> 64-byte alignment. (aliasing does not work: `alias Byte8 =
> align(8) byte; Byte8 willBeUnaligned;`)
Actually align(64), yes. But for this example align(32) was
enough as I just wanted to focus on AVX types now.
> I believe LDC respects the type's alignment when selecting
> instructions, so when you specified align(32) byte for your type
> it can use the aligned load instructions. If you did not specify
> that alignment, or a lower alignment, it will use unaligned loads.
>
> A problem arises when you cast a (pointer of a) type with lower
> alignment to a type with higher alignment; in that case,
> currently LDC assumes that cast was valid in terms of alignment
> and <boom>!
>
> -Johan
That sounds reasonable. Thanks for the insight.
--
Marco
More information about the Digitalmars-d
mailing list