我这样定义对齐浮动
typedef __attribute((aligned(64))) float aligned_float;
然后我定义对齐的浮动restrict
像这样的关键字
typedef aligned_float * restrict aligned_floatptr;
这就像我期望的那样工作。但因为我几乎总是想把这两个放在一起,所以我在一行中尝试了 typedef 像这样
typedef __attribute((aligned(64))) float * restrict aligned_floatptr2
然而,这是行不通的。这restrict
关键字仍可识别,但对齐方式无法识别。但是编译器没有给我任何警告。我只是通过查看装配体才意识到对齐不起作用。
为什么组合定义不起作用并且为什么我没有收到警告?
您可以看到 Clang 和 GCC 的程序集here.
我想这样做的原因是我有这样的代码
static void kernel(float * restrict a, float * restrict b, float * restrict c, int n) {
a = __builtin_assume_aligned(a, 64);
b = __builtin_assume_aligned(b, 64);
c = __builtin_assume_aligned(c, 64);
//rest of code
}
我对此有很多变体。我觉得用起来比较方便
static void kernel(aligned_flotptr a, aligned_floatptr b, aligned_floatptr c, int n) {
//rest of code
}
我刚刚意识到 Clang 似乎甚至不认识aligned_float
。只有 GCC 承认它。对于 Clang 我仍然需要使用__builtin_assume_aligned
(或者可能#praga omp sind aligned
)。另一方面,即使没有对齐,Clang 也能生成良好的代码(未对齐的指令与现在几代的对齐版本一样快),因此对于 GCC,我确实需要对齐。