<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Clang wrongly defines __ARM_FEATURE_FMA, then generates slow emulation code"
   href="https://llvm.org/bugs/show_bug.cgi?id=27216">27216</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang wrongly defines __ARM_FEATURE_FMA, then generates slow emulation code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.8
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jacob.benoit.1@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=16169" name="attach_16169" title="testcase">attachment 16169</a> <a href="attachment.cgi?id=16169&action=edit" title="testcase">[details]</a></span>
testcase

*** Steps to reproduce ***

With Clang 3.8; here I'm using the toolchain in the Android N repo.

prebuilts/clang/host/linux-x86/clang-2690385/bin/clang++ -target
arm-linux-androideabi ~/vrac/arm_feature_fma_testcase.cc -c -march=armv7-a
-mfloat-abi=softfp -mfpu=neon

The 'testcase' is just checking if __ARM_FEATURE_FMA is defined. It shouldn't
be, unless we pass -mfpu=neon-vfpv4.

*** More context ***

The __ARM_FEATURE_FMA preprocessor token is supposed to be defined only when
hardware FMA instructions are defined, see
<a href="http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053b/IHI0053B_arm_c_language_extensions_2013.pdf">http://infocenter.arm.com/help/topic/com.arm.doc.ihi0053b/IHI0053B_arm_c_language_extensions_2013.pdf</a>
section 6.5.5:
"If __ARM_FEATURE_FMA and __ARM_NEON_FP are both defined, fused-multiply
instructions are available in NEON also."

These instructions are available only if VFPv4 is enabled. Thus, the expected
result should be:

-mfpu=neon        ---> __ARM_FEATURE_FMA is not defined
-mfpu=neon-vfpv4  ---> __ARM_FEATURE_FMA is defined

High-performance numerical code needs to know whether hardware FMA instructions
are available, because when they are available, they are generally faster
(thanks to not having to do the intermediate rounding).

For example, the Eigen matrix library relies on this to get faster FMA
instructions when available:
<a href="https://bitbucket.org/eigen/eigen/src/78884e16715fc9a7b726db39195ac8bb17103181/Eigen/src/Core/arch/NEON/PacketMath.h?at=default&fileviewer=file-view-default#PacketMath.h-180">https://bitbucket.org/eigen/eigen/src/78884e16715fc9a7b726db39195ac8bb17103181/Eigen/src/Core/arch/NEON/PacketMath.h?at=default&fileviewer=file-view-default#PacketMath.h-180</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>