<?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="ftmad_z_zzi" title="FTMAD" type="instruction">
  <docvars>
    <docvar key="instr-class" value="sve" />
    <docvar key="isa" value="A64" />
    <docvar key="mnemonic" value="FTMAD" />
  </docvars>
  <heading>FTMAD</heading>
  <desc>
    <brief>Floating-point trigonometric multiply-add coefficient</brief>
    <description>
      <para>The <instruction>FTMAD</instruction> instruction calculates the series terms for either <arm-defined-word>sin(x)</arm-defined-word> or <arm-defined-word>cos(x)</arm-defined-word>, where the argument <arm-defined-word>x</arm-defined-word> has been adjusted to be in the range -π/4 &lt; <arm-defined-word>x</arm-defined-word> ≤ π/4.</para>
      <para>To calculate the series terms of <arm-defined-word>sin(x)</arm-defined-word> and <arm-defined-word>cos(x)</arm-defined-word> the initial source operands of <instruction>FTMAD</instruction> should be zero in the first source vector and <arm-defined-word>x</arm-defined-word><sup>2</sup> in the second source vector. The <instruction>FTMAD</instruction> instruction is then executed eight times to calculate the sum of eight series terms, which gives a result of sufficient precision.</para>
      <para>The <instruction>FTMAD</instruction> instruction multiplies each element of the first source vector by the absolute value of the corresponding element of the second source vector and performs a fused addition of each product with a value obtained from a table of hard-wired coefficients, and places the results destructively in the first source vector.</para>
      <para>The coefficients are different for <arm-defined-word>sin(x)</arm-defined-word> and <arm-defined-word>cos(x)</arm-defined-word>, and are selected by a combination of the sign bit in the second source element and an immediate index in the range 0 to 7.</para>
      <para />
      <para>Double-precision coefficient table for sin(x) (s2&lt;63&gt; == '0')</para>
      <table class="valuetable">
        <tgroup cols="4">
          <thead>
            <row>
              <entry>Index</entry>
              <entry>Hexadecimal</entry>
              <entry>Decimal</entry>
              <entry>Exact Value</entry>
            </row>
          </thead>
          <tbody>
            <row>
              <entry>0</entry>
              <entry>3ff0 0000 0000 0000</entry>
              <entry>1.0</entry>
              <entry>= 1/1!</entry>
            </row>
            <row>
              <entry>1</entry>
              <entry>bfc5 5555 5555 5543</entry>
              <entry>-0.1666666666666661</entry>
              <entry>&gt; -1/3!</entry>
            </row>
            <row>
              <entry>2</entry>
              <entry>3f81 1111 1110 f30c</entry>
              <entry>0.8333333333320002e-02</entry>
              <entry>&lt; 1/5!</entry>
            </row>
            <row>
              <entry>3</entry>
              <entry>bf2a 01a0 19b9 2fc6</entry>
              <entry>-0.1984126982840213e-03</entry>
              <entry>&gt; -1/7!</entry>
            </row>
            <row>
              <entry>4</entry>
              <entry>3ec7 1de3 51f3 d22b</entry>
              <entry>0.2755731329901505e-05</entry>
              <entry>&lt; 1/9!</entry>
            </row>
            <row>
              <entry>5</entry>
              <entry>be5a e5e2 b60f 7b91</entry>
              <entry>-0.2505070584637887e-07</entry>
              <entry>&gt; -1/11!</entry>
            </row>
            <row>
              <entry>6</entry>
              <entry>3de5 d840 8868 552f</entry>
              <entry>0.1589413637195215e-09</entry>
              <entry>&lt; 1/13!</entry>
            </row>
            <row>
              <entry>7</entry>
              <entry>0000 0000 0000 0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/15!</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
      <para>Double-precision coefficient table for cos(x) (s2&lt;63&gt; == '1')</para>
      <table class="valuetable">
        <tgroup cols="4">
          <thead>
            <row>
              <entry>Index</entry>
              <entry>Hexadecimal</entry>
              <entry>Decimal</entry>
              <entry>Exact Value</entry>
            </row>
          </thead>
          <tbody>
            <row>
              <entry>0</entry>
              <entry>3ff0 0000 0000 0000</entry>
              <entry>1.0</entry>
              <entry>= 1/0!</entry>
            </row>
            <row>
              <entry>1</entry>
              <entry>bfe0 0000 0000 0000</entry>
              <entry>-0.5000000000000000</entry>
              <entry>= -1/2!</entry>
            </row>
            <row>
              <entry>2</entry>
              <entry>3fa5 5555 5555 5536</entry>
              <entry>0.4166666666666645e-01</entry>
              <entry>&lt; 1/4!</entry>
            </row>
            <row>
              <entry>3</entry>
              <entry>bf56 c16c 16c1 3a0b</entry>
              <entry>-0.1388888888886111e-02</entry>
              <entry>&gt; -1/6!</entry>
            </row>
            <row>
              <entry>4</entry>
              <entry>3efa 01a0 19b1 e8d8</entry>
              <entry>0.2480158728388683e-04</entry>
              <entry>&lt; 1/8!</entry>
            </row>
            <row>
              <entry>5</entry>
              <entry>be92 7e4f 7282 f468</entry>
              <entry>-0.2755731309913950e-06</entry>
              <entry>&gt; -1/10!</entry>
            </row>
            <row>
              <entry>6</entry>
              <entry>3e21 ee96 d264 1b13</entry>
              <entry>0.2087558253975872e-08</entry>
              <entry>&lt; 1/12!</entry>
            </row>
            <row>
              <entry>7</entry>
              <entry>bda8 f763 80fb b401</entry>
              <entry>-0.1135338700720054e-10</entry>
              <entry>&gt; -1/14!</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
      <para>Single-precision coefficient table for sin(x) (s2&lt;31&gt; == '0')</para>
      <table class="valuetable">
        <tgroup cols="4">
          <thead>
            <row>
              <entry>Index</entry>
              <entry>Hexadecimal</entry>
              <entry>Decimal</entry>
              <entry>Exact Value</entry>
            </row>
          </thead>
          <tbody>
            <row>
              <entry>0</entry>
              <entry>3f80 0000</entry>
              <entry>1.0</entry>
              <entry>= 1/1!</entry>
            </row>
            <row>
              <entry>1</entry>
              <entry>be2a aaab</entry>
              <entry>-1.666666716337e-01</entry>
              <entry>&gt; -1/3!</entry>
            </row>
            <row>
              <entry>2</entry>
              <entry>3c08 8886</entry>
              <entry>8.333330973983e-03</entry>
              <entry>&lt; 1/5!</entry>
            </row>
            <row>
              <entry>3</entry>
              <entry>b950 08b9</entry>
              <entry>-1.983967522392e-04</entry>
              <entry>&gt; -1/7!</entry>
            </row>
            <row>
              <entry>4</entry>
              <entry>3636 9d6d</entry>
              <entry>2.721174723774e-06</entry>
              <entry>&lt; 1/9!</entry>
            </row>
            <row>
              <entry>5</entry>
              <entry>0000 0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/11!</entry>
            </row>
            <row>
              <entry>6</entry>
              <entry>0000 0000</entry>
              <entry>0.0</entry>
              <entry>&lt; 1/13!</entry>
            </row>
            <row>
              <entry>7</entry>
              <entry>0000 0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/15!</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
      <para>Single-precision coefficient table for cos(x) (s2&lt;31&gt; == '1')</para>
      <table class="valuetable">
        <tgroup cols="4">
          <thead>
            <row>
              <entry>Index</entry>
              <entry>Hexadecimal</entry>
              <entry>Decimal</entry>
              <entry>Exact Value</entry>
            </row>
          </thead>
          <tbody>
            <row>
              <entry>0</entry>
              <entry>3f80 0000</entry>
              <entry>1.0</entry>
              <entry>= 1/0!</entry>
            </row>
            <row>
              <entry>1</entry>
              <entry>bf00 0000</entry>
              <entry>-5.000000000000e-01</entry>
              <entry>= -1/2!</entry>
            </row>
            <row>
              <entry>2</entry>
              <entry>3d2a aaa6</entry>
              <entry>4.166664928198e-02</entry>
              <entry>&lt; 1/4!</entry>
            </row>
            <row>
              <entry>3</entry>
              <entry>bab6 0705</entry>
              <entry>-1.388759003021e-03</entry>
              <entry>&gt; -1/6!</entry>
            </row>
            <row>
              <entry>4</entry>
              <entry>37cd 37cc</entry>
              <entry>2.446388680255e-05</entry>
              <entry>&lt; 1/8!</entry>
            </row>
            <row>
              <entry>5</entry>
              <entry>0000 0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/10!</entry>
            </row>
            <row>
              <entry>6</entry>
              <entry>0000 0000</entry>
              <entry>0.0</entry>
              <entry>&lt; 1/12!</entry>
            </row>
            <row>
              <entry>7</entry>
              <entry>0000 0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/14!</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
      <para>Half-precision coefficient table for sin(x) (s2&lt;15&gt; == '0')</para>
      <table class="valuetable">
        <tgroup cols="4">
          <thead>
            <row>
              <entry>Index</entry>
              <entry>Hexadecimal</entry>
              <entry>Decimal</entry>
              <entry>Exact Value</entry>
            </row>
          </thead>
          <tbody>
            <row>
              <entry>0</entry>
              <entry>3c00</entry>
              <entry>1.0</entry>
              <entry>= 1/1!</entry>
            </row>
            <row>
              <entry>1</entry>
              <entry>b155</entry>
              <entry>-1.666666716337e-01</entry>
              <entry>&gt; -1/3!</entry>
            </row>
            <row>
              <entry>2</entry>
              <entry>2030</entry>
              <entry>8.333330973983e-03</entry>
              <entry>&lt; 1/5!</entry>
            </row>
            <row>
              <entry>3</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/7!</entry>
            </row>
            <row>
              <entry>4</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&lt; 1/9!</entry>
            </row>
            <row>
              <entry>5</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/11!</entry>
            </row>
            <row>
              <entry>6</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&lt; 1/13!</entry>
            </row>
            <row>
              <entry>7</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/15!</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
      <para>Half-precision coefficient table for cos(x) (s2&lt;15&gt; == '1')</para>
      <table class="valuetable">
        <tgroup cols="4">
          <thead>
            <row>
              <entry>Index</entry>
              <entry>Hexadecimal</entry>
              <entry>Decimal</entry>
              <entry>Exact Value</entry>
            </row>
          </thead>
          <tbody>
            <row>
              <entry>0</entry>
              <entry>3c00</entry>
              <entry>1.0</entry>
              <entry>= 1/0!</entry>
            </row>
            <row>
              <entry>1</entry>
              <entry>b800</entry>
              <entry>-5.000000000000e-01</entry>
              <entry>= -1/2!</entry>
            </row>
            <row>
              <entry>2</entry>
              <entry>293a</entry>
              <entry>4.166664928198e-02</entry>
              <entry>&lt; 1/4!</entry>
            </row>
            <row>
              <entry>3</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/6!</entry>
            </row>
            <row>
              <entry>4</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&lt; 1/8!</entry>
            </row>
            <row>
              <entry>5</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/10!</entry>
            </row>
            <row>
              <entry>6</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&lt; 1/12!</entry>
            </row>
            <row>
              <entry>7</entry>
              <entry>0000</entry>
              <entry>0.0</entry>
              <entry>&gt; -1/14!</entry>
            </row>
          </tbody>
        </tgroup>
      </table>
      <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>
    <takes_movprfx>True</takes_movprfx>
    <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="FTMAD" />
      </docvars>
      <iclassintro count="1"></iclassintro>
      <regdiagram form="32" psname="FTMAD-Z.ZZI-_">
        <box hibit="31" width="8" settings="8">
          <c>0</c>
          <c>1</c>
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>1</c>
          <c>0</c>
          <c>1</c>
        </box>
        <box hibit="23" width="2" name="size" usename="1">
          <c colspan="2"></c>
        </box>
        <box hibit="21" width="3" settings="3">
          <c>0</c>
          <c>1</c>
          <c>0</c>
        </box>
        <box hibit="18" width="3" name="imm3" usename="1">
          <c colspan="3"></c>
        </box>
        <box hibit="15" width="6" settings="6">
          <c>1</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
          <c>0</c>
        </box>
        <box hibit="9" width="5" name="Zm" usename="1">
          <c colspan="5"></c>
        </box>
        <box hibit="4" width="5" name="Zdn" usename="1">
          <c colspan="5"></c>
        </box>
      </regdiagram>
      <encoding name="ftmad_z_zzi_" oneofinclass="1" oneof="1" label="">
        <docvars>
          <docvar key="instr-class" value="sve" />
          <docvar key="isa" value="A64" />
          <docvar key="mnemonic" value="FTMAD" />
        </docvars>
        <asmtemplate><text>FTMAD   </text><a link="sa_zdn" hover="First source and destination scalable vector register (field &quot;Zdn&quot;)">&lt;Zdn&gt;</a><text>.</text><a link="sa_t" hover="Size specifier (field &quot;size&quot;) [D,H,S]">&lt;T&gt;</a><text>, </text><a link="sa_zdn" hover="First source and destination scalable vector register (field &quot;Zdn&quot;)">&lt;Zdn&gt;</a><text>.</text><a link="sa_t" hover="Size specifier (field &quot;size&quot;) [D,H,S]">&lt;T&gt;</a><text>, </text><a link="sa_zm" hover="Second source scalable vector register (field &quot;Zm&quot;)">&lt;Zm&gt;</a><text>.</text><a link="sa_t" hover="Size specifier (field &quot;size&quot;) [D,H,S]">&lt;T&gt;</a><text>, #</text><a link="sa_imm" hover="Unsigned immediate operand [0-7] (field &quot;imm3&quot;)">&lt;imm&gt;</a></asmtemplate>
      </encoding>
      <ps_section howmany="1">
        <ps name="FTMAD-Z.ZZI-_" mylink="FTMAD-Z.ZZI-_" 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;
