<?xml version="1.0" encoding="utf-8"?>
<?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-2022 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="SETPTN" title="SETPTN, SETMTN, SETETN -- A64" type="instruction">
  <docvars>
    <docvar key="instr-class" value="general" />
    <docvar key="isa" value="A64" />
  </docvars>
  <heading>SETPTN, SETMTN, SETETN</heading>
  <desc>
    <brief>
      <para>Memory Set, unprivileged and non-temporal</para>
    </brief>
    <authored>
      <para>Memory Set, unprivileged and non-temporal. These instructions perform a memory set using the value in the bottom byte of the source register. The prologue, main, and epilogue instructions are expected to be run in succession and to appear consecutively in memory: SETPTN, then SETMTN, and then SETETN.</para>
      <para>SETPTN performs some preconditioning of the arguments suitable for using the SETMTN instruction, and performs an <arm-defined-word>implementation defined</arm-defined-word> amount of the memory set. SETMTN performs an <arm-defined-word>implementation defined</arm-defined-word> amount of the memory set. SETETN performs the last part of the memory set.</para>
      <note>
        <para>The inclusion of <arm-defined-word>implementation defined</arm-defined-word> amounts of memory set allows some optimization of the size that can be performed.</para>
      </note>
      <para>The architecture supports two algorithms for the memory set: option A and option B. Which algorithm is used is <arm-defined-word>implementation defined</arm-defined-word>.</para>
      <note>
        <para>Portable software should not assume that the choice of algorithm is constant.</para>
      </note>
      <para>After execution of SETPTN, option A (which results in encoding PSTATE.C = 0):</para>
      <list type="unordered">
        <listitem><content>If Xn&lt;63&gt; == 1, the set size is saturated to <hexnumber>0x7FFFFFFFFFFFFFFF</hexnumber>.</content></listitem>
        <listitem><content>Xd holds the original Xd + saturated Xn.</content></listitem>
        <listitem><content>Xn holds -1* saturated Xn + an <arm-defined-word>implementation defined</arm-defined-word> number of bytes set.</content></listitem>
        <listitem><content>PSTATE.{N,Z,V} are set to {0,0,0}.</content></listitem>
      </list>
      <para>After execution of SETPTN, option B (which results in encoding PSTATE.C = 1):</para>
      <list type="unordered">
        <listitem><content>If Xn&lt;63&gt; == 1, the copy size is saturated to <hexnumber>0x7FFFFFFFFFFFFFFF</hexnumber>.</content></listitem>
        <listitem><content>Xd holds the original Xd + an <arm-defined-word>implementation defined</arm-defined-word> number of bytes set.</content></listitem>
        <listitem><content>Xn holds the saturated Xn - an <arm-defined-word>implementation defined</arm-defined-word> number of bytes set.</content></listitem>
        <listitem><content>PSTATE.{N,Z,V} are set to {0,0,0}.</content></listitem>
      </list>
      <para>For SETMTN, option A (encoded by PSTATE.C = 0), the format of the arguments is:</para>
      <list type="unordered">
        <listitem><content>Xn is treated as a signed 64-bit number.</content></listitem>
        <listitem><content>Xn holds -1* number of bytes remaining to be set in the memory set in total.</content></listitem>
        <listitem><content>Xd holds the lowest address that the set is made to -Xn.</content></listitem>
        <listitem><content>At the end of the instruction, the value of Xn is written back with -1* the number of bytes remaining to be set in the memory set in total.</content></listitem>
      </list>
      <para>For SETMTN, option B (encoded by PSTATE.C = 1), the format of the arguments is:</para>
      <list type="unordered">
        <listitem><content>Xn holds the number of bytes remaining to be set in the memory set in total.</content></listitem>
        <listitem><content>Xd holds the lowest address that the set is made to.</content></listitem>
        <listitem><content>At the end of the instruction:<list type="unordered"><listitem><content>the value of Xn is written back with the number of bytes remaining to be set in the memory set in total.</content></listitem><listitem><content>the value of Xd is written back with the lowest address that has not been set.</content></listitem></list></content></listitem>
      </list>
      <para>For SETETN, option A (encoded by PSTATE.C = 0), the format of the arguments is:</para>
      <list type="unordered">
        <listitem><content>Xn is treated as a signed 64-bit number.</content></listitem>
        <listitem><content>Xn holds -1* the number of bytes remaining to be set in the memory set in total.</content></listitem>
        <listitem><content>Xd holds the lowest address that the set is made to -Xn.</content></listitem>
        <listitem><content>At the end of the instruction, the value of Xn is written back with 0.</content></listitem>
      </list>
      <para>For SETETN, option B (encoded by PSTATE.C = 1), the format of the arguments is:</para>
      <list type="unordered">
        <listitem><content>Xn holds the number of bytes remaining to be set in the memory set in total.</content></listitem>
        <listitem><content>Xd holds the lowest address that the set is made to.</content></listitem>
        <listitem><content>At the end of the instruction:<list type="unordered"><listitem><content>the value of Xn is written back with 0.</content></listitem><listitem><content>the value of Xd is written back with the lowest address that has not been set.</content></listitem></list></content></listitem>
      </list>
    </authored>
    <encodingnotes>
      <para>For information about the <arm-defined-word>constrained unpredictable</arm-defined-word> behavior of this instruction, see <xref linkend="CJAEGDJC">Architectural Constraints on UNPREDICTABLE behaviors</xref>, and particularly <xref linkend="CEGDGDDAG2">Memory Copy and Memory Set SET*</xref>.</para>
    </encodingnotes>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <iclass name="Integer" oneof="1" id="iclass_general" no_encodings="3" isa="A64">
      <docvars>
        <docvar key="instr-class" value="general" />
        <docvar key="isa" value="A64" />
      </docvars>
      <iclassintro count="3"></iclassintro>
      <arch_variants>
        <arch_variant name="ARMv8.8" feature="FEAT_MOPS" />
      </arch_variants>
      <regdiagram form="32" psname="aarch64/instrs/memory/mcpymset/set" tworows="1">
        <box hibit="31" width="2" name="sz" usename="1">
          <c colspan="2"></c>
        </box>
        <box hibit="29" width="3" settings="3">
          <c>0</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="26" name="o0" settings="1">
          <c>0</c>
        </box>
        <box hibit="25" width="2" settings="2">
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="23" width="2" name="op1" settings="2">
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="21" settings="1">
          <c>0</c>
        </box>
        <box hibit="20" width="5" name="Rs" usename="1">
          <c colspan="5"></c>
        </box>
        <box hibit="15" width="4" name="op2" usename="1" settings="2" psbits="xxxx">
          <c>x</c>
          <c>x</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="11" width="2" settings="2">
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="9" width="5" name="Rn" usename="1">
          <c colspan="5"></c>
        </box>
        <box hibit="4" width="5" name="Rd" usename="1">
          <c colspan="5"></c>
        </box>
      </regdiagram>
      <encoding name="SETETN_SET_memcms" oneofinclass="3" oneof="3" label="Epilogue" bitdiffs="op2 == 1011">
        <docvars>
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="SETETN" />
          <docvar key="pme" value="pme-epilogue" />
        </docvars>
        <box hibit="15" width="4" name="op2">
          <c>1</c>
          <c>0</c>
          <c></c>
          <c></c>
        </box>
        <asmtemplate><text>SETETN  [</text><a link="sa_xd_1" hover="64-bit general-purpose register that holds an encoding of destination address and for option B is updated by the instruction (field &quot;Rd&quot;)">&lt;Xd&gt;</a><text>]!, </text><a link="sa_xn_2" hover="64-bit general-purpose register that holds the number of bytes to be set and is set to zero at the end of instruction (field &quot;Rn&quot;)">&lt;Xn&gt;</a><text>!, </text><a link="sa_xs" hover="64-bit general-purpose register that holds the source data (field &quot;Rs&quot;)">&lt;Xs&gt;</a></asmtemplate>
      </encoding>
      <encoding name="SETMTN_SET_memcms" oneofinclass="3" oneof="3" label="Main" bitdiffs="op2 == 0111">
        <docvars>
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="SETMTN" />
          <docvar key="pme" value="pme-main" />
        </docvars>
        <box hibit="15" width="4" name="op2">
          <c>0</c>
          <c>1</c>
          <c></c>
          <c></c>
        </box>
        <asmtemplate><text>SETMTN  [</text><a link="sa_xd_1" hover="64-bit general-purpose register that holds an encoding of destination address and for option B is updated by the instruction (field &quot;Rd&quot;)">&lt;Xd&gt;</a><text>]!, </text><a link="sa_xn_1" hover="64-bit general-purpose register that holds an encoding of number of bytes to be set and is updated by the instruction (field &quot;Rn&quot;)">&lt;Xn&gt;</a><text>!, </text><a link="sa_xs" hover="64-bit general-purpose register that holds the source data (field &quot;Rs&quot;)">&lt;Xs&gt;</a></asmtemplate>
      </encoding>
      <encoding name="SETPTN_SET_memcms" oneofinclass="3" oneof="3" label="Prologue" bitdiffs="op2 == 0011">
        <docvars>
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="SETPTN" />
          <docvar key="pme" value="pme-prologue" />
        </docvars>
        <box hibit="15" width="4" name="op2">
          <c>0</c>
          <c>0</c>
          <c></c>
          <c></c>
        </box>
        <asmtemplate><text>SETPTN  [</text><a link="sa_xd" hover="64-bit general-purpose register that holds the destination address and is updated by the instruction (field &quot;Rd&quot;)">&lt;Xd&gt;</a><text>]!, </text><a link="sa_xn" hover="64-bit general-purpose register that holds the number of bytes to be set and is updated by the instruction (field &quot;Rn&quot;)">&lt;Xn&gt;</a><text>!, </text><a link="sa_xs" hover="64-bit general-purpose register that holds the source data (field &quot;Rs&quot;)">&lt;Xs&gt;</a></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="aarch64/instrs/memory/mcpymset/set" mylink="aarch64.instrs.memory.mcpymset.set" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-shared.HaveFeatMOPS.0" file="shared_pseudocode.xml" hover="function: boolean HaveFeatMOPS()">HaveFeatMOPS</a>() then UNDEFINED;
