How do I tell whether AMOCAS.W succeeded?
Compare the old value returned in rd with the expected value; equality indicates that the swap store occurred.
Atomic compare-and-swap word: compare memory with rd[31:0], store rs2[31:0] on match, return old value in rd
AMOCAS.W (Zacas extension) atomically loads a 32-bit value from the address in rs1 and compares it with the low 32 bits of rd; on a bitwise match it stores the low 32 bits of rs2 back to the same address. The loaded old value is sign-extended to XLEN and written to rd regardless of success. aq/rl ordering bits are supported.
AMOCAS.W atomically loads a 32-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.w a0, a2, (a1)».
Understand this scenario with real code like «amocas.w 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.