Path: blob/main/contrib/llvm-project/libc/src/__support/FPUtil/FMA.h
213799 views
//===-- Common header for FMA implementations -------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H9#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H1011#include "src/__support/CPP/type_traits.h"12#include "src/__support/FPUtil/generic/FMA.h"13#include "src/__support/macros/config.h"14#include "src/__support/macros/properties/architectures.h"15#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA1617namespace LIBC_NAMESPACE_DECL {18namespace fputil {1920template <typename OutType, typename InType>21LIBC_INLINE OutType fma(InType x, InType y, InType z) {22return generic::fma<OutType>(x, y, z);23}2425#ifdef LIBC_TARGET_CPU_HAS_FMA2627#ifdef LIBC_TARGET_CPU_HAS_FMA_FLOAT28template <> LIBC_INLINE float fma(float x, float y, float z) {29#if __has_builtin(__builtin_elementwise_fma)30return __builtin_elementwise_fma(x, y, z);31#else32return __builtin_fmaf(x, y, z);33#endif34}35#endif // LIBC_TARGET_CPU_HAS_FMA_FLOAT3637#ifdef LIBC_TARGET_CPU_HAS_FMA_DOUBLE38template <> LIBC_INLINE double fma(double x, double y, double z) {39#if __has_builtin(__builtin_elementwise_fma)40return __builtin_elementwise_fma(x, y, z);41#else42return __builtin_fma(x, y, z);43#endif44}45#endif // LIBC_TARGET_CPU_HAS_FMA_DOUBLE46#endif // LIBC_TARGET_CPU_HAS_FMA4748} // namespace fputil49} // namespace LIBC_NAMESPACE_DECL5051#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_FMA_H525354