if sz != '00' then UNDEFINED;

integer d = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Rd);
integer s = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Rs);
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Rn);
bits(2) options = op2&lt;1:0&gt;;

<a link="MOPSStage" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage</a> stage;
case op2&lt;3:2&gt; of
    when '00' stage = <a link="MOPSStage_Prologue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Prologue</a>;
    when '01' stage = <a link="MOPSStage_Main" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Main</a>;
    when '10' stage = <a link="MOPSStage_Epilogue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Epilogue</a>;
    otherwise UNDEFINED;

<a link="impl-aarch64.CheckMOPSEnabled.0" file="shared_pseudocode.xml" hover="function: CheckMOPSEnabled()">CheckMOPSEnabled</a>();

if s == n || s == d || n == d || d == 31 || n == 31 then
    c = <a link="impl-shared.ConstrainUnpredictable.1" file="shared_pseudocode.xml" hover="function: Constraint ConstrainUnpredictable(Unpredictable which)">ConstrainUnpredictable</a>(<a link="Unpredictable_MOPSOVERLAP31" file="shared_pseudocode.xml" hover="enumeration Unpredictable {  Unpredictable_VMSR,  Unpredictable_WBOVERLAPLD,  Unpredictable_WBOVERLAPST,  Unpredictable_LDPOVERLAP,  Unpredictable_BASEOVERLAP,  Unpredictable_DATAOVERLAP,  Unpredictable_DEVPAGE2,  Unpredictable_INSTRDEVICE,  Unpredictable_RESCPACR,  Unpredictable_RESMAIR,  Unpredictable_S1CTAGGED,  Unpredictable_S2RESMEMATTR,  Unpredictable_RESTEXCB,  Unpredictable_RESPRRR,  Unpredictable_RESDACR,  Unpredictable_RESVTCRS,  Unpredictable_RESTnSZ,  Unpredictable_RESTCF,  Unpredictable_DEVICETAGSTORE,  Unpredictable_OORTnSZ,  Unpredictable_LARGEIPA,  Unpredictable_ESRCONDPASS,  Unpredictable_ILZEROIT,  Unpredictable_ILZEROT,  Unpredictable_BPVECTORCATCHPRI,  Unpredictable_VCMATCHHALF,   Unpredictable_VCMATCHDAPA,  Unpredictable_WPMASKANDBAS,  Unpredictable_WPBASCONTIGUOUS,  Unpredictable_RESWPMASK,  Unpredictable_WPMASKEDBITS,  Unpredictable_RESBPWPCTRL,  Unpredictable_BPNOTIMPL,  Unpredictable_RESBPTYPE,  Unpredictable_BPNOTCTXCMP,  Unpredictable_BPMATCHHALF,  Unpredictable_BPMISMATCHHALF,  Unpredictable_RESTARTALIGNPC,  Unpredictable_RESTARTZEROUPPERPC,  Unpredictable_ZEROUPPER,   Unpredictable_ERETZEROUPPERPC,   Unpredictable_A32FORCEALIGNPC,  Unpredictable_SMD,  Unpredictable_NONFAULT,  Unpredictable_SVEZEROUPPER,  Unpredictable_SVELDNFDATA,  Unpredictable_SVELDNFZERO,  Unpredictable_CHECKSPNONEACTIVE,  Unpredictable_SMEZEROUPPER,  Unpredictable_NVNV1,  Unpredictable_Shareability,  Unpredictable_AFUPDATE,  Unpredictable_DBUPDATE,  Unpredictable_IESBinDebug,  Unpredictable_BADPMSFCR,  Unpredictable_ZEROBTYPE,  Unpredictable_EL2TIMESTAMP, Unpredictable_EL1TIMESTAMP,  Unpredictable_RESERVEDNSxB,  Unpredictable_WFxTDEBUG,  Unpredictable_LS64UNSUPPORTED,   Unpredictable_MISALIGNEDATOMIC,  Unpredictable_CLEARERRITEZERO,   Unpredictable_ALUEXCEPTIONRETURN,  Unpredictable_IGNORETRAPINDEBUG,  Unpredictable_DBGxVR_RESS,  Unpredictable_PMUEVENTCOUNTER,  Unpredictable_PMSCR_PCT,   Unpredictable_CounterReservedForEL2,  Unpredictable_BRBFILTRATE,   Unpredictable_MOPSOVERLAP31,  Unpredictable_STOREONLYTAGCHECKEDCAS,  Unpredictable_RESTC }">Unpredictable_MOPSOVERLAP31</a>);
    assert c IN {<a link="Constraint_UNDEF" file="shared_pseudocode.xml" hover="enumeration Constraint    { Constraint_NONE,   Constraint_UNKNOWN,  Constraint_UNDEF, Constraint_UNDEFEL0, Constraint_NOP, Constraint_TRUE, Constraint_FALSE, Constraint_DISABLED, Constraint_UNCOND, Constraint_COND, Constraint_ADDITIONAL_DECODE,   Constraint_WBSUPPRESS, Constraint_FAULT, Constraint_LIMITED_ATOMICITY,   Constraint_NVNV1_00, Constraint_NVNV1_01, Constraint_NVNV1_11, Constraint_EL1TIMESTAMP, Constraint_EL2TIMESTAMP, Constraint_OSH, Constraint_ISH, Constraint_NSH,  Constraint_NC, Constraint_WT, Constraint_WB,   Constraint_FORCE, Constraint_FORCENOSLCHECK,  Constraint_MAPTOALLOCATED,  Constraint_PMSCR_PCT_VIRT }">Constraint_UNDEF</a>, <a link="Constraint_NOP" file="shared_pseudocode.xml" hover="enumeration Constraint    { Constraint_NONE,   Constraint_UNKNOWN,  Constraint_UNDEF, Constraint_UNDEFEL0, Constraint_NOP, Constraint_TRUE, Constraint_FALSE, Constraint_DISABLED, Constraint_UNCOND, Constraint_COND, Constraint_ADDITIONAL_DECODE,   Constraint_WBSUPPRESS, Constraint_FAULT, Constraint_LIMITED_ATOMICITY,   Constraint_NVNV1_00, Constraint_NVNV1_01, Constraint_NVNV1_11, Constraint_EL1TIMESTAMP, Constraint_EL2TIMESTAMP, Constraint_OSH, Constraint_ISH, Constraint_NSH,  Constraint_NC, Constraint_WT, Constraint_WB,   Constraint_FORCE, Constraint_FORCENOSLCHECK,  Constraint_MAPTOALLOCATED,  Constraint_PMSCR_PCT_VIRT }">Constraint_NOP</a>};
    case c of
        when <a link="Constraint_UNDEF" file="shared_pseudocode.xml" hover="enumeration Constraint    { Constraint_NONE,   Constraint_UNKNOWN,  Constraint_UNDEF, Constraint_UNDEFEL0, Constraint_NOP, Constraint_TRUE, Constraint_FALSE, Constraint_DISABLED, Constraint_UNCOND, Constraint_COND, Constraint_ADDITIONAL_DECODE,   Constraint_WBSUPPRESS, Constraint_FAULT, Constraint_LIMITED_ATOMICITY,   Constraint_NVNV1_00, Constraint_NVNV1_01, Constraint_NVNV1_11, Constraint_EL1TIMESTAMP, Constraint_EL2TIMESTAMP, Constraint_OSH, Constraint_ISH, Constraint_NSH,  Constraint_NC, Constraint_WT, Constraint_WB,   Constraint_FORCE, Constraint_FORCENOSLCHECK,  Constraint_MAPTOALLOCATED,  Constraint_PMSCR_PCT_VIRT }">Constraint_UNDEF</a>      UNDEFINED;
        when <a link="Constraint_NOP" file="shared_pseudocode.xml" hover="enumeration Constraint    { Constraint_NONE,   Constraint_UNKNOWN,  Constraint_UNDEF, Constraint_UNDEFEL0, Constraint_NOP, Constraint_TRUE, Constraint_FALSE, Constraint_DISABLED, Constraint_UNCOND, Constraint_COND, Constraint_ADDITIONAL_DECODE,   Constraint_WBSUPPRESS, Constraint_FAULT, Constraint_LIMITED_ATOMICITY,   Constraint_NVNV1_00, Constraint_NVNV1_01, Constraint_NVNV1_11, Constraint_EL1TIMESTAMP, Constraint_EL2TIMESTAMP, Constraint_OSH, Constraint_ISH, Constraint_NSH,  Constraint_NC, Constraint_WT, Constraint_WB,   Constraint_FORCE, Constraint_FORCENOSLCHECK,  Constraint_MAPTOALLOCATED,  Constraint_PMSCR_PCT_VIRT }">Constraint_NOP</a>        <a link="impl-shared.EndOfInstruction.0" file="shared_pseudocode.xml" hover="function: EndOfInstruction()">EndOfInstruction</a>();</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="SETMTN_SET_memcms, SETETN_SET_memcms" symboldefcount="1">
      <symbol link="sa_xd_1">&lt;Xd&gt;</symbol>
      <account encodedin="Rd">
        <intro>
          <para>For the epilogue and main variant: is the 64-bit name of the general-purpose register that holds an encoding of the destination address and for option B is updated by the instruction, encoded in the "Rd" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SETPTN_SET_memcms" symboldefcount="2">
      <symbol link="sa_xd">&lt;Xd&gt;</symbol>
      <account encodedin="Rd">
        <docvars>
          <docvar key="mnemonic" value="SETPTN" />
          <docvar key="pme" value="pme-prologue" />
        </docvars>
        <intro>
          <para>For the prologue variant: is the 64-bit name of the general-purpose register that holds the destination address and is updated by the instruction, encoded in the "Rd" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SETETN_SET_memcms" symboldefcount="1">
      <symbol link="sa_xn_2">&lt;Xn&gt;</symbol>
      <account encodedin="Rn">
        <docvars>
          <docvar key="mnemonic" value="SETETN" />
          <docvar key="pme" value="pme-epilogue" />
        </docvars>
        <intro>
          <para>For the epilogue variant: is the 64-bit name of the general-purpose register that holds the number of bytes to be set and is set to zero at the end of the instruction, encoded in the "Rn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SETMTN_SET_memcms" symboldefcount="2">
      <symbol link="sa_xn_1">&lt;Xn&gt;</symbol>
      <account encodedin="Rn">
        <docvars>
          <docvar key="mnemonic" value="SETMTN" />
          <docvar key="pme" value="pme-main" />
        </docvars>
        <intro>
          <para>For the main variant: is the 64-bit name of the general-purpose register that holds an encoding of the number of bytes to be set and is updated by the instruction, encoded in the "Rn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SETPTN_SET_memcms" symboldefcount="3">
      <symbol link="sa_xn">&lt;Xn&gt;</symbol>
      <account encodedin="Rn">
        <docvars>
          <docvar key="mnemonic" value="SETPTN" />
          <docvar key="pme" value="pme-prologue" />
        </docvars>
        <intro>
          <para>For the prologue variant: is the 64-bit name of the general-purpose register that holds the number of bytes to be set and is updated by the instruction, encoded in the "Rn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SETPTN_SET_memcms, SETMTN_SET_memcms, SETETN_SET_memcms" symboldefcount="1">
      <symbol link="sa_xs">&lt;Xs&gt;</symbol>
      <account encodedin="Rs">
        <intro>
          <para>Is the 64-bit name of the general-purpose register that holds the source data, encoded in the "Rs" field.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="aarch64/instrs/memory/mcpymset/set" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute">bits(64) toaddress = <a link="impl-aarch64.X.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) X[integer n, integer width]">X</a>[d, 64];
