diff --git a/libc/shared/math.h b/libc/shared/math.h index 7fb4c43f509c4..c06802dbb576e 100644 --- a/libc/shared/math.h +++ b/libc/shared/math.h @@ -39,6 +39,7 @@ #include "math/coshf16.h" #include "math/cospif.h" #include "math/cospif16.h" +#include "math/dfmal.h" #include "math/dsqrtl.h" #include "math/erff.h" #include "math/exp.h" diff --git a/libc/shared/math/dfmal.h b/libc/shared/math/dfmal.h new file mode 100644 index 0000000000000..05d83caad3926 --- /dev/null +++ b/libc/shared/math/dfmal.h @@ -0,0 +1,24 @@ +//===-- Shared dfmal 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_DFMAL_H +#define LLVM_LIBC_SHARED_MATH_DFMAL_H + +#include "shared/libc_common.h" + +#include "src/__support/math/dfmal.h" + +namespace LIBC_NAMESPACE_DECL { +namespace shared { + +using math::dfmal; + +} // namespace shared +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SHARED_MATH_DFMAL_H diff --git a/libc/src/__support/math/CMakeLists.txt b/libc/src/__support/math/CMakeLists.txt index 741da7432c94f..9f3e749615c1d 100644 --- a/libc/src/__support/math/CMakeLists.txt +++ b/libc/src/__support/math/CMakeLists.txt @@ -1040,3 +1040,13 @@ add_header_library( libc.src.__support.math.sincos_eval libc.src.__support.macros.optimization ) + +add_header_library( + dfmal + HDRS + dfmal.h + DEPENDS + libc.src.__support.FPUtil.fma + libc.src.__support.common + libc.src.__support.macros.config +) diff --git a/libc/src/__support/math/dfmal.h b/libc/src/__support/math/dfmal.h new file mode 100644 index 0000000000000..ffe94bc4abcc6 --- /dev/null +++ b/libc/src/__support/math/dfmal.h @@ -0,0 +1,26 @@ +//===-- Implementation header for dfmal -----------------------------------===// +// +// 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_DFMAL_H +#define LLVM_LIBC_SRC___SUPPORT_MATH_DFMAL_H + +#include "src/__support/FPUtil/FMA.h" +#include "src/__support/common.h" +#include "src/__support/macros/config.h" + +namespace LIBC_NAMESPACE_DECL { +namespace math { + +LIBC_INLINE static double dfmal(long double x, long double y, long double z) { + return fputil::fma(x, y, z); +} + +} // namespace math +} // namespace LIBC_NAMESPACE_DECL + +#endif // LLVM_LIBC_SRC___SUPPORT_MATH_DFMAL_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt index 9c0da076b6cf0..02362ad10b2b9 100644 --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -260,7 +260,7 @@ add_entrypoint_object( HDRS ../dfmal.h DEPENDS - libc.src.__support.FPUtil.fma + libc.src.__support.math.dfmal ) add_entrypoint_object( diff --git a/libc/src/math/generic/dfmal.cpp b/libc/src/math/generic/dfmal.cpp index 02e0ce84ace83..a50d837458476 100644 --- a/libc/src/math/generic/dfmal.cpp +++ b/libc/src/math/generic/dfmal.cpp @@ -7,15 +7,13 @@ //===----------------------------------------------------------------------===// #include "src/math/dfmal.h" -#include "src/__support/FPUtil/FMA.h" -#include "src/__support/common.h" -#include "src/__support/macros/config.h" +#include "src/__support/math/dfmal.h" namespace LIBC_NAMESPACE_DECL { LLVM_LIBC_FUNCTION(double, dfmal, (long double x, long double y, long double z)) { - return fputil::fma(x, y, z); + return math::dfmal(x, y, z); } } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt index 0f23162798a8b..b62db2064187c 100644 --- a/libc/test/shared/CMakeLists.txt +++ b/libc/test/shared/CMakeLists.txt @@ -35,6 +35,7 @@ add_fp_unittest( libc.src.__support.math.coshf16 libc.src.__support.math.cospif libc.src.__support.math.cospif16 + libc.src.__support.math.dfmal libc.src.__support.math.dsqrtl libc.src.__support.math.exp10m1f libc.src.__support.math.exp10m1f16 diff --git a/libc/test/shared/shared_math_test.cpp b/libc/test/shared/shared_math_test.cpp index f823d414e2afd..79c341e86971f 100644 --- a/libc/test/shared/shared_math_test.cpp +++ b/libc/test/shared/shared_math_test.cpp @@ -92,7 +92,10 @@ TEST(LlvmLibcSharedMathTest, AllDouble) { EXPECT_FP_EQ(0x0p+0, LIBC_NAMESPACE::shared::expm1(0.0)); EXPECT_FP_EQ(0.0, LIBC_NAMESPACE::shared::sin(0.0)); } - +TEST(LlvmLibcSharedMathTest, AllLongDouble) { + EXPECT_FP_EQ(0x0p+0L, + LIBC_NAMESPACE::shared::dfmal(0x0.p+0L, 0x0.p+0L, 0x0.p+0L)); +} #ifdef LIBC_TYPES_HAS_FLOAT128 TEST(LlvmLibcSharedMathTest, AllFloat128) { diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 210c25dddd0b9..e74f98fe9dba7 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -3118,6 +3118,16 @@ libc_support_library( ], ) +libc_support_library( + name = "__support_math_dfmal", + hdrs = ["src/__support/math/dfmal.h"], + deps = [ + ":__support_common", + ":__support_fputil_fma", + ":__support_macros_config", + ], +) + libc_support_library( name = "__support_range_reduction_double", hdrs = [ @@ -3718,7 +3728,7 @@ libc_math_function(name = "ddivf128") libc_math_function( name = "dfmal", additional_deps = [ - ":__support_fputil_fma", + ":__support_math_dfmal", ], )