xref: /aosp_15_r20/external/llvm-libc/src/__support/FPUtil/FMA.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
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/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
17 
18 namespace LIBC_NAMESPACE_DECL {
19 namespace fputil {
20 
21 template <typename OutType, typename InType>
fma(InType x,InType y,InType z)22 LIBC_INLINE OutType fma(InType x, InType y, InType z) {
23   return generic::fma<OutType>(x, y, z);
24 }
25 
26 #ifdef LIBC_TARGET_CPU_HAS_FMA
fma(float x,float y,float z)27 template <> LIBC_INLINE float fma(float x, float y, float z) {
28   return __builtin_fmaf(x, y, z);
29 }
30 
fma(double x,double y,double z)31 template <> LIBC_INLINE double fma(double x, double y, double z) {
32   return __builtin_fma(x, y, z);
33 }
34 #endif // LIBC_TARGET_CPU_HAS_FMA
35 
36 } // namespace fputil
37 } // namespace LIBC_NAMESPACE_DECL
38 
39 #endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
40