I am trying to embed the following assembly instruction (of an ARM-like architecture) using GCC's extended asm syntax:
__asm__("lsr %[xj], %[xj], %[xn]" :
[xj] "=r" (j) :
[xi] "[xj]" (j) , [xn] "[xn]" (n)); // j = j >> n
i
, j
, and n
are declared as integers int i, j, n;
(note that j
serves as both in and out parameter)
The compiler generates the error:
../src/fft2dlib.c:55:5: error: matching constraint references invalid operand number
../src/fft2dlib.c:53:3: error: matching constraint references invalid operand number
where lines 53 and 55 are the first and third lines of the above asm code.
When I replace the n
input parameter with an explicit constant in the assembly instruction, it compiles fine:
__asm__("lsr %[xj], %[xj], 27" :
[xj] "=r" (j) :
[xi] "[xj]" (j)); // j = j >> 27
I am following examples from the GCC manual , but I can't figure out the problem.
The contraint "[xn]"
in [xn] "[xn]" (n)
doesn't really make sense. Using a parameter name or number as a constraint means "put this operand in the same location as the named operand". So in this case you're telling GCC to put [xn]
in the same location as [xn]
, which is meaningless and doesn't actually give information about the operand type.
You need to use another constraint type, such as "r"
for a register operand, depending on what the assembly instruction allows.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.