bits(64) setsize   = <a link="impl-aarch64.X.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) X[integer n, integer width]">X</a>[n, 64];
bits(8) data = <a link="impl-aarch64.X.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) X[integer n, integer width]">X</a>[s, 8];
bits(4) nzcv = PSTATE.&lt;N,Z,C,V&gt;;
bits(64) stagesetsize;
boolean is_setg = FALSE;
integer B;

boolean supports_option_a = <a link="impl-aarch64.SETOptionA.0" file="shared_pseudocode.xml" hover="function: boolean SETOptionA()">SETOptionA</a>();
boolean privileged;

case PSTATE.EL of
    when <a link="EL0" file="shared_pseudocode.xml" hover="constant bits(2) EL0 = '00'">EL0</a>
        privileged = FALSE;
    when <a link="EL1" file="shared_pseudocode.xml" hover="constant bits(2) EL1 = '01'">EL1</a>
        if <a link="impl-shared.EL2Enabled.0" file="shared_pseudocode.xml" hover="function: boolean EL2Enabled()">EL2Enabled</a>() &amp;&amp; <a link="impl-shared.HaveNVExt.0" file="shared_pseudocode.xml" hover="function: boolean HaveNVExt()">HaveNVExt</a>() &amp;&amp; HCR_EL2.&lt;NV,NV1&gt; == '11' then
            privileged = TRUE;
        else
            privileged = options&lt;0&gt; == '0';
    when <a link="EL2" file="shared_pseudocode.xml" hover="constant bits(2) EL2 = '10'">EL2</a>
        if <a link="impl-shared.HaveVirtHostExt.0" file="shared_pseudocode.xml" hover="function: boolean HaveVirtHostExt()">HaveVirtHostExt</a>() &amp;&amp; HCR_EL2.&lt;E2H,TGE&gt; == '11' then
            privileged = options&lt;0&gt; == '0';
        else
            privileged = TRUE;
    when <a link="EL3" file="shared_pseudocode.xml" hover="constant bits(2) EL3 = '11'">EL3</a>
        privileged = TRUE;

