error: invalid 'asm': operand number missing after %-letter
代码如下:
int get_max(int *a, int len)
{
assert(l % 4 == 0);
int ret, tmp[4];
__asm__ __volatile__(
"xorps %%xmm0, %%xmm0\n"
"LP3:\n\t"
"movdqa %%xmm0, %%xmm1\n\t"
"pcmpgtd (%1), %%xmm1\n\t"
"andps %%xmm1, %%xmm0\n\t"
"andnps (%1), %%xmm1\n\t"
"orps %%xmm1, %xmm0\n\t" // %xmm0 -> %%xmm0
"addl $16, %1\n\t"
"subl $4, %2\n\t"
"jnz LP3\n\t"
"movdqu %%xmm0, (%3)\n\t"
"movl (%3), %%eax\n\t"
"cmpl 4(%3), %%eax\n\t"
"cmovll 4(%3), %%eax\n\t"
"cmpl 8(%3), %%eax\n\t"
"cmovll 8(%3), %%eax\n\t"
"cmpl 12(%3), %%eax\n\t"
"cmovll 12(%3), %%eax\n\t"
"movl %%eax, %0\n"
:"=m"(ret)
:"r"(a),"r"(len),"r"(tmp)
:"%eax"
);
return ret;
}
修改成
int get_max(int *a, int len)
{
assert(l % 4 == 0);
int ret, tmp[4];
__asm__ __volatile__(
"xorps %%xmm0, %%xmm0\n"
"LP3:\n\t"
"movdqa %%xmm0, %%xmm1\n\t"
"pcmpgtd (%1), %%xmm1\n\t"
"andps %%xmm1, %%xmm0\n\t"
"andnps (%1), %%xmm1\n\t"
"orps %%xmm1, %%xmm0\n\t" // %xmm0 -> %%xmm0
"addl $16, %1\n\t"
"subl $4, %2\n\t"
"jnz LP3\n\t"
"movdqu %%xmm0, (%3)\n\t"
"movl (%3), %%eax\n\t"
"cmpl 4(%3), %%eax\n\t"
"cmovll 4(%3), %%eax\n\t"
"cmpl 8(%3), %%eax\n\t"
"cmovll 8(%3), %%eax\n\t"
"cmpl 12(%3), %%eax\n\t"
"cmovll 12(%3), %%eax\n\t"
"movl %%eax, %0\n"
:"=m"(ret)
:"r"(a),"r"(len),"r"(tmp)
:"%eax"
);
return ret;
}
编译通过。