Compare and Swap Pair of words or doublewords in memory reads a pair of 32-bit words or 64-bit doublewords from memory, and compares them against the values held in the first pair of registers. If the comparison is equal, the values in the second pair of registers are written to memory. If the writes are performed, the reads and writes occur atomically such that no other modification of the memory location can take place between the reads and writes.
For more information about memory ordering semantics see Load-Acquire, Store-Release.
For information about memory accesses see Load/Store addressing modes.
The architecture permits that the data read clears any exclusive monitors associated with that location, even if the compare subsequently fails.
If the instruction generates a synchronous Data Abort, the registers which are compared and loaded, that is <Ws> and <W(s+1)>, or <Xs> and <X(s+1)>, are restored to the values held in the registers before the instruction was executed.
31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
0 | sz | 0 | 0 | 1 | 0 | 0 | 0 | 0 | L | 1 | Rs | o0 | 1 | 1 | 1 | 1 | 1 | Rn | Rt | ||||||||||||
Rt2 |
if !HaveAtomicExt() then UNDEFINED; if Rs<0> == '1' then UNDEFINED; if Rt<0> == '1' then UNDEFINED; integer n = UInt(Rn); integer t = UInt(Rt); integer s = UInt(Rs); integer datasize = 32 << UInt(sz); integer regsize = datasize; AccType ldacctype = if L == '1' then AccType_ORDEREDATOMICRW else AccType_ATOMICRW; AccType stacctype = if o0 == '1' then AccType_ORDEREDATOMICRW else AccType_ATOMICRW; boolean tag_checked = n != 31;
<Ws> |
Is the 32-bit name of the first general-purpose register to be compared and loaded, encoded in the "Rs" field. <Ws> must be an even-numbered register. |
<W(s+1)> |
Is the 32-bit name of the second general-purpose register to be compared and loaded. |
<Wt> |
Is the 32-bit name of the first general-purpose register to be conditionally stored, encoded in the "Rt" field. <Wt> must be an even-numbered register. |
<W(t+1)> |
Is the 32-bit name of the second general-purpose register to be conditionally stored. |
<Xs> |
Is the 64-bit name of the first general-purpose register to be compared and loaded, encoded in the "Rs" field. <Xs> must be an even-numbered register. |
<X(s+1)> |
Is the 64-bit name of the second general-purpose register to be compared and loaded. |
<Xt> |
Is the 64-bit name of the first general-purpose register to be conditionally stored, encoded in the "Rt" field. <Xt> must be an even-numbered register. |
<X(t+1)> |
Is the 64-bit name of the second general-purpose register to be conditionally stored. |
<Xn|SP> |
Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the "Rn" field. |
bits(64) address; bits(2*datasize) comparevalue; bits(2*datasize) newvalue; bits(2*datasize) data; bits(datasize) s1 = X[s]; bits(datasize) s2 = X[s+1]; bits(datasize) t1 = X[t]; bits(datasize) t2 = X[t+1]; comparevalue = if BigEndian(ldacctype) then s1:s2 else s2:s1; newvalue = if BigEndian(stacctype) then t1:t2 else t2:t1; if HaveMTE2Ext() then SetTagCheckedInstruction(tag_checked); if n == 31 then CheckSPAlignment(); address = SP[]; else address = X[n]; data = MemAtomicCompareAndSwap(address, comparevalue, newvalue, ldacctype, stacctype); if BigEndian(ldacctype) then X[s] = data<2*datasize-1:datasize>; X[s+1] = data<datasize-1:0>; else X[s] = data<datasize-1:0>; X[s+1] = data<2*datasize-1:datasize>;
Internal version only: isa v33.11seprel, AdvSIMD v29.05, pseudocode v2021-09_rel, sve v2021-09_rc3d ; Build timestamp: 2021-10-06T11:41
Copyright © 2010-2021 Arm Limited or its affiliates. All rights reserved. This document is Non-Confidential.