if <a link="impl-shared.HaveUAOExt.0" file="shared_pseudocode.xml" hover="function: boolean HaveUAOExt()">HaveUAOExt</a>() &amp;&amp; PSTATE.UAO == '1' then
    privileged = PSTATE.EL != <a link="EL0" file="shared_pseudocode.xml" hover="constant bits(2) EL0 = '00'">EL0</a>;

boolean nontemporal = options&lt;1&gt; == '1';
<a link="AccessDescriptor" file="shared_pseudocode.xml" hover="type AccessDescriptor is ( AccessType acctype, bits(2) el, SecurityState ss, boolean acqsc, boolean acqpc, boolean relsc, boolean limitedordered, boolean exclusive, boolean atomicop, MemAtomicOp modop, boolean nontemporal, boolean read, boolean write, CacheOp cacheop, CacheOpScope opscope, CacheType cachetype, boolean pan, boolean transactional, boolean nonfault, boolean firstfault, boolean first, boolean contiguous, boolean streamingsve, boolean ls64, boolean mops, boolean rcw, boolean rcws, boolean toplevel, VARange varange, boolean a32lsmd, boolean tagchecked, boolean tagaccess, MPAMinfo mpam )">AccessDescriptor</a> accdesc = <a link="impl-shared.CreateAccDescMOPS.3" file="shared_pseudocode.xml" hover="function: AccessDescriptor CreateAccDescMOPS(MemOp memop, boolean privileged, boolean nontemporal)">CreateAccDescMOPS</a>(<a link="MemOp_STORE" file="shared_pseudocode.xml" hover="enumeration MemOp {MemOp_LOAD, MemOp_STORE, MemOp_PREFETCH}">MemOp_STORE</a>, privileged, nontemporal);

