<?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="STGM" title="STGM -- A64" type="instruction">
  <docvars>
    <docvar key="instr-class" value="general" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="STGM" />
  </docvars>
  <heading>STGM</heading>
  <desc>
    <brief>
      <para>Store Tag Multiple</para>
    </brief>
    <authored>
      <para>Store Tag Multiple writes a naturally aligned block of N Allocation Tags, where the size of N is identified in GMID_EL1.BS, and the Allocation Tag written to address A is taken from the source register at 4*A&lt;7:4&gt;+3:4*A&lt;7:4&gt;.</para>
      <para>This instruction is <arm-defined-word>undefined</arm-defined-word> at EL0.</para>
      <para>This instruction generates an Unchecked access.</para>
    </authored>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <iclass name="Integer" oneof="1" id="iclass_general" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="instr-class" value="general" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="STGM" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <arch_variants>
        <arch_variant name="ARMv8.5" feature="FEAT_MTE2" />
      </arch_variants>
      <regdiagram form="32" psname="aarch64/instrs/integer/tags/mcsettagarray">
        <box hibit="31" width="8" settings="8">
          <c>1</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="23" name="opc&lt;1&gt;" settings="1">
          <c>1</c>
        </box>
        <box hibit="22" name="opc&lt;0&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="21" settings="1">
          <c>1</c>
        </box>
        <box hibit="20" name="imm9&lt;8&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="19" name="imm9&lt;7&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="18" name="imm9&lt;6&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="17" name="imm9&lt;5&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="16" name="imm9&lt;4&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="15" name="imm9&lt;3&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="14" name="imm9&lt;2&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="13" name="imm9&lt;1&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="12" name="imm9&lt;0&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="11" name="op2&lt;1&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="10" name="op2&lt;0&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="9" width="5" name="Xn" usename="1">
          <c colspan="5"></c>
        </box>
        <box hibit="4" width="5" name="Xt" usename="1">
          <c colspan="5"></c>
        </box>
      </regdiagram>
      <encoding name="STGM_64bulk_ldsttags" oneofinclass="1" oneof="1" label="">
        <docvars>
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="STGM" />
        </docvars>
        <asmtemplate><text>STGM  </text><a link="sa_xt" hover="64-bit general-purpose source register (field &quot;Xt&quot;)">&lt;Xt&gt;</a><text>, [</text><a link="sa_xn_sp" hover="64-bit general-purpose base register or SP (field &quot;Xn&quot;)">&lt;Xn|SP&gt;</a><text>]</text></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="aarch64/instrs/integer/tags/mcsettagarray" mylink="aarch64.instrs.integer.tags.mcsettagarray" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-shared.HaveMTE2Ext.0" file="shared_pseudocode.xml" hover="function: boolean HaveMTE2Ext()">HaveMTE2Ext</a>() then UNDEFINED;
integer t = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Xt);
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Xn);</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="STGM_64bulk_ldsttags" symboldefcount="1">
      <symbol link="sa_xt">&lt;Xt&gt;</symbol>
      <account encodedin="Xt">
        <intro>
          <para>Is the 64-bit name of the general-purpose source register, encoded in the "Xt" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="STGM_64bulk_ldsttags" symboldefcount="1">
      <symbol link="sa_xn_sp">&lt;Xn|SP&gt;</symbol>
      <account encodedin="Xn">
        <intro>
          <para>Is the 64-bit name of the general-purpose base register or stack pointer, encoded in the "Xn" field.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="aarch64/instrs/integer/tags/mcsettagarray" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute">if PSTATE.EL == <a link="EL0" file="shared_pseudocode.xml" hover="constant bits(2) EL0 = '00'">EL0</a> then
    UNDEFINED;

bits(64) data = <a link="impl-aarch64.X.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) X[integer n, integer width]">X</a>[t, 64];
bits(64) address;

if n == 31 then
    <a link="impl-aarch64.CheckSPAlignment.0" file="shared_pseudocode.xml" hover="function: CheckSPAlignment()">CheckSPAlignment</a>();
    address = <a link="impl-aarch64.SP.read.0" file="shared_pseudocode.xml" hover="accessor: bits(64) SP[]">SP</a>[];
else
    address = <a link="impl-aarch64.X.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) X[integer n, integer width]">X</a>[n, 64];

integer size = 4*(2^(<a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(GMID_EL1.BS)));
address = <a link="impl-shared.Align.2" file="shared_pseudocode.xml" hover="function: integer Align(integer x, integer y)">Align</a>(address,size);
integer count = size &gt;&gt; <a link="LOG2_TAG_GRANULE" file="shared_pseudocode.xml" hover="constant integer LOG2_TAG_GRANULE = 4">LOG2_TAG_GRANULE</a>;
integer index = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(address&lt;<a link="LOG2_TAG_GRANULE" file="shared_pseudocode.xml" hover="constant integer LOG2_TAG_GRANULE = 4">LOG2_TAG_GRANULE</a>+3:<a link="LOG2_TAG_GRANULE" file="shared_pseudocode.xml" hover="constant integer LOG2_TAG_GRANULE = 4">LOG2_TAG_GRANULE</a>&gt;);
<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.CreateAccDescLDGSTG.1" file="shared_pseudocode.xml" hover="function: AccessDescriptor CreateAccDescLDGSTG(MemOp memop)">CreateAccDescLDGSTG</a>(<a link="MemOp_STORE" file="shared_pseudocode.xml" hover="enumeration MemOp {MemOp_LOAD, MemOp_STORE, MemOp_PREFETCH}">MemOp_STORE</a>);

for i = 0 to count-1
    bits(4) tag = data&lt;(index*4)+3:index*4&gt;;
    <a link="AArch64.MemTag.write.2" file="shared_pseudocode.xml" hover="accessor: AArch64.MemTag[bits(64) address, AccessDescriptor accdesc_in] = bits(4) value">AArch64.MemTag</a>[address, accdesc] = tag;
    address = address + <a link="TAG_GRANULE" file="shared_pseudocode.xml" hover="constant integer TAG_GRANULE = 1 &lt;&lt; LOG2_TAG_GRANULE">TAG_GRANULE</a>;
    index = index + 1;</pstext>
    </ps>
  </ps_section>
</instructionsection>
