aboutsummaryrefslogtreecommitdiff
path: root/libc/src/__support/FPUtil/FMA.h
blob: eb95bf0f2ee108f0783d1db18c4cf3892c7c4b88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//===-- Common header for FMA implementations -------------------*- 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_FMA_H
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_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_RISCV64)
#include "riscv64/FMA.h"
#elif defined(LIBC_TARGET_ARCH_IS_GPU)
#include "gpu/FMA.h"
#endif

#else
// FMA instructions are not available
#include "generic/FMA.h"
#include "src/__support/CPP/type_traits.h"

namespace __llvm_libc {
namespace fputil {

template <typename T> LIBC_INLINE T fma(T x, T y, T z) {
  return generic::fma(x, y, z);
}

} // namespace fputil
} // namespace __llvm_libc

#endif

#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H