if stage == <a link="MOPSStage_Prologue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Prologue</a> then
    if setsize&lt;63&gt; == '1' then setsize = 0x7FFFFFFFFFFFFFFF&lt;63:0&gt;;

    if supports_option_a then
        nzcv = '0000';
        toaddress = toaddress + setsize;
        setsize   = <a link="impl-shared.Zeros.1" file="shared_pseudocode.xml" hover="function: bits(N) Zeros(integer N)">Zeros</a>(64) - setsize;
    else
        nzcv = '0010';

    stagesetsize = <a link="impl-aarch64.SETPreSizeChoice.3" file="shared_pseudocode.xml" hover="function: bits(64) SETPreSizeChoice(bits(64) toaddress, bits(64) setsize, boolean IsSETGP)">SETPreSizeChoice</a>(toaddress, setsize, is_setg);
    assert stagesetsize&lt;63&gt; == setsize&lt;63&gt; || stagesetsize == <a link="impl-shared.Zeros.1" file="shared_pseudocode.xml" hover="function: bits(N) Zeros(integer N)">Zeros</a>(64);

    if <a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(setsize) &gt; 0 then
        assert <a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(stagesetsize) &lt;= <a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(setsize);
    else
        assert <a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(stagesetsize) &gt;= <a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(setsize);
