<?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-2025 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="SQRSHRN_advsimd" title="SQRSHRN, SQRSHRN2 -- A64" type="instruction">
  <docvars>
    <docvar key="instr-class" value="advsimd"/>
    <docvar key="isa" value="A64"/>
    <docvar key="mnemonic" value="SQRSHRN"/>
  </docvars>
  <heading>SQRSHRN, SQRSHRN2</heading>
  <desc>
    <brief>
      <para>Signed saturating rounded shift right narrow (immediate)</para>
    </brief>
    <authored>
      <para>This instruction reads
each vector element in the
 source SIMD&amp;FP
register,
right shifts each result by an immediate value,
saturates each shifted result to a value
that is half the original width,
puts the final result into a vector,
and writes the vector to the
lower or upper half of the destination SIMD&amp;FP register.
All the values in this instruction are signed integer values.
The destination vector elements are half as long as the source vector elements.
The results are rounded. For truncated results, see
<xref linkend="ARMARM_A64.instructions.SQSHRN_advsimd">SQSHRN</xref>.</para>
      <para>The <instruction>SQRSHRN</instruction> instruction writes the vector
to the lower half of the
destination register and clears the upper half.
The <instruction>SQRSHRN2</instruction> instruction writes the vector
to the upper half of the
destination register without affecting the other bits of the register.</para>
      <para>If saturation occurs, the cumulative saturation bit
<register_link id="AArch64-fpsr.xml" state="AArch64">FPSR</register_link>.QC is set.</para>
      <para>Depending on the settings in the <register_link id="AArch64-cpacr_el1.xml" state="AArch64">CPACR_EL1</register_link>,
  <register_link id="AArch64-cptr_el2.xml" state="AArch64">CPTR_EL2</register_link>, and <register_link id="AArch64-cptr_el3.xml" state="AArch64">CPTR_EL3</register_link> registers,
  and the current Security state and Exception level,
  an attempt to execute the instruction might be trapped.</para>
    </authored>
  </desc>
  <alias_list howmany="0"/>
  <classes>
    <classesintro count="2">
      <txt>It has encodings from 2 classes:</txt>
      <a href="#iclass_scalar">Scalar</a>
      <txt> and </txt>
      <a href="#iclass_vector">Vector</a>
    </classesintro>
    <iclass name="Scalar" oneof="2" id="iclass_scalar" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="advsimd-type" value="sisd"/>
        <docvar key="instr-class" value="advsimd"/>
        <docvar key="isa" value="A64"/>
        <docvar key="mnemonic" value="SQRSHRN"/>
      </docvars>
      <iclassintro count="1"/>
      <arch_variants>
        <arch_variant feature="FEAT_AdvSIMD" name="v8Ap0"/>
      </arch_variants>
      <regdiagram form="32" psname="A64.simd_dp.asisdshf.SQRSHRN_asisdshf_N" tworows="1">
        <box hibit="31" width="2" settings="2">
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="29" name="U" usename="1" settings="1" psbits="x">
          <c>0</c>
        </box>
        <box hibit="28" width="1" settings="1">
          <c>1</c>
        </box>
        <box hibit="27" width="3" settings="3">
          <c>1</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="24" width="2" settings="2">
          <c>1</c>
          <c>0</c>
        </box>
        <box hibit="22" width="4" name="immh" usename="1" settings="4" constraint="!= 0000">
          <c colspan="4">!= 0000</c>
        </box>
        <box hibit="18" width="3" name="immb" usename="1">
          <c colspan="3"/>
        </box>
        <box hibit="15" width="4" settings="4">
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="11" name="op" usename="1" settings="1" psbits="x">
          <c>1</c>
        </box>
        <box hibit="10" width="1" settings="1">
          <c>1</c>
        </box>
        <box hibit="9" width="5" name="Rn" usename="1">
          <c colspan="5"/>
        </box>
        <box hibit="4" width="5" name="Rd" usename="1">
          <c colspan="5"/>
        </box>
      </regdiagram>
      <encoding name="SQRSHRN_asisdshf_N" oneofinclass="1" oneof="2" label="">
        <docvars>
          <docvar key="advsimd-type" value="sisd"/>
          <docvar key="instr-class" value="advsimd"/>
          <docvar key="isa" value="A64"/>
          <docvar key="mnemonic" value="SQRSHRN"/>
        </docvars>
        <asmtemplate><text>SQRSHRN  </text><a hover="Is the destination width specifier, " link="Vb_option">&lt;Vb&gt;</a><a hover="Is the number of the SIMD&amp;FP destination register, encoded in the &quot;Rd&quot; field." link="d">&lt;d&gt;</a><text>, </text><a hover="Is the source width specifier, " link="Va_option">&lt;Va&gt;</a><a hover="Is the number of the SIMD&amp;FP source register, encoded in the &quot;Rn&quot; field." link="n__3">&lt;n&gt;</a><text>, #</text><a hover="For the &quot;Scalar&quot; variant: is the right shift amount, in the range 1 to the destination operand width in bits, " link="immh_shift__2">&lt;shift&gt;</a></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="A64.simd_dp.asisdshf.SQRSHRN_asisdshf_N" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !IsFeatureImplemented(FEAT_AdvSIMD) then EndOfDecode(Decode_UNDEF); end;
