<?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="wrffr_f_p" title="WRFFR" type="instruction">
  <docvars>
    <docvar key="instr-class" value="sve" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="WRFFR" />
  </docvars>
  <heading>WRFFR</heading>
  <desc>
    <brief>Write the first-fault register</brief>
    <description>
      <para>Read the source predicate register and place in the first-fault register (<asm-code>FFR</asm-code>). This instruction is intended to restore a saved <asm-code>FFR</asm-code> and is not recommended for general use by applications.</para>
      <para>This instruction requires that the source predicate contains a <arm-defined-word>monotonic</arm-defined-word> predicate value, in which starting from bit 0 there are zero or more <value>1</value> bits, followed only by <value>0</value> bits in any remaining bit positions. If the source is not a monotonic predicate value, then the resulting value in the <asm-code>FFR</asm-code> will be UNPREDICTABLE. It is not possible to generate a non-monotonic value in <asm-code>FFR</asm-code> when using <instruction>SETFFR</instruction> followed by first-fault or non-fault loads.</para>
      <para>This instruction is illegal when executed in Streaming SVE mode, unless FEAT_SME_FA64 is implemented and enabled.</para>
    </description>
    <status>Green</status>
    <predicated>False</predicated>
    <uses_dit condition="FEAT_SVE2 is implemented or FEAT_SME is implemented">True</uses_dit>
    <sm_policy>SM_0_only</sm_policy>
  </desc>
  <alias_list howmany="0"></alias_list>
  <classes>
    <iclass name="SVE" oneof="1" id="iclass_sve" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="instr-class" value="sve" />
        <docvar key="isa" value="A64" />
        <docvar key="mnemonic" value="WRFFR" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <regdiagram form="32" psname="WRFFR-F.P-_">
        <box hibit="31" width="2" settings="2">
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="29" width="6" settings="6">
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="23" name="opc&lt;1&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="22" name="opc&lt;0&gt;" settings="1">
          <c>0</c>
        </box>
        <box hibit="21" width="2" settings="2">
          <c>1</c>
          <c>0</c>
        </box>
        <box hibit="19" width="10" settings="10">
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</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" settings="1">
          <c>0</c>
        </box>
        <box hibit="2" settings="1">
          <c>0</c>
        </box>
        <box hibit="1" width="2" settings="2">
          <c>0</c>
          <c>0</c>
        </box>
      </regdiagram>
      <encoding name="wrffr_f_p_" oneofinclass="1" oneof="1" label="">
        <docvars>
          <docvar key="instr-class" value="sve" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="WRFFR" />
        </docvars>
        <asmtemplate><text>WRFFR   </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="WRFFR-F.P-_" mylink="WRFFR-F.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>() then UNDEFINED;
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Pn);</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="wrffr_f_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="WRFFR-F.P-_" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute"><a link="impl-aarch64.CheckNonStreamingSVEEnabled.0" file="shared_pseudocode.xml" hover="function: CheckNonStreamingSVEEnabled()">CheckNonStreamingSVEEnabled</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;
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];

constant integer hsb = <a link="impl-shared.HighestSetBit.1" file="shared_pseudocode.xml" hover="function: integer HighestSetBit(bits(N) x)">HighestSetBit</a>(operand);
if hsb &lt; 0 || <a link="impl-shared.IsOnes.1" file="shared_pseudocode.xml" hover="function: boolean IsOnes(bits(N) x)">IsOnes</a>(operand&lt;hsb:0&gt;) then
    <a link="impl-aarch64.FFR.write.1" file="shared_pseudocode.xml" hover="accessor: FFR[integer width] = bits(width) value">FFR</a>[PL] = operand;
else // not a monotonic predicate
    <a link="impl-aarch64.FFR.write.1" file="shared_pseudocode.xml" hover="accessor: FFR[integer width] = bits(width) value">FFR</a>[PL] = bits(PL) UNKNOWN;</pstext>
    </ps>
  </ps_section>
</instructionsection>