else
    bits(64) postsize = <a link="impl-aarch64.SETPostSizeChoice.3" file="shared_pseudocode.xml" hover="function: bits(64) SETPostSizeChoice(bits(64) toaddress, bits(64) setsize, boolean IsSETGE)">SETPostSizeChoice</a>(toaddress, setsize, is_setg);
    assert postsize&lt;63&gt; == setsize&lt;63&gt; || postsize == <a link="impl-shared.Zeros.1" file="shared_pseudocode.xml" hover="function: bits(N) Zeros(integer N)">Zeros</a>(64);

    boolean zero_size_exceptions = <a link="impl-aarch64.MemSetZeroSizeCheck.0" file="shared_pseudocode.xml" hover="function: boolean MemSetZeroSizeCheck()">MemSetZeroSizeCheck</a>();

    // Check if this version is consistent with the state of the call.
    if zero_size_exceptions || <a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(setsize) != 0 then
        if supports_option_a then
            if nzcv&lt;1&gt; == '1' then   // PSTATE.C
                boolean wrong_option  = TRUE;
                boolean from_epilogue = stage == <a link="MOPSStage_Epilogue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Epilogue</a>;
                <a link="impl-aarch64.MismatchedMemSetException.8" file="shared_pseudocode.xml" hover="function: MismatchedMemSetException(boolean option_a, integer destreg, integer datareg, integer sizereg, boolean wrong_option, boolean from_epilogue, bits(2) options, boolean is_SETG)">MismatchedMemSetException</a>(supports_option_a, d, s, n, wrong_option,
                from_epilogue, options, is_setg);
        else
            if nzcv&lt;1&gt; == '0' then   // PSTATE.C
                boolean wrong_option  = TRUE;
                boolean from_epilogue = stage == <a link="MOPSStage_Epilogue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Epilogue</a>;
                <a link="impl-aarch64.MismatchedMemSetException.8" file="shared_pseudocode.xml" hover="function: MismatchedMemSetException(boolean option_a, integer destreg, integer datareg, integer sizereg, boolean wrong_option, boolean from_epilogue, bits(2) options, boolean is_SETG)">MismatchedMemSetException</a>(supports_option_a, d, s, n, wrong_option,
                from_epilogue, options, is_setg);

    if stage == <a link="MOPSStage_Main" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Main</a> then
        stagesetsize = setsize - postsize;
        if <a link="impl-aarch64.MemSetParametersIllformedM.3" file="shared_pseudocode.xml" hover="function: boolean MemSetParametersIllformedM(bits(64) toaddress, bits(64) setsize, boolean IsSETGM)">MemSetParametersIllformedM</a>(toaddress, setsize, is_setg) then
            boolean wrong_option  = FALSE;
            boolean from_epilogue = FALSE;
            <a link="impl-aarch64.MismatchedMemSetException.8" file="shared_pseudocode.xml" hover="function: MismatchedMemSetException(boolean option_a, integer destreg, integer datareg, integer sizereg, boolean wrong_option, boolean from_epilogue, bits(2) options, boolean is_SETG)">MismatchedMemSetException</a>(supports_option_a, d, s, n, wrong_option,
            from_epilogue, options, is_setg);
    else
        stagesetsize = postsize;
        if (setsize != postsize || <a link="impl-aarch64.MemSetParametersIllformedE.3" file="shared_pseudocode.xml" hover="function: boolean MemSetParametersIllformedE(bits(64) toaddress, bits(64) setsize, boolean IsSETGE)">MemSetParametersIllformedE</a>(toaddress, setsize, is_setg)) then
            boolean wrong_option  = FALSE;
            boolean from_epilogue = TRUE;
            <a link="impl-aarch64.MismatchedMemSetException.8" file="shared_pseudocode.xml" hover="function: MismatchedMemSetException(boolean option_a, integer destreg, integer datareg, integer sizereg, boolean wrong_option, boolean from_epilogue, bits(2) options, boolean is_SETG)">MismatchedMemSetException</a>(supports_option_a, d, s, n, wrong_option,
            from_epilogue, options, is_setg);