if immh == '0000' then EndOfDecode(Decode_UNDEF); end;
if immh[3] == '1' then EndOfDecode(Decode_UNDEF); end;

let d : integer{} = UInt(Rd);
let n : integer{} = UInt(Rn);
let esize : integer{} = 8 &lt;&lt; HighestSetBitNZ(immh[2:0]);
let datasize : integer{} = esize;
let elements : integer = 1;
let part : integer = 0;

let shift : integer = (2 * esize) - UInt(immh::immb);
let round : boolean = TRUE;
let unsigned : boolean = FALSE;</pstext></ps>
      </ps_section>
    </iclass>
    <iclass name="Vector" oneof="2" id="iclass_vector" no_encodings="1" isa="A64">
      <docvars>
        <docvar key="advsimd-type" value="simd"/>
        <docvar key="instr-class" value="advsimd"/>
        <docvar key="isa" value="A64"/>
        <docvar key="mnemonic" value="SQRSHRN"/>
      </docvars>
      <iclassintro count="1"/>
      <arch_variants>
        <arch_variant feature="FEAT_AdvSIMD" name="v8Ap0"/>
      </arch_variants>
      <regdiagram form="32" psname="A64.simd_dp.asimdshf.SQRSHRN_asimdshf_N" tworows="1">
        <box hibit="31" width="1" settings="1">
          <c>0</c>
        </box>
        <box hibit="30" width="1" name="Q" usename="1">
          <c colspan="1"/>
        </box>
        <box hibit="29" name="U" usename="1" settings="1" psbits="x">
          <c>0</c>
        </box>
        <box hibit="28" width="1" settings="1">
          <c>0</c>
        </box>
        <box hibit="27" width="3" settings="3">
          <c>1</c>
          <c>1</c>
          <c>1</c>
        </box>
        <box hibit="24" width="2" settings="2">
          <c>1</c>
          <c>0</c>
        </box>
        <box hibit="22" width="4" name="immh" usename="1" settings="4" constraint="!= 0000">
          <c colspan="4">!= 0000</c>
        </box>
        <box hibit="18" width="3" name="immb" usename="1">
          <c colspan="3"/>
        </box>
        <box hibit="15" width="4" settings="4">
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="11" name="op" usename="1" settings="1" psbits="x">
          <c>1</c>
        </box>
        <box hibit="10" width="1" settings="1">
          <c>1</c>
        </box>
        <box hibit="9" width="5" name="Rn" usename="1">
          <c colspan="5"/>
        </box>
        <box hibit="4" width="5" name="Rd" usename="1">
          <c colspan="5"/>
        </box>
      </regdiagram>
      <encoding name="SQRSHRN_asimdshf_N" oneofinclass="1" oneof="2" label="">
        <docvars>
          <docvar key="advsimd-type" value="simd"/>
          <docvar key="instr-class" value="advsimd"/>
          <docvar key="isa" value="A64"/>
          <docvar key="mnemonic" value="SQRSHRN"/>
        </docvars>
        <asmtemplate><text>SQRSHRN{</text><a hover="Is the second and upper half specifier. If present it causes the operation to be performed on the upper 64 bits of the registers holding the narrower elements, and is " link="s_2_option">2</a><text>}  </text><a hover="Is the name of the SIMD&amp;FP destination register, encoded in the &quot;Rd&quot; field." link="Vd">&lt;Vd&gt;</a><text>.</text><a hover="Is an arrangement specifier, " link="Tb_option">&lt;Tb&gt;</a><text>, </text><a hover="Is the name of the SIMD&amp;FP source register, encoded in the &quot;Rn&quot; field." link="Vn">&lt;Vn&gt;</a><text>.</text><a hover="Is an arrangement specifier, " link="Ta_option">&lt;Ta&gt;</a><text>, #</text><a hover="For the &quot;Vector&quot; variant: is the right shift amount, in the range 1 to the destination element width in bits, " link="immh_shift__6">&lt;shift&gt;</a></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="A64.simd_dp.asimdshf.SQRSHRN_asimdshf_N" sections="1" secttype="noheading">
          <pstext mayhavelinks="1" section="Decode" rep_section="decode">if !IsFeatureImplemented(FEAT_AdvSIMD) then EndOfDecode(Decode_UNDEF); end;
