【发布时间】:2016-05-16 00:33:17
【问题描述】:
我是 X86 的新手,我一直坚持使用另一个双精度数组的值来更新双精度数组。以下代码是我的函数,我想使用内联汇编来替换循环内的一段代码。我在下面附上了错误消息。谁能帮我指出我的错误?我对错误消息感到困惑,不知道如何修改它。
static inline void update(double * x,double * y,double * z,double * vx,
double * vy,double * vz,uint32_t size){
for (uint32_t i=0;i<size;++i){
x[i] = x[i] + vx[i];
y[i] = y[i] + vy[i];
z[i] = z[i] + vz[i];
}
}
uint32_t counter = 0;
__asm__ __volatile__ (
"loop: \n\t"
"faddq (%4), (%1)\n\t"
"faddq (%5), (%2)\n\t"
"faddq (%6), (%3)\n\t"
"addq $8, %1\n\t"
"addq $8, %2\n\t"
"addq $8, %3\n\t"
"addq $8, %4\n\t"
"addq $8, %5\n\t"
"addq $8, %6\n\t"
"incq %0\n\t"
"cmp %0, %7\n\t"
"jne loopb"
: "+r"(counter)
: "r" (x),"r" (y),"r"(z),"r"(vx),"r"(vy),"r"(vz),"r"(size)
: "memory", "cc");
错误信息:
update_locations_ass.c:150:15: error: invalid instruction mnemonic 'faddq'
"loop: \n\t"
^
<inline asm>:2:2: note: instantiated into assembly here
faddq (%rdi), (%rcx)
^~~~~
update_locations_ass.c:151:25: error: invalid instruction mnemonic 'faddq'
"faddq (%4), (%1)\n\t"
^
<inline asm>:3:2: note: instantiated into assembly here
faddq (%r8), (%rdx)
^~~~~
update_locations_ass.c:152:28: error: invalid instruction mnemonic 'faddq'
"faddq (%5), (%2)\n\t"
^
<inline asm>:4:2: note: instantiated into assembly here
faddq (%r9), (%rsi)
^~~~~
update_locations_ass.c:159:23: error: invalid operand for instruction
"addq $8, %6\n\t"
^
<inline asm>:11:7: note: instantiated into assembly here
incq %eax
编译器版本: 配置: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM 版本 6.1.0 (clang-602.0.53)(基于 LLVM 3.6.0svn) 目标:x86_64-apple-darwin14.0.0 线程模型:posix
【问题讨论】:
-
你用的是什么编译器?请不要发布错误消息的屏幕截图。将它们复制并粘贴到您的问题中。另外你为什么要在汇编中写这个?编译器可以生成更好的代码。
-
它无法识别
faddq指令。可能你的编译器不支持 FPU.. -
编译器是clang-602.0.53
-
@EugeneSh。它甚至不存在,不是编译器的错
-
除非数据始终在 L1 中,否则此内核受带宽限制,不值得浪费时间编写汇编而不是 C。
标签: c arrays assembly x86 inline-assembly