Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Counterexample. The following code is meant to atomically remove the head item from a linked list and return the pointer the item. The output argument "tmp" is not marked early-clobber with "&" so the compiler is in principle free to reuse the register used for the input "&_head". In one case the compiler used r0 for both ("%2" and "%1"). Note also that in this case "%2" may be used more than once if we have to loop, making it especially important to never to change it.

Code Block
  Flink<T>* head;
  Flink<T>* tmp;
  asm volatile ("1:;"
                "lwarx  %0,0,%2;"
                "lwzx   %1,0,(%0);"
                "stwcx. %1,0,%2;"
                "bne-   1b;"
                : "=&r" (head), "=r" (tmp) : "r" (&_head) : "cc", "memory");
  return static_cast<T*>(head);

...