c - GCC ARM register expected -
i'm trying port bunny armv7h, uses x86 asm stuff i'm having trouble converting 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 error message - entirely accurate.
arm arithmetic instructions take 3 operands:
add{s} rd, rs, <operand>
sub{s} rd, rs, <operand>
where operand 1 of:
- a register
- an immediate value
- a register shifted constant
- a register shifted register
in case, imagine want immediate constant of 1, give assembler instruction of
add rd, rd, #1
however, misses fundamental flaw trying implement atomic increment of memory location. compiler generating load memory instruction in order implement dereference of ptr. it's not obvious ever generates stores of result. if did, @ best, non-atomic sequence of 3 instructions (load, increment, store).
i recommend looking @ gcc's atomic intrinsics rather rolling own.
Comments
Post a Comment