brintos

brintos / llvm-project-archived public Read only

0
0
Text · 715 B · 93d6c51 Raw
24 lines · c
1void __attribute__((naked)) branch_cas(int *a, int *b) {2  // Stop at the first instruction. The atomic sequence contains active forward3  // branch (bne a5, a1, 2f). After step instruction lldb should stop at the4  // branch's target address (ret instruction).5  asm volatile("1:\n\t"6               "lr.w a2, (a0)\n\t"7               "and a5, a2, a4\n\t"8               "bne a5, a1, 2f\n\t"9               "xor a5, a2, a0\n\t"10               "and a5, a5, a4\n\t"11               "xor a5, a2, a5\n\t"12               "sc.w a5, a1, (a3)\n\t"13               "beqz a5, 1b\n\t"14               "nop\n\t"15               "2:\n\t"16               "ret\n\t");17}18 19int main() {20  int a = 4;21  int b = 2;22  branch_cas(&a, &b);23}24