<?xml-stylesheet type="text/xsl" encoding="UTF-8" href="iform.xsl" version="1.0"?>
<!DOCTYPE instructionsection PUBLIC "-//ARM//DTD instructionsection //EN" "iform-p.dtd">
<!-- Copyright (c) 2010-2025 Arm Limited or its affiliates. All rights reserved. -->
<!-- This document is Non-Confidential. This document may only be used and distributed in accordance with the terms of the agreement entered into by Arm and the party that Arm delivered this document to. -->
<instructionsection id="CASP" title="CASP, CASPA, CASPAL, CASPL -- A64" type="instruction">
  <docvars>
    <docvar key="address-form" value="base-register"/>
    <docvar key="instr-class" value="general"/>
    <docvar key="isa" value="A64"/>
  </docvars>
  <heading>CASP, CASPA, CASPAL, CASPL</heading>
  <desc>
    <brief>
      <para>Compare and swap pair of words or doublewords in memory</para>
    </brief>
    <authored>
      <para>This instruction 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 comparison is not equal, the architecture permits writing
the value read from the location 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.</para>
      <list type="unordered">
        <listitem>
          <content>
            <instruction>CASPA</instruction> and <instruction>CASPAL</instruction> load from memory with acquire semantics.</content>
        </listitem>
        <listitem>
          <content>
            <instruction>CASPL</instruction> and <instruction>CASPAL</instruction> store to memory with release semantics.</content>
        </listitem>
        <listitem>
          <content>
            <instruction>CASP</instruction> has neither acquire nor release semantics.</content>
        </listitem>
      </list>
      <para>The architecture permits that the data read clears any exclusive
monitors associated with that location, even if the compare
subsequently fails.</para>
      <para>If the instruction generates a synchronous Data Abort, the registers
which are compared and loaded, that is <syntax>&lt;Ws&gt;</syntax> and
<syntax>&lt;W(s+1)&gt;</syntax>, or <syntax>&lt;Xs&gt;</syntax> and <syntax>&lt;X(s+1)&gt;</syntax>, are
restored to the values held in the registers before the instruction
was executed.</para>
      <para>For a <instruction>CASP</instruction> or <instruction>CASPA</instruction> instruction, when <syntax>&lt;Ws&gt;</syntax>
or <syntax>&lt;Xs&gt;</syntax> specifies the same register as <syntax>&lt;Wt&gt;</syntax> or <syntax>&lt;Xt&gt;</syntax>,
this signals to the memory system that an additional subsequent <instruction>CASP</instruction>,
<instruction>CASPA</instruction>, <instruction>CASPAL</instruction>, or <instruction>CASPL</instruction>
access to the specified location is likely to occur in the near future. The memory system can respond by
taking actions that are expected to enable the subsequent <instruction>CASP</instruction>,
<instruction>CASPA</instruction>, <instruction>CASPAL</instruction>, or <instruction>CASPL</instruction> access to succeed when it does occur.</para>
      <para>A code sequence starting with a <instruction>CASP</instruction> or <instruction>CASPA</instruction> instruction for which
<syntax>&lt;Ws&gt;</syntax> or <syntax>&lt;Xs&gt;</syntax> specifies the same register as <syntax>&lt;Wt&gt;</syntax>
or <syntax>&lt;Xt&gt;</syntax>, and ending with a subsequent <instruction>CASP</instruction>, <instruction>CASPA</instruction>,
<instruction>CASPAL</instruction>, or <instruction>CASPL</instruction> to the same location, exhibits the following
properties for best performance when the location may be accessed concurrently, on one or more other PEs:</para>
      <list type="unordered">
        <listitem>
          <content>The sequence does not contain any direct system register writes, address translation instructions, cache or TLB
  maintenance operations, exception producing instructions, exception returns, or <instruction>ISB</instruction> barriers.</content>
        </listitem>
        <listitem>
          <content>The execution of the sequence includes 32 or fewer instructions.</content>
        </listitem>
        <listitem>
          <content>The value provided in <syntax>&lt;Ws&gt;</syntax> or <syntax>&lt;Xs&gt;</syntax> of the first <instruction>CASP</instruction> or <instruction>CASPA</instruction>
  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.</content>
        </listitem>
      </list>
      <note>
        <para>For a <instruction>CASP</instruction> or <instruction>CASPA</instruction> instruction, when <syntax>&lt;Ws&gt;</syntax> or
