1 //===-- Common header for FMA implementations -------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
10 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
12 #include "src/__support/CPP/type_traits.h"
13 #include "src/__support/FPUtil/generic/FMA.h"
14 #include "src/__support/macros/config.h"
15 #include "src/__support/macros/properties/architectures.h"
16 #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
18 namespace LIBC_NAMESPACE_DECL
{
21 template <typename OutType
, typename InType
>
22 LIBC_INLINE OutType
fma(InType x
, InType y
, InType z
) {
23 return generic::fma
<OutType
>(x
, y
, z
);
26 #ifdef LIBC_TARGET_CPU_HAS_FMA
27 template <> LIBC_INLINE
float fma(float x
, float y
, float z
) {
28 return __builtin_fmaf(x
, y
, z
);
31 template <> LIBC_INLINE
double fma(double x
, double y
, double z
) {
32 return __builtin_fma(x
, y
, z
);
34 #endif // LIBC_TARGET_CPU_HAS_FMA
37 } // namespace LIBC_NAMESPACE_DECL
39 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H