D / DLang / GDC - 结构中 SIMD 字段的对齐

D / DLang / GDC - Alignment of SIMD fields in struct

struct vec_struct {
    alias field this;
    bool b;
    int8 field; // ymm 
    }

在这段代码中,当您查看由 GDC 输出的生成的 x64 代码时,它似乎做得很好,因为它已获得 256 位 YMM 'field' 正确的偏移量。

Q: D是否自动将字段的对齐限制传播到静态结构或堆栈上结构的分配?

在这种情况下 -

struct vec_struct {
    bool b2;
    struct {
        alias field this;
        bool b;
        int8 field; // umm
        }
    }

'field' 的偏移量似乎不再正确对齐 - GDC 中的偏移量为 40 字节。我不认为编译器会只使用未对齐的指令?无论如何,如果我理解 D 文档,我可以获取字段的地址,然后将其传递给希望拾取保证正确对齐的东西的人。 :这是正确的 - 一个严重的问题,还是我愚蠢?

请不要咬人。我是 D 的新手,我希望我已经理解了 x86 SIMD 指令的文档。 (非常有经验的专业 asm 和 C 程序员,但是已经过时了。)

Noob q:我注意到 GDC 操作码看起来有点奇怪,例如,编译器生成一个 256 位未对齐的提取,然后是一个对齐的二进制操作(我认为),例如 movdqu 后跟一个 vpaddd r, ymm ptr blah - 后者是否仅对齐?抱歉,如果我弄错了,需要阅读。 有人好心帮我检查一下吗?

Does D automatically propagate the alignment restrictions on the field to the allocation of static structs or structs on the stack?

我认为它应该支持并且 GDC/LDC 应该已经支持正确的堆栈对齐。 DMD 在这方面可能有一些错误: https://issues.dlang.org/show_bug.cgi?id=16098

it appears that the offset to 'field' is no longer aligned correctly - offset is 40 bytes in GDC.

正如 Iain 已经在 D.learn 线程中回答的那样,这是共享 DMD/GDC 代码库中的错误。

错误报告:https://issues.dlang.org/show_bug.cgi?id=17237

DMD 错误修复:https://github.com/dlang/dmd/pull/6582

GDC 向后移植:https://github.com/D-Programming-GDC/GDC/pull/408