This is an archive of the discontinued LLVM Phabricator instance.

[libc] Add support for x86-64 targets that do not have FMA instructions.
ClosedPublic

Authored by lntue on Apr 7 2022, 1:05 PM.

Details

Summary

Make FMA flag checks more accurate for x86-64 targets, and refactor
polyeval to use multiply and add instead when FMA instructions are not
available.

Diff Detail

Event Timeline

lntue created this revision.Apr 7 2022, 1:05 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 7 2022, 1:05 PM
lntue requested review of this revision.Apr 7 2022, 1:05 PM
lntue updated this revision to Diff 421340.Apr 7 2022, 2:32 PM

Fix missing endif directive and bazel BUILD file.

LGTM as is, I looked into if this patch allowed for reverting this one: https://reviews.llvm.org/D122689 and added my results as a comment.

libc/src/math/generic/CMakeLists.txt
517

On windows, removing the -mfma options in this cmake file with this patch doesn't break any of the tests except for this one. The expm1f tests fail with a ULP error, copied below.

[ RUN      ] LlvmLibcExpm1fTest.InFloatRange
C:/src/llvm-project/libc/test/src/math/expm1f_test.cpp:119: FAILURE
Failed to match __llvm_libc::expm1f(x) against __llvm_libc::testing::mpfr::get_mpfr_matcher<mpfr::Operation::Expm1>( x, __llvm_libc::expm1f(x), 0.5, mpfr::RoundingMode::TowardZero).
Match value not within tolerance value of MPFR result:
  Input decimal: -0.00000000000000000000000000000000000001175976677754
     Input bits: 0x80800d72, (S | E | M) = (1 | 0x01 | 0x000d72)

  Match decimal: -0.00000000000000000000000000000000000001175976677754
     Match bits: 0x80800d72, (S | E | M) = (1 | 0x01 | 0x000d72)

    MPFR result: -0.00000000000000000000000000000000000001175976537624
   MPFR rounded: 0x80800d71, (S | E | M) = (1 | 0x01 | 0x000d71)

      ULP error: 1.000000
[  FAILED  ] LlvmLibcExpm1fTest.InFloatRange
Ran 5 tests.  PASS: 4  FAIL: 1
lntue added inline comments.Apr 7 2022, 7:19 PM
libc/src/math/generic/CMakeLists.txt
517

This is expected. There will be followup changes to take care of different exceptional values from math functions when FMA instructions are not supported.

sivachandra accepted this revision.Apr 8 2022, 9:45 AM
sivachandra added inline comments.
libc/src/__support/architectures.h
41

Nit: a more indicative name is probably LIBC_TARGET_HAS_FMA? Drop the LLVM_ prefix also.

This revision is now accepted and ready to land.Apr 8 2022, 9:45 AM
lntue updated this revision to Diff 421584.Apr 8 2022, 10:35 AM

Change the macro name to LIBC_TARGET_HAS_FMA.

lntue marked an inline comment as done.Apr 8 2022, 10:36 AM
michaelrj accepted this revision.Apr 8 2022, 10:37 AM