How do I tell whether AMOCAS.D succeeded?
Compare the old value returned in rd with the expected value; equality indicates that the swap store occurred.
Atomic compare-and-swap doubleword: compare memory with rd/register pair, store rs2/register pair on match, return old value in rd
AMOCAS.D (Zacas extension) atomically loads a 64-bit doubleword from the address in rs1 and compares it with the compare operand; on a match it stores the swap operand. On RV64, the compare value is rd, the swap value is rs2, and the old value is written to rd. On RV32, the compare value is the even rd/rd+1 register pair, the swap value is the even rs2/rs2+1 pair, and the old value is written to rd/rd+1; odd rd or rs2 encodings are reserved. aq/rl ordering bits are supported.
AMOCAS.D atomically loads a 64-bit memory value, compares it bitwise with the compare value supplied in rd, stores the rs2 swap value on equality, and always writes the old memory value back to rd.
Understand this scenario with real code like «amocas.d a0, a2, (a1)».
Understand this scenario with real code like «amocas.d a0, a2, (a1)».
Compare the old value returned in rd with the expected value; equality indicates that the swap store occurred.
No. rs2 supplies the new value to store on success; the compare value comes from rd before execution, or from the rd register pair.