<?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="RMIF" title="RMIF -- A64" type="instruction">
  <docvars>
    <docvar key="instr-class" value="general" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="RMIF" />
  </docvars>
  <heading>RMIF</heading>
  <desc>
    <brief>
      <para>Rotate, Mask Insert Flags</para>
    </brief>
    <authored>
      <para>Performs a rotation right of a value held in a general purpose register by an immediate value, and then inserts a selection of the bottom four bits of the result of the rotation into the PSTATE flags, under the control of a second immediate mask.</para>
    </authored>
  </desc>
  <operationalnotes>
    <para>If PSTATE.DIT is 1:</para>
    <list type="unordered">
      <listitem><content>The execution time of this instruction is independent of:<list type="unordered"><listitem><content>The values of the data supplied in any of its registers.</content></listitem><listitem><content>The values of the NZCV flags.</content></listitem></list></content></listitem>
      <listitem><content>The response of this instruction to asynchronous exceptions does not vary based on:<list type="unordered"><listitem><content>The values of the data supplied in any of its registers.</content></listitem><listitem><content>The values of the NZCV flags.</content></listitem></list></content></listitem>
    </list>
  </operationalnotes>
  <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="RMIF" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <arch_variants>
        <arch_variant name="ARMv8.4" feature="FEAT_FlagM" />
      </arch_variants>
      <regdiagram form="32" psname="aarch64/instrs/integer/flags/rmif" tworows="1">
        <box hibit="31" name="sf" usename="1" settings="1" psbits="x">
          <c>1</c>
        </box>
        <box hibit="30" name="op" settings="1">
          <c>0</c>
        </box>
        <box hibit="29" name="S" settings="1">
          <c>1</c>
        </box>
        <box hibit="28" width="8" settings="8">
          <c>1</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="20" width="6" name="imm6" usename="1">
          <c colspan="6"></c>
        </box>
        <box hibit="14" width="5" settings="5">
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="9" width="5" name="Rn" usename="1">
          <c colspan="5"></c>
        </box>
        <box hibit="4" name="o2" settings="1">
          <c>0</c>
        </box>
        <box hibit="3" width="4" name="mask" usename="1">
          <c colspan="4"></c>
        </box>
      </regdiagram>
      <encoding name="RMIF_only_rmif" oneofinclass="1" oneof="1" label="">
        <docvars>
          <docvar key="instr-class" value="general" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="RMIF" />
        </docvars>
        <asmtemplate><text>RMIF  </text><a link="sa_xn" hover="64-bit general-purpose source register (field &quot;Rn&quot;)">&lt;Xn&gt;</a><text>, #</text><a link="sa_shift" hover="Shift amount [0-63], default 0 (field &quot;imm6&quot;)">&lt;shift&gt;</a><text>, #</text><a link="sa_mask" hover="Flag bit mask, an immediate [0-15], which selects the bits that are inserted into the NZCV condition flags (field &quot;mask&quot;)">&lt;mask&gt;</a></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="aarch64/instrs/integer/flags/rmif" mylink="aarch64.instrs.integer.flags.rmif" enclabels="" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !<a link="impl-shared.HaveFlagManipulateExt.0" file="shared_pseudocode.xml" hover="function: boolean HaveFlagManipulateExt()">HaveFlagManipulateExt</a>() || sf != '1' then UNDEFINED;
integer lsb = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(imm6);
integer n = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Rn);</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="RMIF_only_rmif" symboldefcount="1">
      <symbol link="sa_xn">&lt;Xn&gt;</symbol>
      <account encodedin="Rn">
        <intro>
          <para>Is the 64-bit name of the general-purpose source register, encoded in the "Rn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="RMIF_only_rmif" symboldefcount="1">
      <symbol link="sa_shift">&lt;shift&gt;</symbol>
      <account encodedin="imm6">
        <intro>
          <para>Is the shift amount, in the range 0 to 63, defaulting to 0 and encoded in the "imm6" field,</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="RMIF_only_rmif" symboldefcount="1">
      <symbol link="sa_mask">&lt;mask&gt;</symbol>
      <account encodedin="mask">
        <intro>
          <para>Is the flag bit mask, an immediate in the range 0 to 15, which selects the bits that are inserted into the NZCV condition flags, encoded in the "mask" field.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="aarch64/instrs/integer/flags/rmif" mylink="execute" enclabels="" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute">bits(4) tmp;
bits(64) tmpreg = <a link="impl-aarch64.X.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) X[integer n, integer width]">X</a>[n, 64];
tmp = (tmpreg:tmpreg)&lt;lsb+3:lsb&gt;;
if mask&lt;3&gt; == '1' then PSTATE.N = tmp&lt;3&gt;;
if mask&lt;2&gt; == '1' then PSTATE.Z = tmp&lt;2&gt;;
if mask&lt;1&gt; == '1' then PSTATE.C = tmp&lt;1&gt;;
if mask&lt;0&gt; == '1' then PSTATE.V = tmp&lt;0&gt;;</pstext>
    </ps>
  </ps_section>
</instructionsection>
