How do I tell whether AMOCAS.B succeeded?
Compare the old value returned in rd with the expected value; equality indicates that the swap store occurred.
Atomic compare-and-swap byte: compare memory with rd[7:0], store rs2[7:0] on match, return old value in rd
AMOCAS.B (the byte AMOCAS form provided by Zabha, with Zacas CAS semantics) atomically loads a 8-bit value from the address in rs1 and compares it with the low 8 bits of rd; on a bitwise match it stores the low 8 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.
Shows Zabha + Zacas byte atomic field decode, aq/rl ordering bits, memory read, and CAS state update.
Zabha + Zacas-extension byte atomic instructions use a 32-bit encoding; the animation starts by splitting the fields.
This animation shows ISA-visible atomic read-modify-write, compare-and-swap, LR/SC reservation state, and ordering bits, not any specific CPU cache-coherence implementation, pipeline, or timing.
AMOCAS.B atomically loads a 8-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.b a0, a2, (a1)».
Understand this scenario with real code like «amocas.b 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.