In arm64, compiling the inline assembly below causes a warning below:
value size does not match register size specified by the constraint and modifier [-Wasm-operand-widths].
This is because the arm64's register is 64bit.
int a = 1;
int b = 2;
asm volatile(
"add %[a], %[a], %[b] \n"
:
[a] "+r"(a)
:
[b] "r"(b)
:
);
And clang give the fix advice, use constraint modifier "w".
value size does not match register size specified by the constraint and modifier
means:
your variable is 32bit
not match with ARM64's 64bit
register
you could:
64bit
long a = 1;
long b = 2;
asm volatile(
"add %[a], %[a], %[b] \n"
: [a] "+r"(a)
: [b] "r"(b)
:);
or
32bit
=Word register, by add prefix w
clang
suggestedint a = 1;
int b = 2;
asm volatile(
"add %w[a], %w[a], %w[b] \n"
: [a] "+r"(a)
: [b] "r"(b)
:);