[aarch64-port-dev ] Possible problem in MacroAssembler::cmpxchgw

Andrew Dinn adinn at redhat.com
Thu Aug 1 02:47:25 PDT 2013


Code is appended below. I think the cmp in this routine probably ought
be a cmpw. Does anyone know better?

We /probably/ get away with this because oldv will have been written
using an operation with an int destination.


regards,


Andrew Dinn
-----------

void MacroAssembler::cmpxchgw(Register oldv, Register newv, Register
addr, Register tmp,
				Label &succeed, Label &fail) {
  // oldv holds comparison value
  // newv holds value to write in exchange
  // addr identifies memory word to compare against/update
  // tmp returns 0/1 for success/failure
  Label retry_load, nope;

  bind(retry_load);
  // flush and load exclusive from the memory location
  // and fail if it is not what we expect
  ldaxrw(tmp, addr);
  cmp(tmp, oldv); // <----- should be cmpw?
  br(Assembler::NE, nope);
  // if we store+flush with no intervening write tmp wil be zero
  stlxrw(tmp, newv, addr);
  cbzw(tmp, succeed);
  // retry so we only ever return after a load fails to compare
  // ensures we don't return a stale value after a failed write.
  b(retry_load);
  // if the memory word differs we return it in oldv and signal a fail
  bind(nope);
  mov(oldv, tmp);
  b(fail);
}




More information about the aarch64-port-dev mailing list