if supports_option_a then
    while <a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(stagesetsize) &lt; 0 do
        // IMP DEF selection of the block size that is worked on. While many
        // implementations might make this constant, that is not assumed.
        B = <a link="impl-aarch64.SETSizeChoice.3" file="shared_pseudocode.xml" hover="function: integer SETSizeChoice(bits(64) toaddress, bits(64) setsize, integer AlignSize)">SETSizeChoice</a>(toaddress, setsize, 1);
        assert B &lt;= -1*<a link="impl-shared.SInt.1" file="shared_pseudocode.xml" hover="function: integer SInt(bits(N) x)">SInt</a>(stagesetsize);

        Mem[toaddress + setsize, B, accdesc] = <a link="impl-shared.Replicate.2" file="shared_pseudocode.xml" hover="function: bits(M*N) Replicate(bits(M) x, integer N)">Replicate</a>(data, B);
        setsize = setsize + B;
        stagesetsize = stagesetsize + B;
        if stage != <a link="MOPSStage_Prologue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Prologue</a> then
            <a link="impl-aarch64.X.write.2" file="shared_pseudocode.xml" hover="accessor: X[integer n, integer width] = bits(width) value">X</a>[n, 64] = setsize;
else
    while <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(stagesetsize) &gt; 0 do
        // IMP DEF selection of the block size that is worked on. While many
        // implementations might make this constant, that is not assumed.
        B = <a link="impl-aarch64.SETSizeChoice.3" file="shared_pseudocode.xml" hover="function: integer SETSizeChoice(bits(64) toaddress, bits(64) setsize, integer AlignSize)">SETSizeChoice</a>(toaddress, setsize, 1);
        assert B &lt;= <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(stagesetsize);

        Mem[toaddress, B, accdesc] = <a link="impl-shared.Replicate.2" file="shared_pseudocode.xml" hover="function: bits(M*N) Replicate(bits(M) x, integer N)">Replicate</a>(data, B);
        toaddress = toaddress + B;
        setsize = setsize - B;
        stagesetsize = stagesetsize - B;
        if stage != <a link="MOPSStage_Prologue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Prologue</a> then
            <a link="impl-aarch64.X.write.2" file="shared_pseudocode.xml" hover="accessor: X[integer n, integer width] = bits(width) value">X</a>[n, 64] = setsize;
            <a link="impl-aarch64.X.write.2" file="shared_pseudocode.xml" hover="accessor: X[integer n, integer width] = bits(width) value">X</a>[d, 64] = toaddress;

if stage == <a link="MOPSStage_Prologue" file="shared_pseudocode.xml" hover="enumeration MOPSStage { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue }">MOPSStage_Prologue</a> then
    <a link="impl-aarch64.X.write.2" file="shared_pseudocode.xml" hover="accessor: X[integer n, integer width] = bits(width) value">X</a>[n, 64] = setsize;
    <a link="impl-aarch64.X.write.2" file="shared_pseudocode.xml" hover="accessor: X[integer n, integer width] = bits(width) value">X</a>[d, 64] = toaddress;
    PSTATE.&lt;N,Z,C,V&gt; = nzcv;</pstext>
    </ps>
  </ps_section>
</instructionsection>
