Open
Description
example:
#include <stdio.h>
typedef struct {
volatile int counter;
} Counter;
void foo(Counter *v, int i) {
int result, val, tmp;
__asm__ __volatile__(
".arch_extension mp\n"
"9998: " "pldw\t%a0" "\n"
" .pushsection \".alt.smp.init\", \"a\"\n"
" .long 9998b - .\n"
" " "pld\t%a0" "\n"
" .popsection\n"
"1: ldrex %0, [%4]\n"
" add %1, %0, %5\n"
" strex %2, %1, [%4]\n"
" teq %2, #0\n"
" bne 1b"
: "=&r" (result), "=&r" (val), "=&r" (tmp), "+Qo" (v->counter)
: "r" (&v->counter), "Ir" (i)
: "cc"
);
printf("Updated counter: %d\n", v->counter);
}
int main() {
Counter c = {0};
printf("Initial counter: %d\n", c.counter);
foo(&c, 5);
return 0;
}
https://godbolt.org/z/Px35ejvbn
compile option:-ffunction-sections -fdata-sections -march=armv7-a
Clang will split the foo
function in the example into two parts, using Ltmp0
to represent the embedded assembly logic in the source code. Why is this done?