1 //===-- Common header for FMA implementations -------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
10 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
11
12 #include "src/__support/CPP/type_traits.h"
13 #include "src/__support/macros/properties/architectures.h"
14 #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
15
16 #if defined(LIBC_TARGET_CPU_HAS_FMA)
17
18 namespace LIBC_NAMESPACE {
19 namespace fputil {
20
21 template <typename T>
fma(T x,T y,T z)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>
fma(T x,T y,T z)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
33
34 #else
35 // FMA instructions are not available
36 #include "generic/FMA.h"
37
38 namespace LIBC_NAMESPACE {
39 namespace fputil {
40
fma(T x,T y,T z)41 template <typename T> LIBC_INLINE T fma(T x, T y, T z) {
42 return generic::fma(x, y, z);
43 }
44
45 } // namespace fputil
46 } // namespace LIBC_NAMESPACE
47
48 #endif
49
50 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
51