[libc][math] Refactor fma implementation to header-only in src/__support/math folder. (#163968)
Part of #147386 in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
This commit is contained in:
parent
3d0e7e04c8
commit
d0d1f0b7af
@ -137,6 +137,7 @@
|
||||
#include "math/floorf128.h"
|
||||
#include "math/floorf16.h"
|
||||
#include "math/floorl.h"
|
||||
#include "math/fma.h"
|
||||
#include "math/fmabf16.h"
|
||||
#include "math/fmax.h"
|
||||
#include "math/fmaxbf16.h"
|
||||
|
||||
23
libc/shared/math/fma.h
Normal file
23
libc/shared/math/fma.h
Normal file
@ -0,0 +1,23 @@
|
||||
//===-- Shared fma function -------------------------------------*- 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_SHARED_MATH_FMA_H
|
||||
#define LLVM_LIBC_SHARED_MATH_FMA_H
|
||||
|
||||
#include "shared/libc_common.h"
|
||||
#include "src/__support/math/fma.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
namespace shared {
|
||||
|
||||
using math::fma;
|
||||
|
||||
} // namespace shared
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SHARED_MATH_FMA_H
|
||||
@ -1320,6 +1320,15 @@ add_header_library(
|
||||
libc.src.__support.macros.properties.types
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
fma
|
||||
HDRS
|
||||
fma.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.fma
|
||||
libc.src.__support.macros.config
|
||||
)
|
||||
|
||||
add_header_library(
|
||||
ffma
|
||||
HDRS
|
||||
|
||||
27
libc/src/__support/math/fma.h
Normal file
27
libc/src/__support/math/fma.h
Normal file
@ -0,0 +1,27 @@
|
||||
//===-- Implementation header for fma ---------------------------*- 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_MATH_FMA_H
|
||||
#define LLVM_LIBC_SRC___SUPPORT_MATH_FMA_H
|
||||
|
||||
#include "src/__support/FPUtil/FMA.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
namespace math {
|
||||
|
||||
LIBC_INLINE double fma(double x, double y, double z) {
|
||||
return fputil::fma<double>(x, y, z);
|
||||
}
|
||||
|
||||
} // namespace math
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
#endif // LLVM_LIBC_SRC___SUPPORT_MATH_FMA_H
|
||||
@ -4399,7 +4399,7 @@ add_entrypoint_object(
|
||||
HDRS
|
||||
../fma.h
|
||||
DEPENDS
|
||||
libc.src.__support.FPUtil.fma
|
||||
libc.src.__support.math.fma
|
||||
)
|
||||
|
||||
add_entrypoint_object(
|
||||
|
||||
@ -7,15 +7,12 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "src/math/fma.h"
|
||||
#include "src/__support/common.h"
|
||||
|
||||
#include "src/__support/FPUtil/FMA.h"
|
||||
#include "src/__support/macros/config.h"
|
||||
#include "src/__support/math/fma.h"
|
||||
|
||||
namespace LIBC_NAMESPACE_DECL {
|
||||
|
||||
LLVM_LIBC_FUNCTION(double, fma, (double x, double y, double z)) {
|
||||
return fputil::fma<double>(x, y, z);
|
||||
return math::fma(x, y, z);
|
||||
}
|
||||
|
||||
} // namespace LIBC_NAMESPACE_DECL
|
||||
|
||||
@ -134,6 +134,7 @@ add_fp_unittest(
|
||||
libc.src.__support.math.floorf128
|
||||
libc.src.__support.math.floorf16
|
||||
libc.src.__support.math.floorl
|
||||
libc.src.__support.math.fma
|
||||
libc.src.__support.math.fmabf16
|
||||
libc.src.__support.math.fmax
|
||||
libc.src.__support.math.fmaxbf16
|
||||
|
||||
@ -247,6 +247,7 @@ TEST(LlvmLibcSharedMathTest, AllDouble) {
|
||||
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp2(0.0));
|
||||
EXPECT_FP_EQ(0x1p+0, LIBC_NAMESPACE::shared::exp10(0.0));
|
||||
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::expm1(0.0));
|
||||
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::fma(0.0, 0.0, 0.0));
|
||||
EXPECT_FP_EQ(0x0p+0f, LIBC_NAMESPACE::shared::ffma(0.0, 0.0, 0.0));
|
||||
EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::hypot(0.0, 0.0));
|
||||
EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::fsqrt(0.0));
|
||||
|
||||
@ -4311,6 +4311,14 @@ libc_support_library(
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_fma",
|
||||
hdrs = ["src/__support/math/fma.h"],
|
||||
deps = [
|
||||
":__support_fputil_fma",
|
||||
],
|
||||
)
|
||||
|
||||
libc_support_library(
|
||||
name = "__support_math_frexpf128",
|
||||
hdrs = ["src/__support/math/frexpf128.h"],
|
||||
@ -7090,7 +7098,7 @@ libc_math_function(
|
||||
libc_math_function(
|
||||
name = "fmaf16",
|
||||
additional_deps = [
|
||||
":__support_fputil_fma",
|
||||
":__support_math_fma",
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user