<?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="addha_za_pp_z" title="ADDHA" type="instruction">
  <docvars>
    <docvar key="instr-class" value="mortlach" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="ADDHA" />
  </docvars>
  <heading>ADDHA</heading>
  <desc>
    <brief>Add horizontally vector elements to ZA tile</brief>
    <description>
      <para>Add each element of the source vector to the corresponding active element of each horizontal slice of a ZA tile. The tile elements are predicated by a pair of governing predicates. An element of a horizontal slice is considered active if its corresponding element in the second governing predicate is TRUE and the element corresponding to its horizontal slice number in the first governing predicate is TRUE. Inactive elements in the destination tile remain unmodified.</para>
      <para>ID_AA64SMFR0_EL1.I16I64 indicates whether the 64-bit integer variant is implemented.</para>
    </description>
    <status>Green</status>
    <predicated>True</predicated>
    <uses_dit condition="FEAT_SVE2 is implemented or FEAT_SME is implemented">True</uses_dit>
    <sm_policy>SM_1_only</sm_policy>
    <is_gov_pred_pair>True</is_gov_pred_pair>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <classesintro count="2">
      <txt>It has encodings from 2 classes:</txt>
      <a href="#iclass_per_word">32-bit</a>
      <txt> and </txt>
      <a href="#iclass_per_doubleword">64-bit</a>
    </classesintro>
    <iclass name="32-bit" oneof="2" id="iclass_per_word" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="asimdimm-datatype" value="per-word" />
        <docvar key="instr-class" value="mortlach" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="ADDHA" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <arch_variants>
        <arch_variant name="FEAT_SME" feature="FEAT_SME" />
      </arch_variants>
      <regdiagram form="32" psname="ADDHA-ZA.PP.Z-32" tworows="1">
        <box hibit="31" width="2" settings="2">
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="29" width="7" settings="7">
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="22" name="op" settings="1">
          <c>0</c>
        </box>
        <box hibit="21" width="2" settings="2">
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="19" width="3" settings="3">
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="16" name="V" usename="1" settings="1">
          <c>0</c>
        </box>
        <box hibit="15" width="3" name="Pm" usename="1">
          <c colspan="3"></c>
        </box>
        <box hibit="12" width="3" name="Pn" usename="1">
          <c colspan="3"></c>
        </box>
        <box hibit="9" width="5" name="Zn" usename="1">
          <c colspan="5"></c>
        </box>
        <box hibit="4" settings="1">
          <c>0</c>
        </box>
        <box hibit="3" settings="1">
          <c>0</c>
        </box>
        <box hibit="2" settings="1">
          <c>0</c>
        </box>
        <box hibit="1" width="2" name="ZAda" usename="1">
          <c colspan="2"></c>
        </box>
      </regdiagram>
      <encoding name="addha_za_pp_z_32" oneofinclass="1" oneof="2" label="">
        <docvars>
          <docvar key="asimdimm-datatype" value="per-word" />
          <docvar key="instr-class" value="mortlach" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="ADDHA" />
        </docvars>
        <asmtemplate><text>ADDHA   </text><a link="sa_zada" hover="ZA tile ZA0-ZA3 (field &quot;ZAda&quot;)">&lt;ZAda&gt;</a><text>.S, </text><a link="sa_pn" hover="First governing scalable predicate register P0-P7 (field &quot;Pn&quot;)">&lt;Pn&gt;</a><text>/M, </text><a link="sa_pm" hover="Second governing scalable predicate register P0-P7 (field &quot;Pm&quot;)">&lt;Pm&gt;</a><text>/M, </text><a link="sa_zn" hover="Source scalable vector register (field &quot;Zn&quot;)">&lt;Zn&gt;</a><text>.S</text></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="ADDHA-ZA.PP.Z-32" mylink="ADDHA-ZA.PP.Z-32" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-aarch64.HaveSME.0" file="shared_pseudocode.xml" hover="function: boolean HaveSME()">HaveSME</a>() then UNDEFINED;
constant integer esize = 32;
integer a = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pn);
integer b = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pm);
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Zn);
integer da = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(ZAda);</pstext>
        </ps>
      </ps_section>
    </iclass>
    <iclass name="64-bit" oneof="2" id="iclass_per_doubleword" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="asimdimm-datatype" value="per-doubleword" />
        <docvar key="instr-class" value="mortlach" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="ADDHA" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <arch_variants>
        <arch_variant name="FEAT_SME_I16I64" feature="FEAT_SME_I16I64" />
      </arch_variants>
      <regdiagram form="32" psname="ADDHA-ZA.PP.Z-64" tworows="1">
        <box hibit="31" width="2" settings="2">
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="29" width="7" settings="7">
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="22" name="op" settings="1">
          <c>1</c>
        </box>
        <box hibit="21" width="5" settings="5">
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="16" name="V" usename="1" settings="1">
          <c>0</c>
        </box>
        <box hibit="15" width="3" name="Pm" usename="1">
          <c colspan="3"></c>
        </box>
        <box hibit="12" width="3" name="Pn" usename="1">
          <c colspan="3"></c>
        </box>
        <box hibit="9" width="5" name="Zn" usename="1">
          <c colspan="5"></c>
        </box>
        <box hibit="4" settings="1">
          <c>0</c>
        </box>
        <box hibit="3" settings="1">
          <c>0</c>
        </box>
        <box hibit="2" width="3" name="ZAda" usename="1">
          <c colspan="3"></c>
        </box>
      </regdiagram>
      <encoding name="addha_za_pp_z_64" oneofinclass="1" oneof="2" label="">
        <docvars>
          <docvar key="asimdimm-datatype" value="per-doubleword" />
          <docvar key="instr-class" value="mortlach" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="ADDHA" />
        </docvars>
        <asmtemplate><text>ADDHA   </text><a link="sa_zada_1" hover="ZA tile ZA0-ZA7 (field &quot;ZAda&quot;)">&lt;ZAda&gt;</a><text>.D, </text><a link="sa_pn" hover="First governing scalable predicate register P0-P7 (field &quot;Pn&quot;)">&lt;Pn&gt;</a><text>/M, </text><a link="sa_pm" hover="Second governing scalable predicate register P0-P7 (field &quot;Pm&quot;)">&lt;Pm&gt;</a><text>/M, </text><a link="sa_zn" hover="Source scalable vector register (field &quot;Zn&quot;)">&lt;Zn&gt;</a><text>.D</text></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="ADDHA-ZA.PP.Z-64" mylink="ADDHA-ZA.PP.Z-64" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-aarch64.HaveSMEI16I64.0" file="shared_pseudocode.xml" hover="function: boolean HaveSMEI16I64()">HaveSMEI16I64</a>() then UNDEFINED;
