CAS, CASA, CASAL, CASL
Compare and swap word or doubleword in memory
This instruction reads a 32-bit word or 64-bit doubleword from memory, and compares it against the value held in a first register. If the comparison is equal, the value in a second register is written to memory. If the comparison is not equal, the architecture permits writing the value read from the location to memory. If the write is performed, the read and write occur atomically such that no other modification of the memory location can take place between the read and write.
- If the destination register is not one of WZR or XZR, CASA and CASAL load from memory with acquire semantics.
- CASL and CASAL store to memory with release semantics.
- CAS has neither acquire nor release semantics.
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 register which is compared and loaded, that is <Ws>, or <Xs>, is restored to the value held in the register before the instruction was executed.
For a CAS or CASA instruction, when <Ws> or <Xs> specifies the same register as <Wt> or <Xt>, this signals to the memory system that an additional subsequent CAS, CASA, CASAL, or CASL access to the specified location is expected to occur in the near future in the absence of taking an exception or exceptional software conditions. The memory system can respond by taking actions that are expected to enable the subsequent CAS, CASA, CASAL, or CASL access to succeed when it does occur.
A code sequence starting with a CAS or CASA instruction for which <Ws> or <Xs> specifies the same register as <Wt> or <Xt>, and ending with a subsequent CAS, CASA, CASAL, or CASL to the same location, exhibits the following properties for best performance when the location may be accessed concurrently, on one or more other PEs:
- The sequence does not contain any direct System register writes, address translation instructions, cache or TLB maintenance operations, exception producing instructions, exception returns, or ISB barriers.
- The execution of the sequence includes 32 or fewer instructions.
- The value provided in <Ws> or <Xs> of the first CAS or CASA is a value likely to result in the comparison failing. A failing comparison result may lead to better performance due to the hardware not performing a write to memory.
Note
For a CAS or CASA instruction, when <Ws> or <Xs> specifies the same register as <Wt> or <Xt>, the value in memory is not modified, because the CAS or CASA either fails its compare or writes the same value back to memory.
For performance reasons, Arm recommends that software not use a CAS or CASA instruction when <Ws> or <Xs> specifies the same register as <Wt> or <Xt> in a routine that includes a subsequent CAS, CASA, CASAL, or CASL for any of the following purposes:
- To load the value that will be compared to conditionally determine whether or not to execute the subsequent CAS, CASA, CASAL, or CASL.
- As a form of prefetch executed between the instruction loading the value that will be compared and the subsequent compare instruction that conditionally determines whether or not to execute the subsequent CAS, CASA, CASAL, or CASL.
This guidance does not apply when <Ws> or <Xs> specifies the same register as <Wt> or <Xt> for a CAS or CASA instruction and the compare between the CAS or CASA and the subsequent CAS, CASA, CASAL, or CASL is intended to detect an exceptional software condition such that the result of the compare does not prevent the subsequent CAS, CASA, CASAL, or CASL from executing under normal operating conditions.
For more information about memory ordering semantics, see Load-Acquire, Store-Release.
For information about addressing modes, see Load/Store addressing modes.
No offset class
(FEAT_LSE)
| 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | x | 0 | 0 | 1 | 0 | 0 | 0 | 1 | A | 1 | Rs | R | 1 | 1 | 1 | 1 | 1 | Rn | Rt | ||||||||||||
| size | Rt2 | ||||||||||||||||||||||||||||||
Decode (all encodings)
if !IsFeatureImplemented(FEAT_LSE) then EndOfDecode(Decode_UNDEF); end;
let s : integer{} = UInt(Rs);
let t : integer{} = UInt(Rt);
let n : integer{} = UInt(Rn);
let datasize : integer{} = 8 << UInt(size);
let regsize : integer{} = if datasize == 64 then 64 else 32;
let acquire : boolean = A == '1' && s != 31;
let release : boolean = R == '1';
let tagchecked : boolean = n != 31;
Assembler Symbols
| <Ws> |
Is the 32-bit name of the general-purpose register to be compared and loaded, encoded in the "Rs" field. |
| <Wt> |
Is the 32-bit name of the general-purpose register to be conditionally stored, encoded in the "Rt" field. |
| <Xn|SP> |
Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the "Rn" field. |
| <Xs> |
Is the 64-bit name of the general-purpose register to be compared and loaded, encoded in the "Rs" field. |
| <Xt> |
Is the 64-bit name of the general-purpose register to be conditionally stored, encoded in the "Rt" field. |
Operation
var address : bits(64);
var comparevalue : bits(datasize);
var newvalue : bits(datasize);
let privileged : boolean = PSTATE.EL != EL0;
let accdesc : AccessDescriptor = CreateAccDescAtomicOp(MemAtomicOp_CAS, acquire, release,
tagchecked, privileged, t, s);
comparevalue = X{datasize}(s);
newvalue = X{datasize}(t);
if n == 31 then
CheckSPAlignment();
address = SP{64}();
else
address = X{64}(n);
end;
let data : bits(datasize) = MemAtomic{}(address, comparevalue, newvalue, accdesc);
X{regsize}(s) = ZeroExtend{regsize}(data);
Version 2026.09 — Copyright © 2010-2026 Arm Limited or its affiliates.
This site is provided as a community resource and is NOT affiliated with nor endorsed by Arm Limited.