Skip to content

Commit e1f279e

Browse files
authored
[libc] Use __builtin_fma(f) by default if LIBC_TARGET_CPU_HAS_FMA is defined. (llvm#91535)
1 parent 317e6ff commit e1f279e

File tree

6 files changed

+16
-213
lines changed

6 files changed

+16
-213
lines changed

libc/src/__support/FPUtil/FMA.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
1010
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
1111

12+
#include "src/__support/CPP/type_traits.h"
1213
#include "src/__support/macros/properties/architectures.h"
1314
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
1415

1516
#if defined(LIBC_TARGET_CPU_HAS_FMA)
1617

17-
#if defined(LIBC_TARGET_ARCH_IS_X86_64)
18-
#include "x86_64/FMA.h"
19-
#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
20-
#include "aarch64/FMA.h"
21-
#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
22-
#include "riscv/FMA.h"
23-
#elif defined(LIBC_TARGET_ARCH_IS_GPU)
24-
#include "gpu/FMA.h"
25-
#endif
18+
namespace LIBC_NAMESPACE {
19+
namespace fputil {
20+
21+
template <typename T>
22+
LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, float>, T> fma(T x, T y, T z) {
23+
return __builtin_fmaf(x, y, z);
24+
}
25+
26+
template <typename T>
27+
LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y, T z) {
28+
return __builtin_fma(x, y, z);
29+
}
30+
31+
} // namespace fputil
32+
} // namespace LIBC_NAMESPACE
2633

2734
#else
2835
// FMA instructions are not available
2936
#include "generic/FMA.h"
30-
#include "src/__support/CPP/type_traits.h"
3137

3238
namespace LIBC_NAMESPACE {
3339
namespace fputil {

libc/src/__support/FPUtil/aarch64/FMA.h

Lines changed: 0 additions & 50 deletions
This file was deleted.

libc/src/__support/FPUtil/gpu/FMA.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

libc/src/__support/FPUtil/riscv/FMA.h

Lines changed: 0 additions & 54 deletions
This file was deleted.

libc/src/__support/FPUtil/x86_64/FMA.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -913,17 +913,9 @@ fma_common_hdrs = [
913913
"src/__support/FPUtil/generic/FMA.h",
914914
]
915915

916-
fma_platform_hdrs = [
917-
"src/__support/FPUtil/x86_64/FMA.h",
918-
"src/__support/FPUtil/aarch64/FMA.h",
919-
]
920-
921916
libc_support_library(
922917
name = "__support_fputil_fma",
923918
hdrs = fma_common_hdrs,
924-
# These are conditionally included and will #error out if the platform
925-
# doesn't support FMA, so they can't be compiled on their own.
926-
textual_hdrs = fma_platform_hdrs,
927919
deps = [
928920
":__support_cpp_bit",
929921
":__support_cpp_type_traits",

0 commit comments

Comments
 (0)