1 //===-- Common header for multiply-add 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_MULTIPLY_ADD_H
10 #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H
12 #include "src/__support/common.h"
13 #include "src/__support/macros/properties/architectures.h"
14 #include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
16 namespace __llvm_libc
{
19 // Implement a simple wrapper for multiply-add operation:
20 // multiply_add(x, y, z) = x*y + z
21 // which uses FMA instructions to speed up if available.
23 template <typename T
> LIBC_INLINE T
multiply_add(T x
, T y
, T z
) {
28 } // namespace __llvm_libc
30 #if defined(LIBC_TARGET_CPU_HAS_FMA)
32 // FMA instructions are available.
35 namespace __llvm_libc
{
38 template <> LIBC_INLINE
float multiply_add
<float>(float x
, float y
, float z
) {
43 LIBC_INLINE
double multiply_add
<double>(double x
, double y
, double z
) {
48 } // namespace __llvm_libc
50 #endif // LIBC_TARGET_CPU_HAS_FMA
52 #endif // LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H