我正在尝试使用内联汇编将一堆结构成员(Particle
是指向此类结构的指针)加载到一些寄存器中。这是我最初的解决方案:
asm("mov %1(%0), %%edx\n"
"fld %2(%0)\n"
"fld %3(%0)\n"
"fld %4(%0)\n"
"fld %5(%0)\n"
"movups %6(%0), %%xmm1\n"
"movups %7(%0), %%xmm2\n"
"movups %8(%0), %%xmm3\n"
"movups %9(%0), %%xmm4\n"
:
: "r" (Particle),
"n" (offsetof(ptcParticle, Active)),
"n" (offsetof(ptcParticle, Size)),
"n" (offsetof(ptcParticle, Rotation)),
"n" (offsetof(ptcParticle, Time)),
"n" (offsetof(ptcParticle, TimeScale)),
"n" (offsetof(ptcParticle, Colour)),
"n" (offsetof(ptcParticle, Location)),
"n" (offsetof(ptcParticle, Velocity)),
"n" (offsetof(ptcParticle, Accel))
: "%edx", "%st", "%st(1)", "%st(2)", "%st(3)", "%xmm1", "%xmm2",
"%xmm3", "%xmm4"
);
但是,它不起作用,因为 GCC 将这些偏移量输出为立即数文字,如下所示:
mov $0(%eax), %edx
fld $44(%eax)
fld $40(%eax)
fld $8(%eax)
fld $4(%eax)
movups $12(%eax), %xmm1
movups $28(%eax), %xmm2
movups $48(%eax), %xmm3
movups $60(%eax), %xmm4
结果,在表达式之后被gas
视为(%eax)
垃圾:
Error: junk `(%eax)' after expression
如果我只能摆脱输出中的美元符号,这将起作用。知道如何访问结构成员吗?