On Sunday, 9 August 2020 at 09:58:18 UTC, Johan wrote:
On Sunday, 9 August 2020 at 01:03:51 UTC, Bruce Carneal wrote:
The .alignof attribute of __vector(ubyte[32]) is 32 but initializing an array of such vectors via an assignment to .length has given me 16 byte alignment (and subsequent seg faults which I suspect are related).

Is sub .alignof alignment expected here? IOW, do I have to manually manage memory if I want alignments above 16?

Do you have a code example?
And what compiler are you using?

-Johan

At run.dlang.io recent runs of both dmd and lcd compilations of the below revealed misalignment.

import std;

void main() @safe
{
alias V = __vector(ubyte[32]); // requires -mcpu=native or other on cmd line
    V[] va;
    size_t misalignments;
    foreach(N; 1..101) {
        va.length = N;
        const uptr = cast(ulong)va.ptr;
        misalignments += (uptr % V.alignof) != 0;
    }
    writefln("misaligned %s per cent of the time", misalignments);
}

Reply via email to