<?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="punpkhi_p_p" title="PUNPKHI, PUNPKLO" type="instruction">
  <docvars>
    <docvar key="instr-class" value="sve" />
    <docvar key="isa" value="A64" />
  </docvars>
  <heading>PUNPKHI, PUNPKLO</heading>
  <desc>
    <brief>Unpack and widen half of predicate</brief>
    <description>
      <para>Unpack elements from the lowest or highest half of the source predicate and place in elements of twice their size within the destination predicate. This instruction is unpredicated.</para>
    </description>
    <status>Green</status>
    <predicated>False</predicated>
    <uses_dit condition="FEAT_SVE2 is implemented or FEAT_SME is implemented">True</uses_dit>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <classesintro count="2">
      <txt>It has encodings from 2 classes:</txt>
      <a href="#iclass_sve_high_half">High half</a>
      <txt> and </txt>
      <a href="#iclass_sve_low_half">Low half</a>
    </classesintro>
    <iclass name="High half" oneof="2" id="iclass_sve_high_half" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="instr-class" value="sve" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="PUNPKHI" />
        <docvar key="sve-half" value="sve-high-half" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <regdiagram form="32" psname="PUNPKHI-P.P-_" tworows="1">
        <box hibit="31" width="15" settings="15">
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="16" name="H" usename="1" settings="1">
          <c>1</c>
        </box>
        <box hibit="15" width="6" settings="6">
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="9" settings="1">
          <c>0</c>
        </box>
        <box hibit="8" width="4" name="Pn" usename="1">
          <c colspan="4"></c>
        </box>
        <box hibit="4" settings="1">
          <c>0</c>
        </box>
        <box hibit="3" width="4" name="Pd" usename="1">
          <c colspan="4"></c>
        </box>
      </regdiagram>
      <encoding name="punpkhi_p_p_" oneofinclass="1" oneof="2" label="">
        <docvars>
          <docvar key="instr-class" value="sve" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="PUNPKHI" />
          <docvar key="sve-half" value="sve-high-half" />
        </docvars>
        <asmtemplate><text>PUNPKHI </text><a link="sa_pd" hover="Destination scalable predicate register (field &quot;Pd&quot;)">&lt;Pd&gt;</a><text>.H, </text><a link="sa_pn" hover="Source scalable predicate register (field &quot;Pn&quot;)">&lt;Pn&gt;</a><text>.B</text></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="PUNPKHI-P.P-_" mylink="PUNPKHI-P.P-_" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-aarch64.HaveSVE.0" file="shared_pseudocode.xml" hover="function: boolean HaveSVE()">HaveSVE</a>() &amp;&amp; !<a link="impl-aarch64.HaveSME.0" file="shared_pseudocode.xml" hover="function: boolean HaveSME()">HaveSME</a>() then UNDEFINED;
constant integer esize = 16;
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pn);
integer d = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pd);
boolean hi = TRUE;</pstext>
        </ps>
      </ps_section>
    </iclass>
    <iclass name="Low half" oneof="2" id="iclass_sve_low_half" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="instr-class" value="sve" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="PUNPKLO" />
        <docvar key="sve-half" value="sve-low-half" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <regdiagram form="32" psname="PUNPKLO-P.P-_" tworows="1">
        <box hibit="31" width="15" settings="15">
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="16" name="H" usename="1" settings="1">
          <c>0</c>
        </box>
        <box hibit="15" width="6" settings="6">
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="9" settings="1">
          <c>0</c>
        </box>
        <box hibit="8" width="4" name="Pn" usename="1">
          <c colspan="4"></c>
        </box>
        <box hibit="4" settings="1">
          <c>0</c>
        </box>
        <box hibit="3" width="4" name="Pd" usename="1">
          <c colspan="4"></c>
        </box>
      </regdiagram>
      <encoding name="punpklo_p_p_" oneofinclass="1" oneof="2" label="">
        <docvars>
          <docvar key="instr-class" value="sve" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="PUNPKLO" />
          <docvar key="sve-half" value="sve-low-half" />
        </docvars>
        <asmtemplate><text>PUNPKLO </text><a link="sa_pd" hover="Destination scalable predicate register (field &quot;Pd&quot;)">&lt;Pd&gt;</a><text>.H, </text><a link="sa_pn" hover="Source scalable predicate register (field &quot;Pn&quot;)">&lt;Pn&gt;</a><text>.B</text></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="PUNPKLO-P.P-_" mylink="PUNPKLO-P.P-_" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-aarch64.HaveSVE.0" file="shared_pseudocode.xml" hover="function: boolean HaveSVE()">HaveSVE</a>() &amp;&amp; !<a link="impl-aarch64.HaveSME.0" file="shared_pseudocode.xml" hover="function: boolean HaveSME()">HaveSME</a>() then UNDEFINED;
constant integer esize = 16;
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pn);
integer d = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pd);
boolean hi = FALSE;</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="punpkhi_p_p_, punpklo_p_p_" symboldefcount="1">
      <symbol link="sa_pd">&lt;Pd&gt;</symbol>
      <account encodedin="Pd">
        <intro>
          <para>Is the name of the destination scalable predicate register, encoded in the "Pd" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="punpkhi_p_p_, punpklo_p_p_" symboldefcount="1">
      <symbol link="sa_pn">&lt;Pn&gt;</symbol>
      <account encodedin="Pn">
        <intro>
          <para>Is the name of the source scalable predicate register, encoded in the "Pn" field.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="PUNPKHI-P.P-_" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute"><a link="impl-aarch64.CheckSVEEnabled.0" file="shared_pseudocode.xml" hover="function: CheckSVEEnabled()">CheckSVEEnabled</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 elements = VL DIV esize;
bits(PL) operand = <a link="impl-aarch64.P.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) P[integer n, integer width]">P</a>[n, PL];
bits(PL) result;
constant integer psize = esize DIV 8;

for e = 0 to elements-1
    bit pbit = <a link="impl-aarch64.PredicateElement.3" file="shared_pseudocode.xml" hover="function: bit PredicateElement(bits(N) pred, integer e, integer esize)">PredicateElement</a>(operand, if hi then e + elements else e, esize DIV 2);
    <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, e, psize] = <a link="impl-shared.ZeroExtend.2" file="shared_pseudocode.xml" hover="function: bits(N) ZeroExtend(bits(M) x, integer N)">ZeroExtend</a>(pbit, psize);

<a link="impl-aarch64.P.write.2" file="shared_pseudocode.xml" hover="accessor: P[integer n, integer width] = bits(width) value">P</a>[d, PL] = result;</pstext>
    </ps>
  </ps_section>
</instructionsection>
