我正在尝试使用k1om-mpss-linux-gcc
编译器为Xeon Phi平台编写一些带有KNC指令的内联汇编代码.我想在我的代码中使用掩码寄存器来向量化我的计算.这是我的代码:
#include
#include
#include
#include
#include
#include
void* aligned_malloc(size_t size, size_t alignment) {
uintptr_t r = (uintptr_t)malloc(size + --alignment + sizeof(uintptr_t));
uintptr_t t = r + sizeof(uintptr_t);
uintptr_t o =(t + alignment) & ~(uintptr_t)alignment;
if (!r) return NULL;
((uintptr_t*)o)[-1] = r;
return (void*)o;
}
int main(int argc, char* argv[])
{
const int vectorSize = 16;
int * n_arr = (int *) aligned_malloc(16 * sizeof(int),64);
int * lenS_arr = (int *) aligned_malloc(16 * sizeof(int),64);
int * tt_i = (int *) aligned_malloc(16 * sizeof(int),64);
int * tt = (int *) aligned_malloc(16 * sizeof(int),64);
int n = 5;
int lenS = 16;
int i;
for(i=0; i< 16; i++){
tt_i[i] = 1;
n_arr[i] = n;
lenS_arr[i] = lenS;
}
__asm__("vmovdqa32 %1,%%zmm0\n\t"
"vmovdqa32 %2,%%zmm1\n\t"
"vmovdqa32 %3,%%zmm2\n\t"
"vpaddd %%zmm0,%%zmm1,%%zmm0\n\t"
"vpcmpgtd %%zmm0,%%zmm2,%%k1\n\t"
"vpsubd %%zmm2,%%zmm0,%%zmm0 {{%%k1}}\n\t"
"vmovdqa32 %%zmm1,%0;"
: "=m" (tt[0]) : "m" (tt_i[0]), "m" (n_arr[0]), "m" (lenS_arr[0]));
for (i=0; i <16 ; i++)
{
printf("tt_i[%d] = %d --- tt[%d] = %d\n",i, tt_i[i], i, tt[i]);
}
return 0;
}
当我编译代码时,我遇到了这个错误:
error: invalid 'asm': nested assembly dialect alternatives
这与该装配线有关:
"vpsubd %%zmm2,%%zmm0,%%zmm0 {{%%k1}}\n\t"
有关此错误的任何想法?
尝试%{%%k1%}
在内联asm中使用以{%k1}
进入实际的asm输出. {
并}
需要逃脱.
谷歌搜索错误消息:nested assembly dialect alternatives
找到一个关于asm方言替代品的邮件列表帖子,包括一个示例测试用例.
{}
在GNU C中,inline asm已经具有特殊含义:为不同的ASM方言提供替代方案.
使用{{%%k1}}
gcc看起来像嵌套的替代品,这是无效的.
测试用例/示例是:
int main (void) { int f = 0; asm ("{movl $42, %%eax | mov eax, 42}" : :); asm ("{movl $41, %0||mov %0, 43}" : "=r"(f)); if (f != 42) abort (); return 0; }