struct field alignment

bearophile bearophileHUGS at lycos.com
Mon Oct 18 04:16:56 PDT 2010


Walter Bright:

> I'm painfully aware that align(8)/(16) don't work on the 32 bit targets. I've 
> been reluctant to fix that because it involves some performance degradation 
> (keeping the stack so aligned requires the insertion of stack adjustment 
> instructions here and there).

On the other hand stack-allocated structs and arrays that need to be 16-byte aligned may speed up the code if used with certain SSE+ instructions.

If it is something that must be used for the whole program then you may add a compiler switch to activate stack alignment on request.

If it may work for a single compilation unit then use something like:
align(16) module foobar;

If it may work for a single function, then then you may add the alignment for functions:
align(16) int foo(int x) {...

Bye,
bearophile


More information about the Digitalmars-d mailing list