Bee*_*ope 7 c++ optimization x86 vectorization clang
考虑下面的小搜索函数:
template <uint32_t N>
int32_t countsearch(const uint32_t *base, uint32_t needle) {
uint32_t count = 0;
#pragma clang loop vectorize(disable)
for (const uint32_t *probe = base; probe < base + N; probe++) {
if (*probe < needle)
count++;
}
return count;
}
Run Code Online (Sandbox Code Playgroud)
在-O2以上,铛这个矢量化搜索,例如,。产生这样的代码(对于 10 个元素):
int countsearch<10u>(unsigned int const*, unsigned int): # @int countsearch<10u>(unsigned int const*, unsigned int)
vmovd xmm0, esi
vpbroadcastd ymm0, xmm0
vpbroadcastd ymm1, dword ptr [rip + .LCPI0_0] # ymm1 = [2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648,2147483648]
vpxor ymm2, ymm1, ymmword ptr [rdi]
vpxor ymm0, ymm0, ymm1
vpcmpgtd ymm0, ymm0, ymm2
cmp dword ptr [rdi + 32], esi
vpsrld ymm1, ymm0, 31
vextracti128 xmm1, ymm1, 1
vpsubd ymm0, ymm1, ymm0
vpshufd xmm1, xmm0, 78 # xmm1 = xmm0[2,3,0,1]
vpaddd ymm0, ymm0, ymm1
vphaddd ymm0, ymm0, ymm0
vmovd eax, xmm0
adc eax, 0
cmp dword ptr [rdi + 36], esi
adc eax, 0
vzeroupper
ret
Run Code Online (Sandbox Code Playgroud)
如何在命令行或#pragma在代码中使用 a 禁用此矢量化?
我尝试了以下命令行参数,没有一个能阻止矢量化:
-disable-loop-vectorization
-disable-vectorization
-fno-vectorize
-fno-tree-vectorize
Run Code Online (Sandbox Code Playgroud)
#pragma clang loop vectorize(disable)正如你在上面的代码中看到的那样,我也尝试了循环,但没有运气。
关闭SLP 矢量化:
clang++ -O2 -fno-slp-vectorize
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1939 次 |
| 最近记录: |