if immh[3] == '1' then EndOfDecode(Decode_UNDEF); end;

let d : integer{} = UInt(Rd);
let n : integer{} = UInt(Rn);
let esize : integer{} = 8 &lt;&lt; HighestSetBitNZ(immh[2:0]);
let datasize : integer{} = 64;
let part : integer = UInt(Q);
let elements : integer = datasize DIV esize;

let shift : integer = (2 * esize) - UInt(immh::immb);
let round : boolean = TRUE;
let unsigned : boolean = FALSE;</pstext></ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="SQRSHRN_asisdshf_N" symboldefcount="1">
      <symbol link="Vb_option">&lt;Vb&gt;</symbol>
      <definition encodedin="immh">
        <intro>Is the destination width specifier, </intro>
        <table class="valuetable">
          <tgroup cols="2">
            <thead>
              <row>
                <entry class="bitfield">immh</entry>
                <entry class="symbol">&lt;Vb&gt;</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">0001</entry>
                <entry class="symbol">B</entry>
              </row>
              <row>
                <entry class="bitfield">001x</entry>
                <entry class="symbol">H</entry>
              </row>
              <row>
                <entry class="bitfield">01xx</entry>
                <entry class="symbol">S</entry>
              </row>
              <row>
                <entry class="bitfield">1xxx</entry>
                <entry class="symbol">RESERVED</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
    <explanation enclist="SQRSHRN_asisdshf_N" symboldefcount="1">
      <symbol link="d">&lt;d&gt;</symbol>
      <account encodedin="Rd">
        <intro>
          <para>Is the number of the SIMD&amp;FP destination register, encoded in the "Rd" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SQRSHRN_asisdshf_N" symboldefcount="1">
      <symbol link="Va_option">&lt;Va&gt;</symbol>
      <definition encodedin="immh">
        <intro>Is the source width specifier, </intro>
        <table class="valuetable">
          <tgroup cols="2">
            <thead>
              <row>
                <entry class="bitfield">immh</entry>
                <entry class="symbol">&lt;Va&gt;</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">0001</entry>
                <entry class="symbol">H</entry>
              </row>
              <row>
                <entry class="bitfield">001x</entry>
                <entry class="symbol">S</entry>
              </row>
              <row>
                <entry class="bitfield">01xx</entry>
                <entry class="symbol">D</entry>
              </row>
              <row>
                <entry class="bitfield">1xxx</entry>
                <entry class="symbol">RESERVED</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
    <explanation enclist="SQRSHRN_asisdshf_N" symboldefcount="1">
      <symbol link="n__3">&lt;n&gt;</symbol>
      <account encodedin="Rn">
        <intro>
          <para>Is the number of the SIMD&amp;FP source register, encoded in the "Rn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SQRSHRN_asisdshf_N" symboldefcount="1">
      <symbol link="immh_shift__2">&lt;shift&gt;</symbol>
      <definition encodedin="(immh :: immb)">
        <intro>For the "Scalar" variant: is the right shift amount, in the range 1 to the destination operand width in bits, </intro>
        <table class="valuetable">
          <tgroup cols="2">
            <thead>
              <row>
                <entry class="bitfield">immh</entry>
                <entry class="symbol">&lt;shift&gt;</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">0001</entry>
                <entry class="symbol">16 - UInt(immh :: immb)</entry>
              </row>
              <row>
                <entry class="bitfield">001x</entry>
                <entry class="symbol">32 - UInt(immh :: immb)</entry>
              </row>
              <row>
                <entry class="bitfield">01xx</entry>
                <entry class="symbol">64 - UInt(immh :: immb)</entry>
              </row>
              <row>
                <entry class="bitfield">1xxx</entry>
                <entry class="symbol">RESERVED</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
    <explanation enclist="SQRSHRN_asimdshf_N" symboldefcount="2">
      <symbol link="immh_shift__6">&lt;shift&gt;</symbol>
      <definition encodedin="(immh :: immb)">
        <intro>For the "Vector" variant: is the right shift amount, in the range 1 to the destination element width in bits, </intro>
        <table class="valuetable">
          <tgroup cols="2">
            <thead>
              <row>
                <entry class="bitfield">immh</entry>
                <entry class="symbol">&lt;shift&gt;</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">0001</entry>
                <entry class="symbol">16 - UInt(immh :: immb)</entry>
              </row>
              <row>
                <entry class="bitfield">001x</entry>
                <entry class="symbol">32 - UInt(immh :: immb)</entry>
              </row>
              <row>
                <entry class="bitfield">01xx</entry>
                <entry class="symbol">64 - UInt(immh :: immb)</entry>
              </row>
              <row>
                <entry class="bitfield">1xxx</entry>
                <entry class="symbol">RESERVED</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
    <explanation enclist="SQRSHRN_asimdshf_N" symboldefcount="1">
      <symbol link="s_2_option">2</symbol>
      <definition encodedin="Q">
        <intro>Is the second and upper half specifier. If present it causes the operation to be performed on the upper 64 bits of the registers holding the narrower elements, and is </intro>
        <table class="valuetable">
          <tgroup cols="2">
            <thead>
              <row>
                <entry class="bitfield">Q</entry>
                <entry class="symbol">2</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">0</entry>
                <entry class="symbol">[absent]</entry>
              </row>
              <row>
                <entry class="bitfield">1</entry>
                <entry class="symbol">[present]</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
    <explanation enclist="SQRSHRN_asimdshf_N" symboldefcount="1">
      <symbol link="Vd">&lt;Vd&gt;</symbol>
      <account encodedin="Rd">
        <intro>
          <para>Is the name of the SIMD&amp;FP destination register, encoded in the "Rd" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SQRSHRN_asimdshf_N" symboldefcount="1">
      <symbol link="Tb_option">&lt;Tb&gt;</symbol>
      <definition encodedin="(immh :: Q)">
        <intro>Is an arrangement specifier, </intro>
        <table class="valuetable">
          <tgroup cols="3">
            <thead>
              <row>
                <entry class="bitfield">immh</entry>
                <entry class="bitfield">Q</entry>
                <entry class="symbol">&lt;Tb&gt;</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">0001</entry>
                <entry class="bitfield">0</entry>
                <entry class="symbol">8B</entry>
              </row>
              <row>
                <entry class="bitfield">0001</entry>
                <entry class="bitfield">1</entry>
                <entry class="symbol">16B</entry>
              </row>
              <row>
                <entry class="bitfield">001x</entry>
                <entry class="bitfield">0</entry>
                <entry class="symbol">4H</entry>
              </row>
              <row>
                <entry class="bitfield">001x</entry>
                <entry class="bitfield">1</entry>
                <entry class="symbol">8H</entry>
              </row>
              <row>
                <entry class="bitfield">01xx</entry>
                <entry class="bitfield">0</entry>
                <entry class="symbol">2S</entry>
              </row>
              <row>
                <entry class="bitfield">01xx</entry>
                <entry class="bitfield">1</entry>
                <entry class="symbol">4S</entry>
              </row>
              <row>
                <entry class="bitfield">1xxx</entry>
                <entry class="bitfield">x</entry>
                <entry class="symbol">RESERVED</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
    <explanation enclist="SQRSHRN_asimdshf_N" symboldefcount="1">
      <symbol link="Vn">&lt;Vn&gt;</symbol>
      <account encodedin="Rn">
        <intro>
          <para>Is the name of the SIMD&amp;FP source register, encoded in the "Rn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="SQRSHRN_asimdshf_N" symboldefcount="1">
      <symbol link="Ta_option">&lt;Ta&gt;</symbol>
      <definition encodedin="immh">
        <intro>Is an arrangement specifier, </intro>
        <table class="valuetable">
          <tgroup cols="2">
            <thead>
              <row>
                <entry class="bitfield">immh</entry>
                <entry class="symbol">&lt;Ta&gt;</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">0001</entry>
                <entry class="symbol">8H</entry>
              </row>
              <row>
                <entry class="bitfield">001x</entry>
                <entry class="symbol">4S</entry>
              </row>
              <row>
                <entry class="bitfield">01xx</entry>
                <entry class="symbol">2D</entry>
              </row>
              <row>
                <entry class="bitfield">1xxx</entry>
                <entry class="symbol">RESERVED</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="A64.simd_dp.asisdshf.SQRSHRN_asisdshf_N" sections="1" secttype="Operation">
      <pstext mayhavelinks="1" section="Execute" rep_section="execute">AArch64_CheckFPAdvSIMDEnabled();
let operand : bits(datasize*2) = V{}(n);
var result : bits(datasize);
var sat : boolean;

for e = 0 to elements-1 do
    let opelt : bits(2*esize) = operand[e*:(2*esize)];
    if unsigned then
        let element : integer = RShr(UInt(opelt), shift, round);
        (result[e*:esize], sat) = UnsignedSatQ{esize}(element);
    else
        let element : integer = RShr(SInt(opelt), shift, round);
        (result[e*:esize], sat) = SignedSatQ{esize}(element);
    end;
    if sat then FPSR().QC = '1'; end;
end;

Vpart{datasize}(d, part) = result;</pstext></ps>
  </ps_section>
  <timestamp>2026-03-12 12:23:09</timestamp>
  <commit_id>2025-09_rel_asl1</commit_id>
</instructionsection>