constant integer esize = 64;
integer a = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pn);
integer b = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pm);
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Zn);
integer da = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(ZAda);</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="addha_za_pp_z_32" symboldefcount="1">
      <symbol link="sa_zada">&lt;ZAda&gt;</symbol>
      <account encodedin="ZAda">
        <docvars>
          <docvar key="asimdimm-datatype" value="per-word" />
        </docvars>
        <intro>
          <para>For the 32-bit variant: is the name of the ZA tile ZA0-ZA3, encoded in the "ZAda" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="addha_za_pp_z_64" symboldefcount="2">
      <symbol link="sa_zada_1">&lt;ZAda&gt;</symbol>
      <account encodedin="ZAda">
        <docvars>
          <docvar key="asimdimm-datatype" value="per-doubleword" />
        </docvars>
        <intro>
          <para>For the 64-bit variant: is the name of the ZA tile ZA0-ZA7, encoded in the "ZAda" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="addha_za_pp_z_32, addha_za_pp_z_64" symboldefcount="1">
      <symbol link="sa_pn">&lt;Pn&gt;</symbol>
      <account encodedin="Pn">
        <intro>
          <para>Is the name of the first governing scalable predicate register P0-P7, encoded in the "Pn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="addha_za_pp_z_32, addha_za_pp_z_64" symboldefcount="1">
      <symbol link="sa_pm">&lt;Pm&gt;</symbol>
      <account encodedin="Pm">
        <intro>
          <para>Is the name of the second governing scalable predicate register P0-P7, encoded in the "Pm" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="addha_za_pp_z_32, addha_za_pp_z_64" symboldefcount="1">
      <symbol link="sa_zn">&lt;Zn&gt;</symbol>
      <account encodedin="Zn">
        <intro>
          <para>Is the name of the source scalable vector register, encoded in the "Zn" field.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="ADDHA-ZA.PP.Z-32" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute"><a link="impl-aarch64.CheckStreamingSVEAndZAEnabled.0" file="shared_pseudocode.xml" hover="function: CheckStreamingSVEAndZAEnabled()">CheckStreamingSVEAndZAEnabled</a>();
constant integer VL = <a link="impl-aarch64.CurrentVL.read.none" file="shared_pseudocode.xml" hover="accessor: integer CurrentVL">CurrentVL</a>;
constant integer PL = VL DIV 8;
constant integer dim = VL DIV esize;
bits(PL) mask1 = <a link="impl-aarch64.P.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) P[integer n, integer width]">P</a>[a, PL];
bits(PL) mask2 = <a link="impl-aarch64.P.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) P[integer n, integer width]">P</a>[b, PL];
bits(VL) operand_src = <a link="impl-aarch64.Z.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) Z[integer n, integer width]">Z</a>[n, VL];
bits(dim*dim*esize) operand_acc = <a link="impl-aarch64.ZAtile.read.3" file="shared_pseudocode.xml" hover="accessor: bits(width) ZAtile[integer tile, integer esize, integer width]">ZAtile</a>[da, esize, dim*dim*esize];
bits(dim*dim*esize) result;

for col = 0 to dim-1
    bits(esize) element = <a link="impl-shared.Elem.read.3" file="shared_pseudocode.xml" hover="accessor: bits(size) Elem[bits(N) vector, integer e, integer size]">Elem</a>[operand_src, col, esize];
    for row = 0 to dim-1
        bits(esize) res = <a link="impl-shared.Elem.read.3" file="shared_pseudocode.xml" hover="accessor: bits(size) Elem[bits(N) vector, integer e, integer size]">Elem</a>[operand_acc, row*dim+col, esize];
        if (<a link="impl-aarch64.ActivePredicateElement.3" file="shared_pseudocode.xml" hover="function: boolean ActivePredicateElement(bits(N) pred, integer e, integer esize)">ActivePredicateElement</a>(mask1, row, esize) &amp;&amp;
              <a link="impl-aarch64.ActivePredicateElement.3" file="shared_pseudocode.xml" hover="function: boolean ActivePredicateElement(bits(N) pred, integer e, integer esize)">ActivePredicateElement</a>(mask2, col, esize)) then
            res = res + element;
        <a link="impl-shared.Elem.write.3" file="shared_pseudocode.xml" hover="accessor: Elem[bits(N) &amp;vector, integer e, integer size] = bits(size) value">Elem</a>[result, row*dim+col, esize] = res;

<a link="impl-aarch64.ZAtile.write.3" file="shared_pseudocode.xml" hover="accessor: ZAtile[integer tile, integer esize, integer width] = bits(width) value">ZAtile</a>[da, esize, dim*dim*esize] = result;</pstext>
    </ps>
  </ps_section>
</instructionsection>
