53 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H10#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H11 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_FMA17 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_FMA27 28#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT29template <> 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#else33 return __builtin_fmaf(x, y, z);34#endif35}36#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT37 38#ifdef LIBC_TARGET_CPU_HAS_FMA_DOUBLE39template <> 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#else43 return __builtin_fma(x, y, z);44#endif45}46#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE47#endif // LIBC_TARGET_CPU_HAS_FMA48 49} // namespace fputil50} // namespace LIBC_NAMESPACE_DECL51 52#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H53