Thread overview
Can we rely on LDC respecting "align" (for avx) ??
Sep 08, 2021
james.p.leblanc
Sep 08, 2021
Tejas
Sep 08, 2021
Tejas
Sep 08, 2021
Johan
September 08, 2021

Dear All,

In searching through the forum archives (going back to 2013, 2016
etc), and experiments, it appears to me that LDC does indeed
respect the standard "align" properties. (Meaning: proper alignment
for using AVX with static arrays can be guaranteed).

Experiments (and forum discussions) also lead me to believe that
DMD does NOT respect this alignment.

So, what is the "official status" of AVX alignment possibilities?

Succinctly:

  1. Can we truly rely on LDC's alignment for AVX ?

  2. Is DMD presently not respecting alignment? (Or have I
    misunderstood?)

This has important impact on performance of numerical computations.

Thanks for all illumination!

James

September 08, 2021

On Wednesday, 8 September 2021 at 04:32:50 UTC, james.p.leblanc wrote:

>

Dear All,

In searching through the forum archives (going back to 2013, 2016
etc), and experiments, it appears to me that LDC does indeed
respect the standard "align" properties. (Meaning: proper alignment
for using AVX with static arrays can be guaranteed).

Experiments (and forum discussions) also lead me to believe that
DMD does NOT respect this alignment.

So, what is the "official status" of AVX alignment possibilities?

Succinctly:

  1. Can we truly rely on LDC's alignment for AVX ?

  2. Is DMD presently not respecting alignment? (Or have I
    misunderstood?)

This has important impact on performance of numerical computations.

Thanks for all illumination!

James

Yes you are correct (to my understanding)

DMD only respects align keyword upto the value 16,ie, until align(16), the code behaves the way you expect it to. It is 100% a bug(don't have the link on me right now)

Try the following code on DMD, then LDC. See for yourself

import std.stdio:writeln;

void main()
{
    align(16) int[100] a;
    align(1024) int[100] b;
    writeln(cast(ulong)&a[0] % 16);
    writeln(cast(ulong)&b[0] % 1024);
}
September 08, 2021

On Wednesday, 8 September 2021 at 04:43:31 UTC, Tejas wrote:

>

On Wednesday, 8 September 2021 at 04:32:50 UTC, james.p.leblanc wrote:

>

[...]

Yes you are correct (to my understanding)

DMD only respects align keyword upto the value 16,ie, until align(16), the code behaves the way you expect it to. It is 100% a bug(don't have the link on me right now)

Try the following code on DMD, then LDC. See for yourself

import std.stdio:writeln;

void main()
{
    align(16) int[100] a;
    align(1024) int[100] b;
    writeln(cast(ulong)&a[0] % 16);
    writeln(cast(ulong)&b[0] % 1024);
}

Here's the link:
https://issues.dlang.org/show_bug.cgi?id=16098

September 08, 2021

On Wednesday, 8 September 2021 at 04:32:50 UTC, james.p.leblanc wrote:

>
  1. Can we truly rely on LDC's alignment for AVX ?

Yes.
If you find wrong alignment, it's a bug.

-Johan