diff --git a/libc/src/__support/FPUtil/FMA.h b/libc/src/__support/FPUtil/FMA.h index 0e1ede02d5cc0..c277da49538bf 100644 --- a/libc/src/__support/FPUtil/FMA.h +++ b/libc/src/__support/FPUtil/FMA.h @@ -9,25 +9,31 @@ #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H +#include "src/__support/CPP/type_traits.h" #include "src/__support/macros/properties/architectures.h" #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA #if defined(LIBC_TARGET_CPU_HAS_FMA) -#if defined(LIBC_TARGET_ARCH_IS_X86_64) -#include "x86_64/FMA.h" -#elif defined(LIBC_TARGET_ARCH_IS_AARCH64) -#include "aarch64/FMA.h" -#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) -#include "riscv/FMA.h" -#elif defined(LIBC_TARGET_ARCH_IS_GPU) -#include "gpu/FMA.h" -#endif +namespace LIBC_NAMESPACE { +namespace fputil { + +template +LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { + return __builtin_fmaf(x, y, z); +} + +template +LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { + return __builtin_fma(x, y, z); +} + +} // namespace fputil +} // namespace LIBC_NAMESPACE #else // FMA instructions are not available #include "generic/FMA.h" -#include "src/__support/CPP/type_traits.h" namespace LIBC_NAMESPACE { namespace fputil { diff --git a/libc/src/__support/FPUtil/aarch64/FMA.h b/libc/src/__support/FPUtil/aarch64/FMA.h deleted file mode 100644 index 6254a0673ff42..0000000000000 --- a/libc/src/__support/FPUtil/aarch64/FMA.h +++ /dev/null @@ -1,50 +0,0 @@ -//===-- Aarch64 implementations of the fma function -------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_AARCH64_FMA_H -#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_AARCH64_FMA_H - -#include "src/__support/macros/attributes.h" // LIBC_INLINE -#include "src/__support/macros/properties/architectures.h" -#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA - -#if !defined(LIBC_TARGET_ARCH_IS_AARCH64) -#error "Invalid include" -#endif - -#if !defined(LIBC_TARGET_CPU_HAS_FMA) -#error "FMA instructions are not supported" -#endif - -#include "src/__support/CPP/type_traits.h" - -namespace LIBC_NAMESPACE { -namespace fputil { - -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - float result; - LIBC_INLINE_ASM("fmadd %s0, %s1, %s2, %s3\n\t" - : "=w"(result) - : "w"(x), "w"(y), "w"(z)); - return result; -} - -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - double result; - LIBC_INLINE_ASM("fmadd %d0, %d1, %d2, %d3\n\t" - : "=w"(result) - : "w"(x), "w"(y), "w"(z)); - return result; -} - -} // namespace fputil -} // namespace LIBC_NAMESPACE - -#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_AARCH64_FMA_H diff --git a/libc/src/__support/FPUtil/gpu/FMA.h b/libc/src/__support/FPUtil/gpu/FMA.h deleted file mode 100644 index ef1cd26a72dd7..0000000000000 --- a/libc/src/__support/FPUtil/gpu/FMA.h +++ /dev/null @@ -1,36 +0,0 @@ -//===-- GPU implementations of the fma function -----------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_GPU_FMA_H -#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_GPU_FMA_H - -#include "src/__support/CPP/type_traits.h" - -// These intrinsics map to the FMA instructions in the target ISA for the GPU. -// The default rounding mode generated from these will be to the nearest even. -#if !__has_builtin(__builtin_fma) || !__has_builtin(__builtin_fmaf) -#error "FMA builtins must be defined"); -#endif - -namespace LIBC_NAMESPACE { -namespace fputil { - -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - return __builtin_fmaf(x, y, z); -} - -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - return __builtin_fma(x, y, z); -} - -} // namespace fputil -} // namespace LIBC_NAMESPACE - -#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_GPU_FMA_H diff --git a/libc/src/__support/FPUtil/riscv/FMA.h b/libc/src/__support/FPUtil/riscv/FMA.h deleted file mode 100644 index f01962174f16f..0000000000000 --- a/libc/src/__support/FPUtil/riscv/FMA.h +++ /dev/null @@ -1,54 +0,0 @@ -//===-- RISCV implementations of the fma function ---------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FMA_H -#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FMA_H - -#include "src/__support/macros/attributes.h" // LIBC_INLINE -#include "src/__support/macros/properties/architectures.h" -#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA - -#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) -#error "Invalid include" -#endif - -#if !defined(LIBC_TARGET_CPU_HAS_FMA) -#error "FMA instructions are not supported" -#endif - -#include "src/__support/CPP/type_traits.h" - -namespace LIBC_NAMESPACE { -namespace fputil { - -#ifdef __riscv_flen -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - float result; - LIBC_INLINE_ASM("fmadd.s %0, %1, %2, %3\n\t" - : "=f"(result) - : "f"(x), "f"(y), "f"(z)); - return result; -} - -#if __riscv_flen >= 64 -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - double result; - LIBC_INLINE_ASM("fmadd.d %0, %1, %2, %3\n\t" - : "=f"(result) - : "f"(x), "f"(y), "f"(z)); - return result; -} -#endif // __riscv_flen >= 64 -#endif // __riscv_flen - -} // namespace fputil -} // namespace LIBC_NAMESPACE - -#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FMA_H diff --git a/libc/src/__support/FPUtil/x86_64/FMA.h b/libc/src/__support/FPUtil/x86_64/FMA.h deleted file mode 100644 index 91ef7f96ff4d3..0000000000000 --- a/libc/src/__support/FPUtil/x86_64/FMA.h +++ /dev/null @@ -1,55 +0,0 @@ -//===-- x86_64 implementations of the fma function --------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_FMA_H -#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_FMA_H - -#include "src/__support/macros/attributes.h" // LIBC_INLINE -#include "src/__support/macros/properties/architectures.h" -#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA - -#if !defined(LIBC_TARGET_ARCH_IS_X86_64) -#error "Invalid include" -#endif - -#if !defined(LIBC_TARGET_CPU_HAS_FMA) -#error "FMA instructions are not supported" -#endif - -#include "src/__support/CPP/type_traits.h" -#include - -namespace LIBC_NAMESPACE { -namespace fputil { - -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - float result; - __m128 xmm = _mm_load_ss(&x); // NOLINT - __m128 ymm = _mm_load_ss(&y); // NOLINT - __m128 zmm = _mm_load_ss(&z); // NOLINT - __m128 r = _mm_fmadd_ss(xmm, ymm, zmm); // NOLINT - _mm_store_ss(&result, r); // NOLINT - return result; -} - -template -LIBC_INLINE cpp::enable_if_t, T> fma(T x, T y, T z) { - double result; - __m128d xmm = _mm_load_sd(&x); // NOLINT - __m128d ymm = _mm_load_sd(&y); // NOLINT - __m128d zmm = _mm_load_sd(&z); // NOLINT - __m128d r = _mm_fmadd_sd(xmm, ymm, zmm); // NOLINT - _mm_store_sd(&result, r); // NOLINT - return result; -} - -} // namespace fputil -} // namespace LIBC_NAMESPACE - -#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_X86_64_FMA_H diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 055630cb6a005..6255ac998db10 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -913,17 +913,9 @@ fma_common_hdrs = [ "src/__support/FPUtil/generic/FMA.h", ] -fma_platform_hdrs = [ - "src/__support/FPUtil/x86_64/FMA.h", - "src/__support/FPUtil/aarch64/FMA.h", -] - libc_support_library( name = "__support_fputil_fma", hdrs = fma_common_hdrs, - # These are conditionally included and will #error out if the platform - # doesn't support FMA, so they can't be compiled on their own. - textual_hdrs = fma_platform_hdrs, deps = [ ":__support_cpp_bit", ":__support_cpp_type_traits",