<syntax>&lt;Xs&gt;</syntax> specifies the same register as <syntax>&lt;Wt&gt;</syntax> or <syntax>&lt;Xt&gt;</syntax>, the
value in memory is not modified, because the <instruction>CASP</instruction> or <instruction>CASPA</instruction> either fails its compare or writes the same value back to memory.</para>
      </note>
      <para>For more information about memory ordering semantics, see <xref linkend="ARMARM_BEIHCHEF">Load-Acquire, Store-Release</xref>.</para>
      <para>For information about addressing modes, see
<xref linkend="ARMARM_CHDIIIBB">Load/Store addressing modes</xref>.</para>
    </authored>
  </desc>
  <alias_list howmany="0"/>
  <classes>
    <iclass name="No offset" oneof="1" id="iclass_no_offset" no_encodings="8" isa="A64">
      <docvars>
        <docvar key="address-form" value="base-register"/>
        <docvar key="instr-class" value="general"/>
        <docvar key="isa" value="A64"/>
      </docvars>
      <iclassintro count="8"/>
      <arch_variants>
        <arch_variant feature="FEAT_LSE" name="v8Ap1"/>
      </arch_variants>
      <regdiagram form="32" psname="A64.ldst.comswappr.CASP_CP32_comswappr" tworows="1">
        <box hibit="31" width="1" settings="1">
          <c>0</c>
        </box>
        <box hibit="30" width="1" name="sz" usename="1">
          <c colspan="1"/>
        </box>
        <box hibit="29" width="7" settings="7">
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="22" width="1" name="L" usename="1">
          <c colspan="1"/>
        </box>
        <box hibit="21" width="1" settings="1">
          <c>1</c>
        </box>
        <box hibit="20" width="5" name="Rs" usename="1">
          <c colspan="5"/>
        </box>
        <box hibit="15" width="1" name="o0" usename="1">
          <c colspan="1"/>
        </box>
        <box hibit="14" width="5" name="Rt2" usename="1" settings="5" psbits="xxxxx">
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="9" width="5" name="Rn" usename="1">
          <c colspan="5"/>
        </box>
        <box hibit="4" width="5" name="Rt" usename="1">
          <c colspan="5"/>
        </box>
      </regdiagram>
      <encoding name="CASP_CP32_comswappr" oneofinclass="8" oneof="8" label="32-bit CASP" bitdiffs="sz == 0 &amp;&amp; L == 0 &amp;&amp; o0 == 0">
        <docvars>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-32"/>
          <docvar key="atomic-ops" value="CASP-pair-32"/>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="reg-type" value="pair-32"/>
          <docvar key="mnemonic" value="CASP"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>0</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>0</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>0</c>
        </box>
        <asmtemplate><text>CASP  </text><a hover="Is the 32-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Ws&gt; must be an even-numbered register." link="Ws">&lt;Ws&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be compared and loaded." link="WsPlus1">&lt;W(s+1)&gt;</a><text>, </text><a hover="Is the 32-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Wt&gt; must be an even-numbered register." link="Wt">&lt;Wt&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be conditionally stored." link="WtPlus1">&lt;W(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <encoding name="CASPA_CP32_comswappr" oneofinclass="8" oneof="8" label="32-bit CASPA" bitdiffs="sz == 0 &amp;&amp; L == 1 &amp;&amp; o0 == 0">
        <docvars>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-32"/>
          <docvar key="atomic-ops" value="CASPA-pair-32"/>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="reg-type" value="pair-32"/>
          <docvar key="mnemonic" value="CASPA"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>0</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>1</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>0</c>
        </box>
        <asmtemplate><text>CASPA  </text><a hover="Is the 32-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Ws&gt; must be an even-numbered register." link="Ws">&lt;Ws&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be compared and loaded." link="WsPlus1">&lt;W(s+1)&gt;</a><text>, </text><a hover="Is the 32-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Wt&gt; must be an even-numbered register." link="Wt">&lt;Wt&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be conditionally stored." link="WtPlus1">&lt;W(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <encoding name="CASPAL_CP32_comswappr" oneofinclass="8" oneof="8" label="32-bit CASPAL" bitdiffs="sz == 0 &amp;&amp; L == 1 &amp;&amp; o0 == 1">
        <docvars>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-32"/>
          <docvar key="atomic-ops" value="CASPAL-pair-32"/>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="reg-type" value="pair-32"/>
          <docvar key="mnemonic" value="CASPAL"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>0</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>1</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>1</c>
        </box>
        <asmtemplate><text>CASPAL  </text><a hover="Is the 32-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Ws&gt; must be an even-numbered register." link="Ws">&lt;Ws&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be compared and loaded." link="WsPlus1">&lt;W(s+1)&gt;</a><text>, </text><a hover="Is the 32-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Wt&gt; must be an even-numbered register." link="Wt">&lt;Wt&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be conditionally stored." link="WtPlus1">&lt;W(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <encoding name="CASPL_CP32_comswappr" oneofinclass="8" oneof="8" label="32-bit CASPL" bitdiffs="sz == 0 &amp;&amp; L == 0 &amp;&amp; o0 == 1">
        <docvars>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-32"/>
          <docvar key="atomic-ops" value="CASPL-pair-32"/>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="reg-type" value="pair-32"/>
          <docvar key="mnemonic" value="CASPL"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>0</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>0</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>1</c>
        </box>
        <asmtemplate><text>CASPL  </text><a hover="Is the 32-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Ws&gt; must be an even-numbered register." link="Ws">&lt;Ws&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be compared and loaded." link="WsPlus1">&lt;W(s+1)&gt;</a><text>, </text><a hover="Is the 32-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Wt&gt; must be an even-numbered register." link="Wt">&lt;Wt&gt;</a><text>, </text><a hover="Is the 32-bit name of the second general-purpose register to be conditionally stored." link="WtPlus1">&lt;W(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <encoding name="CASP_CP64_comswappr" oneofinclass="8" oneof="8" label="64-bit CASP" bitdiffs="sz == 1 &amp;&amp; L == 0 &amp;&amp; o0 == 0">
        <docvars>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-64"/>
          <docvar key="atomic-ops" value="CASP-pair-64"/>
          <docvar key="reg-type" value="pair-64"/>
          <docvar key="mnemonic" value="CASP"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>1</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>0</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>0</c>
        </box>
        <asmtemplate><text>CASP  </text><a hover="Is the 64-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Xs&gt; must be an even-numbered register." link="Xs">&lt;Xs&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be compared and loaded." link="XsPlus1">&lt;X(s+1)&gt;</a><text>, </text><a hover="Is the 64-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Xt&gt; must be an even-numbered register." link="Xt">&lt;Xt&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be conditionally stored." link="XtPlus1__3">&lt;X(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <encoding name="CASPA_CP64_comswappr" oneofinclass="8" oneof="8" label="64-bit CASPA" bitdiffs="sz == 1 &amp;&amp; L == 1 &amp;&amp; o0 == 0">
        <docvars>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-64"/>
          <docvar key="atomic-ops" value="CASPA-pair-64"/>
          <docvar key="reg-type" value="pair-64"/>
          <docvar key="mnemonic" value="CASPA"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>1</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>1</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>0</c>
        </box>
        <asmtemplate><text>CASPA  </text><a hover="Is the 64-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Xs&gt; must be an even-numbered register." link="Xs">&lt;Xs&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be compared and loaded." link="XsPlus1">&lt;X(s+1)&gt;</a><text>, </text><a hover="Is the 64-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Xt&gt; must be an even-numbered register." link="Xt">&lt;Xt&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be conditionally stored." link="XtPlus1__3">&lt;X(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <encoding name="CASPAL_CP64_comswappr" oneofinclass="8" oneof="8" label="64-bit CASPAL" bitdiffs="sz == 1 &amp;&amp; L == 1 &amp;&amp; o0 == 1">
        <docvars>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-64"/>
          <docvar key="atomic-ops" value="CASPAL-pair-64"/>
          <docvar key="reg-type" value="pair-64"/>
          <docvar key="mnemonic" value="CASPAL"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>1</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>1</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>1</c>
        </box>
        <asmtemplate><text>CASPAL  </text><a hover="Is the 64-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Xs&gt; must be an even-numbered register." link="Xs">&lt;Xs&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be compared and loaded." link="XsPlus1">&lt;X(s+1)&gt;</a><text>, </text><a hover="Is the 64-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Xt&gt; must be an even-numbered register." link="Xt">&lt;Xt&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be conditionally stored." link="XtPlus1__3">&lt;X(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <encoding name="CASPL_CP64_comswappr" oneofinclass="8" oneof="8" label="64-bit CASPL" bitdiffs="sz == 1 &amp;&amp; L == 0 &amp;&amp; o0 == 1">
        <docvars>
          <docvar key="instr-class" value="general"/>
          <docvar key="isa" value="A64"/>
          <docvar key="address-form" value="base-register"/>
          <docvar key="address-form-reg-type" value="base-register-pair-64"/>
          <docvar key="atomic-ops" value="CASPL-pair-64"/>
          <docvar key="reg-type" value="pair-64"/>
          <docvar key="mnemonic" value="CASPL"/>
        </docvars>
        <box hibit="30" width="1" name="sz">
          <c>1</c>
        </box>
        <box hibit="22" width="1" name="L">
          <c>0</c>
        </box>
        <box hibit="15" width="1" name="o0">
          <c>1</c>
        </box>
        <asmtemplate><text>CASPL  </text><a hover="Is the 64-bit name of the first general-purpose register to be compared and loaded, encoded in the &quot;Rs&quot; field. &lt;Xs&gt; must be an even-numbered register." link="Xs">&lt;Xs&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be compared and loaded." link="XsPlus1">&lt;X(s+1)&gt;</a><text>, </text><a hover="Is the 64-bit name of the first general-purpose register to be conditionally stored, encoded in the &quot;Rt&quot; field. &lt;Xt&gt; must be an even-numbered register." link="Xt">&lt;Xt&gt;</a><text>, </text><a hover="Is the 64-bit name of the second general-purpose register to be conditionally stored." link="XtPlus1__3">&lt;X(t+1)&gt;</a><text>, [</text><a hover="Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the &quot;Rn&quot; field." link="XnSP_option">&lt;Xn|SP&gt;</a><text>{, #0}]</text></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="A64.ldst.comswappr.CASP_CP32_comswappr" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !IsFeatureImplemented(FEAT_LSE) then EndOfDecode(Decode_UNDEF); end;
if Rs[0] == '1' || Rt[0] == '1' then EndOfDecode(Decode_UNDEF); end;
let s : integer{} = UInt(Rs);
let t : integer{} = UInt(Rt);
let n : integer{} = UInt(Rn);
let datasize : integer{} = 32 &lt;&lt; UInt(sz);
let acquire : boolean = L == '1';
let release : boolean = o0 == '1';
let tagchecked : boolean = n != 31;</pstext></ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="CASP_CP32_comswappr, CASPA_CP32_comswappr, CASPAL_CP32_comswappr, CASPL_CP32_comswappr" symboldefcount="1">
      <symbol link="Ws">&lt;Ws&gt;</symbol>
      <account encodedin="Rs">
        <intro>
          <para>Is the 32-bit name of the first general-purpose register to be compared and loaded, encoded in the "Rs" field. &lt;Ws&gt; must be an even-numbered register.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP32_comswappr, CASPA_CP32_comswappr, CASPAL_CP32_comswappr, CASPL_CP32_comswappr" symboldefcount="1">
      <symbol link="WsPlus1">&lt;W(s+1)&gt;</symbol>
      <account encodedin="Rs">
        <intro>
          <para>Is the 32-bit name of the second general-purpose register to be compared and loaded.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP32_comswappr, CASPA_CP32_comswappr, CASPAL_CP32_comswappr, CASPL_CP32_comswappr" symboldefcount="1">
      <symbol link="Wt">&lt;Wt&gt;</symbol>
      <account encodedin="Rt">
        <intro>
          <para>Is the 32-bit name of the first general-purpose register to be conditionally stored, encoded in the "Rt" field. &lt;Wt&gt; must be an even-numbered register.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP32_comswappr, CASPA_CP32_comswappr, CASPAL_CP32_comswappr, CASPL_CP32_comswappr" symboldefcount="1">
      <symbol link="WtPlus1">&lt;W(t+1)&gt;</symbol>
      <account encodedin="Rt">
        <intro>
          <para>Is the 32-bit name of the second general-purpose register to be conditionally stored.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP32_comswappr, CASPA_CP32_comswappr, CASPAL_CP32_comswappr, CASPL_CP32_comswappr, CASP_CP64_comswappr, CASPA_CP64_comswappr, CASPAL_CP64_comswappr, CASPL_CP64_comswappr" symboldefcount="1">
      <symbol link="XnSP_option">&lt;Xn|SP&gt;</symbol>
      <account encodedin="Rn">
        <intro>
          <para>Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the "Rn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP64_comswappr, CASPA_CP64_comswappr, CASPAL_CP64_comswappr, CASPL_CP64_comswappr" symboldefcount="1">
      <symbol link="Xs">&lt;Xs&gt;</symbol>
      <account encodedin="Rs">
        <intro>
          <para>Is the 64-bit name of the first general-purpose register to be compared and loaded, encoded in the "Rs" field. &lt;Xs&gt; must be an even-numbered register.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP64_comswappr, CASPA_CP64_comswappr, CASPAL_CP64_comswappr, CASPL_CP64_comswappr" symboldefcount="1">
      <symbol link="XsPlus1">&lt;X(s+1)&gt;</symbol>
      <account encodedin="Rs">
        <intro>
          <para>Is the 64-bit name of the second general-purpose register to be compared and loaded.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP64_comswappr, CASPA_CP64_comswappr, CASPAL_CP64_comswappr, CASPL_CP64_comswappr" symboldefcount="1">
      <symbol link="Xt">&lt;Xt&gt;</symbol>
      <account encodedin="Rt">
        <intro>
          <para>Is the 64-bit name of the first general-purpose register to be conditionally stored, encoded in the "Rt" field. &lt;Xt&gt; must be an even-numbered register.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="CASP_CP64_comswappr, CASPA_CP64_comswappr, CASPAL_CP64_comswappr, CASPL_CP64_comswappr" symboldefcount="1">
      <symbol link="XtPlus1__3">&lt;X(t+1)&gt;</symbol>
      <account encodedin="Rt">
        <intro>
          <para>Is the 64-bit name of the second general-purpose register to be conditionally stored.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="A64.ldst.comswappr.CASP_CP32_comswappr" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute">var address : bits(64);
var comparevalue : bits(2*datasize);
var newvalue : bits(2*datasize);
var data : bits(2*datasize);

let s1 : bits(datasize) = X{}(s);
let s2 : bits(datasize) = X{}(s+1);
let t1 : bits(datasize) = X{}(t);
let t2 : bits(datasize) = X{}(t+1);

let privileged : boolean = PSTATE.EL != EL0;
let accdesc : AccessDescriptor = CreateAccDescAtomicOp(MemAtomicOp_CAS, acquire, release,
                                                       tagchecked, privileged, t, t+1, s, s+1);

comparevalue = if BigEndian(accdesc.acctype) then s1::s2 else s2::s1;
newvalue     = if BigEndian(accdesc.acctype) then t1::t2 else t2::t1;
if n == 31 then
    CheckSPAlignment();
    address = SP{64}();
else
    address = X{64}(n);
end;

data = MemAtomic{2*datasize}(address, comparevalue, newvalue, accdesc);

if BigEndian(accdesc.acctype) then
    X{datasize}(s)   = data[2*datasize-1:datasize];
    X{datasize}(s+1) = data[datasize-1:0];
else
    X{datasize}(s)   = data[datasize-1:0];
    X{datasize}(s+1) = data[2*datasize-1:datasize];
end;</pstext></ps>
  </ps_section>
  <timestamp>2026-03-12 12:23:09</timestamp>
  <commit_id>2025-09_rel_asl1</commit_id>
</instructionsection>
