Warning: This file is not a C or C++ file. It does not have highlighting.

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
18namespace LIBC_NAMESPACE_DECL {
19namespace fputil {
20
21template <typename OutType, typename InType>
22LIBC_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
27
28#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT
29template <> LIBC_INLINE float fma(float x, float y, float z) {
30#if __has_builtin(__builtin_elementwise_fma)
31 return __builtin_elementwise_fma(x, y, z);
32#else
33 return __builtin_fmaf(x, y, z);
34#endif
35}
36#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT
37
38#ifdef LIBC_TARGET_CPU_HAS_FMA_DOUBLE
39template <> LIBC_INLINE double fma(double x, double y, double z) {
40#if __has_builtin(__builtin_elementwise_fma)
41 return __builtin_elementwise_fma(x, y, z);
42#else
43 return __builtin_fma(x, y, z);
44#endif
45}
46#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE
47#endif // LIBC_TARGET_CPU_HAS_FMA
48
49} // namespace fputil
50} // namespace LIBC_NAMESPACE_DECL
51
52#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H
53

Warning: This file is not a C or C++ file. It does not have highlighting.

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of libc/src/__support/FPUtil/FMA.h