Reputation: 55
I get this error, when I try to atomically increment number. (Yes, I have to do it with inline assembly and command xaddl, and not fetch_and_add etc.)
tslock.c:23:3: error: matching constraint references invalid operand number
: "cc", "memory");
^
tslock.c:20:2: error: matching constraint references invalid operand number
__asm__ __volatile__ (
^
void atomicIncrement(int number){
int one = 1;
__asm__ __volatile__ (
"lock xaddl %1, %0;"
:: "0"(number), "m"(one)
: "cc", "memory");
printf("new value = %d\n", number);
}
Upvotes: 0
Views: 1902
Reputation: 58858
If you use a number as a constraint (the string next to the operand), it means "put this operand in the same location as the one with this number".
So "0"(number)
means that number
goes in the same location as operand 0. But in this case, number
is operand 0, so that doesn't actually tell the compiler where to put it.
You need to use a different constraint for number
- for example "r" if it should be in a register or "m" if it should be in memory.
Upvotes: 1