【发布时间】:2014-06-01 11:06:36
【问题描述】:
我正在尝试将 bunny 移植到 armv7h,它使用了一些我无法转换为 asm 的 x86 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));
}
有什么,我试过了
"ADD/SUB %0 %0": "=r" (*ptr): "m" (*ptr));
两个都给
Error: ARM register expected -- `add [r3] [r3]'
和
Error: ARM register expected -- `sub [r4] [r4]'
编译使用:
armv7l-unknown-linux-gnueabihf-gcc -Wall -O3 -funroll-loops -fno-strict-aliasing
-ffast-math -Wno-pointer-sign -mcpu=cortex-a15 -mfpu=neon -marm
【问题讨论】:
-
"m" 是错误的约束,首先(它应该是“0”,我认为 - 我讨厌 GCC 的扩展 asm 有多么令人困惑)。更一般地说,这不会是原子的。简单搜索 ARM 参考手册或在此处将告诉您如何使用
LDREX/STREX实现原子。 -
@Notlikethat 尝试给出“警告匹配约束不允许注册”并且仍然错误。
标签: c gcc assembly arm inline-assembly