Align a variable on the stack.
TheFlyingFiddle via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 3 15:29:43 PST 2015
Is there a built in way to do this in dmd?
Basically I want to do this:
auto decode(T)(...)
{
while(...)
{
T t = T.init; //I want this aligned to 64 bytes.
}
}
Currently I am using:
align(64) struct Aligner(T)
{
T value;
}
auto decode(T)(...)
{
Aligner!T t = void;
while(...)
{
t.value = T.init;
}
}
But is there a less hacky way? From the documentation of align it
seems i cannot use that for this kind of stuff. Also I don't want
to have to use align(64) on my T struct type since for my usecase
I am decoding arrays of T.
The reason that I want to do this in the first place is that if
the variable is aligned i get about a 2.5x speedup (i don't
really know why... found it by accident)
More information about the Digitalmars-d-learn
mailing list