if size == '00' then UNDEFINED;
constant integer esize = 8 &lt;&lt; <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(size);
integer dn = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Zdn);
integer m = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(Zm);
integer imm = <a link="impl-shared.UInt.1" file="shared_pseudocode.xml" hover="function: integer UInt(bits(N) x)">UInt</a>(imm3);</pstext>
        </ps>
      </ps_section>
    </iclass>
  </classes>
  <explanations scope="all">
    <explanation enclist="ftmad_z_zzi_" symboldefcount="1">
      <symbol link="sa_zdn">&lt;Zdn&gt;</symbol>
      <account encodedin="Zdn">
        <intro>
          <para>Is the name of the first source and destination scalable vector register, encoded in the "Zdn" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="ftmad_z_zzi_" symboldefcount="1">
      <symbol link="sa_t">&lt;T&gt;</symbol>
      <definition encodedin="size">
        <intro>Is the size specifier, </intro>
        <table class="valuetable">
          <tgroup cols="2">
            <thead>
              <row>
                <entry class="bitfield">size</entry>
                <entry class="symbol">&lt;T&gt;</entry>
              </row>
            </thead>
            <tbody>
              <row>
                <entry class="bitfield">00</entry>
                <entry class="symbol">RESERVED</entry>
              </row>
              <row>
                <entry class="bitfield">01</entry>
                <entry class="symbol">H</entry>
              </row>
              <row>
                <entry class="bitfield">10</entry>
                <entry class="symbol">S</entry>
              </row>
              <row>
                <entry class="bitfield">11</entry>
                <entry class="symbol">D</entry>
              </row>
            </tbody>
          </tgroup>
        </table>
      </definition>
    </explanation>
    <explanation enclist="ftmad_z_zzi_" symboldefcount="1">
      <symbol link="sa_zm">&lt;Zm&gt;</symbol>
      <account encodedin="Zm">
        <intro>
          <para>Is the name of the second source scalable vector register, encoded in the "Zm" field.</para>
        </intro>
      </account>
    </explanation>
    <explanation enclist="ftmad_z_zzi_" symboldefcount="1">
      <symbol link="sa_imm">&lt;imm&gt;</symbol>
      <account encodedin="imm3">
        <intro>
          <para>Is the unsigned immediate operand, in the range 0 to 7, encoded in the "imm3" field.</para>
        </intro>
      </account>
    </explanation>
  </explanations>
  <ps_section howmany="1">
    <ps name="FTMAD-Z.ZZI-_" 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;
constant integer elements = VL DIV esize;
bits(VL) operand1 = <a link="impl-aarch64.Z.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) Z[integer n, integer width]">Z</a>[dn, VL];
bits(VL) operand2 = <a link="impl-aarch64.Z.read.2" file="shared_pseudocode.xml" hover="accessor: bits(width) Z[integer n, integer width]">Z</a>[m, VL];
bits(VL) result;

for e = 0 to elements-1
    bits(esize) element1 = <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>[operand1, e, esize];
    bits(esize) element2 = <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>[operand2, e, esize];
    <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, esize] = <a link="impl-aarch64.FPTrigMAdd.4" file="shared_pseudocode.xml" hover="function: bits(N) FPTrigMAdd(integer x_in, bits(N) op1, bits(N) op2_in, FPCRType fpcr)">FPTrigMAdd</a>(imm, element1, element2, FPCR[]);

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