Can we rely on LDC respecting "align" (for avx) ??

Tejas notrealemail at gmail.com
Wed Sep 8 04:43:31 UTC 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

```d
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);
}
```


More information about the Digitalmars-d-learn mailing list