And*_*mov 2 c c++ reference simd
我正在玩Apple Metal API以及所谓的simd库.标题中有这样的代码:
typedef __attribute__((__ext_vector_type__(3))) float vector_float3;
Run Code Online (Sandbox Code Playgroud)
我很好奇它实际上做了什么以及为什么编译器不允许在函数的参数中或以下一种方式引用vector_float3:
vector_float3 v;
vector_float3& ref = v;
Run Code Online (Sandbox Code Playgroud)
它似乎是GNU C向量扩展的clang扩展,这样的东西是正常的:
typedef int v4si __attribute__ ((vector_size (16)));
Run Code Online (Sandbox Code Playgroud)
ext_vector_type没有领先/尾随下划线的谷歌搜索发现了Clang文档.IDK为什么添加了一个下划线版本,因为它已经只在GNU C中有效__attribute__.
我最好的猜测是让编译器知道你只关心4元素SIMD寄存器的前3个元素的值. 因此,它可能会进行优化,在高元素中留下不同的垃圾而不是源.
为什么编译器不允许引用
vector_float3
使用clang3.8为我工作.尝试不同的编译器.
typedef __attribute__((__ext_vector_type__(3))) float vector_float3;
int foo(vector_float3 &arg) {
vector_float3 v;
vector_float3& ref = v; // unused, but syntactically valid
return arg[0]; // return the low element of the vector, converted to an integer. GNU C vector-extensions syntax.
}
Run Code Online (Sandbox Code Playgroud)
# targeting x86-64 SystemV ABI (so the first integer/pointer arg is in rdi)
cvttss2si eax, dword ptr [rdi]
ret
Run Code Online (Sandbox Code Playgroud)