llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[arm inline asm] invalid operand in inline asm

Open weiguozhi opened this issue 14 years ago • 4 comments

Bugzilla Link 12570
Resolution FIXED
Resolved on Aug 03, 2014 14:38
Version trunk
OS All
CC @asl,@compnerd

Extended Description

When I compile the following function contains arm inline assembler

int64_t dvmQuasiAtomicRead64(volatile const int64_t* addr) { int64_t value; asm volatile ("@ dvmQuasiAtomicRead64\n" "ldrexd %0, %H0, [%1]" : "=&r" (value) : "r" (addr)); return value; }

clang/llvm reports:

Atomic.c:110:27: error: invalid operand in inline asm: '@ dvmQuasiAtomicRead64 ldrexd $0, ${0:H}, [$1]' asm volatile ("@ dvmQuasiAtomicRead64\n" ^ src/vm/Atomic.c:110:27: error: invalid operand in inline asm: '@ dvmQuasiAtomicRead64 ldrexd $0, ${0:H}, [$1]' src/vm/Atomic.c:110:27: error: invalid operand in inline asm: '@ dvmQuasiAtomicRead64 ldrexd $0, ${0:H}, [$1]' src/vm/Atomic.c:110:27: error: invalid operand in inline asm: '@ dvmQuasiAtomicRead64 ldrexd $0, ${0:H}, [$1]' src/vm/Atomic.c:110:27: error: invalid operand in inline asm: '@ dvmQuasiAtomicRead64 ldrexd $0, ${0:H}, [$1]'

But gcc can compile it successfully.

weiguozhi avatar Apr 17 '12 11:04 weiguozhi

Sorry, I don't have a commit that resolves this, but with current trunk, the provided snippet assembles properly. Marking this as fixed. Feel free to reopen if this is still an issue with current trunk for you.

compnerd avatar Aug 03 '14 21:08 compnerd

Hi guys.

Same problem here - have you some progress on it?

JFYI mentioned in description code can be replaced with follow:

int64_t dvmQuasiAtomicRead64(volatile const int64_t* addr) { unsigned int val0, val1; asm volatile( "@ dvmQuasiAtomicRead64\n" "ldrexd r0, r1, [%2]\n" "mov %0, r0\n" "mov %1, r1\n" : "=&r" (val0), "=&r" (val1) : "r" (addr) : "r0", "r1" ); return (argtype)val0 | ((argtype)val1 << 32); }

and used as workaround. So looks like llvm compiler doesn't understand %H registers notation. Of course mentioned above workaround acceptable but it becomes a real pain to use list of clobbered registers when u have to work with a quite big number of arguments in inline function.

Looking forward on your reply. Any help will be really appreciated.

llvmbot avatar May 04 '12 18:05 llvmbot

Hrm, and you're compiling this for arm, right? Not for x86 :)

Yes, it is indicated in the title.

weiguozhi avatar Apr 18 '12 03:04 weiguozhi

Hrm, and you're compiling this for arm, right? Not for x86 :)

asl avatar Apr 17 '12 16:04 asl