Is placing data with align(32) on the stack with 16-byte alignment an error?
Johan Engelen via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 29 06:20:12 PDT 2016
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?
With LDC, the type `float8` has 32-byte alignment and so will be
placed with that alignment on the stack. 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;`)
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
More information about the Digitalmars-d
mailing list