[英]GCC ARM register expected
I'm trying to port bunny to armv7h, which uses some x86 asm stuff that I'm having trouble converting to asm. 我正在尝试将bunny移植到armv7h,它使用了一些x86 asm东西,但我无法转换为asm。
static __inline__ void atomic_inc(volatile int* ptr){
__asm__ __volatile__("lock incl %0": "=m" (*ptr): "m" (*ptr));
}
static __inline__ void atomic_dec(volatile int* ptr){
__asm__ __volatile__("lock decl %0": "=m" (*ptr): "m" (*ptr));
}
Is what's there, I've tried 有什么东西,我试过了
"ADD/SUB %0 %0": "=r" (*ptr): "m" (*ptr));
And both give 两者都给
Error: ARM register expected -- `add [r3] [r3]'
and 和
Error: ARM register expected -- `sub [r4] [r4]'
Compiled using: 编译使用:
armv7l-unknown-linux-gnueabihf-gcc -Wall -O3 -funroll-loops -fno-strict-aliasing
-ffast-math -Wno-pointer-sign -mcpu=cortex-a15 -mfpu=neon -marm
The clue lies in the error message - which is entirely accurate. 线索在于错误消息-完全正确。
ARM arithmetic instructions take three operands : ARM算术指令采用三个操作数 :
ADD{S} rd, rs, <operand>
SUB{S} rd, rs, <operand>
Where operand
is one of: 其中operand
是以下之一:
in your case, I imagine you would want an immediate constant of 1
, which would give an assembler instruction of 在您的情况下,我想您会希望立即数为1
,这将给出汇编程序指令:
ADD rd, rd, #1
However, this misses the fundamental flaw that you are trying to implement an atomic increment of a memory location . 但是,这错过了您试图实现内存位置的原子增量的基本缺陷。 The compiler is generating a load from memory instruction in order to implement the dereference of ptr
. 编译器正在从内存指令生成负载,以实现对ptr
的取消引用。 It's not immediately obvious it ever generates a stores of the result. 产生结果的存储并不立刻显而易见。 Even if it did, this would be at best, a non-atomic sequence of 3 instructions (load, increment, store). 即使这样做,充其量也是3条指令(加载,递增,存储)的非原子序列。
I would recommend looking at GCC's atomic intrinsics rather than rolling your own. 我建议您查看GCC的原子内在函数,而不要自己动手。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.